Skip to content

Commit 7432013

Browse files
xjlimgaearon
authored andcommitted
make linc script cross platform (#11447)
* make linc script cross platform * fix typo * attempt to fix long command error * use eslint node api * Update linc.js
1 parent 366600d commit 7432013

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
},
9999
"scripts": {
100100
"build": "npm run version-check && node scripts/rollup/build.js",
101-
"linc": "git diff --name-only --diff-filter=ACMRTUB `git merge-base HEAD master` | grep '\\.js$' | xargs eslint --",
101+
"linc": "node ./scripts/tasks/linc.js",
102102
"lint": "node ./scripts/tasks/eslint.js",
103103
"postinstall": "node node_modules/fbjs-scripts/node/check-dev-engines.js package.json",
104104
"test": "jest",

scripts/tasks/linc.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* Copyright (c) 2013-present, Facebook, Inc.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
'use strict';
9+
10+
const execFileSync = require('child_process').execFileSync;
11+
const CLIEngine = require('eslint').CLIEngine;
12+
13+
const cli = new CLIEngine();
14+
const formatter = cli.getFormatter();
15+
16+
const mergeBase = execFileSync('git', ['merge-base', 'HEAD', 'master'], {
17+
stdio: 'pipe',
18+
encoding: 'utf-8',
19+
}).trim();
20+
const changedFiles = execFileSync(
21+
'git',
22+
['diff', '--name-only', '--diff-filter=ACMRTUB', mergeBase],
23+
{
24+
stdio: 'pipe',
25+
encoding: 'utf-8',
26+
}
27+
)
28+
.trim()
29+
.toString()
30+
.split('\n');
31+
const jsFiles = changedFiles.filter(file => file.match(/.js$/g));
32+
33+
const report = cli.executeOnFiles(jsFiles);
34+
console.log(formatter(report.results));
35+
36+
if (report.errorCount > 0) {
37+
console.log('Lint failed for changed files.');
38+
process.exit(1);
39+
} else {
40+
console.log('Lint passed for changed files.');
41+
}

0 commit comments

Comments
 (0)