Skip to content

Commit

Permalink
Use ruff for linting (#404)
Browse files Browse the repository at this point in the history
Also fixes a few items that were marked as issues by ruff.
  • Loading branch information
jorisroovers authored Jan 5, 2023
1 parent cb9acf1 commit e01e900
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 14 deletions.
8 changes: 3 additions & 5 deletions gitlint-core/gitlint/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion gitlint-core/gitlint/tests/cli/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import io
import os
import sys
import platform
Expand Down
1 change: 0 additions & 1 deletion gitlint-core/gitlint/tests/cli/test_cli_hooks.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import io
from io import StringIO
import os

Expand Down
1 change: 0 additions & 1 deletion gitlint-core/gitlint/tests/git/test_git_commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

from gitlint.tests.base import BaseTestCase
from gitlint.git import (
GitChangedFileStats,
GitContext,
GitCommit,
GitContextError,
Expand Down
30 changes: 28 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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\""
]
Expand All @@ -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"
Expand Down Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions qa/samples/user_rules/extra/extra_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion qa/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def stderr(self):

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)

Expand Down

0 comments on commit e01e900

Please sign in to comment.