Skip to content

Commit 3349548

Browse files
Max Summejrolfs
Max Summe
authored andcommitted
feat(scripts/lint): allow glob arguments to linter
1 parent 7170bbc commit 3349548

File tree

5 files changed

+11
-25
lines changed

5 files changed

+11
-25
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ dist
55
.opt-out
66
.DS_Store
77
.eslintcache
8+
.idea

src/config/lintstagedrc.js

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
const {resolveHoverScripts, resolveBin} = require('../utils')
22

3-
const kcdScripts = resolveHoverScripts()
3+
const hoverScripts = resolveHoverScripts()
44
const doctoc = resolveBin('doctoc')
55

66
module.exports = {
77
'README.md': [`${doctoc} --maxlevel 3 --notitle`],
8-
'*.+(js|jsx|json|yml|yaml|css|less|scss|ts|tsx|md|graphql|mdx|vue)': [
9-
`${kcdScripts} format`,
10-
`${kcdScripts} lint`,
11-
`${kcdScripts} test --findRelatedTests`,
8+
'*.+(json|yml|yaml|css|less|scss|md|graphql|mdx|vue)': [
9+
`${hoverScripts} format`,
10+
`${hoverScripts} test --findRelatedTests`,
11+
],
12+
'*.+(js|jsx|ts|tsx)': [
13+
`${hoverScripts} format`,
14+
`${hoverScripts} lint`,
15+
`${hoverScripts} test --findRelatedTests`,
1216
],
1317
}

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

-2
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,3 @@ exports[`lint does not use built-in ignore with .eslintignore file 1`] = `eslint
1717
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 --ext .js,.jsx,.ts,.tsx --ignore-path ./my-ignore .`;
1818
1919
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 --ext .js,.jsx,.ts,.tsx .`;
20-
21-
exports[`lint runs on given files, but only js and ts files 1`] = `eslint --config ./src/config/eslintrc.js --ignore-path ./src/config/eslintignore --cache --cache-location <PROJECT_ROOT>/node_modules/.cache/.eslintcache --ext .js,.jsx,.ts,.tsx ./src/index.js ./src/index.ts ./src/component.jsx ./src/component.tsx`;

src/scripts/__tests__/lint.js

-10
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,5 @@ cases(
7575
'--no-cache will disable caching': {
7676
args: ['--no-cache'],
7777
},
78-
'runs on given files, but only js and ts files': {
79-
args: [
80-
'./src/index.js',
81-
'./src/index.ts',
82-
'./package.json',
83-
'./src/index.css',
84-
'./src/component.jsx',
85-
'./src/component.tsx',
86-
],
87-
},
8878
},
8979
)

src/scripts/lint.js

+1-8
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const spawn = require('cross-spawn')
33
const yargsParser = require('yargs-parser')
44
const {hasPkgProp, resolveBin, hasFile, fromRoot} = require('../utils')
55

6-
let args = process.argv.slice(2)
6+
const args = process.argv.slice(2)
77
const here = p => path.join(__dirname, p)
88
const hereRelative = p => here(p).replace(process.cwd(), '.')
99
const parsedArgs = yargsParser(args)
@@ -42,13 +42,6 @@ const filesGiven = parsedArgs._.length > 0
4242

4343
const filesToApply = filesGiven ? [] : ['.']
4444

45-
if (filesGiven) {
46-
// we need to take all the flag-less arguments (the files that should be linted)
47-
// and filter out the ones that aren't js files. Otherwise json or css files
48-
// may be passed through
49-
args = args.filter(a => !parsedArgs._.includes(a) || /\.(j|t)sx?$/.test(a))
50-
}
51-
5245
const result = spawn.sync(
5346
resolveBin('eslint'),
5447
[...config, ...ignore, ...cache, ...extensions, ...args, ...filesToApply],

0 commit comments

Comments
 (0)