JSPM

  • Created
  • Published
  • Downloads 173
  • Score
    100M100P100Q81514F
  • License MIT

Yet another configurable linter for TypeScript and JavaScript.

Package Exports

  • ts-standardx
  • ts-standardx/.eslintrc.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (ts-standardx) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

ts-standardx

Yet another configurable linter for TypeScript and JavaScript.

npm GitHub Workflow Status (branch) Codecov branch libera manifesto

๐Ÿš€ Features

Todo

๐Ÿ’พ Install

npm install --save-dev ts-standardx

๐Ÿค– CLI

$ npx ts-standardx

To enable auto fix and format, use --fix.

$ npx ts-standardx --fix

To lint text from stdin, use - or --stdin.

$ echo "const salute = ( ) => 'hi'" | npx ts-standardx -
output

<text>:1:7: 'salute' is assigned a value but never used.
<text>:1:17: Delete `ยท`

Run `ts-standardx --fix` to automatically fix some problems.


Add --fix to output fixed text.

$ echo "const salute = ( ) => 'hi'" | npx ts-standardx - --fix
output

const salute = () => 'hi'

--help

ts-standardx: Yet another customizable linter for TypeScript and JavaScript. (https://github.com/exuanbo/ts-standardx#readme)

Usage: ts-standardx <flags> [FILES...]

  If FILES is omitted, all source files (*.ts, *.tsx, *.js, *.jsx, *.mjs, *.cjs)
  in the current working directory will be checked recursively.

  By default, files/folders that begin with '.' like .eslintrc .cache/
  and paths in the project's root .gitignore are automatically ignored.

Basic:
  --fix                Automatically fix problems
  --verbose            Show rule names for errors (to ignore specific rules)

Config:
  --env                Use custom eslint environment
  --ext                Specify file extensions
  --global             Declare global variable
  --parser             Use custom parser (e.g. babel-eslint)
  --plugin             Use custom eslint plugin

Input:
  --stdin              Read file text from stdin
  --disable-gitignore  Disable use of .gitignore by default

Misc:
  -h, --help           Show usage information
  -v, --version        Show current version

โŒจ๏ธ API

// index.d.ts

import { ProvidedOptions, Linter, CLI } from 'standard-engine-ts'

declare const opts: ProvidedOptions

declare const linter: Linter
declare const cli: CLI

export { cli, linter, opts }

โš™๏ธ Configuration

ts-standardx uses .eslintrc.* from the current working directory. Note that rules for TypeScript need to be placed in overrides as example below.

// .eslintrc.js

module.exports = {
  overrides: [
    {
      files: ['**/*.ts', '**/*.tsx'],
      rules: {
        '@typescript-eslint/no-explicit-any': 'off'
      }
    }
  ]
}

Editor extension

Add the default config to extends to use the official ESLint extension.

// .eslintrc.js

module.exports = {
  extends: ['./node_modules/ts-standardx/.eslintrc.js']
}
But wait a second...

"So why can't I just use npx eslint . directly?" Yes, you can :p

๐Ÿ”Ž Details

This package includes:

  • @typescript-eslint/eslint-plugin
  • @typescript-eslint/parser
  • eslint
  • eslint-config-prettier
  • eslint-config-standard
  • eslint-config-standard-jsx
  • eslint-plugin-import
  • eslint-plugin-node
  • eslint-plugin-prettier
  • eslint-plugin-promise
  • eslint-plugin-react
  • prettier
  • standard-engine-ts

eslintrc.ts

import { Linter } from 'eslint'
import { compatRules } from './compatRules'
import { rules } from './rules'
import { isModuleAvailable } from './utils'

const PRETTIER_STANDARD = {
  arrowParens: 'avoid',
  bracketSpacing: true,
  jsxBracketSameLine: true,
  semi: false,
  singleQuote: true,
  tabWidth: 2,
  trailingComma: 'none'
}

const eslintrc: Linter.BaseConfig = {
  extends: [
    'standard',
    'standard-jsx',
    'plugin:prettier/recommended',
    'prettier/react',
    'prettier/standard'
  ],
  overrides: isModuleAvailable('typescript')
    ? [
        {
          files: ['**/*.ts', '**/*.tsx'],
          extends: [
            'plugin:@typescript-eslint/recommended',
            'prettier/@typescript-eslint'
          ],
          parser: '@typescript-eslint/parser',
          parserOptions: {
            project: './tsconfig.json'
          },
          rules: {
            ...compatRules,
            ...rules
          }
        }
      ]
    : undefined,
  plugins: ['prettier'],
  rules: {
    'prettier/prettier': ['error', PRETTIER_STANDARD]
  }
}

export default eslintrc

๐Ÿค” Why

Todo

๐Ÿ“ƒ Todo

  • Document
  • Allow specify parserOptions: { project: './tsconfig.json' }
  • Prettier output
  • Better integrate with Prettier

License

MIT License ยฉ 2020 Exuanbo