~cytrogen/masto-fe

masto-fe/eslint.config.js -rw-r--r-- 4.2 KiB
f8dc013b — Cytrogen [feature] Add language selector to local settings 4 days ago
                                                                                
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
163
164
165
166
167
168
169
170
171
172
173
const globals = require("globals");
const importPlugin = require("eslint-plugin-import");
const reactPlugin = require("eslint-plugin-react");
const reactHooks = require("eslint-plugin-react-hooks");
const jsxA11y = require("eslint-plugin-jsx-a11y");
const pluginPromise = require("eslint-plugin-promise");
const pluginJest = require("eslint-plugin-jest");

module.exports = [

  // Global settings.
  {
    settings: {
      react: {
        version: "detect",
      },
    },
  },

  // Import set of sensible rules from f0x and
  // override some of them to fit the masto style
  // to avoid reformatting a million files.
  ...require("@f0x52/eslint-config"),
  {
    rules: {
      "@stylistic/indent": ["error", 2],
      "no-unused-vars": "off",
      "no-use-before-define": "off",
      "no-useless-assignment": "off",
      "no-case-declarations": "warn",
      "quotes": ["error", "double"],
    },
  },

  // Files about which
  // we do not care.
  {
    ignores: [
      "build/**/*",
      "coverage/**/*",
      "db/**/*",
      "lib/**/*",
      "log/**/*",
      "node_modules/**/*",
      "nonobox/**/*",
      "public/**/*",
      "!public/embed.js",
      "spec/**/*",
      "tmp/**/*",
      "vendor/**/*",
      "!**/.eslintrc.js",
    ],
  },

  // Main rules for source
  // files defined here.
  {
    files: [
      "**/*.ts",
      "**/*.tsx",
      "**/*.js",
      "**/*.jsx",
    ],
    plugins: {
      import: importPlugin,
      react: reactPlugin,
      "react-hooks": reactHooks,
      "jsx-a11y": jsxA11y,
      "promise": pluginPromise,
    },
    languageOptions: {
      ecmaVersion: 2022,
      sourceType: "module",
      globals: {
        ...globals.browser,
        ...globals.node,
      },
      parserOptions: {
        ecmaFeatures: {
          jsx: true,
        },
        project: true,
      },
    },
    rules: {
      // Import recommended rules for plugins.
      ...importPlugin.flatConfigs.warnings.rules,
      ...reactPlugin.configs.flat.recommended.rules,
      ...reactHooks.configs.flat.recommended.rules,
      ...jsxA11y.flatConfigs.recommended.rules,
      ...pluginPromise.configs["flat/recommended"].rules,
      
      // Override ones we don"t need.
      "react/jsx-uses-react": "off",
      "react/jsx-no-target-blank": "warn",
      "react/react-in-jsx-scope": "off",
      "react/prop-types": "off",
      "react/no-unknown-property": "warn",
      "react/display-name": "warn",
      "react/no-deprecated": "warn",

      // TODO: Fix these jsx-a11y warnings.
      "jsx-a11y/accessible-emoji": "warn",
      "jsx-a11y/click-events-have-key-events": "warn",
      "jsx-a11y/label-has-associated-control": "warn",
      "jsx-a11y/media-has-caption": "warn",
      "jsx-a11y/no-autofocus": "warn",
      "jsx-a11y/no-noninteractive-tabindex": "warn",
      "jsx-a11y/no-onchange": "warn",
      "jsx-a11y/no-interactive-element-to-noninteractive-role": "warn",
      "jsx-a11y/no-static-element-interactions": [
        "warn",
        {
          handlers: [
            "onClick",
          ],
        },
      ],

      // Todo: fix these promise warnings.
      "promise/always-return": "warn",
      "promise/catch-or-return": [
        "error",
        {
          allowFinally: true,
        },
      ],
      "promise/no-callback-in-promise": "warn",
      "promise/no-nesting": "warn",
      "promise/no-promise-in-callback": "warn",
    },
  },

  // Rules for test files.
  {
    files: [
      "**/__tests__/*.js",
      "**/__tests__/*.jsx",
    ],
    plugins: { jest: pluginJest },
    languageOptions: {
      globals: pluginJest.environments.globals.globals,
    },
    rules: {
      "jest/no-disabled-tests": "warn",
      "jest/no-focused-tests": "error",
      "jest/no-identical-title": "error",
      "jest/prefer-to-have-length": "warn",
      "jest/valid-expect": "error",
    },
  },

  // Rules for other bits and
  // bobs and odds and ends.
  {
    files: [
      "*.config.js",
      ".*rc.js",
      "ide-helper.js",
      "config/webpack/**/*",
      "config/formatjs-formatter.js",
    ],
    languageOptions: {
      sourceType: "script",
      globals: {
        ...globals.commonjs,
      },
    },
    rules: {
      "import/no-commonjs": "off",
    },
  },
];