File size: 1,087 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env node

/**
 * Runs `eslint` only on the files the current branch modified.
 * Note that this has file-level granularity, so if you modified a
 * small bit of a big fail, you may get errors that weren't caused by you.
 */

const child_process = require( 'child_process' );
const path = require( 'path' );
const yargs = require( 'yargs' );

const branchName = child_process.execSync( 'git rev-parse --abbrev-ref HEAD' ).toString().trim();

const revision = child_process
	.execSync( 'git merge-base ' + branchName + ' trunk' )
	.toString()
	.trim();

const files = child_process
	.execSync( 'git diff --name-only --diff-filter=d ' + revision + ' HEAD' )
	.toString()
	.split( '\n' )
	.map( ( name ) => name.trim() )
	.filter( ( name ) => /\.[jt]sx?$/.test( name ) );

const flags = [ '--cache' ];

if ( yargs.argv.fix ) {
	flags.push( '--fix' );
}

const eslintBin = path.join( '.', 'node_modules', '.bin', 'eslint' );

const lintResult = child_process.spawnSync( eslintBin, [ ...flags, ...files ], {
	shell: true,
	stdio: 'inherit',
} );

process.exit( lintResult.status );