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

Flat config #293

Merged
merged 10 commits into from
May 27, 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
8 changes: 1 addition & 7 deletions .github/workflows/external.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,6 @@ jobs:
- name: build project if needed
run: npm run build-for-test --if-present
working-directory: ./project
- name: modify project eslint config
run: sed 's/"@voxpelli"/"..\/main\/test.eslintrc"/' .eslintrc > tmp.eslintrc && rm .eslintrc && mv tmp.eslintrc .eslintrc
working-directory: ./project
- name: modify project eslint config (ESM version)
run: sed 's/"@voxpelli\/eslint-config\/esm"/"..\/main\/test-esm.eslintrc"/' .eslintrc > tmp.eslintrc && rm .eslintrc && mv tmp.eslintrc .eslintrc
working-directory: ./project
- name: run eslint
run: ../main/node_modules/.bin/eslint --resolve-plugins-relative-to ../main --ext js --ext cjs --ext mjs --report-unused-disable-directives .
run: ../main/node_modules/.bin/eslint -c ../main/eslint.config.js
working-directory: ./project
5 changes: 2 additions & 3 deletions .knip.jsonc
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"$schema": "https://unpkg.com/knip@2/schema.json",
"eslint": {
"config": [".eslintrc", "index.js", "esm.js", "mocha.js"]
},
"ignoreDependencies": ["@types/eslint"]
"config": ["eslint.config.js", "index.js"]
}
}
147 changes: 92 additions & 55 deletions base-configs/additional-rules.js
Original file line number Diff line number Diff line change
@@ -1,75 +1,112 @@
'use strict';
// @ts-ignore
import esxPlugin from 'eslint-plugin-es-x';
// import importPlugin from 'eslint-plugin-import-x';
// @ts-ignore
import nPlugin from 'eslint-plugin-n';
// // @ts-ignore
// import promisePlugin from 'eslint-plugin-promise';
// @ts-ignore
import securityPlugin from 'eslint-plugin-security';
// @ts-ignore
import sortDestructureKeysPlugin from 'eslint-plugin-sort-destructure-keys';
// @ts-ignore
import unicornPlugin from 'eslint-plugin-unicorn';

/** @satisfies {import('eslint').ESLint.ConfigData} */
const config = {
plugins: [
'es-x',
'import',
'jsdoc',
'promise',
'security',
'sort-destructure-keys',
'unicorn',
],
'extends': [
'plugin:n/recommended',
'plugin:security/recommended',
'plugin:unicorn/recommended',
'plugin:promise/recommended',
'plugin:jsdoc/recommended',
],
/** @satisfies {import('@typescript-eslint/utils/ts-eslint').FlatConfig.Config} */
const addititionalCoreRules = {
rules: {
// Added ESLint core rules

'func-style': ['warn', 'expression', { 'allowArrowFunctions': true }],
'no-console': 'warn',
'no-constant-binary-expression': 'error',
'no-unsafe-optional-chaining': ['error', { 'disallowArithmeticOperators': true }],
'no-warning-comments': ['warn', { 'terms': ['fixme'] }],
'object-shorthand': ['error', 'properties', { 'avoidQuotes': true }],
'quote-props': ['error', 'as-needed', { 'keywords': true, 'numbers': true, 'unnecessary': false }],
'@stylistic/quote-props': ['error', 'as-needed', { 'keywords': true, 'numbers': true, 'unnecessary': false }],
},
};

// Overrides of other extended ESLint rule packages
/** @satisfies {import('@typescript-eslint/utils/ts-eslint').FlatConfig.ConfigArray} */
const adaptedNodeRules = [
nPlugin.configs['flat/recommended'],
{
name: 'Adapted Node Rules',
rules: {
// Overriding
'n/no-process-exit': 'off',

'n/no-process-exit': 'off',
// Adding
'n/prefer-global/console': 'warn',
'n/prefer-promises/fs': 'warn',
'n/no-process-env': 'warn',
'n/no-sync': 'error',
},
},
];

'security/detect-object-injection': 'off',
'security/detect-unsafe-regex': 'off',
/** @satisfies {import('@typescript-eslint/utils/ts-eslint').FlatConfig.ConfigArray} */
const adaptedUnicornRules = [
unicornPlugin.configs['flat/recommended'],
{
name: 'Additional Node Rules',
rules: {
// Overriding
'unicorn/catch-error-name': ['error', { name: 'err', ignore: ['^cause$'] }],
'unicorn/explicit-length-check': 'off',
'unicorn/no-await-expression-member': 'warn',
'unicorn/no-negated-condition': 'off',
'unicorn/numeric-separators-style': 'off',
'unicorn/prefer-add-event-listener': 'warn',
'unicorn/prefer-event-target': 'warn',
'unicorn/prefer-module': 'off',
'unicorn/prefer-spread': 'warn',
'unicorn/prefer-string-raw': 'off',
'unicorn/prefer-string-replace-all': 'warn',
'unicorn/prevent-abbreviations': 'off',
'unicorn/switch-case-braces': ['error', 'avoid'],
},
},
];

'unicorn/catch-error-name': ['error', { name: 'err', ignore: ['^cause$'] }],
'unicorn/explicit-length-check': 'off',
'unicorn/no-await-expression-member': 'warn',
'unicorn/no-negated-condition': 'off',
'unicorn/numeric-separators-style': 'off',
'unicorn/prefer-add-event-listener': 'warn',
'unicorn/prefer-event-target': 'warn',
'unicorn/prefer-module': 'off',
'unicorn/prefer-string-replace-all': 'warn',
'unicorn/prefer-spread': 'warn',
'unicorn/prevent-abbreviations': 'off',
'unicorn/switch-case-braces': ['error', 'avoid'],
/** @satisfies {import('@typescript-eslint/utils/ts-eslint').FlatConfig.ConfigArray} */
export const additionalRules = [
addititionalCoreRules,
...adaptedNodeRules,
...adaptedUnicornRules,
securityPlugin.configs.recommended,
// TODO: Add promise plugin once https://github.com/eslint-community/eslint-plugin-promise/issues/449 has been fixed
// promisePlugin.?
{
name: 'Additional Rules',
plugins: {
'es-x': esxPlugin,
// TODO: Add back
// 'import': importPlugin,
// TODO: Add back
// 'promise': promisePlugin,
'sort-destructure-keys': sortDestructureKeysPlugin,
},
rules: {
// Overrides of other extended ESLint rule packages

// Additional standalone ESLint rules
'security/detect-object-injection': 'off',
'security/detect-unsafe-regex': 'off',

'es-x/no-exponential-operators': 'warn',
// Additional standalone ESLint rules

'n/prefer-global/console': 'warn',
'n/prefer-promises/fs': 'warn',
'n/no-process-env': 'warn',
'n/no-sync': 'error',
'es-x/no-exponential-operators': 'warn',

'import/no-deprecated': 1,
'import/order': [
'error',
{
'groups': ['builtin', 'external', ['internal', 'parent', 'sibling', 'index'], 'type'],
},
],
// 'import/no-deprecated': 1,
// 'import/order': [
// 'error',
// {
// 'groups': ['builtin', 'external', ['internal', 'parent', 'sibling', 'index'], 'type'],
// },
// ],

'promise/prefer-await-to-then': 'error',
// 'promise/prefer-await-to-then': 'error',

'sort-destructure-keys/sort-destructure-keys': 'error',
'sort-destructure-keys/sort-destructure-keys': 'error',
},
},
};

module.exports = config;
];
10 changes: 10 additions & 0 deletions base-configs/esm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/** @satisfies {import('eslint').Linter.FlatConfig[]} */
export const esmRules = [
{
rules: {
// Overrides of other rules
'func-style': ['warn', 'declaration', { 'allowArrowFunctions': true }],
'unicorn/prefer-module': 'error',
},
},
];
40 changes: 15 additions & 25 deletions base-configs/jsdoc.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,18 @@
'use strict';
import jsdoc from 'eslint-plugin-jsdoc';

/** @satisfies {import('eslint').ESLint.ConfigData} */
const config = {
plugins: [
'jsdoc',
],
'extends': [
'plugin:jsdoc/recommended-typescript-flavor',
],
settings: {
jsdoc: {
mode: 'typescript',
/** @satisfies {import('eslint').Linter.FlatConfig[]} */
export const jsdocRules = [
jsdoc.configs['flat/recommended-typescript-flavor'],
{
rules: {
'jsdoc/check-types': 'off',
'jsdoc/require-jsdoc': 'off',
'jsdoc/require-param-description': 'off',
'jsdoc/require-property-description': 'off',
'jsdoc/require-returns-description': 'off',
'jsdoc/require-yields': 'off',
'jsdoc/tag-lines': ['warn', 'never', { 'startLines': 1 }],
'jsdoc/valid-types': 'off',
},
},
rules: {
'jsdoc/check-types': 'off',
'jsdoc/require-jsdoc': 'off',
'jsdoc/require-param-description': 'off',
'jsdoc/require-property-description': 'off',
'jsdoc/require-returns-description': 'off',
'jsdoc/require-yields': 'off',
'jsdoc/tag-lines': ['warn', 'never', { 'startLines': 1 }],
'jsdoc/valid-types': 'off',
},
};

module.exports = config;
];
20 changes: 20 additions & 0 deletions base-configs/mocha.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// @ts-ignore
import mochaPlugin from 'eslint-plugin-mocha';
import globals from 'globals';
import { config } from 'typescript-eslint';

export const mochaRules = config({
ignores: ['**/*', '!test/**/*'],
'extends': [
mochaPlugin.configs.flat.recommended,
],
languageOptions: {
globals: {
...globals.mocha,
},
},
rules: {
'mocha/no-mocha-arrows': 'off',
'no-unused-expressions': 'off',
},
});
32 changes: 0 additions & 32 deletions base-configs/standard-customizations.js

This file was deleted.

Loading
Loading