pylint-dev / pylint

It's not just a linter that annoys you!
https://pylint.readthedocs.io/en/latest/
GNU General Public License v2.0
5.29k stars 1.13k forks source link

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

Open matkoniecz opened 5 years ago

matkoniecz commented 5 years ago

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

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 commented 5 years ago

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.

quazgar commented 4 years ago

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 commented 4 years ago

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

elbakramer commented 2 years ago

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 commented 2 years ago

@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 commented 2 years ago

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 commented 2 years ago

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 :)