Skip to content

Commit ee780d8

Browse files
committed
add eslint
1 parent 62c8f2b commit ee780d8

File tree

3 files changed

+533
-44
lines changed

3 files changed

+533
-44
lines changed

.eslint.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
module.exports = {
2+
root: true,
3+
env: {
4+
node: true,
5+
es6: true,
6+
},
7+
parserOptions: {ecmaVersion: 8}, // to enable features such as async/await
8+
ignorePatterns: ['node_modules/*', '.next/*', '.out/*', '!.prettierrc.js'], // We don't want to lint generated files nor node_modules, but we want to lint .prettierrc.js (ignored by default by eslint)
9+
extends: ['eslint:recommended'],
10+
overrides: [
11+
// This configuration will apply only to TypeScript files
12+
{
13+
files: ['**/*.ts', '**/*.tsx'],
14+
parser: '@typescript-eslint/parser',
15+
settings: {react: {version: 'detect'}},
16+
env: {
17+
browser: true,
18+
node: true,
19+
es6: true,
20+
},
21+
extends: [
22+
'eslint:recommended',
23+
'plugin:@typescript-eslint/recommended', // TypeScript rules
24+
'plugin:react/recommended', // React rules
25+
'plugin:react-hooks/recommended', // React hooks rules
26+
'plugin:jsx-a11y/recommended', // Accessibility rules
27+
],
28+
rules: {
29+
'react/prop-types': 'off', // We will use TypeScript's types for component props instead
30+
'react/react-in-jsx-scope': 'off', // No need to import React when using Next.js
31+
'jsx-a11y/anchor-is-valid': 'off', // This rule is not compatible with Next.js's <Link /> components
32+
'@typescript-eslint/no-unused-vars': ['error'], // Why would you want unused vars?
33+
'@typescript-eslint/explicit-function-return-type': [
34+
// I suggest this setting for requiring return types on functions only where usefull
35+
'warn',
36+
{
37+
allowExpressions: true,
38+
allowConciseArrowFunctionExpressionsStartingWithVoid: true,
39+
},
40+
],
41+
},
42+
},
43+
],
44+
}

package.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
"analyze": "ANALYZE=true next build",
2525
"make-tags-sitemap": "NODE_ENV=production node tags-sitemap.js",
2626
"storybook": "start-storybook -p 6006",
27-
"build-storybook": "build-storybook"
27+
"build-storybook": "build-storybook",
28+
"type-check": "tsc --project tsconfig.json --pretty --noEmit",
29+
"lint": "eslint --ext ts --ext tsx --fix"
2830
},
2931
"dependencies": {
3032
"@emotion/babel-preset-css-prop": "^10.2.0",
@@ -113,6 +115,8 @@
113115
"@types/react": "^16.9.55",
114116
"@types/react-instantsearch-dom": "^6.3.0",
115117
"@types/yup": "^0.29.9",
118+
"@typescript-eslint/eslint-plugin": "^4.7.0",
119+
"@typescript-eslint/parser": "^4.7.0",
116120
"axios": "^0.21.0",
117121
"babel-jest": "^26.5.2",
118122
"babel-loader": "^8.2.0",
@@ -123,6 +127,10 @@
123127
"dotenv-flow": "^3.2.0",
124128
"emotion": "^10.0.27",
125129
"emotion-server": "^10.0.27",
130+
"eslint": "^7.13.0",
131+
"eslint-plugin-jsx-a11y": "^6.4.1",
132+
"eslint-plugin-react": "^7.21.5",
133+
"eslint-plugin-react-hooks": "^4.2.0",
126134
"globby": "^11.0.1",
127135
"graphql": "^15.4.0",
128136
"husky": "^4.3.0",
@@ -155,6 +163,9 @@
155163
],
156164
"src/**/*.{ts,tsx,md,mdx,js}": [
157165
"prettier --write"
166+
],
167+
"src/**/*.{ts,tsx}": [
168+
"yarn type-check && yarn lint"
158169
]
159170
},
160171
"prettier": {

0 commit comments

Comments
 (0)