Skip to content

Commit 6fc933e

Browse files
authored
ESLint changes preparing for Prettier (#2153)
Switch from StandardJS to ESLint using flat configuration. Add Prettier and configuration.
1 parent 41b12cf commit 6fc933e

25 files changed

+1454
-2142
lines changed

.eslintrc.js

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

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ and can be deleted.
66
77
Please submit pull requests against the develop branch.
88
9-
Follow the existing code style. Check the tests succeed, including lint.
9+
Follow the existing code style. Check the tests succeed, including format and lint.
1010
npm run test
11-
npm run lint
11+
npm run check
1212
1313
Don't update the CHANGELOG or command version number. That gets done by maintainers when preparing the release.
1414

.github/workflows/tests.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,6 @@ jobs:
2727
run: npm ci
2828
- name: npm test
2929
run: npm test
30-
- name: npm run lint
31-
run: npm run lint
30+
- name: npm run check:lint
31+
# switch to full check when have run prettier on all files
32+
run: npm run check:lint

.prettierignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# exclude everything, and opt-in to types we want to format
2+
**.*
3+
# add the filetypes we want to format
4+
!**.js
5+
!**.mjs
6+
!**.cjs
7+
!**.ts
8+
!**.mts
9+
!**.cts
10+
!**.json

.prettierrc.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const config = {
2+
// plugins: ['prettier-plugin-jsdoc'],
3+
singleQuote: true,
4+
overrides: [
5+
{
6+
files: ['tsconfig*.json'],
7+
options: { parser: 'jsonc' },
8+
},
9+
],
10+
};
11+
12+
module.exports = config;

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ or after six months otherwise.
1414

1515
Pull Requests will be considered. Please submit pull requests against the develop branch.
1616

17-
Follow the existing code style. Check the tests succeed, including lint.
17+
Follow the existing code style. Check the tests succeed, including format and lint.
1818

1919
- `npm run test`
20-
- `npm run lint`
20+
- `npm run check`
2121

2222
Don't update the CHANGELOG or command version number. That gets done by maintainers when preparing the release.
2323

eslint.config.js

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
const globals = require('globals');
2+
const esLintjs = require('@eslint/js');
3+
const jest = require('eslint-plugin-jest');
4+
const tseslint = require('typescript-eslint');
5+
const prettier = require('eslint-config-prettier');
6+
//const jsdoc = require('eslint-plugin-jsdoc');
7+
8+
// Using tseslint config helper to customise its setup the tseslint way.
9+
const tsconfigTsFiles = ['**/*.{ts,mts}']; // match "include" in tsconfig.ts.json;
10+
const tsconfigJsFiles = ['*.{js,mjs}', 'lib/**/*.{js,mjs}']; // match "include" in tsconfig.js.json
11+
const tseslintConfigs = tseslint.config(
12+
{
13+
files: tsconfigJsFiles,
14+
languageOptions: {
15+
parserOptions: { project: './tsconfig.js.json' },
16+
},
17+
extends: [
18+
...tseslint.configs.recommended,
19+
],
20+
rules: {
21+
'@typescript-eslint/no-var-requires': 'off', // (tseslint does not autodetect commonjs context )
22+
},
23+
}, {
24+
files: tsconfigTsFiles,
25+
languageOptions: {
26+
parserOptions: { project: './tsconfig.ts.json' },
27+
},
28+
extends: [
29+
...tseslint.configs.recommended,
30+
],
31+
},
32+
);
33+
34+
module.exports = [
35+
esLintjs.configs.recommended,
36+
// jsdoc.configs['flat/recommended'],
37+
jest.configs['flat/recommended'],
38+
...tseslintConfigs,
39+
prettier, // Do Prettier last so it can override previous configs.
40+
41+
// Customise rules.
42+
{
43+
files: ['**/*.{js,mjs,cjs}', '**/*.{ts,mts,cts}'],
44+
rules: {
45+
'no-else-return': ['error', { allowElseIf: false }],
46+
47+
// 'jsdoc/tag-lines': 'off',
48+
// 'jsdoc/require-jsdoc': 'off',
49+
// 'jsdoc/require-param-description': 'off',
50+
// 'jsdoc/require-returns-description': 'off',
51+
},
52+
languageOptions: {
53+
globals: {
54+
...globals.node,
55+
},
56+
},
57+
},
58+
{
59+
files: ['**/*.test.{js,mjs,cjs}'],
60+
rules: {
61+
'no-unused-vars': 'off', // lots in tests, minimise churn for now
62+
}
63+
},
64+
{
65+
files: [...tsconfigTsFiles, ...tsconfigJsFiles],
66+
rules: {
67+
'@typescript-eslint/ban-ts-comment': ['error', {
68+
'ts-expect-error': 'allow-with-description',
69+
'ts-ignore': 'allow-with-description',
70+
'ts-nocheck': true,
71+
'ts-check': true,
72+
}],
73+
},
74+
},
75+
];

examples/arguments-custom-processing.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
const commander = require('commander');
88
const program = new commander.Command();
99

10-
function myParseInt(value, dummyPrevious) {
10+
function myParseInt(value) {
1111
// parseInt takes a string and a radix
1212
const parsedValue = parseInt(value, 10);
1313
if (isNaN(parsedValue)) {

examples/custom-command-class.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ class CommandWithTrace extends commander.Command {
1010
cmd.option('-t, --trace', 'display extra information when run command');
1111
return cmd;
1212
}
13-
};
13+
}
1414

1515
function inpectCommand(command) {
1616
// The option value is stored as property on command because we called .storeOptionsAsProperties()
1717
console.log(`Called '${command.name()}'`);
1818
console.log(`args: ${command.args}`);
1919
console.log('opts: %o', command.opts());
20-
};
20+
}
2121

2222
const program = new CommandWithTrace('program')
2323
.option('-v, ---verbose')

examples/options-custom-processing.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
const commander = require('commander');
88
const program = new commander.Command();
99

10-
function myParseInt(value, dummyPrevious) {
10+
function myParseInt(value) {
1111
// parseInt takes a string and a radix
1212
const parsedValue = parseInt(value, 10);
1313
if (isNaN(parsedValue)) {
@@ -24,7 +24,7 @@ function collect(value, previous) {
2424
return previous.concat([value]);
2525
}
2626

27-
function commaSeparatedList(value, dummyPrevious) {
27+
function commaSeparatedList(value) {
2828
return value.split(',');
2929
}
3030

0 commit comments

Comments
 (0)