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

tools: add -F flag for fixing lint issues #6483

Closed
wants to merge 1 commit into from
Closed
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
15 changes: 13 additions & 2 deletions tools/jslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,15 @@ const CLIEngine = require('./eslint').CLIEngine;
const glob = require('./eslint/node_modules/glob');

const cwd = process.cwd();
const cli = new CLIEngine({
const cliOptions = {
rulePaths: rulesDirs
});
};

// Check if we should fix errors that are fixable
if (process.argv.indexOf('-F') !== -1)
Copy link
Contributor

Choose a reason for hiding this comment

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

process.argv.includes('-F')?

Copy link
Contributor

Choose a reason for hiding this comment

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

Or maybe put the result into above object, like fix: process.argv.includes('-F'), reducing the changes around here to a single line.

Copy link
Member Author

Choose a reason for hiding this comment

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

@silverwind wrote:

process.argv.includes('-F')?

I don't feel strongly about it, but I went with indexOf() !== -1 over includes() so that this could be used in the LTS branch and to be consistent with line 47 and elsewhere in the file that was already using indexOf() !== -1 for existence.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, right. Keep it as-is for LTS then.

cliOptions.fix = true;

const cli = new CLIEngine(cliOptions);

if (cluster.isMaster) {
var numCPUs = 1;
Expand Down Expand Up @@ -240,6 +246,11 @@ if (cluster.isMaster) {
if (files instanceof Array) {
// Lint some files
const report = cli.executeOnFiles(files);

// If we were asked to fix the fixable issues, do so.
if (cliOptions.fix)
CLIEngine.outputFixes(report);
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this line just remove the fixed lint errors from the report?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, that appears to be done by passing fix: true to the constructor. Much to my surprise, passing that to the constructor is not enough to actually fix the fixable issues. That's what this line does.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, I was just surprised it has enough information in the report to fix errors without needing the actual cli instance.


if (config.sendAll) {
// Return both success and error results

Expand Down