Skip to content

Commit

Permalink
chore: setup eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
ChloeMouret committed Nov 24, 2023
1 parent 3b9976c commit 6b9c3f6
Show file tree
Hide file tree
Showing 9 changed files with 1,414 additions and 41 deletions.
209 changes: 199 additions & 10 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,206 @@ module.exports = {
root: true,
env: { browser: true, es2020: true },
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:react-hooks/recommended',
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:react-hooks/recommended",
],
ignorePatterns: ["**/node_modules/", "**/dist/", "**/public/"],
parser: "@typescript-eslint/parser",
parserOptions: {
project: "tsconfig.eslint.json",
tsconfigRootDir: __dirname,
sourceType: "module",
},
plugins: [
"react",
"prefer-arrow",
"import",
"jest",
"react-hooks",
"jsx-a11y",
"risxss",
"testing-library",
"react-refresh",
],
ignorePatterns: ['dist', '.eslintrc.cjs'],
parser: '@typescript-eslint/parser',
plugins: ['react-refresh'],
rules: {
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
"import/extensions": 0,
"import/no-unresolved": 0,
"import/prefer-default-export": 0,
"import/no-duplicates": "error",
complexity: ["error", 8],
"max-lines": ["error", 200],
"max-depth": ["error", 3],
"max-params": ["error", 4],
eqeqeq: ["error", "smart"],
"import/no-extraneous-dependencies": [
"error",
{
devDependencies: true,
optionalDependencies: false,
peerDependencies: false,
},
],
"no-shadow": [
"error",
{
hoist: "all",
},
],
"prefer-const": "error",
"import/order": [
"error",
{
pathGroups: [{ pattern: "@swarmion/**", group: "unknown" }],
groups: [
["external", "builtin"],
"unknown",
"internal",
["parent", "sibling", "index"],
],
alphabetize: {
order: "asc",
caseInsensitive: false,
},
"newlines-between": "always",
pathGroupsExcludedImportTypes: ["builtin"],
},
],
"import/namespace": "off",
"sort-imports": [
"error",
{
ignoreCase: true,
ignoreDeclarationSort: true,
ignoreMemberSort: false,
memberSyntaxSortOrder: ["none", "all", "multiple", "single"],
},
],
"padding-line-between-statements": [
"error",
{
blankLine: "always",
prev: "*",
next: "return",
},
],
"prefer-arrow/prefer-arrow-functions": [
"error",
{
disallowPrototype: true,
singleReturnOnly: false,
classPropertiesAllowed: false,
},
],
"no-restricted-imports": [
"error",
{
paths: [
{
name: "lodash",
message: "Please use lodash/{module} import instead",
},
{
name: "aws-sdk",
message: "Please use aws-sdk/{module} import instead",
},
{
name: ".",
message: "Please use explicit import file",
},
],
},
],
curly: ["error", "all"],
},
}
overrides: [
{
files: ["**/*.ts?(x)"],
extends: [
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
"plugin:import/typescript",
],
parser: "@typescript-eslint/parser",
parserOptions: {
project: "tsconfig.json",
},
rules: {
"@typescript-eslint/prefer-optional-chain": "error",
"no-shadow": "off",
"@typescript-eslint/no-shadow": "error",
"@typescript-eslint/prefer-nullish-coalescing": "error",
"@typescript-eslint/strict-boolean-expressions": [
"error",
{
allowString: false,
allowNumber: false,
allowNullableObject: true,
},
],
"@typescript-eslint/ban-ts-comment": [
"error",
{
"ts-ignore": "allow-with-description",
minimumDescriptionLength: 10,
},
],
"@typescript-eslint/explicit-function-return-type": 0,
"@typescript-eslint/explicit-member-accessibility": 0,
"@typescript-eslint/camelcase": 0,
"@typescript-eslint/interface-name-prefix": 0,
"@typescript-eslint/explicit-module-boundary-types": "error",
"@typescript-eslint/no-explicit-any": "error",
"@typescript-eslint/no-unused-vars": "error",
"@typescript-eslint/ban-types": [
"error",
{
types: {
FC: "Use `const MyComponent = (props: Props): JSX.Element` instead",
SFC: "Use `const MyComponent = (props: Props): JSX.Element` instead",
FunctionComponent:
"Use `const MyComponent = (props: Props): JSX.Element` instead",
"React.FC":
"Use `const MyComponent = (props: Props): JSX.Element` instead",
"React.SFC":
"Use `const MyComponent = (props: Props): JSX.Element` instead",
"React.FunctionComponent":
"Use `const MyComponent = (props: Props): JSX.Element` instead",
},
extendDefaults: true,
},
],
"@typescript-eslint/no-unnecessary-boolean-literal-compare": "error",
"@typescript-eslint/no-unnecessary-condition": "error",
"@typescript-eslint/no-unnecessary-type-arguments": "error",
"@typescript-eslint/prefer-string-starts-ends-with": "error",
"@typescript-eslint/switch-exhaustiveness-check": "error",
"@typescript-eslint/restrict-template-expressions": [
"error",
{
allowNumber: true,
allowBoolean: true,
},
],
},
},
{
files: ["**/src/**"],
excludedFiles: [
"**/__tests__/**",
"**/*.test.ts?(x)",
"**/__benches__/**",
],
rules: {
"import/no-extraneous-dependencies": [
"error",
{
devDependencies: false,
optionalDependencies: false,
peerDependencies: true,
},
],
},
},
],
};
8 changes: 4 additions & 4 deletions .github/workflows/deploy-frontend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ name: Deploy static content to Pages
on:
# Runs on pushes targeting the default branch
push:
branches: ['main']
branches: ["main"]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
Expand All @@ -17,7 +17,7 @@ permissions:

# Allow one concurrent deployment
concurrency:
group: 'pages'
group: "pages"
cancel-in-progress: true

jobs:
Expand Down Expand Up @@ -47,7 +47,7 @@ jobs:
uses: actions/upload-pages-artifact@v2
with:
# Upload dist repository
path: './dist'
path: "./dist"
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v2
uses: actions/deploy-pages@v2
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ If you are developing a production application, we recommend updating the config
export default {
// other rules...
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
project: ['./tsconfig.json', './tsconfig.node.json'],
ecmaVersion: "latest",
sourceType: "module",
project: ["./tsconfig.json", "./tsconfig.node.json"],
tsconfigRootDir: __dirname,
},
}
};
```

- Replace `plugin:@typescript-eslint/recommended` to `plugin:@typescript-eslint/recommended-type-checked` or `plugin:@typescript-eslint/strict-type-checked`
Expand Down
14 changes: 13 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
"dev": "vite",
"build": "tsc && vite build",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview"
"preview": "vite preview",
"lint-fix": "eslint --ext=js,ts --fix",
"lint-check": "eslint .",
"format-check": "prettier --check .",
"format-fix": "prettier --write ."
},
"dependencies": {
"react": "^18.2.0",
Expand All @@ -24,8 +28,16 @@
"@typescript-eslint/parser": "^6.10.0",
"@vitejs/plugin-react": "^4.2.0",
"eslint": "^8.53.0",
"eslint-plugin-import": "^2.29.0",
"eslint-plugin-jest": "^27.6.0",
"eslint-plugin-jsx-a11y": "^6.8.0",
"eslint-plugin-prefer-arrow": "^1.2.3",
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.4",
"eslint-plugin-risxss": "^2.1.0",
"eslint-plugin-testing-library": "^6.2.0",
"prettier": "^3.1.0",
"typescript": "^5.2.2",
"vite": "^5.0.0"
}
Expand Down
Loading

0 comments on commit 6b9c3f6

Please sign in to comment.