Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added react-scripts lint #2729

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions packages/react-scripts/bin/react-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,32 @@ switch (script) {
process.exit(result.status);
break;
}
case 'lint': {
let eslintConfigPath;

try {
eslintConfigPath = require.resolve('eslint-config-react-app');
} catch (e) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When would this throw and why? I don't understand.

eslintConfigPath = require.resolve('../../../package.json');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would package.json count as a valid config?

}

const results = spawn(
'node',
[
require.resolve('eslint/bin/eslint'),
'--config',
eslintConfigPath,
'src/**/*.{js,jsx}',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to include .mjs now that we support it.

It's interesting that this doesn't filter tests out. I guess we can say it's a feature. (Currently there's no way to lint tests.)

],
{ stdio: 'inherit' }
);

results.on('error', err => {
console.log('Error running ESLint: ' + err);
process.exit(results.status);
});
break;
}
default:
console.log('Unknown script "' + script + '".');
console.log('Perhaps you need to update react-scripts?');
Expand Down
6 changes: 6 additions & 0 deletions tasks/e2e-simple.sh
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,9 @@ function verify_module_scope {
# Enter the app directory
cd test-app

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

# Test the build
npm run build
# Check for expected output
Expand Down Expand Up @@ -314,6 +317,9 @@ npm link "$root_path"/packages/eslint-config-react-app
npm link "$root_path"/packages/react-dev-utils
npm link "$root_path"/packages/react-scripts

# Test lint
"$root_path"/packages/react-scripts/bin/react-scripts.js lint
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't make sense to me. What is this testing?

After you eject, react-scripts doesn't exist (it might on CI but you shouldn't rely on this—the point of ejecting is to wipe out react-scripts on the next installs).

So the script clearly doesn't "still work" after ejecting. If you had "lint": "react-scripts lint" before ejecting, it will stop working after.


# Test the build
npm run build
# Check for expected output
Expand Down