From 7cd7b31e1713344f0eecba65f53d17105154acad Mon Sep 17 00:00:00 2001 From: q0w <43147888+q0w@users.noreply.github.com> Date: Sun, 22 Jan 2023 23:37:13 +0300 Subject: [PATCH] Address review comments --- .lintrunner.toml | 2 +- lintrunner_adapters/adapters/flake8_linter.py | 6 +++--- lintrunner_adapters/adapters/newlines_linter.py | 6 +++--- pyproject.toml | 1 + 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/.lintrunner.toml b/.lintrunner.toml index f58fa5b..fe2c86a 100644 --- a/.lintrunner.toml +++ b/.lintrunner.toml @@ -316,5 +316,5 @@ init_command = [ 'run', 'pip_init', '--dry-run={{DRYRUN}}', - 'refurb==1.10.0', + 'refurb==1.10.0;python_version>="3.10"', ] diff --git a/lintrunner_adapters/adapters/flake8_linter.py b/lintrunner_adapters/adapters/flake8_linter.py index 811b9b2..f2cef78 100644 --- a/lintrunner_adapters/adapters/flake8_linter.py +++ b/lintrunner_adapters/adapters/flake8_linter.py @@ -134,7 +134,7 @@ def get_issue_severity(code: str) -> LintSeverity: # "T49": internal type checker errors or unmatched messages if any( code.startswith(x) - for x in [ + for x in ( "B9", "C4", "C9", @@ -143,13 +143,13 @@ def get_issue_severity(code: str) -> LintSeverity: "E5", "T400", "T49", - ] + ) ): return LintSeverity.ADVICE # "F821": Undefined name # "E999": syntax error - if any(code.startswith(x) for x in ["F821", "E999"]): + if any(code.startswith(x) for x in ("F821", "E999")): return LintSeverity.ERROR # "F": PyFlakes Error diff --git a/lintrunner_adapters/adapters/newlines_linter.py b/lintrunner_adapters/adapters/newlines_linter.py index 16e8bb5..ee32997 100644 --- a/lintrunner_adapters/adapters/newlines_linter.py +++ b/lintrunner_adapters/adapters/newlines_linter.py @@ -21,11 +21,11 @@ def check_file(filename: str) -> LintMessage | None: with open(filename, "rb") as f: lines = f.readlines() - if len(lines) == 0: + if not lines: # File is empty, just leave it alone. return None - if len(lines) == 1 and len(lines[0]) == 1: + if len(lines) == len(lines[0]) == 1: # file is wrong whether or not the only byte is a newline return LintMessage( path=filename, @@ -77,7 +77,7 @@ def check_file(filename: str) -> LintMessage | None: for idx, line in enumerate(lines): if len(line) >= 2 and line[-1] == NEWLINE and line[-2] == CARRIAGE_RETURN: if not has_changes: - original_lines = list(lines) + original_lines = lines.copy() has_changes = True lines[idx] = line[:-2] + b"\n" diff --git a/pyproject.toml b/pyproject.toml index f8ebfde..d0dfb69 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -76,3 +76,4 @@ disable = [ [tool.refurb] python_version = "3.7" +disable = ["FURB101", "FURB150"] # disable suggestions using pathlib