Skip to content

Commit

Permalink
Apply a selection of refurb rules (#3244)
Browse files Browse the repository at this point in the history
  • Loading branch information
DimitriPapadopoulos authored Dec 11, 2023
1 parent a7ac7ca commit cfd2109
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
19 changes: 9 additions & 10 deletions codespell_lib/_codespell.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,24 +617,23 @@ def parse_options(


def parse_ignore_words_option(ignore_words_option: List[str]) -> Set[str]:
ignore_words = set()
ignore_words: Set[str] = set()
if ignore_words_option:
for comma_separated_words in ignore_words_option:
for word in comma_separated_words.split(","):
ignore_words.add(word.strip())
ignore_words.update(
word.strip() for word in comma_separated_words.split(",")
)
return ignore_words


def build_exclude_hashes(filename: str, exclude_lines: Set[str]) -> None:
with open(filename, encoding="utf-8") as f:
for line in f:
exclude_lines.add(line.rstrip())
exclude_lines.update(line.rstrip() for line in f)


def build_ignore_words(filename: str, ignore_words: Set[str]) -> None:
with open(filename, encoding="utf-8") as f:
for line in f:
ignore_words.add(line.strip())
ignore_words.update(line.strip() for line in f)


def add_misspelling(
Expand Down Expand Up @@ -811,7 +810,7 @@ def apply_uri_ignore_words(
) -> List[Match[str]]:
if not uri_ignore_words:
return check_matches
for uri in re.findall(uri_regex, line):
for uri in uri_regex.findall(line):
for uri_word in extract_words(uri, word_regex, ignore_word_regex):
if uri_word in uri_ignore_words:
# determine/remove only the first among matches
Expand Down Expand Up @@ -1097,7 +1096,7 @@ def main(*args: str) -> int:
return EX_USAGE
uri_ignore_words = parse_ignore_words_option(options.uri_ignore_words_list)

dictionaries = options.dictionary if options.dictionary else ["-"]
dictionaries = options.dictionary or ["-"]

use_dictionaries = []
for dictionary in dictionaries:
Expand Down Expand Up @@ -1186,7 +1185,7 @@ def main(*args: str) -> int:
if os.path.isdir(filename):
for root, dirs, files in os.walk(filename):
if glob_match.match(root): # skip (absolute) directories
del dirs[:]
dirs.clear()
continue
if is_hidden(root, options.check_hidden): # dir itself hidden
continue
Expand Down
3 changes: 2 additions & 1 deletion codespell_lib/tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,7 @@ def test_ignore(
assert cs.main("--skip=*ignoredir*", tmp_path) == 1
assert cs.main("--skip=ignoredir", tmp_path) == 1
assert cs.main("--skip=*ignoredir/bad*", tmp_path) == 1
assert cs.main(f"--skip={tmp_path}", tmp_path) == 0
badjs = tmp_path / "bad.js"
copyfile(badtxt, badjs)
assert cs.main("--skip=*.js", goodtxt, badtxt, badjs) == 1
Expand Down Expand Up @@ -1218,7 +1219,7 @@ def test_stdin(tmp_path: Path) -> None:
text = ""
for _ in range(input_file_lines):
text += "abandonned\n"
for single_line_per_error in [True, False]:
for single_line_per_error in (True, False):
args: Tuple[str, ...] = ()
if single_line_per_error:
args = ("--stdin-single-line",)
Expand Down
4 changes: 2 additions & 2 deletions codespell_lib/tests/test_dictionary.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def _check_err_rep(
), f"error {err}: correction {rep!r} cannot start with whitespace"
_check_aspell(err, f"error {err!r}", in_aspell[0], fname, languages[0])
prefix = f"error {err}: correction {rep!r}"
for regex, msg in [
for regex, msg in (
(start_comma, "%s starts with a comma"),
(
whitespace_comma,
Expand All @@ -168,7 +168,7 @@ def _check_err_rep(
(comma_without_space, "%s contains a comma *not* followed by a space"),
(whitespace_end, "%s has a trailing space"),
(single_comma, "%s has a single entry but contains a trailing comma"),
]:
):
assert not regex.search(rep), msg % (prefix,)
del msg
if rep.count(","):
Expand Down

0 comments on commit cfd2109

Please sign in to comment.