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

Make no-unused-disable fixable #13

Merged
merged 1 commit into from
Feb 9, 2019

Conversation

ianobermiller
Copy link
Contributor

@ianobermiller ianobermiller commented May 4, 2018

Summary:

Add a fixer for no-unused-disable that just removes the entire comment node. If the comment is disabling multiple rules at once, do not offer to fix.

Test plan:

  • npm run test
  • run the rule on a handful of files in a local project, note that it
    finds many issues and successfully fixes them

@ianobermiller
Copy link
Contributor Author

Ironic, I will fix those lint errors :)

@codecov-io
Copy link

codecov-io commented May 5, 2018

Codecov Report

Merging #13 into master will increase coverage by 0.06%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #13      +/-   ##
==========================================
+ Coverage   96.87%   96.94%   +0.06%     
==========================================
  Files          25       25              
  Lines         320      327       +7     
==========================================
+ Hits          310      317       +7     
  Misses         10       10
Impacted Files Coverage Δ
lib/rules/no-unused-disable.js 100% <ø> (ø) ⬆️
tests/lib/rules/no-unused-disable.js 97.87% <100%> (+0.25%) ⬆️
lib/utils/patch.js 92.98% <100%> (+0.25%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c427c1c...1da89ae. Read the comment docs.

@mysticatea
Copy link
Owner

Thank you very much for this PR.
That idea sounds good to me.

However, unfortunately, I rewrote the no-unused-disable rule massively because the current no-unused-disable rule doesn't work in ESLint 5.0.0-alpha. (v3.0.0-beta.0) (see #12 for details)

If you are still interesting to implement this, you can investigate in lib/patch.js file. This file does the following actions:

  • It overrides the Linter.prototype.verify public method and it does if eslint-comments/no-unused-disable rule is enabled.
    • It verifies the code with reportUnusedDisableDirectives option.
    • It convert the reportUnusedDisableDirectives errors to eslint-comments/no-unused-disable errors before it returns the result.

@ianobermiller
Copy link
Contributor Author

I'll check that out, thanks!

@sindresorhus
Copy link

@ianobermiller Still interested in finishing this? :)

@ianobermiller
Copy link
Contributor Author

Perhaps at some point, but it is no longer a priority.

@ianobermiller
Copy link
Contributor Author

That should do it :)

Copy link
Owner

@mysticatea mysticatea left a comment

Choose a reason for hiding this comment

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

Thank you very much!

That direction looks good to me. But I have some concerns. Would you take a look?

  • please remove yarn.lock file
  • please fix CI errors

And the following comments:

lib/utils/patch.js Outdated Show resolved Hide resolved
} else {
clone.endLine = comment.loc.end.line
clone.endColumn = comment.loc.end.column + 1
clone.fix = function fix(fixer) {
return fixer.remove(comment)
Copy link
Owner

Choose a reason for hiding this comment

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

Please keep line breaks which were in the comment. This can make invalid syntax in semicolon-less style. For example:

foo /*eslint-disable
*/ bar
↓↓↓
foo  bar

Copy link
Owner

Choose a reason for hiding this comment

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

@ianobermiller Thank you for the update! LGTM except this matter. Would you make the replaced text comment.value.includes("\n") ? "\n" : "" or something like (and, add a test case)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Missed that one from the original review, thanks!

@ianobermiller ianobermiller force-pushed the unused-disable-fixer branch 2 times, most recently from e2c4e67 to 11dcac7 Compare January 5, 2019 23:55
@ianobermiller
Copy link
Contributor Author

@mysticatea the fixer will run only when there is a single rule (or no particular rule) being disabled.

Summary:

Add a fixer for no-unused-disable that just removes the entire comment
node. This behavior is undesirable if you frequently disable multiple
rules at a time, as it removes the entire comment even if only one was
unused. Since disabling multiple rules is the exception, I still think
this fixer has tremendous value.

Test plan:

- `npm run test`
- run the rule on a handful of files in a local project, note that it
finds many issues and successfully fixes them
@mysticatea
Copy link
Owner

I apologize for my delay. I had been diving into busy days.

LGTM, thank you so much!

@mysticatea mysticatea merged commit f625cd6 into mysticatea:master Feb 9, 2019
mysticatea added a commit that referenced this pull request Feb 19, 2019
This reverts commit f625cd6.

# Conflicts:
#	docs/rules/no-unused-disable.md
@ianobermiller ianobermiller deleted the unused-disable-fixer branch May 2, 2022 16:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants