aboutsummaryrefslogtreecommitdiffstats
path: root/.eslintrc.cjs
blob: e76ff6fa7acca9ac66ce192fef7450cca3021a1c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
const project = ['./tsconfig.json', './packages/*/tsconfig.json'];

module.exports = {
  root: true,
  plugins: ['@typescript-eslint'],
  extends: [
    'airbnb',
    'airbnb-typescript',
    'airbnb/hooks',
    'plugin:@typescript-eslint/recommended',
    'plugin:@typescript-eslint/recommended-requiring-type-checking',
    'plugin:jest/recommended',
    'plugin:jest/style',
    'plugin:prettier/recommended',
    'plugin:promise/recommended',
    'plugin:security/recommended',
    'plugin:unicorn/recommended',
  ],
  env: {
    es6: true,
    node: true,
    browser: false,
    jest: true,
  },
  parser: '@typescript-eslint/parser',
  parserOptions: {
    extraFileExtensions: ['.cjs'],
    sourceType: 'module',
    project,
    allowAutomaticSingleRunInference: false,
    tsconfigRootDir: __dirname,
    warnOnUnsupportedTypeScriptVersion: false,
    EXPERIMENTAL_useSourceOfProjectReferenceRedirect: false,
  },
  settings: {
    'import/parsers': {
      '@typescript-eslint/parser': ['.ts', '.tsx'],
    },
    'import/resolver': {
      typescript: {
        alwaysTryTypes: true,
        project,
      },
    },
  },
  rules: {
    // `import/exteions` is buggy with ts files:
    // https://github.com/import-js/eslint-plugin-import/issues/2111
    'import/extensions': 'off',
    'import/no-unresolved': 'error',
    'import/order': [
      'error',
      {
        alphabetize: {
          order: 'asc',
        },
        'newlines-between': 'always',
      },
    ],
    // jest-each confuses this rule.
    'jest/no-standalone-expect': 'off',
    // Allows files with names same as the name of their default export.
    'unicorn/filename-case': [
      'error',
      {
        cases: {
          camelCase: true,
          pascalCase: true,
        },
      },
    ],
    // Airbnb prefers forEach.
    'unicorn/no-array-for-each': 'off',
    // Typescript requires exlicit `undefined` arguments.
    'unicorn/no-useless-undefined': [
      'error',
      {
        checkArguments: false,
      },
    ],
    // Common abbreviations are known and readable.
    'unicorn/prevent-abbreviations': 'off',
  },
  overrides: [
    {
      files: ['**/stores/**/*.ts'],
      rules: {
        // In a mobx-state-tree action, we assign to the properties of `self` to update the store.
        'no-param-reassign': [
          'error',
          {
            props: false,
          },
        ],
        // mobx-state-tree uses empty interfaces to speed up typechecking.
        '@typescript-eslint/no-empty-interface': 'off',
      },
    },
    {
      files: ['**/__tests__/*.{ts,tsx}', '**/*.{spec,test}.{ts,tsx}'],
      rules: {
        // If a non-null assertion fails in a test, the test will also fail anyways.
        '@typescript-eslint/no-non-null-assertion': 'off',
        // Jest mocks use unbound method references.
        '@typescript-eslint/unbound-method': 'off',
        // We can't turn this on yet, because it doesn't understand `mocked` from `jest-mock`.
        // 'jest/unbound-method': 'error',
      },
    },
    {
      files: ['**/*.cjs'],
      parserOptions: {
        sourceType: 'script',
      },
      rules: {
        // We have to use `const foo = require('foo')` syntax in CommonJS files.
        '@typescript-eslint/no-var-requires': 'off',
      },
    },
    {
      files: [
        '.electron-builder.config.cjs',
        'config/**/*.{cjs,js}',
        '*.config.{cjs,js}',
        'scripts/**/*.js',
        'packages/*/.eslintrc.cjs',
        'packages/*/*.config.{cjs,js}',
      ],
      env: {
        // Config files are never run in a browser (even in frontend projects).
        browser: false,
        node: true,
        jest: false,
      },
      rules: {
        // Config files and build scripts are allowed to use devDependencies.
        'import/no-extraneous-dependencies': [
          'error',
          {
            devDependencies: true,
          },
        ],
        // Allow reporting progress to the console from scripts.
        'no-console': 'off',
      },
    },
    {
      files: ['packages/*/*.config.{cjs,js}'],
      rules: {
        // Allow relative imports of config files from the root package.
        'import/no-relative-packages': 'off',
      },
    },
    {
      files: ['scripts/**/*.js'],
      rules: {
        // Scripts are allowed to `exit` abruptly.
        'unicorn/no-process-exit': 'off',
      },
    },
  ],
};