diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 07d28ed76..000000000 --- a/.eslintrc.js +++ /dev/null @@ -1,67 +0,0 @@ -const javascriptSettings = { - files: ['*.js', '*.mjs'], - extends: [ - 'standard', - 'plugin:jest/recommended' - ], - rules: { - 'no-else-return': ['error', { allowElseIf: false }], - 'space-before-function-paren': ['error', 'never'], - // manual "semistandard" settings - semi: ['error', 'always'], - 'no-extra-semi': 'error' - } -}; - -const typescriptSettings = { - files: ['*.ts', '*.mts'], - parserOptions: { - project: './tsconfig.ts.json' - }, - plugins: [ - '@typescript-eslint' - ], - extends: [ - 'standard-with-typescript' - ], - rules: { - 'no-else-return': ['error', { allowElseIf: false }], - 'space-before-function-paren': 'off', - '@typescript-eslint/space-before-function-paren': ['error', 'never'], - '@typescript-eslint/member-delimiter-style': [ - 'error', - { - multiline: { - delimiter: 'semi', - requireLast: true - }, - singleline: { - delimiter: 'semi', - requireLast: false - } - } - ], - // manual "semistandard" settings - semi: 'off', - '@typescript-eslint/semi': ['error', 'always'], - 'no-extra-semi': 'off', - '@typescript-eslint/no-extra-semi': ['error'] - } -}; - -module.exports = { - plugins: ['jest'], - parserOptions: { - ecmaVersion: 8 - }, - overrides: [ - javascriptSettings, - typescriptSettings, - { - files: ['*.mjs'], - parserOptions: { - sourceType: 'module' - } - } - ] -}; diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 1323b94ff..b901673ae 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -6,9 +6,9 @@ and can be deleted. Please submit pull requests against the develop branch. -Follow the existing code style. Check the tests succeed, including lint. +Follow the existing code style. Check the tests succeed, including format and lint. npm run test - npm run lint + npm run check Don't update the CHANGELOG or command version number. That gets done by maintainers when preparing the release. diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 5f836193d..5c70079b1 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -27,5 +27,6 @@ jobs: run: npm ci - name: npm test run: npm test - - name: npm run lint - run: npm run lint + - name: npm run check:lint + # switch to full check when have run prettier on all files + run: npm run check:lint diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 000000000..78a5a22d2 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,10 @@ +# exclude everything, and opt-in to types we want to format +**.* +# add the filetypes we want to format +!**.js +!**.mjs +!**.cjs +!**.ts +!**.mts +!**.cts +!**.json diff --git a/.prettierrc.js b/.prettierrc.js new file mode 100644 index 000000000..30eb528d1 --- /dev/null +++ b/.prettierrc.js @@ -0,0 +1,12 @@ +const config = { + plugins: ['prettier-plugin-jsdoc'], + singleQuote: true, + overrides: [ + { + files: ['tsconfig*.json'], + options: { parser: 'jsonc' }, + }, + ], +}; + +module.exports = config; diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f11d40397..e00e59ac1 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -14,10 +14,10 @@ or after six months otherwise. Pull Requests will be considered. Please submit pull requests against the develop branch. -Follow the existing code style. Check the tests succeed, including lint. +Follow the existing code style. Check the tests succeed, including format and lint. - `npm run test` -- `npm run lint` +- `npm run check` Don't update the CHANGELOG or command version number. That gets done by maintainers when preparing the release. diff --git a/eslint.config.js b/eslint.config.js new file mode 100644 index 000000000..79a37bd19 --- /dev/null +++ b/eslint.config.js @@ -0,0 +1,75 @@ +const globals = require('globals'); +const esLintjs = require('@eslint/js'); +const jest = require('eslint-plugin-jest'); +const tseslint = require('typescript-eslint'); +const prettier = require('eslint-config-prettier'); +//const jsdoc = require('eslint-plugin-jsdoc'); + +// Using tseslint config helper to customise its setup the tseslint way. +const tsconfigTsFiles = ['**/*.{ts,mts}']; // match "include" in tsconfig.ts.json; +const tsconfigJsFiles = ['*.{js,mjs}', 'lib/**/*.{js,mjs}']; // match "include" in tsconfig.js.json +const tseslintConfigs = tseslint.config( + { + files: tsconfigJsFiles, + languageOptions: { + parserOptions: { project: './tsconfig.js.json' }, + }, + extends: [...tseslint.configs.recommended], + rules: { + '@typescript-eslint/no-var-requires': 'off', // (tseslint does not autodetect commonjs context ) + }, + }, + { + files: tsconfigTsFiles, + languageOptions: { + parserOptions: { project: './tsconfig.ts.json' }, + }, + extends: [...tseslint.configs.recommended], + }, +); + +module.exports = [ + esLintjs.configs.recommended, + // jsdoc.configs['flat/recommended'], + jest.configs['flat/recommended'], + ...tseslintConfigs, + prettier, // Do Prettier last so it can override previous configs. + + // Customise rules. + { + files: ['**/*.{js,mjs,cjs}', '**/*.{ts,mts,cts}'], + rules: { + 'no-else-return': ['error', { allowElseIf: false }], + + // 'jsdoc/tag-lines': 'off', + // 'jsdoc/require-jsdoc': 'off', + // 'jsdoc/require-param-description': 'off', + // 'jsdoc/require-returns-description': 'off', + }, + languageOptions: { + globals: { + ...globals.node, + }, + }, + }, + { + files: ['**/*.test.{js,mjs,cjs}'], + rules: { + 'no-unused-vars': 'off', // lots in tests, minimise churn for now + }, + }, + { + files: [...tsconfigTsFiles, ...tsconfigJsFiles], + rules: { + '@typescript-eslint/ban-ts-comment': [ + 'error', + { + 'ts-expect-error': 'allow-with-description', + 'ts-ignore': 'allow-with-description', + 'ts-nocheck': true, + 'ts-check': true, + }, + ], + }, + }, +]; diff --git a/esm.mjs b/esm.mjs index e7190a1b8..796ec3a58 100644 --- a/esm.mjs +++ b/esm.mjs @@ -12,5 +12,5 @@ export const { Command, Argument, Option, - Help + Help, } = commander; diff --git a/examples/action-this.js b/examples/action-this.js index 1ff286c4e..45c7efa3c 100644 --- a/examples/action-this.js +++ b/examples/action-this.js @@ -10,7 +10,7 @@ program .command('serve') .argument('