Skip to content

Commit

Permalink
refactor(eslint): use flat config for eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
dipendraupreti committed Sep 20, 2024
1 parent a092996 commit fd989c4
Show file tree
Hide file tree
Showing 9 changed files with 214 additions and 182 deletions.
4 changes: 0 additions & 4 deletions .eslintrc.cjs

This file was deleted.

Empty file removed packages/mailer/.eslintignore
Empty file.
4 changes: 0 additions & 4 deletions packages/mailer/.eslintrc.cjs

This file was deleted.

12 changes: 12 additions & 0 deletions packages/mailer/eslint.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const configCustom = require("eslint-config-custom");

module.exports = [
...configCustom,
{
files: [".js", ".cjs", ".mjs", ".ts", ".cts", ".mts"],
extends: ["eslint:recommended"],
},
{
ignores: ["**/*.log*", "coverage", "dist", "node_modules", "eslint.config.cjs"],
},
];
4 changes: 2 additions & 2 deletions packages/mailer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
],
"scripts": {
"build": "vite build && tsc --emitDeclarationOnly && mv dist/src dist/types",
"lint": "eslint . --ext .js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --ignore-path .gitignore",
"lint:fix": "eslint . --ext .js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore",
"lint": "eslint",
"lint:fix": "eslint . --fix",
"sort-package": "npx sort-package-json",
"test": "vitest run --coverage",
"typecheck": "tsc --noEmit -p tsconfig.json --composite false"
Expand Down
116 changes: 65 additions & 51 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

130 changes: 130 additions & 0 deletions tools/eslint-config-custom/index.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
const { fixupConfigRules, fixupPluginRules } = require("@eslint/compat");
const typescriptEslint = require("@typescript-eslint/eslint-plugin");
const eslintImport = require("eslint-plugin-import");
const n = require("eslint-plugin-n");
const prettier = require("eslint-plugin-prettier");
const promise = require("eslint-plugin-promise");
const unicorn = require("eslint-plugin-unicorn");
const globals = require("globals");
const tsParser = require("@typescript-eslint/parser");
const path = require("node:path");
const { fileURLToPath } = require("node:url");
const js = require("@eslint/js");
const { FlatCompat } = require("@eslint/eslintrc");

const dirname = path.dirname(__filename);
const compat = new FlatCompat({
baseDirectory: dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all
});

module.exports = [...fixupConfigRules(compat.extends(
"eslint:recommended",
"plugin:n/recommended",
"plugin:import/recommended",
"plugin:import/typescript",
"plugin:prettier/recommended",
"plugin:@typescript-eslint/recommended",
"plugin:unicorn/recommended",
"prettier",
)), {
plugins: {
"@typescript-eslint": fixupPluginRules(typescriptEslint),
import: fixupPluginRules(eslintImport),
n: fixupPluginRules(n),
prettier: fixupPluginRules(prettier),
promise,
unicorn: fixupPluginRules(unicorn),
},

languageOptions: {
globals: {
...globals.browser,
...globals.node,
},

parser: tsParser,
ecmaVersion: "latest",
sourceType: "module",
},

settings: {
node: {
tryExtensions: [".cjs", ".js", ".json", ".node", ".ts"],
},
},

rules: {
curly: ["error", "all"],
"brace-style": ["error", "1tbs"],

"import/order": ["error", {
alphabetize: {
order: "asc",
caseInsensitive: true,
},

groups: [
"builtin",
"external",
"internal",
["parent", "sibling"],
"index",
"object",
"type",
],

"newlines-between": "always",
}],

"n/no-unpublished-import": ["error", {
allowModules: ["@faker-js/faker", "mercurius-codegen", "query-string"],
}],

"n/no-unsupported-features/es-syntax": ["error", {
ignores: ["modules"],
}],

"prettier/prettier": "error",

"unicorn/filename-case": ["error", {
cases: {
camelCase: true,
snakeCase: true,
},
}],

"unicorn/import-style": ["error", {
styles: {
"node:path": {
named: true,
},
},
}],

"unicorn/numeric-separators-style": ["error", {
number: {
minimumDigits: 6,
groupLength: 3,
},
}],

"unicorn/prefer-structured-clone": "off",

"unicorn/prevent-abbreviations": ["error", {
allowList: {
db: true,
docs: true,
env: true,
err: true,
i: true,
param: true,
req: true,
res: true,
},
}],
},
}, {
files: ["**/*.spec.ts"],
}];
119 changes: 0 additions & 119 deletions tools/eslint-config-custom/index.js

This file was deleted.

7 changes: 5 additions & 2 deletions tools/eslint-config-custom/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
"name": "eslint-config-custom",
"version": "0.72.1",
"license": "MIT",
"main": "index.js",
"main": "index.cjs",
"scripts": {
"sort-package": "npx sort-package-json"
"sort-package": "npx sort-package-json",
"lint": "eslint .",
"lint:fix": "eslint . --fix"
},
"dependencies": {
"@eslint/compat": "1.1.1",
"@typescript-eslint/eslint-plugin": "7.18.0",
"@typescript-eslint/parser": "7.18.0",
"eslint-config-prettier": "9.1.0",
Expand Down

0 comments on commit fd989c4

Please sign in to comment.