Skip to content

Commit

Permalink
lint task: update scripts/eslint.js sharing code with linc.js; (faceb…
Browse files Browse the repository at this point in the history
…ook#11518)

* (build infrastructure): unify lint and linc buid task;

* Fail on warnings

* Fail on warnings
  • Loading branch information
sjy authored and gaearon committed Nov 13, 2017
1 parent ffc9c37 commit 200db83
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 30 deletions.
19 changes: 19 additions & 0 deletions scripts/eslint/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

'use strict';

const CLIEngine = require('eslint').CLIEngine;
const cli = new CLIEngine();
const formatter = cli.getFormatter();

module.exports = function lintOnFiles(filePatterns) {
const report = cli.executeOnFiles(filePatterns);
const formatedResults = formatter(report.results);
console.log(formatedResults);
return report;
};
29 changes: 8 additions & 21 deletions scripts/tasks/eslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,11 @@

'use strict';

var path = require('path');
var spawn = require('child_process').spawn;

var extension = process.platform === 'win32' ? '.cmd' : '';

spawn(
path.join('node_modules', '.bin', 'eslint' + extension),
['.', '--max-warnings=0'],
{
// Allow colors to pass through
stdio: 'inherit',
}
).on('close', function(code) {
if (code !== 0) {
console.error('Lint failed');
} else {
console.log('Lint passed');
}

process.exit(code);
});
const lintOnFiles = require('../eslint');
const report = lintOnFiles(['.']);
if (report.errorCount > 0 || report.warningCount > 0) {
console.log('Lint failed.');
process.exit(1);
} else {
console.log('Lint passed.');
}
12 changes: 3 additions & 9 deletions scripts/tasks/linc.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,8 @@

'use strict';

const lintOnFiles = require('../eslint');
const execFileSync = require('child_process').execFileSync;
const CLIEngine = require('eslint').CLIEngine;

const cli = new CLIEngine();
const formatter = cli.getFormatter();

const mergeBase = execFileSync('git', ['merge-base', 'HEAD', 'master'], {
stdio: 'pipe',
encoding: 'utf-8',
Expand All @@ -30,10 +26,8 @@ const changedFiles = execFileSync(
.split('\n');
const jsFiles = changedFiles.filter(file => file.match(/.js$/g));

const report = cli.executeOnFiles(jsFiles);
console.log(formatter(report.results));

if (report.errorCount > 0) {
const report = lintOnFiles(jsFiles);
if (report.errorCount > 0 || report.warningCount > 0) {
console.log('Lint failed for changed files.');
process.exit(1);
} else {
Expand Down

0 comments on commit 200db83

Please sign in to comment.