Skip to content

Commit a8ab0c1

Browse files
committed
pylint fixes
1 parent cd0d9ce commit a8ab0c1

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

comment_spell_check/comment_spell_check.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,9 @@ def remove_contractions(word: str):
183183
logger = logging.getLogger("comment_spell_check")
184184
for contraction in CONTRACTIONS:
185185
if word.endswith(contraction):
186-
logger.info("Contraction: %s -> %s", word, word[: -len(contraction)])
186+
logger.info(
187+
"Contraction: %s -> %s", word, word[: -len(contraction)]
188+
)
187189
return word[: -len(contraction)]
188190
return word
189191

@@ -192,7 +194,7 @@ def remove_prefix(word: str, prefixes: list[str]):
192194
"""Remove the prefix from the word."""
193195
for prefix in prefixes:
194196
if word.startswith(prefix):
195-
return word[len(prefix) :]
197+
return word[len(prefix):]
196198
return word
197199

198200

@@ -222,7 +224,9 @@ def spell_check_comment(
222224
prefixes = prefixes or []
223225
error_word = remove_prefix(error_word, prefixes)
224226

225-
if len(error_word) == 0 or error_word in spell or error_word.lower() in spell:
227+
if len(error_word) == 0:
228+
continue
229+
if error_word in spell or error_word.lower() in spell:
226230
continue
227231

228232
# Try splitting camel case words and checking each sub-word
@@ -233,7 +237,10 @@ def spell_check_comment(
233237
if len(sub_words) > 1 and spell_check_words(spell, sub_words):
234238
continue
235239

236-
msg = f"'{error_word}', " + f"suggestions: {spell.candidates(error_word)}"
240+
msg = (
241+
f"'{error_word}', "
242+
+ f"suggestions: {spell.candidates(error_word)}"
243+
)
237244
mistakes.append(msg)
238245

239246
return mistakes
@@ -359,7 +366,8 @@ def output_results(args, bad_words):
359366
print(f"vim +{line_num} {found_file}", file=sys.stderr)
360367
else:
361368
print(
362-
f"file: {found_file:30} line: {line_num:3d} word: {misspelled_word}",
369+
f"file: {found_file:30} line: {line_num:3d} ",
370+
f"word: {misspelled_word}",
363371
file=sys.stderr,
364372
)
365373

@@ -441,7 +449,9 @@ def comment_spell_check(args):
441449
# f is a directory, so search for files inside
442450
dir_entries = []
443451
for s in suffixes:
444-
dir_entries = dir_entries + glob.glob(f + "/**/*" + s, recursive=True)
452+
dir_entries = dir_entries + glob.glob(
453+
f + "/**/*" + s, recursive=True
454+
)
445455

446456
logger.info(dir_entries)
447457

@@ -487,6 +497,7 @@ def comment_spell_check(args):
487497

488498

489499
def main():
500+
"""Main function to run the spell checker."""
490501
args = parseargs.parse_args()
491502
comment_spell_check(args)
492503

comment_spell_check/utils/parseargs.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""command line argument parser for comment_spell_check."""
2+
13
import argparse
24
from importlib.metadata import version, PackageNotFoundError
35

@@ -11,6 +13,7 @@
1113

1214

1315
def create_parser():
16+
"""Create an argument parser for the command-line interface."""
1417
parser = argparse.ArgumentParser()
1518

1619
parser.add_argument("filenames", nargs="*")

tests/test_comment_spell_check.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
2+
""" Test suite for the comment_spell_check command line tool. """
3+
14
# ==========================================================================
25
#
36
# Copyright NumFOCUS
@@ -21,9 +24,11 @@
2124

2225

2326
class TestCommentSpellCheck(unittest.TestCase):
27+
"""Test class for comment_spell_check command line tool."""
2428
@classmethod
25-
def setUpClass(self):
29+
def setUpClass(cls):
2630
"""Setting up comment_spell_check tests"""
31+
return cls()
2732

2833
@classmethod
2934
def tearDownClass(cls):
@@ -43,6 +48,7 @@ def test_basic(self):
4348
],
4449
cwd="comment_spell_check",
4550
stdout=subprocess.PIPE,
51+
check=False,
4652
)
4753
self.assertEqual(runresult.returncode, 0, runresult.stdout)
4854

@@ -62,6 +68,7 @@ def test_codebase(self):
6268
],
6369
cwd="comment_spell_check",
6470
stdout=subprocess.PIPE,
71+
check=False,
6572
)
6673
self.assertEqual(runresult.returncode, 0, runresult.stdout)
6774

@@ -74,6 +81,7 @@ def test_version(self):
7481
],
7582
cwd="comment_spell_check",
7683
stdout=subprocess.PIPE,
84+
check=False,
7785
)
7886
self.assertEqual(runresult.returncode, 0)
7987

@@ -93,6 +101,7 @@ def test_bibtex(self):
93101
],
94102
cwd="comment_spell_check",
95103
stdout=subprocess.PIPE,
104+
check=False,
96105
)
97106
self.assertEqual(runresult.returncode, 0, runresult.stdout)
98107

@@ -111,6 +120,7 @@ def test_url(self):
111120
],
112121
cwd="comment_spell_check",
113122
stdout=subprocess.PIPE,
123+
check=False,
114124
)
115125
self.assertEqual(runresult.returncode, 0, runresult.stdout)
116126

0 commit comments

Comments
 (0)