Skip to content

Allow disabling duplicate-code with a disable comment #5446

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

Merged
merged 4 commits into from
Mar 4, 2022

Conversation

DanielNoord
Copy link
Collaborator

  • Add yourself to CONTRIBUTORS if you are a new contributor.
  • Add a ChangeLog entry describing what your PR does.
  • If it's a new feature, or an important bug fix, add a What's New entry in
    doc/whatsnew/<current release.rst>.
  • Write a good description on what the PR does.

Type of Changes

Type
✨ New feature

Description

Please read

The most important reason why nobody could get this to work (I think) is because the similarity check can be ran stand-alone. I'm not sure what the rationale for this is, but I think that might have caused issues for other contributors.

This PR checks whether self has linter attribute (and therefore is not being run standalone) and then checks for disables. I think this is a fair approach to the problem: if you're running the similarity checker on its own it shouldn't be disabled by pylint type comments.

I would like the opinion of maintainers though as looking at the issues and past PRs has shown that this discussion has been quite opinionated.

Potentially closes #214

@DanielNoord DanielNoord added the Enhancement ✨ Improvement to a component label Nov 30, 2021
@coveralls
Copy link

coveralls commented Nov 30, 2021

Pull Request Test Coverage Report for Build 1933646682

  • 6 of 6 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.009%) to 94.005%

Totals Coverage Status
Change from base Build 1932658032: 0.009%
Covered Lines: 14944
Relevant Lines: 15897

💛 - Coveralls

@DanielNoord DanielNoord added the Needs review 🔍 Needs to be reviewed by one or multiple more persons label Dec 4, 2021
@DanielNoord DanielNoord added this to the 2.13.0 milestone Dec 4, 2021
@DanielNoord
Copy link
Collaborator Author

Good to see pydocstringformatter is working as expected 😄

@Pierre-Sassoulas
Copy link
Member

This PR checks whether self has linter attribute (and therefore is not being run standalone) and then checks for disables. I think this is a fair approach to the problem: if you're running the similarity checker on its own it shouldn't be disabled by pylint type comments.

Is there no way to easily take the disable into account when launched as a standalone ? If not I think it's fair enough, being able to disable when run with pylint is one of the most asked feature so having this one is pretty important.

@DanielNoord
Copy link
Collaborator Author

This PR checks whether self has linter attribute (and therefore is not being run standalone) and then checks for disables. I think this is a fair approach to the problem: if you're running the similarity checker on its own it shouldn't be disabled by pylint type comments.

Is there no way to easily take the disable into account when launched as a standalone ? If not I think it's fair enough, being able to disable when run with pylint is one of the most asked feature so having this one is pretty important.

Well, the issue with that is that the disable param checking is all done on the PyLinter class. In standalone mode no PyLinter class is instantiated so we would need to write a completely separate piece of code to handle this. I think this is why the previous attempts at this all failed: you need to duplicate a lot of work from PyLinter for this to be able to run in standalone and in pylint mode with the same form of disabling.

if hasattr(self, "linter"):
# Remove those lines that should be ignored because of disables
for index, line in enumerate(readlines()):
if self.linter._is_one_message_enabled("R0801", index + 1): # type: ignore[attr-defined]
Copy link
Member

Choose a reason for hiding this comment

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

That's pretty clever.

@Pierre-Sassoulas
Copy link
Member

In standalone mode no PyLinter class is instantiated so we would need to write a completely separate piece of code to handle this

Maybe we can instead instantiate a PyLinter with --disable=all --enable=duplicate-code ?

@DanielNoord
Copy link
Collaborator Author

Maybe we can instead instantiate a PyLinter with --disable=all --enable=duplicate-code ?

Haven't looked into that, but that kind of defeats the purpose of having this be a stand-alone tool. You would then also get all the overhead of configuration loading etc.

Personally I think we should be fine with adding this and then even closing the issue.
If somebody really wants to disable the duplicate-code checker while they are running symilar stand-alone (why even run it in the first place then...) they can create a new issue and we can then discuss if there is a real use case for that.

@Pierre-Sassoulas
Copy link
Member

(why even run it in the first place then...)

Right, it's possible to launch pylint with --disable=all --enable=duplicate-codedirectly instead. And it's also possible to use a specialized tool like Simian or PMD directly

Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Choose a reason for hiding this comment

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

There's currently 121 👍 on the original issue, safe to say (1) you're going made a lot of person happy with this one 😄

(1) unless a catastrophic failure condition eluded me during review 😂

@DanielNoord
Copy link
Collaborator Author

There's currently 121 👍 on the original issue, safe to say (1) you're going made a lot of person happy with this one 😄

(1) unless a catastrophic failure condition eluded me during review 😂

Yeah I completely forgot about this, but my response saying that I had a potential fix also got 12 👍... I'll do one final review as this was quite long ago and then I'll merge (if that's okay with you of course!).

@DanielNoord DanielNoord removed the Needs review 🔍 Needs to be reviewed by one or multiple more persons label Mar 4, 2022
@DanielNoord
Copy link
Collaborator Author

Merging this! @earonesty also thanks for your review!

@DanielNoord DanielNoord merged commit 4ca885f into pylint-dev:main Mar 4, 2022
@DanielNoord DanielNoord deleted the duplicate-code branch March 4, 2022 13:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement ✨ Improvement to a component
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The duplicate-code (R0801) can't be disabled
4 participants