Skip to content

Use pylint to lint check all examples #2

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

Closed
tannewt opened this issue Oct 10, 2017 · 10 comments
Closed

Use pylint to lint check all examples #2

tannewt opened this issue Oct 10, 2017 · 10 comments

Comments

@tannewt
Copy link
Member

tannewt commented Oct 10, 2017

It enforces pep8: https://github.com/PyCQA/pycodestyle

@tannewt tannewt changed the title Use pycodestyle to lint check all examples Use pylint to lint check all examples May 14, 2018
@tannewt
Copy link
Member Author

tannewt commented May 14, 2018

@craigargh
Copy link
Contributor

craigargh commented May 14, 2018

I'm going to work on:

  • ufo
  • Trinket_Ultrasonic_Rangefinder
  • Trinket_Gemma_Space_Invader_Pendant
  • Trinket_Gemma_Servo_Control
  • Trinket_Gemma_Mini_Theramin

@ladyada
Copy link
Member

ladyada commented May 14, 2018

one possible route - have the pylint script live in the root of the repo, and run on any .py script it finds, UNLESS a .circuitpython.skip file exists in the same directory of the .py script

@dylwhich
Copy link
Contributor

I'm working on adding a pylint script and a travis-ci config to run it

@craigargh
Copy link
Contributor

@dylwhich Would you be able to add a pylint config file as well?

@craigargh
Copy link
Contributor

I'm using the following to run pylint

pylint --disable=missing-docstring,invalid-name,bad-whitespace,duplicate-code,import-error,consider-using-enumerate,no-name-in-module,no-member,too-many-arguments,no-else-return */*.py

It might make sense to Flake8 instead of PyLint as it's less opinionated.

@craigargh
Copy link
Contributor

This is the final version of the pylint setup that I'm using

pylint --disable=missing-docstring,invalid-name,bad-whitespace,duplicate-code,import-error,consider-using-enumerate,no-name-in-module,no-member,too-many-arguments,no-else-return,simplifiable-if-statement,global-statement,anomalous-backslash-in-string,too-many-locals,too-many-statements,no-self-use,protected-access,len-as-condition,too-many-instance-attributes,too-few-public-methods,eval-used,redefined-outer-name,broad-except --msg-template='{path} {line}: {msg} ({symbol})' */*.py 

I'll try to explain each of the checks I've disabled in another message.

@craigargh
Copy link
Contributor

craigargh commented May 15, 2018

  • duplicate-code: Each of the examples is a self-contained project so having shared code between them doesn't make sense.
  • import-error: The Circuit Python specific libraries can't be installed/imported in a standard Python installation
  • consider-using-enumerate: A lot of code uses for index in range(len(values_list)): ..., using enumerate instead would require a lot of refactoring that I don't have the time to test.
  • no-name-in-module: This is related to the import-error
  • no-member: This is related to the import-error
  • too-many-arguments: This will complain if there are more than 5 arguments in a function. Only 3D_Printed_LED_Microphone_Flag and Logans_Run_Hand_Jewel_LED have this issue.
  • no-else-return: This stops use of else when the if/elif block have a return statement. I think it is clearer/more consistent to leave in the else block.
  • simplifiable-if-statement: This checks for code like if button == True: led = True; else: led = False. Although this could be simplified to led = button, I think the original version is easier to understand for beginners.
  • global-statement: Doesn't like the use of global var_name in functions. Code could be refactored to remove this
  • anomalous-backslash-in-string: This doesn't like backslashes in strings that aren't used as escape characters.
  • too-many-locals: This happens when a function has a lot of variables. These functions could be refactored to reduce their length
  • too-many-statements: Same as above, this happens when a function a lot of lines. These functions could be refactored to reduce their length
  • no-self-use: Methods in classes that could be static functions as they don't use the self argument. Can be quickly fixed with @staticmethod annotation, however I wasn't sure if this was implemented in CircuitPython
  • protected-access: Raised when code accesses protected attributes of a class (i.e. methods beginning with two underscores). Could be fixed by changing methods to have one or zero underscores at the start.
  • len-as-condition: This happens for if statements that check the length of a list is 0 if len(values) == 0: .... This could be replaced with if values:, however I think the longer version is easier to understand for beginners.
  • too-many-instance-attributes: Classes that have a lot of attributes
  • too-few-public-methods: Classes that have 0~2 methods
  • eval-used: I would remove the use of eval, however I didn't want to refactor without testing.
  • redefined-outer-name: Variables in functions that have the same name as variables in the global scope. I've fixed this in a lot of places, however there were some bits of code I didn't understand the code enough to change it.
  • broad-except: This doesn't like the use of except Exception:.... I didn't know what error was expected to be thrown so I left it as is.
  • --msg-template='{path} {line}: {msg} ({symbol})' */*.py: For an unknown reason some pylint errors weren't listed next to the correct file that they were in. I've modified the pylint output so that you can see the path to the file that has the problem.

@craigargh craigargh mentioned this issue May 15, 2018
kattni added a commit to dylwhich/Adafruit_Learning_System_Guides that referenced this issue May 16, 2018
Updated the pylintrc disable line to include a majority of the suggestions from @craigargh

A detailed explanation of each disable added can be found here: adafruit#2

I chose to leave out anything that Craig stated could or should be refactored, including things he said he didn't have the eq to test etc.
@kattni
Copy link
Contributor

kattni commented May 16, 2018

@craigargh @staticmethod is implemented in CircuitPython.

@dhalbert
Copy link
Contributor

dhalbert commented Jul 7, 2018

Fixed by #166. Thanks @craigargh !

@dhalbert dhalbert closed this as completed Jul 7, 2018
caternuson pushed a commit that referenced this issue Apr 29, 2020
update liltux branch with master
ladyada pushed a commit that referenced this issue Aug 17, 2020
ladyada pushed a commit that referenced this issue Nov 13, 2020
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

No branches or pull requests

6 participants