Skip to content

Commit

Permalink
feat: react-scripts lint command #1217
Browse files Browse the repository at this point in the history
  • Loading branch information
maciej-ka committed Jan 30, 2018
1 parent c9b289b commit aec1ba1
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/react-scripts/bin/react-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ const spawn = require('react-dev-utils/crossSpawn');
const args = process.argv.slice(2);

const scriptIndex = args.findIndex(
x => x === 'build' || x === 'eject' || x === 'start' || x === 'test'
x =>
x === 'build' ||
x === 'eject' ||
x === 'start' ||
x === 'test' ||
x === 'lint'
);
const script = scriptIndex === -1 ? args[0] : args[scriptIndex];
const nodeArgs = scriptIndex > 0 ? args.slice(0, scriptIndex) : [];
Expand All @@ -28,7 +33,8 @@ switch (script) {
case 'build':
case 'eject':
case 'start':
case 'test': {
case 'test':
case 'lint': {
const result = spawn.sync(
'node',
nodeArgs
Expand Down
28 changes: 28 additions & 0 deletions packages/react-scripts/scripts/lint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// @remove-on-eject-begin
/**
* Copyright (c) 2015-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.
*/
// @remove-on-eject-end
'use strict';

const CLIEngine = require('eslint').CLIEngine;

const cli = new CLIEngine({
// @remove-on-eject-begin
configFile: require.resolve('eslint-config-react-app'),
// @remove-on-eject-end
fix: process.argv.slice(2).indexOf('--fix') >= 0,
});
const report = cli.executeOnFiles(['src/**/*.{js,jsx,mjs}']);
const formatter = cli.getFormatter();

// persist changed files when using --fix option
CLIEngine.outputFixes(report);
console.log(formatter(report.results));

if (report.errorCount > 0) {
process.exit(1);
}
6 changes: 6 additions & 0 deletions tasks/e2e-simple.sh
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,9 @@ exists build/static/css/*.css
exists build/static/media/*.svg
exists build/favicon.ico

# Test linter
./node_modules/.bin/react-scripts lint

# Run tests with CI flag
CI=true yarn test
# Uncomment when snapshot testing is enabled by default:
Expand Down Expand Up @@ -273,6 +276,9 @@ exists build/static/css/*.css
exists build/static/media/*.svg
exists build/favicon.ico

# Test linter
node scripts/lint.js

# Run tests, overring the watch option to disable it.
# `CI=true yarn test` won't work here because `yarn test` becomes just `jest`.
# We should either teach Jest to respect CI env variable, or make
Expand Down

0 comments on commit aec1ba1

Please sign in to comment.