Skip to content

Commit 818bf2e

Browse files
author
Kent C. Dodds
committed
feat(lint): move .eslintcache to node_modules
1 parent 7bc29e4 commit 818bf2e

File tree

4 files changed

+35
-12
lines changed

4 files changed

+35
-12
lines changed

src/scripts/__tests__/__snapshots__/lint.js.snap

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@
22

33
exports[`lint --no-cache will disable caching 1`] = `eslint --config ./src/config/eslintrc.js --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 .`;
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 .`;
66
7-
exports[`lint does not use built-in config with .eslintrc file 1`] = `eslint --ignore-path ./src/config/eslintignore --cache .`;
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 .`;
88
9-
exports[`lint does not use built-in config with .eslintrc.js file 1`] = `eslint --ignore-path ./src/config/eslintignore --cache .`;
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 .`;
1010
11-
exports[`lint does not use built-in config with --config 1`] = `eslint --ignore-path ./src/config/eslintignore --cache --config ./custom-config.js .`;
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 .`;
1212
13-
exports[`lint does not use built-in config with eslintConfig pkg prop 1`] = `eslint --ignore-path ./src/config/eslintignore --cache .`;
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 .`;
1414
15-
exports[`lint does not use built-in ignore with .eslintignore file 1`] = `eslint --config ./src/config/eslintrc.js --cache .`;
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 .`;
1616
17-
exports[`lint does not use built-in ignore with --ignore-path 1`] = `eslint --config ./src/config/eslintrc.js --cache --ignore-path ./my-ignore .`;
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 .`;
1818
19-
exports[`lint does not use built-in ignore with eslintIgnore pkg prop 1`] = `eslint --config ./src/config/eslintrc.js --cache .`;
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 .`;
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 ./src/index.js ./src/component.js`;
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`;

src/scripts/__tests__/helpers/serializers.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,15 @@ export const winPathSerializer = {
1111
print: val => slash(val),
1212
test: val => typeof val === 'string' && val.includes('\\'),
1313
}
14+
15+
export const relativePathSerializer = {
16+
print: val => normalizePaths(val),
17+
test: val => normalizePaths(val) !== val,
18+
}
19+
20+
function normalizePaths(value) {
21+
if (typeof value !== 'string') {
22+
return value
23+
}
24+
return value.split(process.cwd()).join('<PROJECT_ROOT>')
25+
}

src/scripts/__tests__/lint.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
import cases from 'jest-in-case'
2-
import {unquoteSerializer, winPathSerializer} from './helpers/serializers'
2+
import {
3+
unquoteSerializer,
4+
winPathSerializer,
5+
relativePathSerializer,
6+
} from './helpers/serializers'
37

48
expect.addSnapshotSerializer(unquoteSerializer)
59
expect.addSnapshotSerializer(winPathSerializer)
10+
expect.addSnapshotSerializer(relativePathSerializer)
611

712
cases(
813
'lint',

src/scripts/lint.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const path = require('path')
22
const spawn = require('cross-spawn')
33
const yargsParser = require('yargs-parser')
4-
const {hasPkgProp, resolveBin, hasFile} = require('../utils')
4+
const {hasPkgProp, resolveBin, hasFile, fromRoot} = require('../utils')
55

66
let args = process.argv.slice(2)
77
const here = p => path.join(__dirname, p)
@@ -27,7 +27,13 @@ const ignore = useBuiltinIgnore
2727
? ['--ignore-path', hereRelative('../config/eslintignore')]
2828
: []
2929

30-
const cache = args.includes('--no-cache') ? [] : ['--cache']
30+
const cache = args.includes('--no-cache')
31+
? []
32+
: [
33+
'--cache',
34+
'--cache-location',
35+
fromRoot('node_modules/.cache/.eslintcache'),
36+
]
3137

3238
const filesGiven = parsedArgs._.length > 0
3339

0 commit comments

Comments
 (0)