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

Add eslint and prettier #65

Merged
merged 1 commit into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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;
76 changes: 76 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
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}'];
const tsconfigJsFiles = ['**.{js,mjs}'];
const tseslintConfigs = tseslint.config(
{
files: tsconfigJsFiles,
extends: [...tseslint.configs.recommended],
rules: {
'@typescript-eslint/no-var-requires': 'off', // (tseslint does not autodetect commonjs context )
},
},
{
files: tsconfigTsFiles,
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: ['tests/*.{js,mjs,cjs,ts,mts,cts}'],
rules: {
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': 'off',
},
},
{
files: ['tests/*.test-d.ts'],
rules: {
'no-constant-condition': 'off', // using `if ('explanation')` for test blocks
},
},
{
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: 2 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,8 @@ export class CommanderError extends Error {

export type OptionValues = Record<string, unknown>;

// eslint unimpressed with `OptionValues = {}`, but not sure what to use instead.
// eslint-disable-next-line @typescript-eslint/ban-types
export class Command<Args extends any[] = [], Opts extends OptionValues = {}> {
args: string[];
processedArgs: Args;
Expand Down
2 changes: 0 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
const commander = require('commander');

// @ts-check

exports = module.exports = {};

// Return a different global program than commander,
Expand Down
10 changes: 10 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const config = {
testEnvironment: 'node',
collectCoverage: true,
transform: {
'^.+\\.tsx?$': ['ts-jest'],
},
testPathIgnorePatterns: ['/node_modules/'],
};

module.exports = config;
Loading
Loading