Skip to content

Commit da5e8f1

Browse files
authored
Merge #490 deps: update eslint, migrate to "flat" config, drop eslint-config-airbnb
2 parents cfa5495 + 4f74d24 commit da5e8f1

File tree

21 files changed

+2822
-2228
lines changed

21 files changed

+2822
-2228
lines changed

.eslintignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

.eslintrc.js

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

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ jobs:
8080
run: npm run build
8181

8282
- name: lint
83-
# Skip on old Node.js, devDependencies use newish JS features.
84-
if: matrix.node != '14'
83+
# Only run lint on latest Node.js, because devDependencies use new JS features.
84+
if: matrix.node == '20' && runner.os != 'Windows'
8585
run: npm run lint
8686

8787
- name: test

eslint.config.mjs

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

0 commit comments

Comments
 (0)