Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reformat files with Prettier #2166

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
def67d1
Separate into ESLint and Prettier, starting with JavaScript
shadowspawn Dec 19, 2023
6cf56ec
Add TypeScript back into linting
shadowspawn Dec 19, 2023
e00fed3
Minor lint. Prepare eslint-plugin-jsdoc
shadowspawn Dec 20, 2023
ce6423b
Apply prettier to lint config
shadowspawn Dec 20, 2023
374d552
Rework npm scripts
shadowspawn Dec 20, 2023
c9eb4a1
ESLint and JSDoc experimentation
shadowspawn Dec 20, 2023
8abde1c
Add json to Prettier coverage
shadowspawn Dec 20, 2023
db46519
Add prettier-plugin-jsdoc
shadowspawn Dec 22, 2023
45164ef
Upgrade to typescript-eslint which supports eslint flat configs
shadowspawn Feb 16, 2024
46e8105
Merge remote-tracking branch 'upstream/develop' into feature/prettier
shadowspawn Feb 16, 2024
2805ac5
Update eslint-plugin-jest with flat config
shadowspawn Feb 16, 2024
d5dd138
Use custom tsconfig for TypeScript eslint
shadowspawn Feb 16, 2024
c1461f8
Update eslint related dependencies
shadowspawn Feb 16, 2024
5b51a14
Rename "check" run-script
shadowspawn Feb 18, 2024
511ad59
Add fix run-scripts
shadowspawn Feb 18, 2024
7586f7f
Add typescript-eslint on javascript files, and rework how configured
shadowspawn Feb 23, 2024
be586dd
Comment out jsdoc and prettier for later
shadowspawn Feb 23, 2024
9f1f116
Reorder eslint configs
shadowspawn Feb 23, 2024
4fb3be4
Simplify eslint run-scripts
shadowspawn Feb 23, 2024
d8c3710
Update tests and instructions for script name change
shadowspawn Feb 23, 2024
57e7cad
Update comment
shadowspawn Feb 24, 2024
87c64a5
Add explicit (missing) @example
shadowspawn Mar 1, 2024
b47d056
Using comments in tsconfig*.json so be explicit that they are jsonc f…
shadowspawn Mar 1, 2024
a36df74
Activate all the checks
shadowspawn Mar 7, 2024
487620e
Do not run format checks yet
shadowspawn Mar 7, 2024
18eb11b
Turn on eslint-config-prettier
shadowspawn Mar 8, 2024
552eb26
Reformat files with Prettier
shadowspawn Mar 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 0 additions & 67 deletions .eslintrc.js

This file was deleted.

4 changes: 2 additions & 2 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 10 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const config = {
plugins: ['prettier-plugin-jsdoc'],
singleQuote: true,
overrides: [
{
files: ['tsconfig*.json'],
options: { parser: 'jsonc' },
},
],
};

module.exports = config;
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
75 changes: 75 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -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,
},
],
},
},
];
2 changes: 1 addition & 1 deletion esm.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ export const {
Command,
Argument,
Option,
Help
Help,
} = commander;
2 changes: 1 addition & 1 deletion examples/action-this.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ program
.command('serve')
.argument('<script>')
.option('-p, --port <number>', 'port number', 80)
.action(function() {
.action(function () {
console.error('Run script %s on port %s', this.args[0], this.opts().port);
});

Expand Down
2 changes: 1 addition & 1 deletion examples/arguments-custom-processing.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
const commander = require('../'); // include commander in git clone of commander repo
const program = new commander.Command();

function myParseInt(value, dummyPrevious) {
function myParseInt(value) {
// parseInt takes a string and a radix
const parsedValue = parseInt(value, 10);
if (isNaN(parsedValue)) {
Expand Down
15 changes: 13 additions & 2 deletions examples/arguments-extra.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,19 @@ const commander = require('../'); // include commander in git clone of commander
const program = new commander.Command();

program
.addArgument(new commander.Argument('<drink-size>', 'drink cup size').choices(['small', 'medium', 'large']))
.addArgument(new commander.Argument('[timeout]', 'timeout in seconds').default(60, 'one minute'))
.addArgument(
new commander.Argument('<drink-size>', 'drink cup size').choices([
'small',
'medium',
'large',
]),
)
.addArgument(
new commander.Argument('[timeout]', 'timeout in seconds').default(
60,
'one minute',
),
)
.action((drinkSize, timeout) => {
console.log(`Drink size: ${drinkSize}`);
console.log(`Timeout (s): ${timeout}`);
Expand Down
12 changes: 9 additions & 3 deletions examples/configure-help.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,17 @@ const program = new commander.Command();

program.configureHelp({
sortSubcommands: true,
subcommandTerm: (cmd) => cmd.name() // Just show the name, instead of short usage.
subcommandTerm: (cmd) => cmd.name(), // Just show the name, instead of short usage.
});

program.command('zebra <herd-size>', 'African equines with distinctive black-and-white striped coats');
program.command('aardvark [colour]', 'medium-sized, burrowing, nocturnal mammal');
program.command(
'zebra <herd-size>',
'African equines with distinctive black-and-white striped coats',
);
program.command(
'aardvark [colour]',
'medium-sized, burrowing, nocturnal mammal',
);
program
.command('beaver', 'large, semiaquatic rodent')
.option('--pond')
Expand Down
20 changes: 8 additions & 12 deletions examples/configure-output.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,15 @@ function errorColor(str) {
return `\x1b[31m${str}\x1b[0m`;
}

program
.configureOutput({
// Visibly override write routines as example!
writeOut: (str) => process.stdout.write(`[OUT] ${str}`),
writeErr: (str) => process.stdout.write(`[ERR] ${str}`),
// Output errors in red.
outputError: (str, write) => write(errorColor(str))
});
program.configureOutput({
// Visibly override write routines as example!
writeOut: (str) => process.stdout.write(`[OUT] ${str}`),
writeErr: (str) => process.stdout.write(`[ERR] ${str}`),
// Output errors in red.
outputError: (str, write) => write(errorColor(str)),
});

program
.version('1.2.3')
.option('-c, --compress')
.command('sub-command');
program.version('1.2.3').option('-c, --compress').command('sub-command');

program.parse();

Expand Down
12 changes: 5 additions & 7 deletions examples/custom-command-class.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ class CommandWithTrace extends commander.Command {
cmd.option('-t, --trace', 'display extra information when run command');
return cmd;
}
};
}

function inpectCommand(command) {
// The option value is stored as property on command because we called .storeOptionsAsProperties()
console.log(`Called '${command.name()}'`);
console.log(`args: ${command.args}`);
console.log('opts: %o', command.opts());
};
}

const program = new CommandWithTrace('program')
.option('-v, ---verbose')
Expand All @@ -34,11 +34,9 @@ program
inpectCommand(command);
});

program
.command('build <target>')
.action((buildTarget, options, command) => {
inpectCommand(command);
});
program.command('build <target>').action((buildTarget, options, command) => {
inpectCommand(command);
});

program.parse();

Expand Down
10 changes: 6 additions & 4 deletions examples/custom-help
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
const { Command } = require('../'); // include commander in git clone of commander repo
const program = new Command();

program
.option('-f, --foo', 'enable some foo');
program.option('-f, --foo', 'enable some foo');

program.addHelpText('after', `
program.addHelpText(
'after',
`

Example call:
$ custom-help --help`);
$ custom-help --help`,
);

program.parse(process.argv);

Expand Down
7 changes: 5 additions & 2 deletions examples/custom-help-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ program
program
.command('extra')
.addHelpText('before', 'Note: the extra command does not do anything')
.addHelpText('after', `
.addHelpText(
'after',
`
Examples:
awesome extra --help
awesome help extra`);
awesome help extra`,
);

program.parse();

Expand Down
16 changes: 12 additions & 4 deletions examples/deploy
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,19 @@ program
.option('-e, --exec_mode <mode>', 'Which exec mode to use', 'fast')
.action((script, options) => {
console.log('read config from %s', program.opts().config);
console.log('exec "%s" using %s mode and config %s', script, options.exec_mode, program.opts().config);
}).addHelpText('after', `
console.log(
'exec "%s" using %s mode and config %s',
script,
options.exec_mode,
program.opts().config,
);
})
.addHelpText(
'after',
`
Examples:
$ deploy exec sequential
$ deploy exec async`
$ deploy exec async`,
);

program.parse(process.argv);
Loading