alvis/presetter

View on GitHub
packages/preset-esm/templates/eslintrc.yaml

Summary

Maintainability
Test Coverage
root: true
extends:
  - eslint:recommended
  - plugin:@typescript-eslint/recommended-type-checked # typescript specific rules
  - plugin:eslint-comments/recommended # ESLint rules for ESLint directive comments
  - plugin:jsdoc/recommended # documentation
  - plugin:import/typescript # support linting import/export statements in typescript
  - prettier # ignore formatting issue
env:
  es6: true
  node: true
  jest: true
parser: '@typescript-eslint/parser'
parserOptions:
  project: true
  sourceType: module
plugins:
  - '@typescript-eslint' # typescript support
  - import # enforce best practices on import/export statements
  - jsdoc # enforce documentation
settings:
  import/internal-regex: '^#'
  jsdoc:
    mode: typescript
ignorePatterns:
  - '{output}'
  - '{test}'
  - types
  - '**/*.js'
rules:
  # Documentation
  jsdoc/tag-lines: # doesn't need a new line after each description
    - error
    - never
  jsdoc/require-description: # a description is a must
    - warn
    - checkConstructors: false
      checkGetters: false
      checkSetters: false
  jsdoc/require-jsdoc: # all functions must be documented
    - warn
    - require:
        ClassDeclaration: true
        ClassExpression: true
        FunctionDeclaration: false
        FunctionExpression: true
        MethodDefinition: false
      exemptEmptyConstructors: true
      contexts:
        # for non-exported functions
        - Program > TSDeclareFunction:not(TSDeclareFunction + TSDeclareFunction)
        - Program > FunctionDeclaration:not(TSDeclareFunction + FunctionDeclaration)
        # for exported functions
        - ExportNamedDeclaration[declaration.type=TSDeclareFunction]:not(ExportNamedDeclaration[declaration.type=TSDeclareFunction]
          + ExportNamedDeclaration[declaration.type=TSDeclareFunction])
        - ExportNamedDeclaration[declaration.type=FunctionDeclaration]:not(ExportNamedDeclaration[declaration.type=TSDeclareFunction]
          + ExportNamedDeclaration[declaration.type=FunctionDeclaration])
        # for class methods
        - MethodDefinition[value.body=null]:not(MethodDefinition[value.body=null] + MethodDefinition[value.body=null])
        - MethodDefinition[value.body]:not(MethodDefinition[value.body=null] + MethodDefinition)
  jsdoc/require-param-type: off # don't need type information as we use typescript
  jsdoc/require-property-type: off # don't need type information as we use typescript
  jsdoc/require-returns: # tell us what the function is expected to return
    - error
    - checkGetters: false
  jsdoc/require-returns-type: off # don't need type information as we use typescript

  # ECMAScript
  '@typescript-eslint/prefer-for-of': warn # use for of if possible
  '@typescript-eslint/prefer-optional-chain': warn # simplify a logic by using the optional chain operator
  object-shorthand: warn # reduce {x:x} to {x}
  prefer-const: # if a variable is never reassigned, using the const declaration is better
    - warn
    - destructuring: all
  prefer-destructuring: # get variables via destructuring for better readability
    - warn
    - AssignmentExpression:
        array: false # allow const foo = array[100];
  prefer-rest-params: error # use a rested variable instead of arguments
  prefer-spread: error # instead of using fn.apply(this, args), simply use fn(...args)
  symbol-description: error # describe a symbol

  # Stylistic Issues
  '@typescript-eslint/member-ordering': error # member group in a class should be in order
  '@typescript-eslint/naming-convention': error # use JS/TS naming convention
  capitalized-comments: # use lower case in comments
    - warn
    - never
    - ignorePattern: '\*|\/|/|\s'
  one-var: # require variable to be declared only one per line
    - warn
    - never
  spaced-comment: error # enforce consistent spacing after the `//` or `/*` in a comment

  # Best Practices
  '@typescript-eslint/array-type': # requires using either T[] or Array<T> depending on the type complexity
    - warn
    - default: array-simple
  '@typescript-eslint/consistent-type-imports': # enforce import type whenever possible
    - warn
  '@typescript-eslint/explicit-function-return-type': # tell us what is expected in return
    - warn
    - allowExpressions: true
  '@typescript-eslint/explicit-member-accessibility': # whether it's protected, private or public, tell us
    - error
    - overrides:
        constructors: 'no-public'
  '@typescript-eslint/no-magic-numbers': # only allow obvious cases
    - warn
    - ignore:
        - -1
        - 0
        - 1
      ignoreArrayIndexes: true
      ignoreNumericLiteralTypes: true
      ignoreReadonlyClassProperties: true
      ignoreEnums: true
      ignoreTypeIndexes: true
  '@typescript-eslint/require-await': off # sometimes you need an async function to fulfil the signature inherited from an abstract class
  import/first: warn # ensure that all import statements are on the top of a file
  import/no-deprecated: warn # use no deprecated method
  import/no-duplicates: warn # merge multiple imports into one
  import/newline-after-import: warn # leave a line after all imports
  import/order: # order and group import statements
    - warn
    - alphabetize: # sort imports
        order: asc
        caseInsensitive: true
      groups: # group imports
        - builtin
        - external
        - - index
          - internal
        - - parent
          - sibling
        - object
        - unknown
        - type
      newlines-between: always-and-inside-groups # enable a space line between import type statements for different module types
      pathGroups: # make type import ordered as the same as the other groups
        - group: type
          pattern: node:*
          position: before
        - group: type
          pattern: '{#*,#*/**,../{,..,../..,../../..,../../../..,../../../../..}/**,./**}'
          position: after
          patternOptions:
            dot: true
      pathGroupsExcludedImportTypes: # exclude other groups so that patterns in pathGroups only affect type imports
        - builtin
        - external
        - index
        - internal
        - parent
        - sibling
        - object
        - unknown
  eqeqeq: error # enforce type-safe equality operators
  max-classes-per-file: error # only one class max for a file
  no-async-promise-executor: off # turn off in order to use await in the executor function
  no-magic-numbers: off # use @typescript-eslint/no-magic-numbers instead
  no-return-await: off # use @typescript-eslint/return-await instead
  no-throw-literal: warn # only an error instance should be thrown
  no-var: error # use let or const instead
  padding-line-between-statements: # always have a blank line before return for better readability
    - warn
    - blankLine: always
      prev: '*'
      next: return
  prefer-object-spread: warn # use {...obj} for cloning instead of Object.assign({}, obj)
  sort-imports: # sort members within each import statement
    - warn
    - ignoreDeclarationSort: true # use import/order for sorting import statements instead
      memberSyntaxSortOrder:
        - multiple
        - single
        - all
        - none

  # Code Quality
  '@typescript-eslint/no-explicit-any': off # allow any type
  '@typescript-eslint/no-unused-vars': # use a name starting with _ as a placeholder instead
    - warn
    - varsIgnorePattern: ^_
      argsIgnorePattern: ^_

  # Error Prevention
  '@typescript-eslint/no-non-null-assertion': off # sometimes typescript fails to detect that a variable is non-null
  '@typescript-eslint/no-use-before-define': # things should be used only after they're declared
    - warn
    - functions: false
  block-scoped-var: error # disallow usage of a scoped variable outside of its scope
  no-param-reassign: error # it may be useful only when you're testing, not something finished
  no-sparse-arrays: warn # very unlikely you want an undefined in something like [va1, , var2]
  no-template-curly-in-string: warn # unlikely you have any use case with the ${} syntax in a string