-
Notifications
You must be signed in to change notification settings - Fork 4k
/
lint-js.js
42 lines (36 loc) · 1.05 KB
/
lint-js.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/**
* External dependencies
*/
const { sync: spawn } = require( 'cross-spawn' );
const { sync: resolveBin } = require( 'resolve-bin' );
/**
* Internal dependencies
*/
const {
fromConfigRoot,
getCliArgs,
hasCliArg,
hasPackageProp,
hasProjectFile,
} = require( '../utils' );
const args = getCliArgs();
const hasLintConfig = hasCliArg( '-c' ) ||
hasCliArg( '--config' ) ||
hasProjectFile( '.eslintrc.js' ) ||
hasProjectFile( '.eslintrc.yaml' ) ||
hasProjectFile( '.eslintrc.yml' ) ||
hasProjectFile( '.eslintrc.json' ) ||
hasProjectFile( '.eslintrc' ) ||
hasPackageProp( 'eslintConfig' );
// When a configuration is not provided by the project, use from the default
// provided with the scripts module. Instruct ESLint to avoid discovering via
// the `--no-eslintrc` flag, as otherwise it will still merge with inherited.
const config = ! hasLintConfig ?
[ '--no-eslintrc', '--config', fromConfigRoot( '.eslintrc.js' ) ] :
[];
const result = spawn(
resolveBin( 'eslint' ),
[ ...config, ...args ],
{ stdio: 'inherit' }
);
process.exit( result.status );