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

Look into using ruff as a linter #93

Open
slint opened this issue Feb 9, 2023 · 2 comments
Open

Look into using ruff as a linter #93

slint opened this issue Feb 9, 2023 · 2 comments

Comments

@slint
Copy link
Member

slint commented Feb 9, 2023

I was also wondering if we could replace flake8, pycodestyle, etc. with ruff, which is the new kid in the Python linters block:

  • written in Rust for performance (10-100x compared to the above tools)
  • compatible with black out of the box
  • widely adopted by other big Python projects
@slint slint transferred this issue from inveniosoftware/cookiecutter-invenio-module Feb 9, 2023
@utnapischtim
Copy link
Contributor

I am using for the tu-graz-library packages pylint as the analyzing tool. At the time where i made the black PR's i tried also to use pylint on the invenio packages. I think we should try it out, but it might be some work to make it working with the linter. further as i saw on the issues for ruff, there is some effort going on to add pylint errors also to ruff.

@utnapischtim
Copy link
Contributor

i did one test with one bigger package (invenio-rdm-records) @slint

  • with ruff check --statistics invenio_rdm_records tests on the root level of the package produces following statistics:
50      F401    [*] `sqlalchemy` imported but unused
47      F841    [*] Local variable `dir_` is assigned to but never used
18      E501    [ ] Line too long (94 > 88 characters)
11      F541    [*] f-string without any placeholders
 2      F811    [ ] Redefinition of unused `test_subjects` from line 224
 1      F821    [ ] Undefined name `RDMRecordService`
 1      E402    [ ] Module level import not at top of file

time: 0.011s

  • with pylint --reports y invenio_rdm_records tests produces following report
+------------------------------------+------------+
|message id                          |occurrences |
+====================================+============+
|unused-argument                     |125         |
+------------------------------------+------------+
|invalid-name                        |118         |
+------------------------------------+------------+
|no-member                           |101         |
+------------------------------------+------------+
|redefined-outer-name                |59          |
+------------------------------------+------------+
|fixme                               |41          |
+------------------------------------+------------+
|too-few-public-methods              |37          |
+------------------------------------+------------+
|line-too-long                       |36          |
+------------------------------------+------------+
|use-dict-literal                    |34          |
+------------------------------------+------------+
|consider-using-f-string             |34          |
+------------------------------------+------------+
|too-many-arguments                  |23          |
+------------------------------------+------------+
|unused-import                       |22          |
+------------------------------------+------------+
|arguments-differ                    |21          |
+------------------------------------+------------+
|arguments-renamed                   |19          |
+------------------------------------+------------+
|protected-access                    |17          |
+------------------------------------+------------+
|duplicate-code                      |12          |
+------------------------------------+------------+
|attribute-defined-outside-init      |12          |
+------------------------------------+------------+
|unused-variable                     |11          |
+------------------------------------+------------+
|redefined-builtin                   |11          |
+------------------------------------+------------+
|no-else-return                      |11          |
+------------------------------------+------------+
|inconsistent-return-statements      |11          |
+------------------------------------+------------+
|c-extension-no-member               |9           |
+------------------------------------+------------+
|unnecessary-pass                    |7           |
+------------------------------------+------------+
|unspecified-encoding                |6           |
+------------------------------------+------------+
|unidiomatic-typecheck               |6           |
+------------------------------------+------------+
|raise-missing-from                  |6           |
+------------------------------------+------------+
|implicit-str-concat                 |6           |
+------------------------------------+------------+
|consider-using-sys-exit             |5           |
+------------------------------------+------------+
|too-many-locals                     |4           |
+------------------------------------+------------+
|missing-function-docstring          |4           |
+------------------------------------+------------+
|dangerous-default-value             |4           |
+------------------------------------+------------+
|broad-exception-caught              |4           |
+------------------------------------+------------+
|no-else-raise                       |3           |
+------------------------------------+------------+
|import-outside-toplevel             |3           |
+------------------------------------+------------+
|expression-not-assigned             |3           |
+------------------------------------+------------+
|abstract-method                     |3           |
+------------------------------------+------------+
|useless-object-inheritance          |2           |
+------------------------------------+------------+
|super-with-arguments                |2           |
+------------------------------------+------------+
|misplaced-bare-raise                |2           |
+------------------------------------+------------+
|f-string-without-interpolation      |2           |
+------------------------------------+------------+
|wrong-import-position               |1           |
+------------------------------------+------------+
|wrong-import-order                  |1           |
+------------------------------------+------------+
|unnecessary-lambda                  |1           |
+------------------------------------+------------+
|ungrouped-imports                   |1           |
+------------------------------------+------------+
|unexpected-special-method-signature |1           |
+------------------------------------+------------+
|too-many-lines                      |1           |
+------------------------------------+------------+
|too-many-instance-attributes        |1           |
+------------------------------------+------------+
|superfluous-parens                  |1           |
+------------------------------------+------------+
|stop-iteration-return               |1           |
+------------------------------------+------------+
|pointless-statement                 |1           |
+------------------------------------+------------+
|missing-class-docstring             |1           |
+------------------------------------+------------+
|keyword-arg-before-vararg           |1           |
+------------------------------------+------------+
|function-redefined                  |1           |
+------------------------------------+------------+
|cyclic-import                       |1           |
+------------------------------------+------------+
|assignment-from-no-return           |1           |
+------------------------------------+------------+

time: 27s

  • my conclusion:
    ruff is extraordinarily fast, but pylint is way more accurate. The problem with pylint is that we would have to create a default ignore list for all packages because something like too-few-public-methods is not changeable for invenio

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

2 participants