Skip to content

Commit ef06f05

Browse files
committed
build: migrate to eslint "flat" config
remove airbnb, update eslint
1 parent 0182751 commit ef06f05

File tree

18 files changed

+89
-65
lines changed

18 files changed

+89
-65
lines changed

.eslintignore

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

eslint.config.mjs

Lines changed: 40 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,23 @@
1-
import js from '@eslint/js';
21
import globals from 'globals';
32
import typescriptEslint from '@typescript-eslint/eslint-plugin';
43
import typescriptParser from '@typescript-eslint/parser';
54
import unicorn from 'eslint-plugin-unicorn';
65
import importPlugin from 'eslint-plugin-import';
7-
import prettierConfig from 'eslint-config-prettier/flat';
86

97
export default [
10-
js.configs.recommended,
11-
typescriptEslint.configs.recommended,
12-
unicorn.configs.recommended,
13-
prettierConfig,
148
{
15-
files: ['**/*.ts', '**/*.js'],
9+
files: ['packages/neovim/bin/cli.js', '**/*.ts'],
1610
ignores: [
11+
'**/*.d.ts',
1712
'.eslintrc.js',
18-
'packages/*/lib/',
19-
'packages/*/bin/',
13+
'packages/*/lib/**',
14+
'packages/*/bin/**',
2015
'packages/neovim/scripts/',
2116
'packages/integration-tests/__tests__/',
22-
'examples/rplugin/node/',
23-
'packages/example-plugin/',
24-
'packages/example-plugin-decorators/',
17+
'__tests__/integration/rplugin/node/',
18+
'examples/rplugin/node/**',
19+
'packages/example-plugin/**',
20+
'packages/example-plugin-decorators/**',
2521
],
2622
languageOptions: {
2723
parser: typescriptParser,
@@ -37,15 +33,16 @@ export default [
3733
},
3834
},
3935
plugins: {
36+
'@typescript-eslint': typescriptEslint,
37+
unicorn,
4038
import: importPlugin,
4139
},
42-
settings: {
43-
'import/resolver': { node: { extensions: ['.js', '.jsx', '.ts'] } },
40+
linterOptions: {
41+
reportUnusedDisableDirectives: true,
4442
},
45-
reportUnusedDisableDirectives: true,
4643
rules: {
47-
curly: 'error', // Enforce braces on "if"/"for"/etc.
48-
// Avoid accidental use of "==" instead of "===".
44+
curly: 'error', // Enforce braces on "if"/"for"/etc.
45+
// Avoid accidental use of "==" instead of "===".
4946
eqeqeq: 'error',
5047
camelcase: ['error', { properties: 'never' }],
5148
'class-methods-use-this': 'off',
@@ -68,21 +65,30 @@ export default [
6865
'max-classes-per-file': 'off',
6966
'operator-assignment': ['error', 'never'],
7067

71-
// For overloading (and typescript throws when dupe members anyway)
68+
// For overloading (and typescript throws when dupe members anyway)
7269
'no-dupe-class-members': 'off',
7370

74-
// Causes issues with enums
71+
// Causes issues with enums
7572
'no-shadow': 'off',
76-
'prefer-destructuring': 'off', // Intentionally disabled trash.
73+
'prefer-destructuring': 'off', // Intentionally disabled trash.
7774

7875
'import/extensions': 'off',
7976
'import/prefer-default-export': 'off',
8077

78+
'global-require': 'error',
79+
'import/no-extraneous-dependencies': 'error',
80+
'import/no-mutable-exports': 'error',
81+
'new-cap': 'error',
82+
'no-console': 'error',
83+
'no-param-reassign': ['error', { props: true }],
84+
'no-void': 'error',
85+
86+
'@typescript-eslint/no-misused-new': 'error',
8187
'@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',
88+
// TODO: '@typescript-eslint/no-floating-promises': 'error', // Promises must catch errors or be awaited.
89+
// TODO? '@typescript-eslint/no-unsafe-assignment': 'error',
90+
// TODO? '@typescript-eslint/no-unsafe-return': 'error',
91+
// TODO? '@typescript-eslint/no-unsafe-call': 'error',
8692
'@typescript-eslint/no-explicit-any': 'off',
8793
'@typescript-eslint/explicit-member-accessibility': 'off',
8894
'@typescript-eslint/no-unused-vars': 'error',
@@ -91,15 +97,15 @@ export default [
9197
'@typescript-eslint/ban-types': 'off',
9298
'@typescript-eslint/explicit-module-boundary-types': 'off',
9399

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',
100+
// Rules from https://github.com/sindresorhus/eslint-plugin-unicorn
101+
// TODO: 'unicorn/no-useless-promise-resolve-reject': 'error',
102+
// TODO: 'unicorn/prefer-event-target': 'error',
103+
// TODO: 'unicorn/prefer-string-slice': 'error',
104+
// TODO? 'unicorn/custom-error-definition': 'error',
105+
// TODO? 'unicorn/prefer-json-parse-buffer': 'error',
106+
// TODO? ESM modules https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-module.md
107+
// 'unicorn/prefer-module': 'error',
108+
// 'unicorn/no-null': 'error',
103109
'unicorn/no-abusive-eslint-disable': 'error',
104110
'unicorn/prefer-at': 'error',
105111
'unicorn/prefer-negative-index': 'error',
@@ -134,6 +140,7 @@ export default [
134140
// `jest` against the compiled .js results (would require compiling
135141
// the test files as well)?
136142
'unicorn/prefer-at': 'off',
143+
'new-cap': 'off',
137144
'import/no-extraneous-dependencies': [
138145
'error',
139146
{ devDependencies: true, optionalDependencies: false, peerDependencies: false },

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
"test-staged": "npm run test-staged --workspaces --if-present -- --",
3333
"test-missing-apis": "npm run test-missing-apis --workspaces --if-present",
3434
"test-lint": "npm run lint",
35-
"lint": "prettier --check . && eslint --format=unix .",
36-
"fixlint": "prettier --write . && eslint --fix --format=unix ."
35+
"lint": "prettier --check . && eslint --format=unix --ignore-pattern 'packages/example*/**' --ignore-pattern 'packages/neovim/lib/**/*.js' .",
36+
"fixlint": "prettier --write . && eslint --fix --format=unix --ignore-pattern 'packages/example*/**' --ignore-pattern 'packages/neovim/lib/**/*.js' ."
3737
},
3838
"husky": {
3939
"hooks": {

packages/integration-tests/__tests__/integration.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ describe('Node host', () => {
6262

6363
it('console.log is monkey-patched to logger.info #329', async () => {
6464
const spy = jestMock.spyOn(nvim.logger, 'info');
65+
// eslint-disable-next-line no-console
6566
console.log('log message');
6667
expect(spy).toHaveBeenCalledWith('log message');
6768
// Still alive?

packages/neovim/bin/cli.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
#!/usr/bin/env node
22
const { Host } = require('../lib/host');
3-
const { spawnSync } = require('child_process');
3+
const { spawnSync } = require('node:child_process');
44

55
// node <current script> <rest of args>
66
const [, , ...args] = process.argv;
77

88
if (args[0] === '--version') {
9-
// eslint-disable-next-line global-require
109
const pkg = require('../package.json');
11-
// eslint-disable-next-line no-console
1210
console.log(pkg.version);
1311
process.exit(0);
1412
}

packages/neovim/scripts/api.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ async function main() {
55
const nvim = await require('./nvim');
66
const results = await nvim.requestApi();
77
const { functions } = results[1];
8-
const lines = functions.filter(({ name }) => name.indexOf(search) > -1);
8+
const lines = functions.filter(({ name }) => name.includes(search));
99
lines
1010
.filter(metadata => typeof metadata.deprecated_since === 'undefined')
1111
.forEach(metadata => {

packages/neovim/scripts/findMissingApi.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ const hasApiMethod = name => {
5656
const descriptor = Object.getOwnPropertyDescriptor(Constructor.prototype, methodName);
5757

5858
// check property descriptors
59-
if (descriptor && ((isSetter && descriptor.set) || (isGetter && descriptor.get))) return true;
59+
if (descriptor && ((isSetter && descriptor.set) || (isGetter && descriptor.get))) {
60+
return true;
61+
}
6062

6163
// check methods
6264
if (
@@ -82,7 +84,7 @@ async function main() {
8284
const nvim = await require('./nvim');
8385
const results = await nvim.requestApi();
8486
const { functions } = results[1];
85-
const lines = functions.filter(({ name }) => name.indexOf(search) > -1);
87+
const lines = functions.filter(({ name }) => name.includes(search));
8688
const missing = lines
8789
.filter(metadata => typeof metadata.deprecated_since === 'undefined')
8890
.filter(metadata => !hasApiMethod(metadata.name));

packages/neovim/bin/generate-typescript-interfaces.js renamed to packages/neovim/scripts/generate-typescript-interfaces.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const cp = require('child_process');
1+
const cp = require('node:child_process');
22
const { attach } = require('../lib/attach');
33

44
const proc = cp.spawn('nvim', ['-u', 'NONE', '--embed', '-n'], {
@@ -14,11 +14,15 @@ const typeMap = {
1414
};
1515

1616
function convertType(type) {
17-
if (typeMap[type]) return typeMap[type];
17+
if (typeMap[type]) {
18+
return typeMap[type];
19+
}
1820
const genericMatch = /Of\((\w+)[^)]*\)/.exec(type);
1921
if (genericMatch) {
2022
const t = convertType(genericMatch[1]);
21-
if (/^Array/.test(type)) return `Array<${t}>`;
23+
if (/^Array/.test(type)) {
24+
return `Array<${t}>`;
25+
}
2226
return `{ [key: string]: ${t}; }`;
2327
}
2428
return type;
@@ -34,7 +38,7 @@ function metadataToSignature(method) {
3438
params.push(`${method.parameters[i]}: ${type}`);
3539
});
3640
const rtype = convertType(method.returnType);
37-
// eslint-disable-next-line
41+
3842
const returnTypeString = rtype === 'void' ? rtype : `Promise<${rtype}>`;
3943
return ` ${method.name}(${params.join(', ')}): ${returnTypeString};\n`;
4044
}
@@ -85,7 +89,6 @@ async function main() {
8589
try {
8690
main();
8791
} catch (err) {
88-
// eslint-disable-next-line no-console
8992
console.error(err);
9093
process.exit(1);
9194
}

packages/neovim/scripts/nvim.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Spawns an embedded neovim instance and returns Neovim API
55
*/
66

7-
const cp = require('child_process');
7+
const cp = require('node:child_process');
88
const { attach } = require('../');
99
// const inspect = require('util').inspect;
1010

packages/neovim/src/api/Base.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export class BaseApi extends EventEmitter {
5555
equals(other: BaseApi): boolean {
5656
try {
5757
return String(this.data) === String(other.data);
58-
} catch (e) {
58+
} catch {
5959
return false;
6060
}
6161
}

0 commit comments

Comments
 (0)