Skip to content

Commit e2f78d8

Browse files
committed
chore: migrate from next lint & move to flat config file for ESLint
1 parent fb73779 commit e2f78d8

File tree

5 files changed

+185
-137
lines changed

5 files changed

+185
-137
lines changed

.eslintrc.json

Lines changed: 0 additions & 41 deletions
This file was deleted.

.lintstagedrc.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1+
// eslint-disable-next-line @typescript-eslint/no-require-imports
12
const path = require('path');
23

34
const buildEslintCommand = (filenames) =>
4-
`next lint --fix --file ${filenames
5-
.map((f) => path.relative(process.cwd(), f))
6-
.join(' --file ')}`;
5+
`npx eslint --fix ${filenames.map((f) => path.relative(process.cwd(), f)).join(' ')}`;
76

87
module.exports = {
98
'*.{js,jsx,ts,tsx}': [buildEslintCommand, 'prettier --write'],

eslint.config.mjs

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import { defineConfig } from "eslint/config";
2+
import { fixupConfigRules, fixupPluginRules } from "@eslint/compat";
3+
import prettier from "eslint-plugin-prettier";
4+
import _import from "eslint-plugin-import";
5+
import path from "node:path";
6+
import { fileURLToPath } from "node:url";
7+
import js from "@eslint/js";
8+
import { FlatCompat } from "@eslint/eslintrc";
9+
10+
const __filename = fileURLToPath(import.meta.url);
11+
const __dirname = path.dirname(__filename);
12+
const compat = new FlatCompat({
13+
baseDirectory: __dirname,
14+
recommendedConfig: js.configs.recommended,
15+
allConfig: js.configs.all
16+
});
17+
18+
export default defineConfig([{
19+
extends: fixupConfigRules(compat.extends(
20+
"next/core-web-vitals",
21+
"next/typescript",
22+
"plugin:prettier/recommended",
23+
"plugin:import/errors",
24+
"plugin:import/warnings",
25+
"plugin:import/typescript",
26+
)),
27+
28+
plugins: {
29+
prettier: fixupPluginRules(prettier),
30+
import: fixupPluginRules(_import),
31+
},
32+
33+
rules: {
34+
// Code quality
35+
"no-console": "warn",
36+
"no-debugger": "error",
37+
"no-unused-vars": "off", // Handled by TS version above
38+
39+
// Import sorting and cleanliness
40+
"import/order": ["error", {
41+
groups: [
42+
"builtin",
43+
"external",
44+
"internal",
45+
"parent",
46+
"sibling",
47+
"index",
48+
"object",
49+
"type",
50+
],
51+
52+
"newlines-between": "always",
53+
54+
alphabetize: {
55+
order: "asc",
56+
caseInsensitive: true,
57+
},
58+
}],
59+
60+
"import/newline-after-import": "error",
61+
"import/no-duplicates": "error",
62+
63+
// Prettier takes over formatting rules now
64+
"prettier/prettier": "error",
65+
},
66+
}]);

0 commit comments

Comments
 (0)