lint task: update scripts/eslint.js sharing code with linc.js; (#11518)
* (build infrastructure): unify lint and linc buid task; * Fail on warnings * Fail on warnings
Johnson committed
Nov 14, 2017 at 01:07 UTC
200db83850257fe2e18d0212a1f96c59c02deb99
3 files changed
+30
-30
scripts/eslint/index.js
new
+19
@@ -0,0 +1,19 @@
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 CLIEngine = require('eslint').CLIEngine;
11
+const cli = new CLIEngine();
12
+const formatter = cli.getFormatter();
13
+
14
+module.exports = function lintOnFiles(filePatterns) {
15
+ const report = cli.executeOnFiles(filePatterns);
16
+ const formatedResults = formatter(report.results);
17
+ console.log(formatedResults);
18
+ return report;
19
+};
scripts/tasks/eslint.js
+8
-21
@@ -7,24 +7,11 @@
7
8
'use strict';
9
10
-var path = require('path');
11
-var spawn = require('child_process').spawn;
12
-
13
-var extension = process.platform === 'win32' ? '.cmd' : '';
14
-
15
-spawn(
16
- path.join('node_modules', '.bin', 'eslint' + extension),
17
- ['.', '--max-warnings=0'],
18
- {
19
- // Allow colors to pass through
20
- stdio: 'inherit',
21
- }
22
-).on('close', function(code) {
23
- if (code !== 0) {
24
- console.error('Lint failed');
25
- } else {
26
- console.log('Lint passed');
27
- }
28
-
29
- process.exit(code);
30
-});
10
+const lintOnFiles = require('../eslint');
11
+const report = lintOnFiles(['.']);
12
+if (report.errorCount > 0 || report.warningCount > 0) {
13
+ console.log('Lint failed.');
14
+ process.exit(1);
15
+} else {
16
+ console.log('Lint passed.');
17
+}
scripts/tasks/linc.js
+3
-9
@@ -7,12 +7,8 @@
7
8
'use strict';
9
10
+const lintOnFiles = require('../eslint');
11
const execFileSync = require('child_process').execFileSync;
11
-const CLIEngine = require('eslint').CLIEngine;
12
-
13
-const cli = new CLIEngine();
14
-const formatter = cli.getFormatter();
15
-
12
const mergeBase = execFileSync('git', ['merge-base', 'HEAD', 'master'], {
13
stdio: 'pipe',
14
encoding: 'utf-8',
@@ -30,10 +26,8 @@ const changedFiles = execFileSync(
26
.split('\n');
27
const jsFiles = changedFiles.filter(file => file.match(/.js$/g));
28
33
-const report = cli.executeOnFiles(jsFiles);
34
-console.log(formatter(report.results));
35
-
36
-if (report.errorCount > 0) {
29
+const report = lintOnFiles(jsFiles);
30
+if (report.errorCount > 0 || report.warningCount > 0) {
31
console.log('Lint failed for changed files.');
32
process.exit(1);
33
} else {