Skip to content

Commit e7e5532

Browse files
Chore/linting updates (#91)
* Fix typescript linting * Override the `no-plusplus` rule that seems to have come with a plugin * Switch from `@ts-ignore` to `eslint-disable` to allow us to prevent `@ts-*` comments as they have the potential to mess stuff up at compile time. * Don't explicitly type property initialized as a boolean. * Setup proper checking of type imports * Allow importing from `estree` directly * Lint js as well as ts 🤦‍♂️
1 parent e76a08e commit e7e5532

File tree

7 files changed

+73
-11
lines changed

7 files changed

+73
-11
lines changed

.eslintrc

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,32 @@
33
"parserOptions": {
44
"sourceType": "module"
55
},
6-
"plugins": ["jest-formatting", "jest"],
6+
"plugins": ["jest-formatting", "jest", "@typescript-eslint/eslint-plugin"],
77
"env": {
88
"jest/globals": true
99
},
1010
"extends": [
1111
"airbnb-base",
12+
"plugin:@typescript-eslint/recommended",
1213
"plugin:prettier/recommended",
13-
"plugin:jest-formatting/recommended"
14+
"plugin:jest-formatting/recommended",
15+
"plugin:import/typescript"
1416
],
1517
"overrides": [
1618
{
1719
"files": ["**.*"],
1820
"rules": {
19-
"camelcase": "off"
21+
"camelcase": "off",
22+
"no-plusplus": "off",
23+
"import/extensions": "off"
2024
}
2125
}
22-
]
26+
],
27+
"settings": {
28+
"import/resolver": {
29+
"typescript": {
30+
"alwaysTryTypes": true // Without this `@types/estree` `estree` isn't actually in our node_modules.
31+
}
32+
}
33+
}
2334
}

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
"module": "src/index.ts",
2121
"scripts": {
2222
"pretty": "yarn prettier '**/*.*'",
23-
"lint": "yarn build && yarn link-plugin && yarn pretty --check && yarn eslint .",
24-
"format": "yarn build && yarn link-plugin && yarn pretty --write && yarn eslint --fix .",
23+
"lint": "yarn build && yarn link-plugin && yarn pretty --check && yarn eslint --ext .ts,.js .",
24+
"format": "yarn build && yarn link-plugin && yarn pretty --write && yarn eslint --fix --ext .ts,.js .",
2525
"build": "tsc",
2626
"test": "yarn build && jest",
2727
"link-plugin": "yarn link && yarn link eslint-plugin-jest-formatting"
@@ -33,10 +33,12 @@
3333
"@types/eslint": "^7.2.0",
3434
"@types/jest": "^26.0.0",
3535
"@types/node": "^14.0.13",
36+
"@typescript-eslint/eslint-plugin": "^3.4.0",
3637
"@typescript-eslint/parser": "^3.4.0",
3738
"eslint": "^7.3.1",
3839
"eslint-config-airbnb-base": "^14.2.0",
3940
"eslint-config-prettier": "^6.11.0",
41+
"eslint-import-resolver-typescript": "^2.0.0",
4042
"eslint-plugin-import": "^2.21.2",
4143
"eslint-plugin-jest": "^23.17.1",
4244
"eslint-plugin-jest-formatting": "file:.",

src/ast-utils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { AST, SourceCode } from 'eslint';
2+
// This is because we are using @types/estree that are brought in with eslint
3+
// eslint-disable-next-line import/no-extraneous-dependencies
24
import { Node } from 'estree';
35

46
export const isTokenASemicolon = (token: AST.Token): boolean =>

src/rules/padding.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
*/
1010

1111
import { AST, Rule, SourceCode } from 'eslint';
12+
// This is because we are using @types/estree that are brought in with eslint
13+
// eslint-disable-next-line import/no-extraneous-dependencies
1214
import { Node } from 'estree';
1315
import * as astUtils from '../ast-utils';
1416

@@ -271,8 +273,8 @@ const verifyNode = (node: Node, paddingContext: PaddingContext): void => {
271273
// ESTree.Node doesn't support the parent property which is added by
272274
// ESLint during traversal. Our best bet is to ignore the property access
273275
// here as it's the only place that it's checked.
274-
// @ts-ignore
275-
if (!astUtils.isValidParent(node.parent.type)) {
276+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
277+
if (!astUtils.isValidParent((node as any).parent.type)) {
276278
return;
277279
}
278280

@@ -314,7 +316,7 @@ const verifyNode = (node: Node, paddingContext: PaddingContext): void => {
314316
*/
315317
export const createRule = (
316318
configs: Config[],
317-
deprecated: boolean = false,
319+
deprecated = false,
318320
): Rule.RuleModule => ({
319321
meta: {
320322
fixable: 'whitespace',

tests/catfood.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* globs.
55
*/
66

7+
/* eslint-disable @typescript-eslint/no-empty-function */
8+
79
beforeAll(() => {});
810
beforeEach(() => {});
911
afterAll(() => {});

tests/dogfood.spec.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* eslint-disable @typescript-eslint/no-empty-function */
2+
13
beforeAll(() => {});
24

35
beforeEach(() => {});

yarn.lock

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,18 @@
615615
dependencies:
616616
"@types/yargs-parser" "*"
617617

618+
"@typescript-eslint/eslint-plugin@^3.4.0":
619+
version "3.4.0"
620+
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-3.4.0.tgz#8378062e6be8a1d049259bdbcf27ce5dfbeee62b"
621+
integrity sha512-wfkpiqaEVhZIuQRmudDszc01jC/YR7gMSxa6ulhggAe/Hs0KVIuo9wzvFiDbG3JD5pRFQoqnf4m7REDsUvBnMQ==
622+
dependencies:
623+
"@typescript-eslint/experimental-utils" "3.4.0"
624+
debug "^4.1.1"
625+
functional-red-black-tree "^1.0.1"
626+
regexpp "^3.0.0"
627+
semver "^7.3.2"
628+
tsutils "^3.17.1"
629+
618630
"@typescript-eslint/[email protected]":
619631
version "3.4.0"
620632
resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-3.4.0.tgz#8a44dfc6fb7f1d071937b390fe27608ebda122b8"
@@ -1443,6 +1455,17 @@ eslint-import-resolver-node@^0.3.3:
14431455
debug "^2.6.9"
14441456
resolve "^1.13.1"
14451457

1458+
eslint-import-resolver-typescript@^2.0.0:
1459+
version "2.0.0"
1460+
resolved "https://registry.yarnpkg.com/eslint-import-resolver-typescript/-/eslint-import-resolver-typescript-2.0.0.tgz#e95f126cc12d3018b9cc11692b4dbfd3e17d3ea6"
1461+
integrity sha512-bT5Frpl8UWoHBtY25vKUOMoVIMlJQOMefHLyQ4Tz3MQpIZ2N6yYKEEIHMo38bszBNUuMBW6M3+5JNYxeiGFH4w==
1462+
dependencies:
1463+
debug "^4.1.1"
1464+
is-glob "^4.0.1"
1465+
resolve "^1.12.0"
1466+
tiny-glob "^0.2.6"
1467+
tsconfig-paths "^3.9.0"
1468+
14461469
eslint-module-utils@^2.6.0:
14471470
version "2.6.0"
14481471
resolved "https://registry.yarnpkg.com/eslint-module-utils/-/eslint-module-utils-2.6.0.tgz#579ebd094f56af7797d19c9866c9c9486629bfa6"
@@ -1902,6 +1925,16 @@ globals@^12.1.0:
19021925
dependencies:
19031926
type-fest "^0.8.1"
19041927

1928+
globalyzer@^0.1.0:
1929+
version "0.1.4"
1930+
resolved "https://registry.yarnpkg.com/globalyzer/-/globalyzer-0.1.4.tgz#bc8e273afe1ac7c24eea8def5b802340c5cc534f"
1931+
integrity sha512-LeguVWaxgHN0MNbWC6YljNMzHkrCny9fzjmEUdnF1kQ7wATFD1RHFRqA1qxaX2tgxGENlcxjOflopBwj3YZiXA==
1932+
1933+
globrex@^0.1.1:
1934+
version "0.1.2"
1935+
resolved "https://registry.yarnpkg.com/globrex/-/globrex-0.1.2.tgz#dd5d9ec826232730cd6793a5e33a9302985e6098"
1936+
integrity sha512-uHJgbwAMwNFf5mLst7IWLNg14x1CkeqglJb/K3doi4dw6q2IvAAmM/Y81kevy83wP+Sst+nutFTYOGg3d1lsxg==
1937+
19051938
graceful-fs@^4.1.2, graceful-fs@^4.2.4:
19061939
version "4.2.4"
19071940
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.4.tgz#2256bde14d3632958c465ebc96dc467ca07a29fb"
@@ -3493,7 +3526,7 @@ regex-not@^1.0.0, regex-not@^1.0.2:
34933526
extend-shallow "^3.0.2"
34943527
safe-regex "^1.1.0"
34953528

3496-
regexpp@^3.1.0:
3529+
regexpp@^3.0.0, regexpp@^3.1.0:
34973530
version "3.1.0"
34983531
resolved "https://registry.yarnpkg.com/regexpp/-/regexpp-3.1.0.tgz#206d0ad0a5648cffbdb8ae46438f3dc51c9f78e2"
34993532
integrity sha512-ZOIzd8yVsQQA7j8GCSlPGXwg5PfmA1mrq0JP4nGhh54LaKN3xdai/vHUDu74pKwV8OxseMS65u2NImosQcSD0Q==
@@ -3587,7 +3620,7 @@ resolve-url@^0.2.1:
35873620
resolved "https://registry.yarnpkg.com/resolve-url/-/resolve-url-0.2.1.tgz#2c637fe77c893afd2a663fe21aa9080068e2052a"
35883621
integrity sha1-LGN/53yJOv0qZj/iGqkIAGjiBSo=
35893622

3590-
resolve@^1.10.0, resolve@^1.13.1, resolve@^1.17.0, resolve@^1.3.2:
3623+
resolve@^1.10.0, resolve@^1.12.0, resolve@^1.13.1, resolve@^1.17.0, resolve@^1.3.2:
35913624
version "1.17.0"
35923625
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.17.0.tgz#b25941b54968231cc2d1bb76a79cb7f2c0bf8444"
35933626
integrity sha512-ic+7JYiV8Vi2yzQGFWOkiZD5Z9z7O2Zhm9XMaTxdJExKasieFCr+yXZ/WmXsckHiKl12ar0y6XiXDx3m4RHn1w==
@@ -4050,6 +4083,14 @@ throat@^5.0.0:
40504083
resolved "https://registry.yarnpkg.com/throat/-/throat-5.0.0.tgz#c5199235803aad18754a667d659b5e72ce16764b"
40514084
integrity sha512-fcwX4mndzpLQKBS1DVYhGAcYaYt7vsHNIvQV+WXMvnow5cgjPphq5CaayLaGsjRdSCKZFNGt7/GYAuXaNOiYCA==
40524085

4086+
tiny-glob@^0.2.6:
4087+
version "0.2.6"
4088+
resolved "https://registry.yarnpkg.com/tiny-glob/-/tiny-glob-0.2.6.tgz#9e056e169d9788fe8a734dfa1ff02e9b92ed7eda"
4089+
integrity sha512-A7ewMqPu1B5PWwC3m7KVgAu96Ch5LA0w4SnEN/LbDREj/gAD0nPWboRbn8YoP9ISZXqeNAlMvKSKoEuhcfK3Pw==
4090+
dependencies:
4091+
globalyzer "^0.1.0"
4092+
globrex "^0.1.1"
4093+
40534094
40544095
version "1.0.4"
40554096
resolved "https://registry.yarnpkg.com/tmpl/-/tmpl-1.0.4.tgz#23640dd7b42d00433911140820e5cf440e521dd1"

0 commit comments

Comments
 (0)