简体   繁体   中英

How can I configure pylint to only work with *.py files?

I have installed and configured and ran pylint like this:

pip install pylint==2.15.3
pylint --generate-rcfile > pylintrc
pylint ./*

However, it is complaining about several non-python files (pylintrc, pytest.ini, various markdown files, etc.)

An example of a few of those complaints:

************* Module README README.rst:1:6: E0001: Parsing failed: 'invalid syntax (, line 1)' (syntax-error) ************* Module pylintrc pylintrc:6:1: E0001: Parsing failed: 'cannot assign to operator (, line 6)' (syntax-error) ************* Module pytest pytest.ini:2:12: E0001: Parsing failed: 'invalid syntax (, line 2)' (syntax-error)

First, this is very surprising, I'd expect pylint to automatically only care about *.py files.

I've tried quite a bit of searching since this seems like it should be a very common problem, but no luck so far.

I've tried setting the [MAIN] ignore since that sounds promising, and looks like it works for others , but no luck. This is what I have for it:

[MAIN]
ignore=
      CVS,
      README.rst
      README.md
      *.rst,
      *.md,
      pylintrc,
      pytest,
      *.txt,
      *.toml

I tried without any wildcards since I read they aren't supported , but no improvement there.

I also tried configuring ignored-modules similarly to what I have for ignore , but no luck there.

I've also tried enumerating things on the command line via:

pylint --ignore=README.rst --ignore=*.md ./*

but no luck there either.

I did have some success finally with the ignore patterns when configured like below, but that can't possibly be the right way to do things?

ignore-patterns=(^\.#)|(.*\.md)|(.*\.rst)|(pytest\.ini)

Is there any way to configure pylint to only care about *.py files? Or if that isn't possible what is the right way to configure pylint to exclude and ignore files I don't want it to look at?

I found an answer. If I change the syntax of invoking pylint ever so subtly and run pylint./project instead of pylint./* it suddenly behaves as expected - ignoring non-python files.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM