Skip to content

Commit 88e1509

Browse files
committed
build: migrate to eslint "flat" config
1 parent 280537b commit 88e1509

File tree

2 files changed

+143
-135
lines changed

2 files changed

+143
-135
lines changed

.eslintrc.js

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

eslint.config.mjs

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
import js from '@eslint/js';
2+
import globals from 'globals';
3+
import typescriptEslint from '@typescript-eslint/eslint-plugin';
4+
import typescriptParser from '@typescript-eslint/parser';
5+
import unicorn from 'eslint-plugin-unicorn';
6+
import importPlugin from 'eslint-plugin-import';
7+
import prettierConfig from 'eslint-config-prettier/flat';
8+
9+
export default [
10+
js.configs.recommended,
11+
typescriptEslint.configs.recommended,
12+
unicorn.configs.recommended,
13+
prettierConfig,
14+
{
15+
files: ['**/*.ts', '**/*.js'],
16+
ignores: [
17+
'.eslintrc.js',
18+
'packages/*/lib/',
19+
'packages/*/bin/',
20+
'packages/neovim/scripts/',
21+
'packages/integration-tests/__tests__/',
22+
'examples/rplugin/node/',
23+
'packages/example-plugin/',
24+
'packages/example-plugin-decorators/',
25+
],
26+
languageOptions: {
27+
parser: typescriptParser,
28+
parserOptions: {
29+
project: './tsconfig.json',
30+
ecmaVersion: 'latest',
31+
sourceType: 'module',
32+
},
33+
globals: {
34+
...globals.node,
35+
...globals.es2020,
36+
...globals.mocha,
37+
},
38+
},
39+
plugins: {
40+
import: importPlugin,
41+
},
42+
settings: {
43+
'import/resolver': { node: { extensions: ['.js', '.jsx', '.ts'] } },
44+
},
45+
reportUnusedDisableDirectives: true,
46+
rules: {
47+
curly: 'error', // Enforce braces on "if"/"for"/etc.
48+
// Avoid accidental use of "==" instead of "===".
49+
eqeqeq: 'error',
50+
camelcase: ['error', { properties: 'never' }],
51+
'class-methods-use-this': 'off',
52+
'comma-dangle': [
53+
'error',
54+
{
55+
arrays: 'only-multiline',
56+
objects: 'only-multiline',
57+
imports: 'only-multiline',
58+
exports: 'only-multiline',
59+
functions: 'ignore',
60+
},
61+
],
62+
'no-restricted-syntax': 'off',
63+
'no-case-declarations': 'off',
64+
'no-prototype-builtins': 'off',
65+
'no-underscore-dangle': 'off',
66+
'no-mixed-operators': 'off',
67+
'func-names': 'off',
68+
'max-classes-per-file': 'off',
69+
'operator-assignment': ['error', 'never'],
70+
71+
// For overloading (and typescript throws when dupe members anyway)
72+
'no-dupe-class-members': 'off',
73+
74+
// Causes issues with enums
75+
'no-shadow': 'off',
76+
'prefer-destructuring': 'off', // Intentionally disabled trash.
77+
78+
'import/extensions': 'off',
79+
'import/prefer-default-export': 'off',
80+
81+
'@typescript-eslint/no-namespace': 'error',
82+
// TODO: '@typescript-eslint/no-floating-promises': 'error', // Promises must catch errors or be awaited.
83+
// TODO? '@typescript-eslint/no-unsafe-assignment': 'error',
84+
// TODO? '@typescript-eslint/no-unsafe-return': 'error',
85+
// TODO? '@typescript-eslint/no-unsafe-call': 'error',
86+
'@typescript-eslint/no-explicit-any': 'off',
87+
'@typescript-eslint/explicit-member-accessibility': 'off',
88+
'@typescript-eslint/no-unused-vars': 'error',
89+
'@typescript-eslint/no-empty-function': 'off',
90+
'@typescript-eslint/explicit-function-return-type': 'off',
91+
'@typescript-eslint/ban-types': 'off',
92+
'@typescript-eslint/explicit-module-boundary-types': 'off',
93+
94+
// Rules from https://github.com/sindresorhus/eslint-plugin-unicorn
95+
// TODO: 'unicorn/no-useless-promise-resolve-reject': 'error',
96+
// TODO: 'unicorn/prefer-event-target': 'error',
97+
// TODO: 'unicorn/prefer-string-slice': 'error',
98+
// TODO? 'unicorn/custom-error-definition': 'error',
99+
// TODO? 'unicorn/prefer-json-parse-buffer': 'error',
100+
// TODO? ESM modules https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-module.md
101+
// 'unicorn/prefer-module': 'error',
102+
// 'unicorn/no-null': 'error',
103+
'unicorn/no-abusive-eslint-disable': 'error',
104+
'unicorn/prefer-at': 'error',
105+
'unicorn/prefer-negative-index': 'error',
106+
'unicorn/prefer-regexp-test': 'error',
107+
'unicorn/prefer-ternary': 'error',
108+
'unicorn/no-unnecessary-polyfills': 'error',
109+
'unicorn/no-useless-spread': 'error',
110+
'unicorn/prefer-array-some': 'error',
111+
'unicorn/prefer-blob-reading-methods': 'error',
112+
'unicorn/prefer-code-point': 'error',
113+
'unicorn/prefer-date-now': 'error',
114+
'unicorn/prefer-dom-node-text-content': 'error',
115+
'unicorn/prefer-includes': 'error',
116+
'unicorn/prefer-keyboard-event-key': 'error',
117+
'unicorn/prefer-modern-dom-apis': 'error',
118+
'unicorn/prefer-modern-math-apis': 'error',
119+
'unicorn/prefer-native-coercion-functions': 'error',
120+
'unicorn/prefer-node-protocol': 'error',
121+
'unicorn/prefer-object-from-entries': 'error',
122+
'unicorn/prefer-reflect-apply': 'error',
123+
'unicorn/prefer-string-trim-start-end': 'error',
124+
'unicorn/prefer-type-error': 'error',
125+
},
126+
},
127+
{
128+
files: ['**/*.test.ts'],
129+
rules: {
130+
// This rule requires es2022(?) but the CI node14 job runs the tests
131+
// in node14, but the test code is not compiled/polyfilled... so the
132+
// test code needs to be compatible with node14.
133+
// TODO: can the back-compat CI jobs for older node.js versions run
134+
// `jest` against the compiled .js results (would require compiling
135+
// the test files as well)?
136+
'unicorn/prefer-at': 'off',
137+
'import/no-extraneous-dependencies': [
138+
'error',
139+
{ devDependencies: true, optionalDependencies: false, peerDependencies: false },
140+
],
141+
},
142+
},
143+
];

0 commit comments

Comments
 (0)