Skip to content

Commit bae586e

Browse files
authored
Add Ruff linting (#1795)
1 parent 35d98dc commit bae586e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+116
-76
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -808,8 +808,11 @@ jobs:
808808
- name: Setup Python environment
809809
run: setup_python_env -c reqs/constraints.txt -r reqs/code_quality.txt
810810

811-
- name: Run Ruff (format check)
812-
run: ruff format --check .
811+
- name: Run linting check (Ruff)
812+
run: ruff check
813+
814+
- name: Run format check (Ruff)
815+
run: ruff format --check
813816

814817
- name: Update skip cache 1
815818
uses: actions/cache@v4

.github/workflows/ci/workflow_template.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,11 @@ jobs:
156156

157157
<% endif %>
158158
<% if j.type == 'test_code_quality' %>
159-
- name: Run Ruff (format check)
160-
run: ruff format --check .
159+
- name: Run linting check (Ruff)
160+
run: ruff check
161+
162+
- name: Run format check (Ruff)
163+
run: ruff format --check
161164

162165
<% endif %>
163166
<% if j.type in ['build', 'test_packaging'] %>

.pre-commit-config.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
repos:
22
- repo: https://github.com/astral-sh/ruff-pre-commit
33
# Ruff version.
4-
rev: v0.12.1 # also update constraints.txt
4+
rev: v0.14.8 # also update constraints.txt
55
hooks:
6+
# Run the linter.
7+
- id: ruff-check
8+
args: [ --fix ]
69
# Run the formatter.
710
- id: ruff-format

doc/conf.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
# Configuration file for the Sphinx documentation builder.
2+
from pygments.lexer import RegexLexer, bygroups
3+
from pygments import token as t
4+
from sphinx.highlighting import lexers
25

36
# -- Project information -----------------------------------------------------
47

@@ -69,10 +72,6 @@
6972
"dark_logo": "dolores.svg",
7073
}
7174

72-
from pygments.lexer import RegexLexer, bygroups
73-
from pygments import token as t
74-
from sphinx.highlighting import lexers
75-
7675

7776
class RTFLexer(RegexLexer):
7877
name = "rtf"

doc/developer_guide.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ any other virtual environment](https://virtualenv.pypa.io/en/latest/user_guide.h
8484

8585
The configuration also provides support for lightweight tests only environment:
8686
`pyX`, where `X` is the version of the Python interpreter to use. E.g. running
87-
`tox -e 'py3,py36,py37,py38,py39` will execute the testsuite for each version
87+
`tox -e 'py3,py310,py311,py312` will execute the testsuite for each version
8888
of Python we support.
8989

9090
# Creating a binary distribution

osx/dmg_resources/settings.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
import plistlib
44
import os.path
55

6+
# `defines` is injected by dmgbuild; default to empty for linters.
7+
defines = globals().get("defines", {})
8+
69
application = defines.get("app", "./dist/Plover.app")
710
appname = os.path.basename(application)
811

plover/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
# exec from `setup.py`, package data
1212
# may not be available, and we don't
1313
# want to translate anyway.
14-
_ = lambda s: s
14+
def _(s):
15+
return s
16+
1517

1618
__version__ = "5.1.0"
1719
__copyright__ = "(C) Open Steno Project"

plover/dictionary/loading_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def __init__(self, filename, state_change_callback):
7575
def needs_reloading(self):
7676
try:
7777
new_timestamp = resource_timestamp(self.filename)
78-
except:
78+
except Exception:
7979
# Bad resource name, permission denied, path
8080
# does not exist, ...
8181
new_timestamp = None

plover/formatting.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,10 @@ def remove_listener(self, callback):
370370

371371
def set_output(self, output):
372372
"""Set the output class."""
373-
noop = lambda x: None
373+
374+
def noop(x):
375+
return None
376+
374377
output_type = self.output_type
375378
fields = output_type._fields
376379
self._output = output_type(*[getattr(output, f, noop) for f in fields])
@@ -921,7 +924,7 @@ def apply_case(text, case):
921924

922925
def apply_mode(text, case, space_char, begin, last_action):
923926
# Should title case be applied to the beginning of the next string?
924-
lower_title_case = begin and not last_action.case in (
927+
lower_title_case = begin and last_action.case not in (
925928
Case.CAP_FIRST_WORD,
926929
Case.UPPER_FIRST_WORD,
927930
)

plover/gui_qt/console_widget.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def _subprocess(self):
6262
while True:
6363
try:
6464
line = self._proc.stdout.readline()
65-
except:
65+
except Exception:
6666
break
6767
if not line:
6868
break

0 commit comments

Comments
 (0)