aboutsummaryrefslogtreecommitdiffstats
path: root/.eslintrc.cjs
blob: 92af738cf50ddda994d73d561f52289f9479fe7b (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
const project = [
  './tsconfig.json',
  './packages/*/tsconfig.json',
];

module.exports = {
  root: true,
  plugins: [
    '@typescript-eslint',
  ],
  extends: [
    'airbnb-base',
    'airbnb-typescript/base',
    'plugin:@typescript-eslint/recommended',
    'plugin:@typescript-eslint/recommended-requiring-type-checking',
  ],
  env: {
    es6: true,
    node: true,
    browser: false,
    jest: true,
  },
  parser: '@typescript-eslint/parser',
  parserOptions: {
    sourceType: 'module',
    project,
    allowAutomaticSingleRunInference: true,
    tsconfigRootDir: __dirname,
    warnOnUnsupportedTypeScriptVersion: false,
  },
  settings: {
    'import/parsers': {
      '@typescript-eslint/parser': ['.ts', '.tsx'],
    },
    'import/resolver': {
      typescript: {
        alwaysTryTypes: true,
        project,
      },
    },
  },
  rules: {
    'import/no-unresolved': 'error',
    'import/order': [
      'error',
      {
        alphabetize: {
          order: 'asc',
        },
        'newlines-between': 'always',
      },
    ],
  },
  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': 'off',
        // 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',
      },
    },
    {
      files: [
        '**/*.js',
      ],
      rules: {
        // ESM requires extensions for imports.
        'import/extensions': [
          'error',
          'ignorePackages',
        ],
      },
    },
    {
      files: [
        '.electron-builder.config.cjs',
        'config/**/*.{cjs,js}',
        'jest.config.js',
        'scripts/**/*.js',
        'packages/*/*.config.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.js',
      ],
      rules: {
        // Allow relative imports of config files from the root package.
        'import/no-relative-packages': 'off',
      },
    },
  ],
};