Skip to content

Commit 8c98e37

Browse files
committed
Add all the various config files for jest -> eslint -> typescript + react plugins
1 parent 2654a93 commit 8c98e37

File tree

5 files changed

+1303
-23
lines changed

5 files changed

+1303
-23
lines changed

.eslintrc.yaml

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
---
2+
env:
3+
browser: true
4+
commonjs: true
5+
es6: true
6+
jest: true
7+
node: true
8+
extends:
9+
- eslint:recommended
10+
- plugin:@typescript-eslint/recommended
11+
- plugin:import/recommended
12+
- plugin:import/typescript
13+
- plugin:react/recommended
14+
- plugin:jsx-a11y/strict
15+
- plugin:compat/recommended
16+
- prettier
17+
parser: "@typescript-eslint/parser"
18+
parserOptions:
19+
ecmaVersion: 2018
20+
project:
21+
- "./tsconfig.json"
22+
- "./lib/ts/coderapi/tsconfig.json"
23+
- "./lib/ts/domutils/tsconfig.json"
24+
- "./lib/ts/ui/tsconfig.json"
25+
- "./product/coder.com/site/tsconfig.json"
26+
- "./product/coder/e2e/tsconfig.json"
27+
- "./product/coder/site/tsconfig.json"
28+
- "./product/cportal/site/tsconfig.json"
29+
sourceType: module
30+
ecmaFeatures:
31+
jsx: true
32+
tsconfigRootDir: "./"
33+
plugins:
34+
- "@typescript-eslint"
35+
- import
36+
- react-hooks
37+
- jest
38+
- no-storage
39+
root: true
40+
rules:
41+
"@typescript-eslint/brace-style":
42+
["error", "1tbs", { "allowSingleLine": false }]
43+
"@typescript-eslint/camelcase": "off"
44+
"@typescript-eslint/explicit-function-return-type": "off"
45+
"@typescript-eslint/explicit-module-boundary-types": "error"
46+
"@typescript-eslint/method-signature-style": ["error", "property"]
47+
"@typescript-eslint/no-invalid-void-type": error
48+
# We're disabling the `no-namespace` rule to use a pattern of defining an interface,
49+
# and then defining functions that operate on that data via namespace. This is helpful for
50+
# dealing with immutable objects. This is a common pattern that shows up in some other
51+
# large TypeScript projects, like VSCode.
52+
# More details: https://github.com/coder/m/pull/9720#discussion_r697609528
53+
"@typescript-eslint/no-namespace": "off"
54+
"@typescript-eslint/no-unnecessary-boolean-literal-compare": error
55+
"@typescript-eslint/no-unnecessary-condition": warn
56+
"@typescript-eslint/no-unnecessary-type-assertion": warn
57+
"@typescript-eslint/no-unused-vars":
58+
- error
59+
- argsIgnorePattern: "^_"
60+
varsIgnorePattern: "^_"
61+
"@typescript-eslint/no-use-before-define": "off"
62+
"@typescript-eslint/object-curly-spacing": ["error", "always"]
63+
"@typescript-eslint/triple-slash-reference": "off"
64+
"brace-style": "off"
65+
"curly": ["error", "all"]
66+
eqeqeq: error
67+
import/default: "off"
68+
import/namespace: "off"
69+
import/newline-after-import:
70+
- error
71+
- count: 1
72+
import/no-named-as-default: "off"
73+
import/no-named-as-default-member: "off"
74+
import/prefer-default-export: "off"
75+
jest/no-focused-tests: "error"
76+
jsx-a11y/label-has-for: "off"
77+
jsx-a11y/no-autofocus: "off"
78+
no-console:
79+
- warn
80+
- allow:
81+
- warn
82+
- error
83+
- info
84+
- debug
85+
no-dupe-class-members: "off"
86+
no-restricted-imports:
87+
- error
88+
- paths:
89+
- name: "@material-ui/core"
90+
message:
91+
"Use path imports to avoid pulling in unused modules. See:
92+
https://material-ui.com/guides/minimizing-bundle-size/"
93+
- name: "@material-ui/icons"
94+
message:
95+
"Use path imports to avoid pulling in unused modules. See:
96+
https://material-ui.com/guides/minimizing-bundle-size/"
97+
- name: "@material-ui/styles"
98+
message:
99+
"Use path imports to avoid pulling in unused modules. See:
100+
https://material-ui.com/guides/minimizing-bundle-size/"
101+
- name: "@material-ui/core/Tooltip"
102+
message: "Use the custom Tooltip on componens/Tooltip"
103+
no-storage/no-browser-storage: error
104+
no-unused-vars: "off"
105+
"object-curly-spacing": "off"
106+
react-hooks/exhaustive-deps: warn
107+
react-hooks/rules-of-hooks: error
108+
react/jsx-no-script-url:
109+
- error
110+
- - name: Link
111+
props:
112+
- to
113+
- name: Button
114+
props:
115+
- href
116+
- name: IconButton
117+
props:
118+
- href
119+
react/prop-types: "off"
120+
react/jsx-boolean-value: ["error", "never"]
121+
react/jsx-curly-brace-presence:
122+
- error
123+
- children: ignore
124+
settings:
125+
react:
126+
version: detect
127+
import/resolver:
128+
typescript: {}

jest-runner.eslint.config.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Toggle eslint --fix by specifying the `FIX` env.
2+
const fix = !!process.env.FIX
3+
4+
module.exports = {
5+
cliOptions: {
6+
ext: [".js", ".ts", ".tsx"],
7+
ignorePath: ".eslintignore",
8+
cache: false,
9+
fix,
10+
resolvePluginsRelativeTo: ".",
11+
maxWarnings: 0,
12+
},
13+
}

jest.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ module.exports = {
1313
testPathIgnorePatterns: ["/node_modules/", "/__tests__/fakes"],
1414
moduleDirectories: ["node_modules", "<rootDir>"],
1515
},
16+
{
17+
displayName: "lint",
18+
runner: "jest-runner-eslint",
19+
testMatch: ["<rootDir>/site/**/*.js", "<rootDir>/site/**/*.ts", "<rootDir>/site/**/*.tsx"],
20+
testPathIgnorePatterns: ["/.next/", "/out/"]
21+
},
1622
],
1723
collectCoverageFrom: [
1824
"<rootDir>/site/**/*.js",

package.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
"export": "next export site",
1111
"format:check": "prettier --check '**/*.{css,html,js,json,jsx,md,ts,tsx,yaml,yml}'",
1212
"format:write": "prettier --write '**/*.{css,html,js,json,jsx,md,ts,tsx,yaml,yml}' && sql-formatter -l postgresql ./database/query.sql -o ./database/query.sql",
13+
"lint": "jest --selectProjects lint",
14+
"lint:fix": "FIX=true yarn lint",
1315
"test": "jest --selectProjects test",
1416
"test:coverage": "jest --selectProjects test --collectCoverage"
1517
},
@@ -24,9 +26,23 @@
2426
"@types/react": "17.0.38",
2527
"@types/react-dom": "17.0.11",
2628
"@types/superagent": "4.1.14",
29+
"@typescript-eslint/eslint-plugin": "4.33.0",
30+
"@typescript-eslint/parser": "4.33.0",
31+
"eslint": "7.32.0",
32+
"eslint-config-prettier": "8.3.0",
33+
"eslint-import-resolver-alias": "1.1.2",
34+
"eslint-import-resolver-typescript": "2.5.0",
35+
"eslint-plugin-compat": "4.0.1",
36+
"eslint-plugin-import": "2.25.4",
37+
"eslint-plugin-jest": "25.7.0",
38+
"eslint-plugin-jsx-a11y": "6.5.1",
39+
"eslint-plugin-no-storage": "1.0.2",
40+
"eslint-plugin-react": "7.28.0",
41+
"eslint-plugin-react-hooks": "4.3.0",
2742
"express": "4.17.2",
2843
"http-proxy-middleware": "2.0.1",
2944
"jest": "27.4.7",
45+
"jest-runner-eslint": "1.0.0",
3046
"next": "12.0.7",
3147
"prettier": "2.5.1",
3248
"react": "17.0.2",

0 commit comments

Comments
 (0)