chore: Depend on external eslint package

This commit is contained in:
Joachim Van Herwegen 2024-07-18 14:48:33 +02:00
parent ecd031e69f
commit 46f5fc239e
8 changed files with 27 additions and 380 deletions

View File

@ -1,19 +1,6 @@
const antfu = require('@antfu/eslint-config');
const fileNamesConfig = require('./eslint/file-names');
const generalConfig = require('./eslint/general');
const testConfig = require('./eslint/test');
const typedConfig = require('./eslint/typed');
const unicornConfig = require('./eslint/unicorn');
const opinionated = require('opinionated-eslint-config');
// The default ignore list contains all `output` folders, which conflicts with our src/http/output folder
// See https://github.com/antfu/eslint-config/blob/7071af7024335aad319a91db41ce594ebc6a0899/src/globs.ts#L55
const index = antfu.GLOB_EXCLUDE.indexOf('**/output');
if (index < 0) {
throw new Error('Could not update GLOB_EXCLUDE. Check if antfu changed how it handles ignores.');
}
antfu.GLOB_EXCLUDE.splice(index, 1);
module.exports = antfu.default(
module.exports = opinionated(
{
// Don't want to lint test assets, or TS snippets in markdown files
ignores: [ 'test/assets/*', '**/*.md' ],
@ -21,36 +8,4 @@ module.exports = antfu.default(
tsconfigPath: [ './tsconfig.json', './scripts/tsconfig.json', './test/tsconfig.json' ],
},
},
)
.append(generalConfig)
.append(unicornConfig)
.append(fileNamesConfig)
// Using an override here so all the type settings are also applied correctly
.override('antfu/typescript/rules-type-aware', typedConfig)
.append({
...testConfig,
files: [ 'test/**/*.ts' ],
})
.override('antfu/jsonc/rules', {
rules: {
// Consistent with how we do it in code
'jsonc/array-bracket-spacing': [ 'error', 'always', {
singleValue: true,
objectsInArrays: false,
arraysInArrays: false,
}],
},
})
.append({
// This is necessary to prevent filename checks caused by JSON being present in a README.
files: [ '**/README.md/**' ],
rules: {
'unicorn/filename-case': 'off',
},
})
.override('antfu/markdown/parser', {
rules: {
// We want to be able to use these in Markdown text
'no-irregular-whitespace': 'off',
},
});
);

View File

@ -1,33 +0,0 @@
module.exports = [
{
name: 'opinionated/file-names/all',
rules: {
'unicorn/filename-case': [ 'error', {
cases: {
camelCase: false,
pascalCase: false,
kebabCase: true,
snakeCase: false,
},
ignore: [
// CODE_OF_CONDUCT.md, etc.
/[A-Z_]+\.md$/u,
],
}],
},
},
{
name: 'opinionated/file-names/ts',
files: [ '**/*.ts' ],
rules: {
'unicorn/filename-case': [ 'error', {
cases: {
camelCase: true,
pascalCase: true,
kebabCase: false,
snakeCase: false,
},
}],
},
},
];

View File

@ -1,136 +0,0 @@
module.exports = {
name: 'opinionated/general',
rules: {
'antfu/consistent-list-newline': 'error',
'arrow-body-style': [ 'error', 'as-needed', { requireReturnForObjectLiteral: false }],
'capitalized-comments': [ 'error', 'always', { ignoreConsecutiveComments: true }],
'callback-return': 'error',
'consistent-this': 'error',
curly: [ 'error', 'all' ],
'default-case': 'error',
eqeqeq: [ 'error', 'always' ],
'for-direction': 'error',
'func-style': [ 'error', 'declaration' ],
'function-call-argument-newline': [ 'error', 'consistent' ],
'function-paren-newline': [ 'error', 'consistent' ],
'getter-return': [ 'error', { allowImplicit: true }],
'global-require': 'error',
'grouped-accessor-pairs': [ 'error', 'getBeforeSet' ],
'guard-for-in': 'error',
'line-comment-position': [ 'error', { position: 'above' }],
'linebreak-style': [ 'error', 'unix' ],
'multiline-comment-style': [ 'error', 'separate-lines' ],
// Need to override `allow` value
'no-console': [ 'error', { allow: [ '' ]}],
'no-constructor-return': 'error',
'no-dupe-else-if': 'error',
'no-else-return': [ 'error', { allowElseIf: false }],
'no-implicit-coercion': 'error',
'no-implicit-globals': 'error',
'no-lonely-if': 'error',
'no-plusplus': [ 'error', { allowForLoopAfterthoughts: true }],
'no-sync': [ 'error', { allowAtRootLevel: false }],
'no-useless-concat': 'error',
'no-useless-escape': 'error',
'operator-assignment': [ 'error', 'always' ],
'prefer-object-spread': 'error',
radix: 'error',
'require-unicode-regexp': 'error',
'require-yield': 'error',
'sort-imports': [
'error',
{
allowSeparatedGroups: false,
ignoreCase: true,
ignoreDeclarationSort: true,
ignoreMemberSort: false,
memberSyntaxSortOrder: [ 'none', 'all', 'multiple', 'single' ],
},
],
'import/extensions': 'error',
'import/no-extraneous-dependencies': 'error',
'jsdoc/tag-lines': [ 'error', 'any', { startLines: 1 }],
'jsdoc/no-multi-asterisks': [ 'error', { allowWhitespace: true }],
'jsdoc/no-types': 'error',
'jsdoc/sort-tags': [ 'error', {
tagSequence: [
{ tags: [ 'param' ]},
{ tags: [ 'returns' ]},
{ tags: [ 'throws' ]},
],
}],
'jsdoc/valid-types': 'error',
'node/prefer-global/buffer': [ 'error', 'always' ],
'node/prefer-global/console': [ 'error', 'always' ],
'node/prefer-global/process': [ 'error', 'always' ],
'node/prefer-global/url': [ 'error', 'always' ],
'style/array-bracket-spacing': [ 'error', 'always', {
singleValue: true,
objectsInArrays: false,
arraysInArrays: false,
}],
// Conflicts with style/object-curly-spacing
'style/block-spacing': 'off',
'style/brace-style': [ 'error', '1tbs', { allowSingleLine: false }],
'style/generator-star-spacing': [ 'error', { before: false, after: true }],
'style/indent-binary-ops': 'error',
'style/member-delimiter-style': [ 'error', {
multiline: { delimiter: 'semi', requireLast: true },
singleline: { delimiter: 'semi', requireLast: false },
}],
'style/no-extra-parens': [ 'error', 'all', {
// To prevent conflicts with style/no-mixed-operators
nestedBinaryExpressions: false,
}],
'style/object-curly-spacing': [ 'error', 'always', {
objectsInObjects: false,
arraysInObjects: false,
}],
'style/operator-linebreak': [ 'error', 'after' ],
'style/semi': [ 'error', 'always' ],
'style/semi-style': [ 'error', 'last' ],
'style/space-before-function-paren': [ 'error', 'never' ],
'style/switch-colon-spacing': 'error',
'style/quote-props': [ 'error', 'as-needed', {
keywords: false,
unnecessary: true,
numbers: false,
}],
'style/yield-star-spacing': [ 'error', 'after' ],
'ts/adjacent-overload-signatures': 'error',
'ts/array-type': 'error',
'ts/ban-ts-comment': [ 'error', {
'ts-expect-error': true,
}],
'ts/consistent-indexed-object-style': [ 'error', 'record' ],
'ts/consistent-type-definitions': 'off',
'ts/explicit-member-accessibility': 'error',
'ts/method-signature-style': 'error',
'ts/no-confusing-non-null-assertion': 'error',
'ts/no-explicit-any': 'error',
'ts/no-extraneous-class': [ 'error', {
allowConstructorOnly: false,
allowEmpty: false,
allowStaticOnly: false,
}],
'ts/no-inferrable-types': [ 'error', {
ignoreParameters: false,
ignoreProperties: false,
}],
'ts/prefer-for-of': 'error',
'ts/prefer-function-type': 'error',
// Only need 1 unused vars rule
'no-unused-vars': 'off',
'unused-imports/no-unused-vars': [
'error',
{ args: 'after-used', vars: 'all', ignoreRestSiblings: true },
],
},
};

View File

@ -1,47 +0,0 @@
const jest = require('eslint-plugin-jest');
// Specifically for tests
module.exports = {
name: 'opinionated/test',
// See https://github.com/jest-community/eslint-plugin-jest/issues/1408
plugins: {
jest,
},
rules: {
...jest.configs.all.rules,
// Rule is not smart enough to check called function in the test
'jest/expect-expect': 'off',
'jest/valid-title': [ 'error', {
mustNotMatch: {
describe: /\.$/u.source,
},
mustMatch: {
it: /\.$/u.source,
},
}],
// Default rules that are overkill
'jest/no-hooks': 'off',
'jest/max-expects': 'off',
'jest/no-conditional-in-test': 'off',
'jest/prefer-expect-assertions': 'off',
'jest/prefer-importing-jest-globals': 'off',
'jest/prefer-lowercase-title': 'off',
'jest/prefer-strict-equal': 'off',
'jest/require-hook': 'off',
'test/prefer-lowercase-title': 'off',
'ts/naming-convention': 'off',
'ts/no-explicit-any': 'off',
'ts/no-unsafe-argument': 'off',
'ts/no-unsafe-assignment': 'off',
'ts/no-unsafe-call': 'off',
'ts/no-unsafe-member-access': 'off',
'ts/no-unsafe-return': 'off',
'ts/unbound-method': 'off',
// Incorrectly detects usage of undefined in "toHaveBeenLastCalledWith" checks
'unicorn/no-useless-undefined': 'off',
},
};

View File

@ -1,57 +0,0 @@
module.exports = {
name: 'opinionated/typed',
rules: {
'ts/consistent-type-assertions': [ 'error', {
assertionStyle: 'as',
}],
'ts/naming-convention': [
'error',
{
selector: 'default',
format: [ 'camelCase' ],
leadingUnderscore: 'forbid',
trailingUnderscore: 'forbid',
},
{
selector: 'import',
format: null,
},
{
selector: 'variable',
format: [ 'camelCase', 'UPPER_CASE' ],
leadingUnderscore: 'forbid',
trailingUnderscore: 'forbid',
},
{
selector: 'typeLike',
format: [ 'PascalCase' ],
},
{
selector: [ 'typeParameter' ],
format: [ 'PascalCase' ],
prefix: [ 'T' ],
},
],
'ts/explicit-function-return-type': [ 'error', {
allowExpressions: false,
allowTypedFunctionExpressions: false,
allowHigherOrderFunctions: false,
}],
'ts/no-base-to-string': 'error',
'ts/no-floating-promises': [ 'error', { ignoreVoid: false }],
'ts/promise-function-async': 'error',
'ts/no-unnecessary-boolean-literal-compare': 'error',
'ts/no-unnecessary-qualifier': 'error',
'ts/prefer-nullish-coalescing': 'error',
'ts/prefer-readonly': 'error',
'ts/prefer-reduce-type-parameter': 'error',
'ts/prefer-regexp-exec': 'error',
// Not sure if this would make code better
'ts/strict-boolean-expressions': 'off',
'ts/prefer-string-starts-ends-with': 'error',
'ts/require-array-sort-compare': 'error',
// These are not type specific, but we only care about these in TS files
'max-len': [ 'error', { code: 120, ignoreUrls: true }],
},
};

View File

@ -1,53 +0,0 @@
module.exports = {
name: 'opinionated/unicorn',
rules: {
'unicorn/better-regex': 'error',
'unicorn/empty-brace-spaces': 'error',
'unicorn/consistent-function-scoping': 'error',
'unicorn/expiring-todo-comments': [ 'error', {
ignoreDatesOnPullRequests: false,
terms: [ 'todo' ],
allowWarningComments: false,
}],
'unicorn/explicit-length-check': 'error',
'unicorn/new-for-builtins': 'error',
'unicorn/no-array-for-each': 'error',
'unicorn/no-array-reduce': 'error',
'unicorn/no-for-loop': 'error',
'unicorn/no-invalid-remove-event-listener': 'error',
'unicorn/no-lonely-if': 'error',
'unicorn/no-negated-condition': 'error',
'unicorn/no-nested-ternary': 'error',
'unicorn/no-object-as-default-parameter': 'error',
'unicorn/no-process-exit': 'error',
'unicorn/no-thenable': 'error',
'unicorn/no-useless-fallback-in-spread': 'error',
'unicorn/no-useless-length-check': 'error',
'unicorn/no-useless-promise-resolve-reject': 'error',
'unicorn/no-useless-spread': 'error',
'unicorn/no-useless-undefined': 'error',
'unicorn/no-zero-fractions': 'error',
'unicorn/prefer-array-find': 'error',
'unicorn/prefer-array-flat-map': 'error',
'unicorn/prefer-array-index-of': 'error',
'unicorn/prefer-array-some': 'error',
'unicorn/prefer-at': 'error',
'unicorn/prefer-code-point': 'error',
'unicorn/prefer-date-now': 'error',
'unicorn/prefer-default-parameters': 'error',
'unicorn/prefer-math-trunc': 'error',
'unicorn/prefer-native-coercion-functions': 'error',
'unicorn/prefer-negative-index': 'error',
'unicorn/prefer-object-from-entries': 'error',
'unicorn/prefer-optional-catch-binding': 'error',
'unicorn/prefer-reflect-apply': 'error',
'unicorn/prefer-regexp-test': 'error',
'unicorn/prefer-set-has': 'error',
'unicorn/prefer-set-size': 'error',
'unicorn/prefer-spread': 'error',
'unicorn/prefer-string-replace-all': 'error',
'unicorn/prefer-string-slice': 'error',
'unicorn/require-array-join-separator': 'error',
'unicorn/require-number-to-fixed-digits-argument': 'error',
},
};

27
package-lock.json generated
View File

@ -82,7 +82,6 @@
"community-solid-server": "bin/server.js"
},
"devDependencies": {
"@antfu/eslint-config": "2.21.3",
"@commitlint/cli": "^19.3.0",
"@commitlint/config-conventional": "^19.2.2",
"@inrupt/solid-client-authn-core": "^2.0.0",
@ -93,7 +92,6 @@
"@types/supertest": "^2.0.14",
"commit-and-tag-version": "^11.3.0",
"componentsjs-generator": "^3.1.2",
"eslint-plugin-jest": "^28.6.0",
"husky": "^4.3.8",
"jest": "^29.7.0",
"jest-esm-transformer-2": "^1.0.0",
@ -101,6 +99,7 @@
"markdownlint-cli2": "^0.13.0",
"node-mocks-http": "^1.13.0",
"nodemon": "^3.0.1",
"opinionated-eslint-config": "0.1.0",
"set-cookie-parser": "^2.6.0",
"simple-git": "^3.20.0",
"supertest": "^6.3.3",
@ -1122,7 +1121,7 @@
},
"node_modules/@clack/prompts/node_modules/is-unicode-supported": {
"version": "1.3.0",
"dev": true,
"extraneous": true,
"inBundle": true,
"license": "MIT",
"engines": {
@ -14219,6 +14218,16 @@
"url": "https://github.com/sponsors/panva"
}
},
"node_modules/opinionated-eslint-config": {
"version": "0.1.0",
"resolved": "https://registry.npmjs.org/opinionated-eslint-config/-/opinionated-eslint-config-0.1.0.tgz",
"integrity": "sha512-z6QHgG4I8I6XSHVss2PzjO4R4gvmvQrwqTNrMFj94I2+BZP5ZU6q/bVqlhRI0oGvGJTfZr/2bl0SXkufOrPt2g==",
"dev": true,
"dependencies": {
"@antfu/eslint-config": "2.21.3",
"eslint-plugin-jest": "28.6.0"
}
},
"node_modules/optionator": {
"version": "0.9.3",
"resolved": "https://registry.npmjs.org/optionator/-/optionator-0.9.3.tgz",
@ -17716,7 +17725,7 @@
"is-unicode-supported": {
"version": "1.3.0",
"bundled": true,
"dev": true
"extraneous": true
}
}
},
@ -28073,6 +28082,16 @@
"oidc-token-hash": "^5.0.3"
}
},
"opinionated-eslint-config": {
"version": "0.1.0",
"resolved": "https://registry.npmjs.org/opinionated-eslint-config/-/opinionated-eslint-config-0.1.0.tgz",
"integrity": "sha512-z6QHgG4I8I6XSHVss2PzjO4R4gvmvQrwqTNrMFj94I2+BZP5ZU6q/bVqlhRI0oGvGJTfZr/2bl0SXkufOrPt2g==",
"dev": true,
"requires": {
"@antfu/eslint-config": "2.21.3",
"eslint-plugin-jest": "28.6.0"
}
},
"optionator": {
"version": "0.9.3",
"resolved": "https://registry.npmjs.org/optionator/-/optionator-0.9.3.tgz",

View File

@ -143,7 +143,6 @@
"yup": "^1.3.2"
},
"devDependencies": {
"@antfu/eslint-config": "2.21.3",
"@commitlint/cli": "^19.3.0",
"@commitlint/config-conventional": "^19.2.2",
"@inrupt/solid-client-authn-core": "^2.0.0",
@ -154,7 +153,6 @@
"@types/supertest": "^2.0.14",
"commit-and-tag-version": "^11.3.0",
"componentsjs-generator": "^3.1.2",
"eslint-plugin-jest": "^28.6.0",
"husky": "^4.3.8",
"jest": "^29.7.0",
"jest-esm-transformer-2": "^1.0.0",
@ -162,6 +160,7 @@
"markdownlint-cli2": "^0.13.0",
"node-mocks-http": "^1.13.0",
"nodemon": "^3.0.1",
"opinionated-eslint-config": "0.1.0",
"set-cookie-parser": "^2.6.0",
"simple-git": "^3.20.0",
"supertest": "^6.3.3",