8000 chore: tighter linting (#535) · ajmacd/typescript-eslint@4496288 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4496288

Browse files
authored
chore: tighter linting (typescript-eslint#535)
1 parent 211b1b5 commit 4496288

File tree

96 files changed

+3454
-1826
lines changed
  • tools
  • typescript-estree
  • tests/integration/utils
  • Some content is hidden

    Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

    96 files changed

    +3454
    -1826
    lines changed

    .eslintrc.js

    Lines changed: 181 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -0,0 +1,181 @@
    1+
    module.exports = {
    2+
    root: true,
    3+
    plugins: [
    4+
    'eslint-plugin',
    5+
    '@typescript-eslint',
    6+
    'jest',
    7+
    'import',
    8+
    'eslint-comments',
    9+
    ],
    10+
    env: {
    11+
    es6: true,
    12+
    node: true,
    13+
    },
    14+
    extends: [
    15+
    'eslint:recommended',
    16+
    'plugin:@typescript-eslint/eslint-recommended',
    17+
    'plugin:@typescript-eslint/recommended',
    18+
    ],
    19+
    rules: {
    20+
    //
    21+
    // our plugin :D
    22+
    //
    23+
    24+
    '@typescript-eslint/ban-ts-ignore': 'error',
    25+
    '@typescript-eslint/consistent-type-definitions': 'error',
    26+
    '@typescript-eslint/explicit-function-return-type': 'off',
    27+
    '@typescript-eslint/explicit-member-accessibility': 'off',
    28+
    '@typescript-eslint/indent': 'off',
    29+
    '@typescript-eslint/no-explicit-any': 'warn',
    30+
    '@typescript-eslint/no-inferrable-types': 'error',
    31+
    '@typescript-eslint/no-misused-promises': 'error',
    32+
    '@typescript-eslint/no-non-null-assertion': 'off',
    33+
    '@typescript-eslint/no-object-literal-type-assertion': 'off',
    34+
    '@typescript-eslint/no-parameter-properties': 'off',
    35+
    '@typescript-eslint/no-unnecessary-type-assertion': 'error',
    36+
    '@typescript-eslint/no-use-before-define': 'off',
    37+
    '@typescript-eslint/no-var-requires': 'off',
    38+
    '@typescript-eslint/prefer-includes': 'error',
    39+
    '@typescript-eslint/prefer-regexp-exec': 'error',
    40+
    '@typescript-eslint/prefer-string-starts-ends-with': 'error',
    41+
    42+
    //
    43+
    // eslint base
    44+
    //
    45+
    46+
    'comma-dangle': ['error', 'always-multiline'],
    47+
    curly: ['error', 'all'],
    48+
    'no-mixed-operators': 'error',
    49+
    'no-console': 'error',
    50+
    'no-process-exit': 'error',
    51+
    52+
    //
    53+
    // eslint-plugin-eslint-comment
    54+
    //
    55+
    56+
    // require a eslint-enable comment for every eslint-disable comment
    57+
    'eslint-comments/disable-enable-pair': [
    58+
    'error',
    59+
    {
    60+
    allowWholeFile: true,
    61+
    },
    62+
    ],
    63+
    // disallow a eslint-enable comment for multiple eslint-disable comments
    64+
    'eslint-comments/no-aggregating-enable': 'error',
    65+
    // disallow duplicate eslint-disable comments
    66+
    'eslint-comments/no-duplicate-disable': 'error',
    67+
    // disallow eslint-disable comments without rule names
    68+
    'eslint-comments/no-unlimited-disable': 'error',
    69+
    // disallow unused eslint-disable comments
    70+
    'eslint-comments/no-unused-disable': 'error',
    71+
    // disallow unused eslint-enable comments
    72+
    'eslint-comments/no-unused-enable': 'error',
    73+
    // disallow ESLint directive-comments
    74+
    'eslint-comments/no-use': [
    75+
    'error',
    76+
    {
    77+
    allow: [
    78+
    'eslint-disable',
    79+
    'eslint-disable-line',
    80+
    'eslint-disable-next-line',
    81+
    'eslint-enable',
    82+
    ],
    83+
    },
    84+
    ],
    85+
    86+
    //
    87+
    // eslint-plugin-import
    88+
    //
    89+
    90+
    // disallow non-import statements appearing before import statements
    91+
    'import/first': 'error',
    92+
    // Require a newline after the last import/require in a group
    93+
    'import/newline-after-import': 'error',
    94+
    // Forbid import of modules using absolute paths
    95+
    'import/no-absolute-path': 'error',
    96+
    // disallow AMD require/define
    97+
    'import/no-amd': 'error',
    98+
    // forbid default exports
    99+
    'import/no-default-export': 'error',
    100+
    // Forbid the use of extraneous packages
    101+
    'import/no-extraneous-dependencies': [
    102+
    'error',
    103+
    {
    104+
    devDependencies: true,
    105+
    peerDependencies: true,
    106+
    optionalDependencies: false,
    107+
    },
    108+
    ],
    109+
    // Forbid mutable exports
    110+
    'import/no-mutable-exports': 'error',
    111+
    // Prevent importing the default as if it were named
    112+
    'import/no-named-default': 'error',
    113+
    // Prohibit named exports // we want everything to be a named export
    114+
    'import/no-named-export': 'off',
    115+
    // Forbid a module from importing itself
    116+
    'import/no-self-import': 'error',
    117+
    // Require modules with a single export to use a default export // we want everything to be named
    118+
    'import/prefer-default-export': 'off',
    119+
    },
    120+
    parserOptions: {
    121+
    sourceType: 'module',
    122+
    ecmaFeatures: {
    123+
    jsx: false,
    124+
    },
    125+
    project: './tsconfig.base.json',
    126+
    },
    127+
    overrides: [
    128+
    {
    129+
    files: [
    130+
    'packages/eslint-plugin-tslint/tests/**/*.ts',
    131+
    'packages/eslint-plugin/tests/**/*.test.ts',
    132+
    'packages/parser/tests/**/*.ts',
    133+
    'packages/typescript-estree/tests/**/*.ts',
    134+
    ],
    135+
    env: {
    136+
    'jest/globals': true,
    137+
    },
    138+
    rules: {
    139+
    'jest/no-disabled-tests': 'warn',
    140+
    'jest/no-focused-tests': 'error',
    141+
    'jest/no-alias-methods': 'error',
    142+
    'jest/no-identical-title': 'error',
    143+
    'jest/no-jasmine-globals': 'error',
    144+
    'jest/no-jest-import': 'error',
    145+
    'jest/no-test-prefixes': 'error',
    146+
    'jest/no-test-callback': 'error',
    147+
    'jest/no-test-return-statement': 'error',
    148+
    'jest/prefer-to-have-length': 'warn',
    149+
    'jest/prefer-spy-on': 'error',
    150+
    'jest/valid-expect': 'error',
    151+
    },
    152+
    },
    153+
    {
    154+
    files: [
    155+
    'packages/eslint-plugin/tests/**/*.test.ts',
    156+
    'packages/eslint-plugin-tslint/tests/**/*.spec.ts',
    157+
    ],
    158+
    rules: {
    159+
    'eslint-plugin/no-identical-tests': 'error',
    160+
    },
    161+
    },
    162+
    {
    163+
    files: [
    164+
    'packages/eslint-plugin/src/rules/**/*.ts',
    165+
    'packages/eslint-plugin/src/configs/**/*.ts',
    166+
    'packages/eslint-plugin-tslint/src/rules/**/*.ts',
    167+
    ],
    168+
    rules: {
    169+
    // specifically for rules - default exports makes the tooling easier
    170+
    'import/no-default-export': 'off',
    171+
    },
    172+
    },
    173+
    {
    174+
    files: ['**/tools/**/*.ts', '**/tests/**/*.ts'],
    175+
    rules: {
    176+
    // allow console logs in tools and tests
    177+
    'no-console': 'off',
    178+
    },
    179+
    },
    180+
    ],
    181+
    };

    .eslintrc.json

    Lines changed: 0 additions & 73 deletions
    This file was deleted.

    package.json

    Lines changed: 18 additions & 25 deletions
    Original file line numberDiff line numberDiff line change
    @@ -50,36 +50,29 @@
    5050
    "node": ">=6.14.0"
    5151
    },
    5252
    "devDependencies": {
    53-
    "@babel/code-frame": "7.0.0",
    54-
    "@babel/parser": "7.3.2",
    55-
    "@commitlint/cli": "^7.1.2",
    56-
    "@commitlint/config-conventional": "^7.1.2",
    57-
    "@commitlint/travis-cli": "^7.1.2",
    58-
    "@types/babel-code-frame": "^6.20.1",
    59-
    "@types/glob": "^7.1.1",
    60-
    "@types/jest": "^24.0.6",
    61-
    "@types/lodash.isplainobject": "^4.0.4",
    62-
    "@types/lodash.unescape": "^4.0.4",
    63-
    "@types/node": "^10.12.2",
    64-
    "@types/semver": "^5.5.0",
    65-
    "all-contributors-cli": "^6.0.0",
    66-
    "babel-code-frame": "^6.26.0",
    53+
    "@commitlint/cli": "^8.1.0",
    54+
    "@commitlint/config-conventional": "^8.1.0",
    55+
    "@commitlint/travis-cli": "^8.1.0",
    56+
    "@types/jest": "^24.0.15",
    57+
    "@types/node": "^12.6.8",
    58+
    "all-contributors-cli": "^6.8.0",
    6759
    "cz-conventional-changelog": "2.1.0",
    6860
    "eslint": "^6.0.0",
    69-
    "eslint-plugin-eslint-plugin": "^2.0.1",
    70-
    "eslint-plugin-jest": "^22.2.2",
    71-
    "glob": "7.1.2",
    72-
    "husky": "^1.3.1",
    61+
    "eslint-plugin-eslint-comments": "^3.1.2",
    62+
    "eslint-plugin-eslint-plugin": "^2.1.0",
    63+
    "eslint-plugin-import": "^2.18.0",
    64+
    "eslint-plugin-jest": "^22.10.0",
    65+
    "glob": "^7.1.4",
    66+
    "husky": "^3.0.0",
    7367
    "isomorphic-fetch": "^2.2.1",
    74-
    "jest": "24.3.0",
    75-
    "lerna": "^3.10.5",
    76-
    "lint-staged": "8.1.0",
    77-
    "lodash.isplainobject": "4.0.6",
    78-
    "prettier": "^1.17.0",
    68+
    "jest": "^24.8.0",
    69+
    "lerna": "^3.15.0",
    70+
    "lint-staged": "^9.2.0",
    71+
    "prettier": "^1.18.2",
    7972
    "rimraf": "^2.6.3",
    8073
    "ts-jest": "^24.0.0",
    81-
    "ts-node": "^8.0.1",
    82-
    "tslint": "^5.11.0",
    74+
    "ts-node": "^8.3.0",
    75+
    "tslint": "^5.18.0",
    8376
    "typescript": ">=3.2.1 <3.6.0"
    8477
    }
    8578
    }

    packages/eslint-plugin-tslint/package.json

    Lines changed: 2 additions & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -36,7 +36,8 @@
    3636
    },
    3737
    "peerDependencies": {
    3838
    "eslint": "^5.0.0 || ^6.0.0",
    39-
    "tslint": "^5.0.0"
    39+
    "tslint": "^5.0.0",
    40+
    "typescript": "*"
    4041
    },
    4142
    "devDependencies": {
    4243
    "@types/lodash.memoize": "^4.1.4",

    packages/eslint-plugin-tslint/src/custom-linter.ts

    Lines changed: 2 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -1,6 +1,8 @@
    11
    import { ILinterOptions, Linter, LintResult } from 'tslint';
    22
    import { Program } from 'typescript';
    33

    4+
    // We need to access the program, but Linter has private program already
    5+
    // eslint-disable-next-line @typescript-eslint/no-explicit-any
    46
    const TSLintLinter = Linter as any;
    57

    68
    export class CustomLinter extends TSLintLinter {

    packages/eslint-plugin-tslint/src/rules/config.ts

    Lines changed: 6 additions & 5 deletions
    Original file line numberDiff line numberDiff line change
    @@ -18,10 +18,10 @@ export type RawRulesConfig = Record<
    1818
    | null
    1919
    | undefined
    2020
    | boolean
    21-
    | any[]
    21+
    | unknown[]
    2222
    | {
    2323
    severity?: RuleSeverity | 'warn' | 'none' | 'default';
    24-
    options?: any;
    24+
    options?: unknown;
    2525
    }
    2626
    >;
    2727

    @@ -31,7 +31,7 @@ export type Options = [
    3131
    rules?: RawRulesConfig;
    3232
    rulesDirectory?: string[];
    3333
    lintFile?: string;
    34-
    }
    34+
    },
    3535
    ];
    3636

    3737
    /**
    @@ -63,7 +63,8 @@ export default createRule<Options, MessageIds>({
    6363
    docs: {
    6464
    description:
    6565
    'Wraps a TSLint configuration and lints the whole source using TSLint',
    66-
    category: 'TSLint' as any,
    66+
    // one off special category for this plugin
    67+
    category: 'TSLint' as any, // eslint-disable-line @typescript-eslint/no-explicit-any
    6768
    recommended: false,
    6869
    },
    6970
    type: 'problem',
    @@ -95,7 +96,7 @@ export default createRule<Options, MessageIds>({
    9596
    },
    9697
    ],
    9798
    },
    98-
    defaultOptions: [] as any,
    99+
    defaultOptions: [{}],
    99100
    create(context) {
    100101
    const fileName = context.getFilename();
    101102
    const sourceCode = context.getSourceCode().text;

    packages/eslint-plugin/docs/rules/generic-type-naming.md

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -15,7 +15,7 @@ Examples of **correct** code with a configuration of `'^T[A-Z][a-zA-Z]+$'`:
    1515

    1616
    ```typescript
    1717
    type ReadOnly<TType extends object> = {
    18-
    readonly [TKey in keyof TType]: TType[TKey]
    18+
    readonly [TKey in keyof TType]: TType[TKey];
    1919
    };
    2020

    2121
    interface SimpleMap<TValue> {

    0 commit comments

    Comments
     (0)
    0