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

Conversation

Trott
Copy link
Member

@Trott Trott commented Apr 29, 2016

Checklist
  • tests and code linting passes
  • the commit message follows commit guidelines
Affected core subsystem(s)

tools

Description of change

Add -F flag to jslint.js which enables the automatic fixing of
issues that are fixable.

R=@mscdex

Add `-F` flag to `jslint.js` which enables the automatic fixing of
issues that are fixable.
@Trott Trott added the tools Issues and PRs related to the tools directory. label Apr 29, 2016

// 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.

@mscdex
Copy link
Contributor

mscdex commented Apr 30, 2016

LGTM if linter is ok with it: https://ci.nodejs.org/job/node-test-linter/2232/

EDIT: hrmm... that's odd, it took almost a minute to lint that time ...

@Trott
Copy link
Member Author

Trott commented Apr 30, 2016

@mscdex wrote:

hrmm... that's odd, it took almost a minute to lint that time ...

That's inline with other linter runs.

Job 2232 (this one): 51 seconds
Job 2231: 65 seconds
Job 2230: 47 seconds
Job 2229: 48 seconds
Job 2228: 47 seconds
Job 2227: 48 seconds
Job 2226: 47 seconds
Job 2225: 50 seconds
Job 2224: 48 seconds
Job 2223: 47 seconds

The time includes doing the git checkout and probably other things.

@mscdex
Copy link
Contributor

mscdex commented Apr 30, 2016

I thought we were consistently getting ~31 seconds after the switch to tools/jslint.js. I guess something else changed on that system in the meantime. Oh well.

@jasnell
Copy link
Member

jasnell commented Apr 30, 2016

Nice. Seems to work well but the lack of feedback that things were fixed in specific files could lead to issues... for instance, if someone doesn't know that a certain file was fixed by the linter, they may forget to add it and commit it to pick up those changes... or, the linter may have done something wrong and the person may need to undo those changes for whatever reason. In any case +1 to this. Appears to work as expected. LGTM

@mscdex
Copy link
Contributor

mscdex commented Apr 30, 2016

@jasnell I agree it would be nice if eslint could instead mark the problems that were fixed and the report formatters could show this.

@silverwind
Copy link
Contributor

they may forget to add it and commit it to pick up those changes

Not really an issue with git commit -a.

Should we expose fixing through something like make jslint-fix?

@Trott
Copy link
Member Author

Trott commented Apr 30, 2016

@silverwind asked:

Should we expose fixing through something like make jslint-fix?

Eventually, that could be a good idea. For now, I think I'd like to dog-food it for a while. There are definite pitfalls, especially around indentation, and I'd rather see how that does or doesn't affect things for a while.

Basically, if you're in the loop enough to be aware of the flag, then maybe you can help dog-food it too. :-)

@jasnell
Copy link
Member

jasnell commented Apr 30, 2016

Basically, if you're in the loop enough to be aware of the flag, then maybe you can help dog-food it too. :-)

given the number of times I have to catch myself fixing the same lints I'll definitely give it a whirl ;-)

@Trott
Copy link
Member Author

Trott commented Apr 30, 2016

given the number of times I have to catch myself fixing the same lints I'll definitely give it a whirl ;-)

My one tip is this: If you run it with -F and it reports no errors, run it again without -F to make sure any fixes didn't create new errors. I've only seen this happen with indentation problems. Other than that, as far as I know, it's a reliable time-saver.

@Trott
Copy link
Member Author

Trott commented May 1, 2016

};

// 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.

Trott added a commit that referenced this pull request May 2, 2016
Add `-F` flag to `jslint.js` which enables the automatic fixing of
issues that are fixable.

PR-URL: #6483
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
@Trott
Copy link
Member Author

Trott commented May 3, 2016

Landed in db3db07

@Trott Trott closed this May 3, 2016
Fishrock123 pushed a commit that referenced this pull request May 4, 2016
Add `-F` flag to `jslint.js` which enables the automatic fixing of
issues that are fixable.

PR-URL: #6483
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
joelostrowski pushed a commit to joelostrowski/node that referenced this pull request May 4, 2016
Add `-F` flag to `jslint.js` which enables the automatic fixing of
issues that are fixable.

PR-URL: nodejs#6483
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
@Trott Trott deleted the fix branch August 14, 2018 18:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tools Issues and PRs related to the tools directory.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants