Skip to content

Commit

Permalink
refactor(backend): convert configs
Browse files Browse the repository at this point in the history
  • Loading branch information
fmauNeko committed Dec 16, 2024
1 parent 148e3e1 commit 5930bbb
Show file tree
Hide file tree
Showing 6 changed files with 263 additions and 120 deletions.
115 changes: 115 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

161 changes: 80 additions & 81 deletions packages/backend/lib/configs/default.ts
Original file line number Diff line number Diff line change
@@ -1,86 +1,85 @@
const defaultConfig = {
plugins: ['prettier'],
extends: ['eslint:recommended'],
rules: {
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/ban-ts-ignore': 'off',
'consistent-return': 'off',
curly: 'error',
'dot-notation': 'error',
eqeqeq: 'error',
'func-names': ['error', 'always'],
'guard-for-in': 'error',
'linebreak-style': ['error', 'unix'],
'new-cap': 'warn',
'no-caller': 'error',
'no-catch-shadow': 'error',
'no-console': 'error',
'no-else-return': 'error',
'no-extend-native': 'error',
'no-extra-bind': 'error',
'no-eval': 'error',
'no-implicit-coercion': 'error',
'no-implied-eval': 'error',
'no-invalid-this': 'error',
'no-irregular-whitespace': 'error',
'no-labels': 'error',
'no-lone-blocks': 'error',
'no-lonely-if': 'warn',
'no-loop-func': 'error',
'no-multi-spaces': 'warn',
'no-multiple-empty-lines': 'warn',
'no-native-reassign': 'error',
'no-nested-ternary': 'error',
'no-new': 'error',
'no-new-func': 'error',
'no-new-require': 'error',
'no-new-wrappers': 'error',
'no-return-assign': 'error',
'no-self-compare': 'error',
'no-sequences': 'error',
'no-shadow': 'error',
'no-shadow-restricted-names': 'error',
'no-throw-literal': 'error',
'no-undef': 'error',
'no-undef-init': 'warn',
'no-unreachable': 'error',
'no-unused-expressions': ['error', { allowShortCircuit: true }],
'no-useless-call': 'error',
'no-with': 'error',
'require-atomic-updates': 'off',
semi: ['error', 'always'],
strict: ['error', 'global'],
'vars-on-top': 'error',
yoda: ['error', 'never'],
'sort-keys': ['error', 'asc'],
'keyword-spacing': ['error', { before: true, after: true }],
'object-curly-spacing': ['error', 'always'],
'comma-spacing': 'error',
'no-return-await': 'error',
import js from '@eslint/js';
import { TSESLint } from '@typescript-eslint/utils';
import jest from 'eslint-plugin-jest';
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended';

// Plugins custom rules
'kuzzle/array-foreach': 'error',
'prettier/prettier': 'error',
},
overrides: [
{
files: ['tests/**/*.js', 'features*/**/*.js'],
extends: ['plugin:jest/recommended', 'plugin:jest/style'],
rules: {
'sort-keys': 'off',
},
const defaultConfig = (plugin: TSESLint.FlatConfig.Plugin): TSESLint.FlatConfig.Config[] => [
js.configs.recommended,
{
plugins: {
[plugin.meta!.name!]: plugin,
},
{
files: ['tests/**/*.ts'],
extends: ['plugin:jest/recommended', 'plugin:jest/style'],
parserOptions: {
parser: '@typescript-eslint/parser',
},
rules: {
'sort-keys': 'off',
},
rules: {
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/ban-ts-ignore': 'off',
'consistent-return': 'off',
curly: 'error',
'dot-notation': 'error',
eqeqeq: 'error',
'func-names': ['error', 'always'],
'guard-for-in': 'error',
'linebreak-style': ['error', 'unix'],
'new-cap': 'warn',
'no-caller': 'error',
'no-catch-shadow': 'error',
'no-console': 'error',
'no-else-return': 'error',
'no-extend-native': 'error',
'no-extra-bind': 'error',
'no-eval': 'error',
'no-implicit-coercion': 'error',
'no-implied-eval': 'error',
'no-invalid-this': 'error',
'no-irregular-whitespace': 'error',
'no-labels': 'error',
'no-lone-blocks': 'error',
'no-lonely-if': 'warn',
'no-loop-func': 'error',
'no-multi-spaces': 'warn',
'no-multiple-empty-lines': 'warn',
'no-native-reassign': 'error',
'no-nested-ternary': 'error',
'no-new': 'error',
'no-new-func': 'error',
'no-new-require': 'error',
'no-new-wrappers': 'error',
'no-return-assign': 'error',
'no-self-compare': 'error',
'no-sequences': 'error',
'no-shadow': 'error',
'no-shadow-restricted-names': 'error',
'no-throw-literal': 'error',
'no-undef': 'error',
'no-undef-init': 'warn',
'no-unreachable': 'error',
'no-unused-expressions': ['error', { allowShortCircuit: true }],
'no-useless-call': 'error',
'no-with': 'error',
'require-atomic-updates': 'off',
semi: ['error', 'always'],
strict: ['error', 'global'],
'vars-on-top': 'error',
yoda: ['error', 'never'],
'sort-keys': ['error', 'asc'],
'keyword-spacing': ['error', { before: true, after: true }],
'object-curly-spacing': ['error', 'always'],
'comma-spacing': 'error',
'no-return-await': 'error',

// Plugins custom rules
'kuzzle/array-foreach': 'error',
'prettier/prettier': 'error',
},
],
};
},
{
files: ['tests/**/*.js', 'features*/**/*.js'],
...jest.configs['flat/recommended'],
...jest.configs['flat/style'],
rules: {
'sort-keys': 'off',
},
},
eslintPluginPrettierRecommended,
];

export default defaultConfig;
26 changes: 15 additions & 11 deletions packages/backend/lib/configs/node.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
const nodeConfig = {
rules: {},
env: {
node: true,
es6: true,
mocha: true,
},
parserOptions: {
ecmaFeatures: {
impliedStrict: false,
},
import { Linter } from 'eslint';
import globals from 'globals';

const nodeConfig: Linter.Config = {
languageOptions: {
ecmaVersion: 2018,
globals: {
...globals.node,
...globals.es2018,
...globals.mocha,
},
parserOptions: {
ecmaFeatures: {
impliedStrict: false,
},
},
},
};

Expand Down
50 changes: 30 additions & 20 deletions packages/backend/lib/configs/typescript.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,34 @@
const typescriptConfig = {
plugins: ['@typescript-eslint'],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
],
parser: '@typescript-eslint/parser',
parserOptions: {
project: ['**/tsconfig.json', '**/tsconfig.*.json'],
import jest from 'eslint-plugin-jest';
import tseslint from 'typescript-eslint';

const typescriptConfig = tseslint.config(
...tseslint.configs.recommended,
tseslint.configs.eslintRecommended,
{
languageOptions: {
parserOptions: {
projectService: true,
},
},
rules: {
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/type-annotation-spacing': 'warn',
'@typescript-eslint/member-delimiter-style': 'warn',
// Fix for https://github.com/typescript-eslint/typescript-eslint/issues/2483
'no-shadow': 'off',
'@typescript-eslint/no-shadow': 'error',
},
},
rules: {
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/type-annotation-spacing': 'warn',
'@typescript-eslint/member-delimiter-style': 'warn',
// Fix for https://github.com/typescript-eslint/typescript-eslint/issues/2483
'no-shadow': 'off',
'@typescript-eslint/no-shadow': 'error',
{
files: ['tests/**/*.ts'],
...jest.configs['flat/recommended'],
...jest.configs['flat/style'],
rules: {
'sort-keys': 'off',
},
},
};
);

export default typescriptConfig;
Loading

0 comments on commit 5930bbb

Please sign in to comment.