ProJSLib/jsbits

View on GitHub
.eslintrc.js

Summary

Maintainability
A
0 mins
Test Coverage
const OFF = 0
const WARN = 1
const ERROR = 2
const ON = 2
const YES = true
const USE = false

module.exports = {
  root: YES,
  parser: 'typescript-eslint-parser',

  plugins: [
    'typescript',
    'promise',
  ],

  parserOptions: {
    ecmaVersion: 6,
    impliedStrict: YES,
    sourceType: 'module',
  },

  // https://github.com/sindresorhus/globals/blob/master/globals.json
  env: {
    node: YES,
    es6: YES,
  },

  // https://github.com/eslint/eslint/blob/master/conf/eslint-recommended.js
  extends: [
    'eslint:recommended',
  ],

  rules: {
    'array-bracket-spacing': ERROR,
    'array-callback-return': ON,
    'arrow-parens': ON,
    'arrow-spacing': ON,
    'block-scoped-var': ON,
    'block-spacing': ERROR,
    'brace-style': [ON, '1tbs', { allowSingleLine: YES }],
    'comma-dangle': [ON, 'always-multiline'],
    'comma-spacing': ERROR,
    'comma-style': [ON, 'last'],
    'complexity': [ON, 8],   // default is 20
    'computed-property-spacing': ERROR,
    'consistent-return': ON,
    'consistent-this': [ON, '_self'],
    'curly': ON,
    'dot-location': [ON, 'property'],
    'dot-notation': WARN,
    'eol-last': ON,
    'eqeqeq': [ON, 'smart'],
    'func-call-spacing': ERROR,
    'guard-for-in': WARN,
    'handle-callback-err': [ON, '^err(or)?$'],
    'implicit-arrow-linebreak': ERROR,
    'indent': [ON, 2, { flatTernaryExpressions: YES, SwitchCase: 1 }],
    'jsx-quotes': [ON, 'prefer-double'],
    'key-spacing': [ON, { mode: 'minimum' }],
    'keyword-spacing': ON,
    'linebreak-style': [ON, 'unix'],
    'max-depth': [ON, 3],
    'max-len': [1, 120, 4, { ignoreUrls: YES, ignoreRegExpLiterals: YES }],
    'max-lines-per-function': [ON, { max: 25, skipBlankLines: YES, skipComments: YES }],
    'max-lines': [ON, { max: 250, skipBlankLines: YES, skipComments: YES }],
    'max-nested-callbacks': [ON, 3],  // default is 10
    'max-params': [ON, 3],
    'max-statements': [ON, 12],
    'new-parens': ON,
    'no-alert': ON,
    'no-array-constructor': ON,
    'no-caller': ON,
    'no-catch-shadow': ON,
    'no-confusing-arrow': [ON, { allowParens: YES }],
    'no-console': ON,
    'no-div-regex': ON,
    'no-duplicate-imports': [ON, { includeExports: YES }],
    'no-eval': ON,
    'no-extend-native': ON,
    'no-extra-bind': ON,
    'no-floating-decimal': ON,
    'no-implicit-globals': ON,
    'no-implied-eval': ON,
    'no-iterator': ON,
    'no-label-var': ON,
    'no-lone-blocks': ON,
    'no-lonely-if': ON,
    'no-loop-func': ON,
    'no-multi-str': ON,
    'no-multiple-empty-lines': [ON, { max: 2 }],
    'no-native-reassign': ON,
    'no-new-func': ON,
    'no-new-object': ON,
    'no-new-wrappers': ON,
    'no-new': ON,
    'no-octal-escape': ON,
    'no-proto': ON,
    'no-prototype-builtins': WARN,
    'no-return-assign': [ON, 'except-parens'],
    'no-script-url': ON,
    'no-self-compare': ON,
    'no-sequences': ON,
    'no-shadow-restricted-names': ON,
    'no-template-curly-in-string': ON,
    'no-throw-literal': ON,
    'no-trailing-spaces': ON,
    'no-undef': OFF,              // handled by TS
    'no-undef-init': ON,
    'no-unexpected-multiline': ON,
    'no-unmodified-loop-condition': WARN,
    'no-unneeded-ternary': ON,
    'no-unused-expressions': WARN,
    'no-unused-vars': OFF,        // handled by TS
    'no-use-before-define': [ON, 'nofunc'],
    'no-useless-call': ON,
    'no-useless-computed-key': ON,
    'no-useless-rename': ON,
    'no-useless-return': ON,
    'no-var': ON,
    'no-void': ON,
    'no-whitespace-before-property': ON,
    'no-with': ON,
    'object-curly-spacing': [ON, 'always'],
    'object-shorthand': WARN,
    'one-var-declaration-per-line': ON,
    'operator-linebreak': ERROR,
    'prefer-const': [ON, { destructuring: 'all' }],
    'prefer-numeric-literals': ON,
    'prefer-promise-reject-errors': ON,
    'quote-props': [ON, 'consistent'],
    'quotes': [ON, 'single', 'avoid-escape'],
    'radix': ON,
    'require-await': ON,
    'require-yield': ON,
    'rest-spread-spacing': ERROR,
    'semi-spacing': ERROR,
    'semi': [ON, 'never'],
    'space-before-blocks': ERROR,
    'space-before-function-paren': [ON, 'always'],
    'space-in-parens': ERROR,
    'space-infix-ops': ERROR,
    'space-unary-ops': ERROR,
    'switch-colon-spacing': [ON, { after: YES }],
    'template-curly-spacing': ERROR,
    'unicode-bom': [ON, 'never'],
    'wrap-iife': [ON, 'inside'],
    'yield-star-spacing': ON,
    'yoda': ERROR,

    // Promise ---------------------------------------------------------------
    'promise/always-return': ON,
    'promise/catch-or-return': [ON, { allowThen: true }],
    'promise/no-callback-in-promise': ON,
    'promise/no-nesting': ON,
    'promise/no-new-statics': ON,
    'promise/no-promise-in-callback': ON,
    'promise/no-return-in-finally': ON,
    'promise/no-return-wrap': ON,
    'promise/param-names': ON,
    'promise/valid-params': ON,

    // Typescript ------------------------------------------------------------
    'typescript/adjacent-overload-signatures': ON,
    'typescript/class-name-casing': ON,
    'typescript/member-delimiter-style': ON,
    'typescript/member-naming': [ON, { private: '^_', protected: '^_' }],
    'typescript/no-use-before-define': [ON, { functions: false, typedefs: false }],
  },
  overrides: [
    {
      files: ['**/test/'],
      env: {
        mocha: YES,
      },
    },
    {
      files: ['packages/*/*.d.ts'],
      rules: {
        'eol-last': OFF,
        'indent': OFF,
        'no-var': OFF,
        'quotes': OFF,
        'semi': OFF,
      },
    },
    {
      files: ['packages/*/*.ts'],
      rules: {
        'require-jsdoc': ON,
        'valid-jsdoc': [ON, {
          matchDescription: '.+',
          requireParamDescription: true,
          requireParamType: true,
          requireReturn: false,
          requireReturnDescription: true,
          requireReturnType: true,
          preferType: { String: 'string', Number: 'number', Boolean: 'boolean', Object: 'object' },
          prefer: {
            arg: 'param',
            argument: 'param',
            class: 'constructor',
            property: 'prop',
            returns: 'returns',
          },
        }],
      },
    }
  ],
}