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

Use ruff for linting #404

Merged
merged 2 commits into from
Jan 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -80,6 +80,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 @@ -91,12 +92,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",
]

# QA
Expand Down Expand Up @@ -143,6 +149,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