Skip to content

Commit

Permalink
fix(eslint): flat configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
abhi-markan committed May 31, 2024
1 parent 74f419e commit b5c7275
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 36 deletions.
71 changes: 35 additions & 36 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const { FlatCompat } = require('@eslint/eslintrc');

const tsParser = require('@typescript-eslint/parser');
const switchCasePlugin = require('eslint-plugin-switch-case');
const simpleImportSortPlugin = require('eslint-plugin-simple-import-sort');
Expand All @@ -13,32 +15,30 @@ const securityPlugin = require('eslint-plugin-security');
const jestPlugin = require('eslint-plugin-jest');
const jestFormattingPlugin = require('eslint-plugin-jest-formatting');

const compat = new FlatCompat({
baseDirectory: __dirname,
});
const ignores = ['node_modules/**', '.eslintrc.js', 'dist/**', 'coverage/**', 'report/**'];
const languageOptions = {
parser: tsParser,
ecmaVersion: 'latest',
sourceType: 'module',
parserOptions: {
project: './tsconfig.json',
},
globals: {
node: true,
jest: true,
},
parserOptions: {
project: 'tsconfig.json',
ecmaVersion: 'latest',
sourceType: 'module',
},
};

module.exports = [
nodePlugin.configs.recommended,
eslintCommentsPlugin.configs.recommended,
optimizeRegexPlugin.configs.recommended,
switchCasePlugin.configs.recommended,
simpleImportSortPlugin,
deprecationPlugin.configs.recommended,
importPlugin.configs.recommended,
unusedImportsPlugin,
tsEslintPlugin.configs.recommended,
...compat.plugins(nodePlugin.configs.recommended.plugins[0]),
// ...compat.plugins(importPlugin.configs.recommended.plugins[0]),
// ...compat.plugins(deprecationPlugin.configs.recommended.plugins[0]),
// ...compat.plugins(prettierPlugin.plugins.prettier.configs.recommended.plugins[0]),
...compat.plugins(optimizeRegexPlugin.configs.recommended.plugins[0]),
...compat.plugins(eslintCommentsPlugin.configs.recommended.plugins[0]),
securityPlugin.configs.recommended,
{
files: ['**/*.ts'],
Expand All @@ -47,33 +47,41 @@ module.exports = [
settings: {
node: {
allowModules: ['express'],
tryExtensions: ['.js', '.json', '.ts'],
tryExtensions: ['.ts'],
},
'import/parsers': {
'@typescript-eslint/parser': ['.ts'],
},
'import/resolver': {
node: {
extensions: ['.js', '.jsx', '.ts', '.tsx'],
extensions: ['.ts', '.tsx'],
},
typescript: {
alwaysTryTypes: true,
},
},
},
plugins: {
'simple-import-sort': simpleImportSortPlugin,
'unused-imports': unusedImportsPlugin,
'switch-case': switchCasePlugin,
'@typescript-eslint': tsEslintPlugin,
import: importPlugin,
deprecation: deprecationPlugin,
prettier: prettierPlugin,
},
rules: {
...prettierPlugin.rules,
...tsEslintPlugin.configs.recommended.rules,
...nodePlugin.configs.recommended.rules,
...eslintCommentsPlugin.configs.recommended.rules,
...optimizeRegexPlugin.configs.recommended.rules,
...switchCasePlugin.configs.recommended.rules,
...securityPlugin.configs.recommended.rules,
...importPlugin.configs.recommended.rules,
...importPlugin.configs.typescript.rules,
...simpleImportSortPlugin.rules,
...unusedImportsPlugin.rules,
...deprecationPlugin.rules,
...deprecationPlugin.configs.recommended.rules,
...prettierPlugin.rules,
...switchCasePlugin.configs.recommended.rules,
...optimizeRegexPlugin.configs.recommended.rules,
...eslintCommentsPlugin.configs.recommended.rules,
...tsEslintPlugin.configs.recommended.rules,
...tsEslintPlugin.configs['recommended-requiring-type-checking'].rules,
'simple-import-sort/imports': 'error',
'simple-import-sort/exports': 'error',
'node/no-unsupported-features/es-syntax': [
'error',
{
Expand All @@ -82,14 +90,9 @@ module.exports = [
],
'node/no-missing-import': 'off',
'node/no-unpublished-import': 'off',
'simple-import-sort/imports': 'error',
'simple-import-sort/exports': 'error',
'import/first': 'error',
'import/no-duplicates': 'error',
'deprecation/deprecation': 'warn',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'import/no-unresolved': 'error',
'prettier/prettier': [
'error',
{
Expand All @@ -116,7 +119,6 @@ module.exports = [
allow: ['info', 'error'],
},
],
'import/no-named-as-default': 'off',
'import/extensions': 'off',
'implicit-arrow-linebreak': 'off',
'import/newline-after-import': 'off',
Expand All @@ -139,7 +141,6 @@ module.exports = [
consistent: true,
},
],
'import/no-named-as-default-member': 'off',
'prefer-destructuring': [
'error',
{
Expand All @@ -154,7 +155,7 @@ module.exports = [
ignores,
languageOptions,
plugins: {
'jest': jestPlugin,
jest: jestPlugin,
'jest-formatting': jestFormattingPlugin,
},
rules: {
Expand All @@ -171,8 +172,6 @@ module.exports = [
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/unbound-method': 'off',
'jest/unbound-method': 'error',
// TODO: Remove below
'security/detect-non-literal-regexp': 'off',
},
},
];
1 change: 1 addition & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"devDependencies": {
"@commitlint/cli": "^19.3.0",
"@commitlint/config-conventional": "^19.2.2",
"@eslint/eslintrc": "^3.1.0",
"@nestjs/cli": "^10.3.2",
"@nestjs/schematics": "^10.1.1",
"@nestjs/testing": "^10.3.8",
Expand Down

0 comments on commit b5c7275

Please sign in to comment.