Skip to content

Commit d60210d

Browse files
committed
style: align ruff across all plugins and tools
Run ruff across the full `check-plugins/` and `tools/` tree with the rule set already in pyproject.toml (B, C4, E, F, I, RUF, SIM, UP, W). This clears ~400 accumulated violations so that `tools/run-static-checks` can be used as a trustworthy gate going forward. Categories fixed: - I001 (324): import blocks normalized (order, grouping, blank lines). - RUF059 (145): discarded tuple-unpack slots prefixed with `_` (`success, result = ...` -> `_success, result = ...`) so the intent is explicit and shadowing is visible. - UP032 (30): `.format()` calls converted to f-strings. - F401 (9): unused imports removed. - RUF005 (8): `[x] + list` rewritten as `[x, *list]`. - RUF100 (6): unused `# noqa` directives removed. - E713/E714 (7): `not x in y` and `not x is y` rewritten to `x not in y` / `x is not y`. - F541 (5): empty f-strings demoted to regular strings. - SIM401/118/115/108/101, RUF015/019 and a few other ruff suggestions. Manual fixes that ruff could not auto-apply: - E402 (39): 7 plugins had the `warnings.filterwarnings()` pattern or an `import lib.smb` try/except in the middle of their import block, which pushed all following imports past ruff's "module level imports at top" rule. Reordered so all unconditional imports sit first and the `warnings.filterwarnings()` / optional-lib try/except blocks come after. about-me no longer imports pymysql at all, so the stale filterwarnings call was dropped. - F403/F405 (8): `from lib.globals import *` in `ping/unit-test/run` replaced with the explicit set of STATE_* names actually used. - E741 (5): single-letter variable `l` in basket-compare's compare_* helpers renamed to `left_item` for readability. - F821 (1): basket-compare referenced `STATE_UNKNOWN` without importing it; the import was added. This was a latent bug that would have crashed `sys.exit(STATE_UNKNOWN)` on any argparse SystemExit. - B007 (1): unused loop variable `value` in check2basket replaced with `for key in parent_value`. - RUF001 (5): ambiguous Unicode characters in DESCRIPTION strings and comments (typographic minus/apostrophes/hyphens) replaced with plain ASCII. - SIM115 (1): path-rw-test's `tempfile.TemporaryFile()` now uses a context manager. Plugin fixes worth calling out: - scanrootkit: kernel symbol matching was already tightened in the previous commit; this pass also fixes the long-standing dead-code directory check (covered in the scanrootkit commit that precedes this one). - Several plugins' inline `os.path.isfile()` checks that were actually intended to test for directories are left alone for now and tracked separately - this commit is scoped to style. Also: aligned the ruff `ignore` list in `pyproject.toml` with the equivalent list in the shared `lib` repo by adding `RUF002`, `RUF003`, `SIM102` and `SIM105`, so the same style expectations hold in both codebases. No behavior change intended. Style-only, per the house rule that pure style passes do not bump plugin `__version__`.
1 parent c86b4f9 commit d60210d

File tree

267 files changed

+723
-1043
lines changed

Some content is hidden

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

267 files changed

+723
-1043
lines changed

check-plugins/about-me/about-me

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@
1010

1111
"""See the check's README for more details."""
1212

13-
import warnings
14-
15-
warnings.filterwarnings('ignore', category=UserWarning, module='pymysql')
16-
1713
import argparse
1814
import os
1915
import re
@@ -137,7 +133,7 @@ def get_birthday():
137133
return f'born {lib.time.epoch2iso(birthday.st_ctime)}. '
138134
# no way to do this in python - getting the birthday of a folder
139135
# hardcoded shell pipeline (no user input); shell=True needed for pipes
140-
success, result = lib.shell.shell_exec(
136+
_success, result = lib.shell.shell_exec(
141137
'stat / | grep "Birth" | sed "s/Birth: //g" | cut -b 2-11',
142138
shell=True, # nosec B604
143139
)
@@ -1346,10 +1342,7 @@ def main():
13461342
if firmware_device_model:
13471343
msg += f'{firmware_device_model}, '
13481344

1349-
if args.DMIDECODE:
1350-
dmi = lib.dmidecode.get_data()
1351-
else:
1352-
dmi = False
1345+
dmi = lib.dmidecode.get_data() if args.DMIDECODE else False
13531346
sys_dimensions = get_sys_dimensions()
13541347
if dmi and sys_dimensions:
13551348
# combine the best from both worlds

check-plugins/apache-httpd-status/apache-httpd-status

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def main():
152152
lib.base.cu('Malformed Apache server info.')
153153
else:
154154
# do not call the command, put in test data
155-
stdout, stderr, retc = lib.lftest.test(args.TEST)
155+
stdout, _stderr, _retc = lib.lftest.test(args.TEST)
156156
result = stdout
157157
result = result.strip().split('\n')
158158

check-plugins/apache-httpd-status/unit-test/run

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ import unittest
1414

1515
sys.path.insert(0, '..')
1616

17-
from lib.globals import STATE_OK, STATE_WARN
1817
import lib.lftest
19-
18+
from lib.globals import STATE_OK, STATE_WARN
2019

2120
CACHE_DB = '/tmp/linuxfabrik-monitoring-plugins-apache-httpd-status.db'
2221

check-plugins/apache-httpd-version/unit-test/run

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ the day Apache 2.4 hits EOL or a 2.6 cycle appears.
2525
"""
2626

2727
import sys
28+
2829
sys.path.insert(0, '..')
2930

3031
import unittest
3132

32-
from lib.globals import STATE_OK, STATE_UNKNOWN
3333
import lib.lftest
34-
34+
from lib.globals import STATE_OK, STATE_UNKNOWN
3535

3636
TESTS = [
3737
{

check-plugins/apache-solr-version/unit-test/run

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ re-pinned every few months.
2929
"""
3030

3131
import sys
32+
3233
sys.path.insert(0, '..')
3334

3435
import unittest
3536

36-
from lib.globals import STATE_OK, STATE_UNKNOWN, STATE_WARN
3737
import lib.lftest
38-
38+
from lib.globals import STATE_OK, STATE_UNKNOWN, STATE_WARN
3939

4040
TESTS = [
4141
{

check-plugins/atlassian-statuspage/unit-test/run

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
# https://github.com/Linuxfabrik/monitoring-plugins/blob/main/CONTRIBUTING.md
1010

1111
import sys
12+
1213
sys.path.insert(0, '..')
1314

1415
import unittest
1516

16-
from lib.globals import STATE_CRIT, STATE_OK, STATE_WARN
1717
import lib.lftest
18-
18+
from lib.globals import STATE_CRIT, STATE_OK, STATE_WARN
1919

2020
# Fixtures were captured from real Atlassian-Statuspage-powered pages:
2121
#

check-plugins/axenita-stats/unit-test/run

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ sys.path.insert(0, '..') # Adds higher directory to python modules path.
1515

1616
import unittest
1717

18-
from lib.globals import STATE_OK, STATE_UNKNOWN, STATE_WARN, STATE_CRIT
1918
import lib.base
2019
import lib.shell
20+
from lib.globals import STATE_OK, STATE_WARN
2121

2222

2323
class TestCheck(unittest.TestCase):

check-plugins/by-ssh/by-ssh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,12 @@ import sys
1616

1717
import lib.args
1818
import lib.base
19-
import lib.shell
2019
import lib.lftest
20+
import lib.shell
2121
import lib.time
2222
import lib.txt
2323
from lib.globals import STATE_CRIT, STATE_OK, STATE_UNKNOWN, STATE_WARN
2424

25-
2625
__author__ = 'Linuxfabrik GmbH, Zurich/Switzerland'
2726
__version__ = '2026040801'
2827

check-plugins/by-winrm/by-winrm

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import lib.time
2121
import lib.winrm
2222
from lib.globals import STATE_CRIT, STATE_OK, STATE_UNKNOWN, STATE_WARN
2323

24-
2524
__author__ = 'Linuxfabrik GmbH, Zurich/Switzerland'
2625
__version__ = '2026033101'
2726

check-plugins/cometsystem/cometsystem

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,15 @@
1111
"""See the check's README for more details."""
1212

1313
import argparse
14-
import sys
1514
import json
15+
import sys
1616

1717
import lib.args
1818
import lib.base
1919
import lib.lftest
2020
import lib.url
2121
from lib.globals import STATE_CRIT, STATE_OK, STATE_UNKNOWN, STATE_WARN
2222

23-
2423
__author__ = """Linuxfabrik GmbH, Zurich/Switzerland;
2524
originally written by Dominik Riva, Universitätsspital Basel/Switzerland"""
2625
__version__ = '2026040801'
@@ -174,7 +173,7 @@ def main():
174173
)
175174
else:
176175
# do not call the command, put in test data
177-
stdout, stderr, retc = lib.lftest.test(args.TEST)
176+
stdout, _stderr, _retc = lib.lftest.test(args.TEST)
178177
result = json.loads(stdout)
179178
if 'ch1' not in result:
180179
lib.base.cu('Malformed Comet System Web Sensors status file.')

0 commit comments

Comments
 (0)