diff options
author | Joris Roovers <joris.roovers@gmail.com> | 2023-01-05 13:19:01 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-05 13:19:01 +0100 |
commit | e01e9001877774aadd836d617855441572280b78 (patch) | |
tree | 9ffce64f75b264c66c736accec4f1648ce27ba34 | |
parent | cb9acf17e8d513f33755921032843f470eaca977 (diff) |
Use ruff for linting (#404)
Also fixes a few items that were marked as issues by ruff.
-rw-r--r-- | gitlint-core/gitlint/cli.py | 8 | ||||
-rw-r--r-- | gitlint-core/gitlint/tests/cli/test_cli.py | 1 | ||||
-rw-r--r-- | gitlint-core/gitlint/tests/cli/test_cli_hooks.py | 1 | ||||
-rw-r--r-- | gitlint-core/gitlint/tests/git/test_git_commit.py | 1 | ||||
-rw-r--r-- | pyproject.toml | 30 | ||||
-rw-r--r-- | qa/samples/user_rules/extra/extra_rules.py | 6 | ||||
-rw-r--r-- | qa/shell.py | 2 |
7 files changed, 35 insertions, 14 deletions
diff --git a/gitlint-core/gitlint/cli.py b/gitlint-core/gitlint/cli.py index 387072e..d1ed456 100644 --- a/gitlint-core/gitlint/cli.py +++ b/gitlint-core/gitlint/cli.py @@ -172,11 +172,9 @@ def build_git_context(lint_config, msg_filename, commit_hash, refspec): from_commit_msg = GitContext.from_commit_msg if lint_config.staged: LOG.debug("Fetching additional meta-data from staged commit") - from_commit_msg = ( - lambda message: GitContext.from_staged_commit( # pylint: disable=unnecessary-lambda-assignment - message, lint_config.target - ) - ) + + def from_commit_msg(message): + return GitContext.from_staged_commit(message, lint_config.target) # Order of precedence: # 1. Any data specified via --msg-filename diff --git a/gitlint-core/gitlint/tests/cli/test_cli.py b/gitlint-core/gitlint/tests/cli/test_cli.py index 45093dd..f0177c4 100644 --- a/gitlint-core/gitlint/tests/cli/test_cli.py +++ b/gitlint-core/gitlint/tests/cli/test_cli.py @@ -1,4 +1,3 @@ -import io import os import sys import platform diff --git a/gitlint-core/gitlint/tests/cli/test_cli_hooks.py b/gitlint-core/gitlint/tests/cli/test_cli_hooks.py index 6564a64..cfdb704 100644 --- a/gitlint-core/gitlint/tests/cli/test_cli_hooks.py +++ b/gitlint-core/gitlint/tests/cli/test_cli_hooks.py @@ -1,4 +1,3 @@ -import io from io import StringIO import os diff --git a/gitlint-core/gitlint/tests/git/test_git_commit.py b/gitlint-core/gitlint/tests/git/test_git_commit.py index b27deaf..ee76a96 100644 --- a/gitlint-core/gitlint/tests/git/test_git_commit.py +++ b/gitlint-core/gitlint/tests/git/test_git_commit.py @@ -10,7 +10,6 @@ from unittest.mock import patch, call from gitlint.tests.base import BaseTestCase from gitlint.git import ( - GitChangedFileStats, GitContext, GitCommit, GitContextError, diff --git a/pyproject.toml b/pyproject.toml index b45cbcf..4a5bed2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -88,6 +88,7 @@ dependencies = [ "pytest-cov==4.0.0", "python-coveralls==2.9.3", "pylint==2.15.3", + "ruff==0.0.211", "radon==5.1.0", "pdbr==0.7.5; sys_platform != \"win32\"" ] @@ -99,12 +100,17 @@ unit-tests = [ u = "unit-tests" unit-tests-no-cov = "pytest -rw -s {args:gitlint-core}" format = "black --check --diff ." -lint = "pylint gitlint-core/gitlint qa" +plint = "pylint gitlint-core/gitlint qa" +lint = "ruff gitlint-core/gitlint qa" +autofix = [ + "ruff --fix gitlint-core/gitlint qa", + "black .", +] all = [ "unit-tests", "format", - "lint" + "lint", ] stats = [ "./tools/stats.sh" @@ -154,6 +160,26 @@ line-length = 120 # extend-exclude: keep excluding files from .gitignore in addition to the ones specified extend-exclude = "gitlint-core/gitlint/tests/samples/user_rules/import_exception/invalid_python.py" +[tool.ruff] +target-version = "py37" +extend-exclude = ["gitlint-core/gitlint/tests/samples/user_rules/import_exception/invalid_python.py"] + +ignore = [ + "E501", # Never enforce `E501` (line length violations) - taken care of by black +] + +select = [ + "E", # Pycodestyle + "F", # PyFlakes + "T20", # no print statements + "UP", # pyupgrade + "PLC", # pylint + "PLE", # pylint + "PLR", # pylint + "PLW", # pylint + "RUF", # ruff specific +] + [tool.coverage.run] branch = true # measure branch coverage in addition to statement coverage diff --git a/qa/samples/user_rules/extra/extra_rules.py b/qa/samples/user_rules/extra/extra_rules.py index cad531b..fa05879 100644 --- a/qa/samples/user_rules/extra/extra_rules.py +++ b/qa/samples/user_rules/extra/extra_rules.py @@ -64,9 +64,9 @@ class ConfigurableCommitRule(CommitRule): def validate(self, _): violations = [ - RuleViolation(self.id, f"int-öption: {self.options[u'int-öption'].value}", line_nr=1), - RuleViolation(self.id, f"str-öption: {self.options[u'str-öption'].value}", line_nr=1), - RuleViolation(self.id, f"list-öption: {self.options[u'list-öption'].value}", line_nr=1), + RuleViolation(self.id, f"int-öption: {self.options['int-öption'].value}", line_nr=1), + RuleViolation(self.id, f"str-öption: {self.options['str-öption'].value}", line_nr=1), + RuleViolation(self.id, f"list-öption: {self.options['list-öption'].value}", line_nr=1), ] return violations diff --git a/qa/shell.py b/qa/shell.py index 7cddf3b..ef94727 100644 --- a/qa/shell.py +++ b/qa/shell.py @@ -49,7 +49,7 @@ else: def __getattr__(self, p): # pylint: disable=invalid-name # https://github.com/amoffat/sh/blob/e0ed8e244e9d973ef4e0749b2b3c2695e7b5255b/sh.py#L952= - _unicode_methods = set(dir(str())) + _unicode_methods = set(dir(str())) # noqa if p in _unicode_methods: return getattr(str(self), p) |