Python analyzer detects issues every developer expects from a python linter

Hello Python developers,

At SonarSource, we aim to provide a Python analyzer that is self-sufficient to help majority of the Python developers to enhance their Code Quality and Security. In order to achieve this goal we added 15 core rules which are expected to be provided by any basic Python linter. Here is the full list.

Bug Detection Rules

  • S5549: Functions called with named arguments should not contain duplicated names (Blocker)
  • S2275: String formatting should not fail (Blocker)
  • S5807: Only defined names should be listed in __all__ (Blocker)
  • S2823: Only strings should be listed in __all__ (Blocker)
  • S5828: The “open” builtin should be called with a valid mode (Blocker)
  • S5780: Expressions creating dictionaries should not have duplicate keys (Major)
  • S905: Non-empty statements should change control flow or have at least one side-effect (Major)
  • S5796: Identity operators should not compare objects which will always be different (Major)

Code Smell Detection Rules

  • S5797: Constants should not be used as conditions (Critical)
  • S2208: Wildcard imports should not be used (Critical)
  • S2836: Loops without “break” should not have “else” clauses (Major)
  • S3457: Strings should be formatted correctly (Major)
  • S5799: Implicit string and byte concatenations should not be confusing (Major)
  • S5806: Builtins should not be shadowed (Major)
  • S5795: Identity comparisons should not rely on interpreter’s cache (Major)

Examples

S2275 raises an issue on Salt because the argument {3} doesn’t have a value. The developer wanted certainly to use {1}:{2} instead of {2}:{3}:

S5780 raises an issue on ERPNext. The entry time_interval is initialized twice with different values:

These features are already available on SonarCloud :sonarcloud:, and will be included in SonarQube 8.4 :sonarqube: .

:thinking: If you believe this or that rule is missing so you can rely only on our Python analyzer, don’t hesitate to share your thoughts in the New Rules channel.

Enjoy!
Alex

4 Likes