Skip to content

Commit 38d546d

Browse files
committed
feat(TS): add support for TypeScript linting
BREAKING CHANGE: TypeScript v4 is required now (if you're using TS)
1 parent 32a4471 commit 38d546d

File tree

4 files changed

+29
-16
lines changed

4 files changed

+29
-16
lines changed

package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,15 @@
5353
"babel-plugin-module-resolver": "^4.0.0",
5454
"babel-plugin-transform-inline-environment-variables": "^0.4.3",
5555
"babel-plugin-transform-react-remove-prop-types": "^0.4.24",
56-
"browserslist": "^4.14.6",
56+
"browserslist": "^4.14.7",
5757
"chalk": "^4.1.0",
5858
"concurrently": "^5.3.0",
5959
"cosmiconfig": "^7.0.0",
6060
"cross-env": "^7.0.2",
6161
"cross-spawn": "^7.0.3",
6262
"doctoc": "^1.4.0",
63-
"eslint": "^7.12.1",
64-
"eslint-config-kentcdodds": "^16.1.0",
63+
"eslint": "^7.13.0",
64+
"eslint-config-kentcdodds": "^17.0.0",
6565
"eslint-config-prettier": "^6.15.0",
6666
"glob": "^7.1.6",
6767
"husky": "^4.3.0",
@@ -84,7 +84,7 @@
8484
"rollup-plugin-terser": "^7.0.2",
8585
"semver": "^7.3.2",
8686
"which": "^2.0.2",
87-
"yargs-parser": "^20.2.3"
87+
"yargs-parser": "^20.2.4"
8888
},
8989
"eslintConfig": {
9090
"extends": [
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`lint --no-cache will disable caching 1`] = `eslint --config ./src/config/eslintrc.js --ignore-path ./src/config/eslintignore --no-cache .`;
3+
exports[`lint --no-cache will disable caching 1`] = `eslint --config ./src/config/eslintrc.js --ext js,ts,tsx --ignore-path ./src/config/eslintignore --no-cache .`;
44

5-
exports[`lint calls eslint CLI with default args 1`] = `eslint --config ./src/config/eslintrc.js --ignore-path ./src/config/eslintignore --cache --cache-location <PROJECT_ROOT>/node_modules/.cache/.eslintcache .`;
5+
exports[`lint calls eslint CLI with default args 1`] = `eslint --config ./src/config/eslintrc.js --ext js,ts,tsx --ignore-path ./src/config/eslintignore --cache --cache-location <PROJECT_ROOT>/node_modules/.cache/.eslintcache .`;
66
7-
exports[`lint does not use built-in config with .eslintrc file 1`] = `eslint --ignore-path ./src/config/eslintignore --cache --cache-location <PROJECT_ROOT>/node_modules/.cache/.eslintcache .`;
7+
exports[`lint does not use built-in config with .eslintrc file 1`] = `eslint --ext js,ts,tsx --ignore-path ./src/config/eslintignore --cache --cache-location <PROJECT_ROOT>/node_modules/.cache/.eslintcache .`;
88
9-
exports[`lint does not use built-in config with .eslintrc.js file 1`] = `eslint --ignore-path ./src/config/eslintignore --cache --cache-location <PROJECT_ROOT>/node_modules/.cache/.eslintcache .`;
9+
exports[`lint does not use built-in config with .eslintrc.js file 1`] = `eslint --ext js,ts,tsx --ignore-path ./src/config/eslintignore --cache --cache-location <PROJECT_ROOT>/node_modules/.cache/.eslintcache .`;
1010
11-
exports[`lint does not use built-in config with --config 1`] = `eslint --ignore-path ./src/config/eslintignore --cache --cache-location <PROJECT_ROOT>/node_modules/.cache/.eslintcache --config ./custom-config.js .`;
11+
exports[`lint does not use built-in config with --config 1`] = `eslint --ext js,ts,tsx --ignore-path ./src/config/eslintignore --cache --cache-location <PROJECT_ROOT>/node_modules/.cache/.eslintcache --config ./custom-config.js .`;
1212
13-
exports[`lint does not use built-in config with eslintConfig pkg prop 1`] = `eslint --ignore-path ./src/config/eslintignore --cache --cache-location <PROJECT_ROOT>/node_modules/.cache/.eslintcache .`;
13+
exports[`lint does not use built-in config with eslintConfig pkg prop 1`] = `eslint --ext js,ts,tsx --ignore-path ./src/config/eslintignore --cache --cache-location <PROJECT_ROOT>/node_modules/.cache/.eslintcache .`;
1414
15-
exports[`lint does not use built-in ignore with .eslintignore file 1`] = `eslint --config ./src/config/eslintrc.js --cache --cache-location <PROJECT_ROOT>/node_modules/.cache/.eslintcache .`;
15+
exports[`lint does not use built-in ignore with .eslintignore file 1`] = `eslint --config ./src/config/eslintrc.js --ext js,ts,tsx --cache --cache-location <PROJECT_ROOT>/node_modules/.cache/.eslintcache .`;
1616
17-
exports[`lint does not use built-in ignore with --ignore-path 1`] = `eslint --config ./src/config/eslintrc.js --cache --cache-location <PROJECT_ROOT>/node_modules/.cache/.eslintcache --ignore-path ./my-ignore .`;
17+
exports[`lint does not use built-in ignore with --ignore-path 1`] = `eslint --config ./src/config/eslintrc.js --ext js,ts,tsx --cache --cache-location <PROJECT_ROOT>/node_modules/.cache/.eslintcache --ignore-path ./my-ignore .`;
1818
19-
exports[`lint does not use built-in ignore with eslintIgnore pkg prop 1`] = `eslint --config ./src/config/eslintrc.js --cache --cache-location <PROJECT_ROOT>/node_modules/.cache/.eslintcache .`;
19+
exports[`lint does not use built-in ignore with eslintIgnore pkg prop 1`] = `eslint --config ./src/config/eslintrc.js --ext js,ts,tsx --cache --cache-location <PROJECT_ROOT>/node_modules/.cache/.eslintcache .`;
2020
21-
exports[`lint runs on given files, but only js files 1`] = `eslint --config ./src/config/eslintrc.js --ignore-path ./src/config/eslintignore --cache --cache-location <PROJECT_ROOT>/node_modules/.cache/.eslintcache ./src/index.js ./src/component.js`;
21+
exports[`lint runs on given files, but only js files 1`] = `eslint --config ./src/config/eslintrc.js --ext js,ts,tsx --ignore-path ./src/config/eslintignore --cache --cache-location <PROJECT_ROOT>/node_modules/.cache/.eslintcache ./src/index.js ./src/thing.ts ./src/lib.tsx ./src/component.js`;
22+
23+
exports[`lint supports custom --ext 1`] = `eslint --config ./src/config/eslintrc.js --ignore-path ./src/config/eslintignore --cache --cache-location <PROJECT_ROOT>/node_modules/.cache/.eslintcache --ext js .`;

src/scripts/__tests__/lint.js

+5
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,16 @@ cases(
7575
'--no-cache will disable caching': {
7676
args: ['--no-cache'],
7777
},
78+
'supports custom --ext': {
79+
args: ['--ext', 'js'],
80+
},
7881
'runs on given files, but only js files': {
7982
args: [
8083
'./src/index.js',
8184
'./package.json',
8285
'./src/index.css',
86+
'./src/thing.ts',
87+
'./src/lib.tsx',
8388
'./src/component.js',
8489
],
8590
},

src/scripts/lint.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ const config = useBuiltinConfig
1818
? ['--config', hereRelative('../config/eslintrc.js')]
1919
: []
2020

21+
const defaultExtensions = 'js,ts,tsx'
22+
const ext = args.includes('--ext') ? [] : ['--ext', defaultExtensions]
23+
const extensions = (parsedArgs.ext || defaultExtensions).split(',')
24+
2125
const useBuiltinIgnore =
2226
!args.includes('--ignore-path') &&
2327
!hasFile('.eslintignore') &&
@@ -43,12 +47,14 @@ if (filesGiven) {
4347
// we need to take all the flag-less arguments (the files that should be linted)
4448
// and filter out the ones that aren't js files. Otherwise json or css files
4549
// may be passed through
46-
args = args.filter(a => !parsedArgs._.includes(a) || /\.jsx?$/.test(a))
50+
args = args.filter(
51+
a => !parsedArgs._.includes(a) || extensions.some(e => a.endsWith(e)),
52+
)
4753
}
4854

4955
const result = spawn.sync(
5056
resolveBin('eslint'),
51-
[...config, ...ignore, ...cache, ...args, ...filesToApply],
57+
[...config, ...ext, ...ignore, ...cache, ...args, ...filesToApply],
5258
{stdio: 'inherit'},
5359
)
5460

0 commit comments

Comments
 (0)