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

Allow to disable specific report in a single file using pylint configuration file or command line arguments #2712

Open
matkoniecz opened this issue Jan 29, 2019 · 7 comments
Labels
Configuration Related to configuration Enhancement ✨ Improvement to a component Needs PR This issue is accepted, sufficiently specified and now needs an implementation Per directory config New per directory config feature

Comments

@matkoniecz
Copy link

Is your feature request related to a problem? Please describe

pylint has a false positive (unfixable one, in usual situation pylint would be right).

It would be both undesirable to

  • litter source code with pylint comments
  • completely disable this check across all files

Describe the solution you'd like

Allow to specify (in config file or command line argument) that given rule should be disabled in a specific file.

Additional context

I have a repository with simple programs, each in multiple stages - from simplest possible to final one with more features. I use it during teaching programming. In this specific case I want to suppress one instance of W0612: Unused variable 'i' (unused-variable) as it becomes used one step later and it makes no sense to switch from _ variable name to i variable name just to pacify validator. And adding magic comment is unwanted as confusing beginners by weird comments is undesirable.

I made usual searches, I opened SO question but it appears that there is currently now way to do that.

rubocop (ruby linter) has config file that allows to do that - for example:

Style/GuardClause:
  Exclude:
    - 'transform_raw_log_data_to_information.rb'
@PCManticore
Copy link
Contributor

There's currently no way to do that, but sounds like something that might be useful and a bit more convenient for folks that want to disable selectively checks without putting those pragmas in the code.

@PCManticore PCManticore added Enhancement ✨ Improvement to a component Configuration Related to configuration labels Jan 30, 2019
@quazgar
Copy link

quazgar commented Sep 25, 2020

Do file-global inline settings like

# pylint: disable=too-many-arguments

near the beginning of a file work for you, or would that be too much littering?

@matkoniecz
Copy link
Author

No. I do not want any pylint specific comment in any source code file.

I am fine with pylint specific separate file, but I prefer to not use given validator warning at all if it generates any false positive in any of my files.

But I would prefer silencing false positive in specific file using pylint configuration file or command line arguments

@Pierre-Sassoulas Pierre-Sassoulas added Per directory config New per directory config feature Needs PR This issue is accepted, sufficiently specified and now needs an implementation labels Jun 30, 2022
@elbakramer
Copy link

This is my first approach on this issue by implementing a plugin:

https://gist.github.com/elbakramer/231e565dc65aecca311fba7b3f71479a

Acts as if the disable pragma comments were added on every line of matched files.
(Tried to disable not in line level but in module level, however it seemed that I have to explicitly find and specifiy an empty line that is placed before the blocks that need to be suppressed)

Because that disabling should be done before any other checkers to run,
I monkey patched the linter's process_tokens(tokens) method to run my custom checker's method after that.

This is a bit off-topic to this issue but I also took liberty of using the glob pattern matching when matching files,
along with the regex pattern matching that is rather more common in pylint environment.

This matching behavior can be ambiuous in certain situations but I'm just happy with that so far.

@Pierre-Sassoulas
Copy link
Member

@matkoniecz would the ignore options work for you ?

Standard Checkers
--ignore-paths
... Add files or directories matching the regular expressions patterns to the ignore-list. ...
--ignore
Files or directories to be skipped. They should be base names, not paths. Default: ('CVS',) ...
--ignore-patterns
Files or directories matching the regular expression patterns are skipped. The regex matches against

@matkoniecz
Copy link
Author

Is it possible to combine them to disable specific report in a single file? Not all reports in a single file, not to disable rule across all files.

@Pierre-Sassoulas
Copy link
Member

Right, no. We need per directory configuration, even per file configuration for that. The easy way to do that is to add pragmas at the top of the file but you already know that seeing the stackoverflow answers :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Configuration Related to configuration Enhancement ✨ Improvement to a component Needs PR This issue is accepted, sufficiently specified and now needs an implementation Per directory config New per directory config feature
Projects
None yet
Development

No branches or pull requests

5 participants