Skip to content

Commit 67327d6

Browse files
authored
chore: use Netlify linting rules (#57)
* chore: use Netlify linting rules * chore: use correct kodiak toml name
1 parent fea7b0f commit 67327d6

File tree

11 files changed

+3007
-3049
lines changed

11 files changed

+3007
-3049
lines changed

.eslintrc.js

Lines changed: 20 additions & 262 deletions
Original file line numberDiff line numberDiff line change
@@ -1,269 +1,27 @@
11
module.exports = {
2-
parser: `@babel/eslint-parser`,
3-
extends: [
4-
`google`,
5-
`eslint:recommended`,
6-
`plugin:react/recommended`,
7-
`prettier`,
8-
],
9-
plugins: [`prettier`, `react`, `filenames`, `@babel`],
2+
extends: '@netlify/eslint-config-node',
3+
rules: {
4+
'max-depth': 0,
5+
complexity: 0,
6+
'fp/no-let': 0,
7+
'fp/no-loops': 0,
8+
'fp/no-mutation': 0,
9+
'fp/no-mutating-methods': 0,
10+
'id-length': 0,
11+
'no-magic-numbers': 0,
12+
'no-param-reassign': 0,
13+
'no-promise-executor-return': 0,
14+
'no-prototype-builtins': 0,
15+
'no-unused-vars': ['error', { ignoreRestSiblings: true }],
16+
'unicorn/filename-case': 0,
17+
'unicorn/numeric-separators-style': 0,
18+
'unicorn/no-empty-file': 0,
19+
'no-plusplus': 0,
20+
},
1021
parserOptions: {
11-
ecmaVersion: 2016,
12-
sourceType: `module`,
13-
ecmaFeatures: {
14-
jsx: true,
15-
},
16-
babelOptions: {
17-
configFile: `./.babelrc`,
18-
},
22+
sourceType: 'module',
1923
},
2024
env: {
21-
browser: true,
22-
es6: true,
23-
node: true,
2425
jest: true,
2526
},
26-
globals: {
27-
before: true,
28-
after: true,
29-
spyOn: true,
30-
// These should be in scope but for some reason eslint can't see them
31-
NodeJS: true,
32-
JSX: true,
33-
NodeRequire: true,
34-
TimerHandler: true,
35-
__PATH_PREFIX__: true,
36-
__BASE_PATH__: true,
37-
__ASSET_PREFIX__: true,
38-
_CFLAGS_: true,
39-
},
40-
rules: {
41-
"@babel/no-unused-expressions": [
42-
`error`,
43-
{
44-
allowTaggedTemplates: true,
45-
},
46-
],
47-
"no-unused-expressions": `off`,
48-
"@babel/no-invalid-this": `error`,
49-
"no-invalid-this": `off`,
50-
"arrow-body-style": [
51-
`error`,
52-
`as-needed`,
53-
{ requireReturnForObjectLiteral: true },
54-
],
55-
"new-cap": `off`,
56-
"no-unused-vars": [
57-
`warn`,
58-
{
59-
varsIgnorePattern: `^_`,
60-
argsIgnorePattern: `^_`,
61-
ignoreRestSiblings: true,
62-
},
63-
],
64-
"consistent-return": [`error`],
65-
"filenames/match-regex": [`error`, `^[a-z-\\d\\.]+$`, true],
66-
"no-console": `off`,
67-
"no-inner-declarations": `off`,
68-
"prettier/prettier": `error`,
69-
quotes: [`error`, `backtick`],
70-
"react/display-name": `off`,
71-
"react/jsx-key": `warn`,
72-
"react/no-unescaped-entities": `off`,
73-
"react/prop-types": `off`,
74-
"require-jsdoc": `off`,
75-
"valid-jsdoc": `off`,
76-
"prefer-promise-reject-errors": `warn`,
77-
"no-prototype-builtins": `warn`,
78-
"guard-for-in": `warn`,
79-
"spaced-comment": [
80-
`error`,
81-
`always`,
82-
{ markers: [`/`], exceptions: [`*`, `+`] },
83-
],
84-
camelcase: [
85-
`error`,
86-
{
87-
properties: `never`,
88-
ignoreDestructuring: true,
89-
allow: [`^unstable_`],
90-
},
91-
],
92-
},
93-
overrides: [
94-
{
95-
files: [
96-
`packages/**/gatsby-browser.js`,
97-
`packages/gatsby/cache-dir/**/*`,
98-
],
99-
env: {
100-
browser: true,
101-
},
102-
globals: {
103-
___loader: false,
104-
___emitter: false,
105-
},
106-
},
107-
{
108-
files: [`**/cypress/integration/**/*`, `**/cypress/support/**/*`],
109-
globals: {
110-
cy: false,
111-
Cypress: false,
112-
},
113-
},
114-
{
115-
files: [`*.ts`, `*.tsx`],
116-
parser: `@typescript-eslint/parser`,
117-
plugins: [`@typescript-eslint/eslint-plugin`],
118-
extends: [`plugin:@typescript-eslint/recommended`],
119-
rules: {
120-
// We should absolutely avoid using ts-ignore, but it's not always possible.
121-
// particular when a dependencies types are incorrect.
122-
"@typescript-eslint/ban-ts-comment": [
123-
`warn`,
124-
{ "ts-ignore": `allow-with-description` },
125-
],
126-
// This rule is great. It helps us not throw on types for areas that are
127-
// easily inferrable. However we have a desire to have all function inputs
128-
// and outputs declaratively typed. So this let's us ignore the parameters
129-
// inferrable lint.
130-
"@typescript-eslint/no-inferrable-types": [
131-
`error`,
132-
{ ignoreParameters: true },
133-
],
134-
"@typescript-eslint/ban-types": [
135-
`error`,
136-
{
137-
extendDefaults: true,
138-
types: {
139-
"{}": {
140-
fixWith: `Record<string, unknown>`,
141-
},
142-
object: {
143-
fixWith: `Record<string, unknown>`,
144-
},
145-
},
146-
},
147-
],
148-
camelcase: `off`,
149-
// TODO: These rules allow a lot of stuff and don't really enforce. If we want to apply our styleguide, we'd need to fix a lot of stuff
150-
"@typescript-eslint/naming-convention": [
151-
`error`,
152-
{
153-
selector: `default`,
154-
format: [`camelCase`],
155-
},
156-
{
157-
selector: `variable`,
158-
format: [`camelCase`, `UPPER_CASE`, `PascalCase`],
159-
leadingUnderscore: `allowSingleOrDouble`,
160-
trailingUnderscore: `allowSingleOrDouble`,
161-
},
162-
{
163-
selector: `function`,
164-
format: [`camelCase`, `PascalCase`],
165-
leadingUnderscore: `allow`,
166-
},
167-
{
168-
selector: `parameter`,
169-
format: [`camelCase`, `PascalCase`, `snake_case`],
170-
leadingUnderscore: `allowSingleOrDouble`,
171-
},
172-
{
173-
selector: `enumMember`,
174-
format: [`camelCase`, `UPPER_CASE`, `PascalCase`],
175-
},
176-
{
177-
selector: `typeLike`,
178-
format: [`PascalCase`],
179-
},
180-
{
181-
selector: `typeAlias`,
182-
format: [`camelCase`, `PascalCase`],
183-
},
184-
{
185-
selector: `property`,
186-
format: [`PascalCase`, `UPPER_CASE`, `camelCase`, `snake_case`],
187-
leadingUnderscore: `allowSingleOrDouble`,
188-
},
189-
{
190-
selector: `objectLiteralProperty`,
191-
format: [`PascalCase`, `UPPER_CASE`, `camelCase`, `snake_case`],
192-
leadingUnderscore: `allowSingleOrDouble`,
193-
trailingUnderscore: `allowSingleOrDouble`,
194-
},
195-
{
196-
selector: `enum`,
197-
format: [`PascalCase`, `UPPER_CASE`],
198-
},
199-
{
200-
selector: `method`,
201-
format: [`PascalCase`, `camelCase`],
202-
leadingUnderscore: `allowSingleOrDouble`,
203-
},
204-
{
205-
selector: `interface`,
206-
format: [`PascalCase`],
207-
prefix: [`I`],
208-
},
209-
],
210-
// This rule tries to prevent using `require()`. However in node code,
211-
// there are times where this makes sense. And it specifically is causing
212-
// problems in our tests where we often want this functionality for module
213-
// mocking. At this point it's easier to have it off and just encourage
214-
// using top-level imports via code reviews.
215-
"@typescript-eslint/no-var-requires": `off`,
216-
"@typescript-eslint/no-extra-semi": `off`,
217-
// This rule ensures that typescript types do not have semicolons
218-
// at the end of their lines, since our prettier setup is to have no semicolons
219-
// e.g.,
220-
// interface Foo {
221-
// - baz: string;
222-
// + baz: string
223-
// }
224-
"@typescript-eslint/member-delimiter-style": [
225-
`error`,
226-
{
227-
multiline: {
228-
delimiter: `none`,
229-
},
230-
},
231-
],
232-
"@typescript-eslint/no-empty-function": `off`,
233-
// This ensures that we always type the return type of functions
234-
// a high level focus of our TS setup is typing fn inputs and outputs.
235-
"@typescript-eslint/explicit-function-return-type": `error`,
236-
// This forces us to use interfaces over types aliases for object definitions.
237-
// Type is still useful for opaque types
238-
// e.g.,
239-
// type UUID = string
240-
"@typescript-eslint/consistent-type-definitions": [
241-
`error`,
242-
`interface`,
243-
],
244-
"@typescript-eslint/no-use-before-define": [
245-
`error`,
246-
{ functions: false },
247-
],
248-
// Allows us to write unions like `type Foo = "baz" | "bar"`
249-
// otherwise eslint will want to switch the strings to backticks,
250-
// which then crashes the ts compiler
251-
quotes: `off`,
252-
"@typescript-eslint/quotes": [
253-
2,
254-
`backtick`,
255-
{
256-
avoidEscape: true,
257-
},
258-
],
259-
260-
"@typescript-eslint/array-type": [`error`, { default: `generic` }],
261-
},
262-
},
263-
],
264-
settings: {
265-
react: {
266-
version: `16.9.0`,
267-
},
268-
},
26927
}
File renamed without changes.

.github/workflows/test.yml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
strategy:
1313
matrix:
1414
os: [ubuntu-latest, macOS-latest] #, windows-latest] # TODO add an e2etest.bat file
15-
node-version: [14.15.0, "*"]
15+
node-version: [14.15.0, '*']
1616
exclude:
1717
- os: macOS-latest
1818
node-version: 14.15.0
@@ -26,7 +26,10 @@ jobs:
2626
uses: actions/setup-node@v2
2727
with:
2828
node-version: ${{ matrix.node-version }}
29-
check-latest: "*"
30-
- run: npm install -g netlify-cli
31-
- run: yarn
32-
- run: yarn test
29+
check-latest: '*'
30+
- name: Install Netlify CLI
31+
run: npm install -g netlify-cli
32+
- name: Install dependencies
33+
run: yarn install --ignore-engines
34+
- name: Run tests
35+
run: yarn test

.prettierrc.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
module.exports = {
2-
arrowParens: `avoid`,
3-
semi: false,
2+
...require("@netlify/eslint-config-node/.prettierrc.json"),
3+
endOfLine: "auto",
44
}

package.json

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,35 +13,26 @@
1313
}
1414
],
1515
"dependencies": {
16-
"@babel/runtime": "^7.14.8",
16+
"@babel/runtime": "^7.16.7",
1717
"fs-extra": "^10.0.0",
18-
"gatsby-core-utils": "^3.3.0",
18+
"gatsby-core-utils": "^3.5.2",
1919
"kebab-hash": "^0.1.2",
2020
"lodash": "^4.17.21",
2121
"webpack-assets-manifest": "^5.0.6"
2222
},
2323
"devDependencies": {
24-
"@babel/cli": "^7.14.8",
25-
"@babel/core": "^7.14.8",
26-
"@babel/eslint-parser": "^7.14.0",
27-
"@babel/eslint-plugin": "^7.14.0",
28-
"@typescript-eslint/eslint-plugin": "^4.28.1",
29-
"@typescript-eslint/parser": "^4.28.1",
30-
"babel-preset-gatsby-package": "^2.3.0",
24+
"@babel/cli": "^7.16.8",
25+
"@babel/core": "^7.16.7",
26+
"@babel/eslint-parser": "^7.16.5",
27+
"@babel/eslint-plugin": "^7.16.5",
28+
"@netlify/eslint-config-node": "^4.1.5",
29+
"babel-preset-gatsby-package": "^2.5.0",
3130
"cross-env": "^7.0.3",
32-
"eslint": "^7.32.0",
33-
"eslint-config-google": "^0.14.0",
34-
"eslint-config-prettier": "^8.3.0",
35-
"eslint-plugin-filenames": "^1.3.2",
36-
"eslint-plugin-import": "^2.23.4",
37-
"eslint-plugin-jsx-a11y": "^6.4.1",
38-
"eslint-plugin-prettier": "^4.0.0",
39-
"eslint-plugin-react": "^7.24.0",
40-
"gatsby": "^4.3.0",
41-
"gatsby-plugin-utils": "^2.3.0",
42-
"jest": "^27.0.6",
31+
"gatsby": "^4.5.3",
32+
"gatsby-plugin-utils": "^2.5.0",
33+
"jest": "^27.4.7",
4334
"prettier": "^2.3.2",
44-
"typescript": "^4.3.5"
35+
"typescript": "^4.5.4"
4536
},
4637
"homepage": "https://github.com/netlify/gatsby-plugin-netlify#readme",
4738
"keywords": [

0 commit comments

Comments
 (0)