Skip to content

Commit 49692f9

Browse files
Merge pull request #73 from barrymun/refactor/linting
Refactoring to include husky pre-commit hooks, improved eslint rules and manual chunking + more
2 parents 06e4987 + 1a7106f commit 49692f9

26 files changed

+2370
-123
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ node_modules
1111
dist
1212
dist-ssr
1313
*.local
14+
*.tsbuildinfo
1415

1516
# Editor directories and files
1617
.vscode/*

.husky/pre-commit

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
npm run lint
2+
npm run build

eslint.config.js

+62-2
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,36 @@
1+
import { fixupPluginRules } from "@eslint/compat";
2+
import { FlatCompat } from "@eslint/eslintrc";
13
import js from "@eslint/js";
24
import globals from "globals";
5+
import reactPlugin from 'eslint-plugin-react';
36
import reactHooks from "eslint-plugin-react-hooks";
47
import reactRefresh from "eslint-plugin-react-refresh";
58
import tseslint from "typescript-eslint";
69
import prettier from "eslint-plugin-prettier/recommended";
710

11+
const project = "./tsconfig.app.json";
12+
// eslint flat structure backwards compatibility
13+
const compat = new FlatCompat({
14+
recommendedConfig: js.configs.recommended,
15+
});
16+
17+
function legacyPlugin(name, alias = name) {
18+
const plugin = compat.plugins(name)[0]?.plugins?.[alias];
19+
if (!plugin) {
20+
throw new Error(`Unable to resolve plugin ${name} and/or alias ${alias}`);
21+
}
22+
return fixupPluginRules(plugin);
23+
}
24+
825
export default tseslint.config(
9-
{ ignores: ["dist"] },
26+
{ ignores: ["node_modules", "dist", "build"] },
1027
{
1128
extends: [
1229
js.configs.recommended,
1330
...tseslint.configs.recommended,
1431
prettier,
32+
...compat.extends("plugin:import/typescript"),
33+
reactPlugin.configs.flat.recommended,
1534
],
1635
files: ["**/*.{ts,tsx}"],
1736
languageOptions: {
@@ -21,14 +40,55 @@ export default tseslint.config(
2140
plugins: {
2241
"react-hooks": reactHooks,
2342
"react-refresh": reactRefresh,
43+
import: legacyPlugin("eslint-plugin-import", "import"),
44+
},
45+
settings: {
46+
"import/resolver": {
47+
typescript: {
48+
project,
49+
alwaysTryTypes: true,
50+
},
51+
},
2452
},
2553
rules: {
2654
...reactHooks.configs.recommended.rules,
55+
"@typescript-eslint/no-empty-object-type": "off",
56+
"@typescript-eslint/no-unused-vars": ["error", {
57+
"argsIgnorePattern": "^_",
58+
"varsIgnorePattern": "^_",
59+
"caughtErrorsIgnorePattern": "^_"
60+
}],
61+
"import/order": ["error", {
62+
"groups": [
63+
"builtin",
64+
"external",
65+
"internal",
66+
["parent", "sibling"],
67+
"index",
68+
"object",
69+
"type",
70+
"unknown"
71+
],
72+
"pathGroups": [
73+
{
74+
"pattern": "@*",
75+
"group": "internal",
76+
"position": "after"
77+
}
78+
],
79+
"pathGroupsExcludedImportTypes": ["builtin", "internal"],
80+
"newlines-between": "always",
81+
"alphabetize": {
82+
"order": "asc",
83+
"caseInsensitive": true
84+
}
85+
}],
86+
"react/react-in-jsx-scope": "off",
2787
"react-refresh/only-export-components": [
2888
"warn",
2989
{ allowConstantExport: true },
3090
],
31-
"prettier/prettier": "error",
91+
"semi": ["error", "always"],
3292
},
3393
}
3494
);

0 commit comments

Comments
 (0)