aboutsummaryrefslogtreecommitdiffstats
path: root/.eslintrc.cjs
blob: 9df1667a5db0fc83d7c26fc4a0ab5dc0d60f8b75 (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
/*
 * SPDX-FileCopyrightText: 2021-2024 The Refinery Authors
 *
 * SPDX-License-Identifier: EPL-2.0
 */

const path = require('node:path');

// Allow the Codium ESLint plugin to find `tsconfig.json` from the repository root.
const project = [
  path.join(__dirname, 'tsconfig.json'),
  path.join(__dirname, 'subprojects/docs/tsconfig.json'),
  path.join(__dirname, 'subprojects/frontend/tsconfig.json'),
  path.join(__dirname, 'subprojects/frontend/tsconfig.node.json'),
  path.join(__dirname, 'subprojects/frontend/tsconfig.shared.json'),
];

/** @type {import('eslint').Linter.Config} */
module.exports = {
  plugins: ['@typescript-eslint', 'mobx'],
  extends: [
    'airbnb',
    'airbnb-typescript',
    'airbnb/hooks',
    'plugin:@typescript-eslint/recommended',
    'plugin:@typescript-eslint/recommended-requiring-type-checking',
    'plugin:mobx/recommended',
    'plugin:prettier/recommended',
  ],
  parserOptions: {
    project,
    sourceType: 'module',
  },
  parser: '@typescript-eslint/parser',
  settings: {
    'import/parsers': {
      '@typescript-eslint/parser': ['.ts', '.tsx'],
    },
    'import/resolver': {
      typescript: {
        alwaysTryTypes: true,
        project,
      },
    },
  },
  env: {
    browser: true,
  },
  ignorePatterns: [
    'build/**/*',
    'subprojects/*/build/**/*',
    'subprojects/docs/.docusaurus/**/*',
    'subprojects/docs/.yarn/**/*',
    'subprojects/frontend/dev-dist/**/*',
    'subprojects/frontend/src/**/*.typegen.ts',
  ],
  rules: {
    // In typescript, some class methods implementing an inderface do not use `this`:
    // https://github.com/typescript-eslint/typescript-eslint/issues/1103
    'class-methods-use-this': 'off',
    // Disable rules with a high performance cost.
    // See https://typescript-eslint.io/linting/troubleshooting/performance-troubleshooting/
    'import/default': 'off',
    'import/extensions': 'off',
    'import/named': 'off',
    'import/namespace': 'off',
    'import/no-named-as-default': 'off',
    'import/no-named-as-default-member': 'off',
    '@typescript-eslint/indent': 'off',
    // Make sure every import can be resolved by `eslint-import-resolver-typescript`.
    'import/no-unresolved': 'error',
    // Organize imports automatically.
    'import/order': [
      'error',
      {
        alphabetize: {
          order: 'asc',
        },
        'newlines-between': 'always',
      },
    ],
    // Not all components depend on observable state.
    'mobx/missing-observer': 'off',
    // A dangling underscore, while not neccessary for all private fields,
    // is useful for backing fields of properties that should be read-only from outside the class.
    'no-underscore-dangle': [
      'error',
      {
        allowAfterThis: true,
        allowFunctionParams: true,
      },
    ],
    // Use prop spreading to conditionally add props with `exactOptionalPropertyTypes`.
    'react/jsx-props-no-spreading': 'off',
    // We use the `react-jsx` runtime, so there is no need to import `React`.
    'react/react-in-jsx-scope': 'off',
  },
  overrides: [
    {
      files: ['subprojects/*/types/**/*.d.ts'],
      rules: {
        // We don't have control over exports of external modules.
        'import/prefer-default-export': 'off',
      },
    },
    {
      files: ['*.cjs'],
      rules: {
        // https://github.com/typescript-eslint/typescript-eslint/issues/1724
        '@typescript-eslint/no-var-requires': 'off',
      },
    },
    {
      files: ['*.cts'],
      rules: {
        // Allow `import type` in CommonJS TypeScript modules.
        'import/no-import-module-exports': 'off',
      },
    },
    {
      files: [
        '.eslintrc.cjs',
        'scripts/*.cjs',
        'subprojects/*/config/*.ts',
        'subprojects/*/config/*.cjs',
        'prettier.config.cjs',
        'subprojects/*/vite.config.ts',
      ],
      env: {
        browser: false,
        node: true,
      },
      rules: {
        // Allow devDependencies in configuration files.
        'import/no-extraneous-dependencies': [
          'error',
          { devDependencies: true },
        ],
        // Allow writing to the console in ad-hoc scripts.
        'no-console': 'off',
        // Access to the environment in configuration files.
        'no-process-env': 'off',
      },
    },
    {
      files: ['subprojects/docs/src/**/*'],
      rules: {
        'import/no-unresolved': [
          'error',
          {
            ignore: [
              // These imports are resolved by Docusaurus, not TypeScript.
              '^@docusaurus/',
              '^@theme/',
              '^@theme-original/',
            ],
          },
        ],
      },
    },
  ],
};