Skip to content

Commit

Permalink
Merge pull request dostonnabotov#73 from barrymun/refactor/linting
Browse files Browse the repository at this point in the history
Refactoring to include husky pre-commit hooks, improved eslint rules and manual chunking + more
  • Loading branch information
Mathys-Gasnier authored Jan 1, 2025
2 parents 06e4987 + 1a7106f commit 49692f9
Show file tree
Hide file tree
Showing 26 changed files with 2,370 additions and 123 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ node_modules
dist
dist-ssr
*.local
*.tsbuildinfo

# Editor directories and files
.vscode/*
Expand Down
2 changes: 2 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
npm run lint
npm run build
64 changes: 62 additions & 2 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,36 @@
import { fixupPluginRules } from "@eslint/compat";
import { FlatCompat } from "@eslint/eslintrc";
import js from "@eslint/js";
import globals from "globals";
import reactPlugin from 'eslint-plugin-react';
import reactHooks from "eslint-plugin-react-hooks";
import reactRefresh from "eslint-plugin-react-refresh";
import tseslint from "typescript-eslint";
import prettier from "eslint-plugin-prettier/recommended";

const project = "./tsconfig.app.json";
// eslint flat structure backwards compatibility
const compat = new FlatCompat({
recommendedConfig: js.configs.recommended,
});

function legacyPlugin(name, alias = name) {
const plugin = compat.plugins(name)[0]?.plugins?.[alias];
if (!plugin) {
throw new Error(`Unable to resolve plugin ${name} and/or alias ${alias}`);
}
return fixupPluginRules(plugin);
}

export default tseslint.config(
{ ignores: ["dist"] },
{ ignores: ["node_modules", "dist", "build"] },
{
extends: [
js.configs.recommended,
...tseslint.configs.recommended,
prettier,
...compat.extends("plugin:import/typescript"),
reactPlugin.configs.flat.recommended,
],
files: ["**/*.{ts,tsx}"],
languageOptions: {
Expand All @@ -21,14 +40,55 @@ export default tseslint.config(
plugins: {
"react-hooks": reactHooks,
"react-refresh": reactRefresh,
import: legacyPlugin("eslint-plugin-import", "import"),
},
settings: {
"import/resolver": {
typescript: {
project,
alwaysTryTypes: true,
},
},
},
rules: {
...reactHooks.configs.recommended.rules,
"@typescript-eslint/no-empty-object-type": "off",
"@typescript-eslint/no-unused-vars": ["error", {
"argsIgnorePattern": "^_",
"varsIgnorePattern": "^_",
"caughtErrorsIgnorePattern": "^_"
}],
"import/order": ["error", {
"groups": [
"builtin",
"external",
"internal",
["parent", "sibling"],
"index",
"object",
"type",
"unknown"
],
"pathGroups": [
{
"pattern": "@*",
"group": "internal",
"position": "after"
}
],
"pathGroupsExcludedImportTypes": ["builtin", "internal"],
"newlines-between": "always",
"alphabetize": {
"order": "asc",
"caseInsensitive": true
}
}],
"react/react-in-jsx-scope": "off",
"react-refresh/only-export-components": [
"warn",
{ allowConstantExport: true },
],
"prettier/prettier": "error",
"semi": ["error", "always"],
},
}
);
Loading

0 comments on commit 49692f9

Please sign in to comment.