Skip to content

Commit c1e515e

Browse files
authored
Remove EM from ruff ignores (#3356)
1 parent ba608c8 commit c1e515e

File tree

17 files changed

+66
-71
lines changed

17 files changed

+66
-71
lines changed

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,6 @@ ignore = [
232232
"BLE",
233233
"D",
234234
"RET",
235-
"EM",
236235
"EXE",
237236
"FBT",
238237
"INP",

src/ansiblelint/__main__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,8 @@ def path_inject() -> None: # noqa: C901
424424
# our dependency, but addressing this would be done by ansible-compat.
425425
for cmd in ("ansible", "git"):
426426
if not shutil.which(cmd):
427-
raise RuntimeError(f"Failed to find runtime dependency '{cmd}' in PATH")
427+
msg = f"Failed to find runtime dependency '{cmd}' in PATH"
428+
raise RuntimeError(msg)
428429

429430

430431
# Based on Ansible implementation

src/ansiblelint/cli.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ def load_config(config_file: str | None) -> tuple[dict[Any, Any], str | None]:
8888

8989
config = clean_json(config_lintable.data)
9090
if not isinstance(config, dict):
91-
raise RuntimeError("Schema failed to properly validate the config file.")
91+
msg = "Schema failed to properly validate the config file."
92+
raise RuntimeError(msg)
9293
config["config_file"] = config_path
9394
config_dir = os.path.dirname(config_path)
9495
expand_to_normalized_paths(config, config_dir)
@@ -158,9 +159,11 @@ def __init__( # pylint: disable=too-many-arguments,redefined-builtin
158159
) -> None:
159160
"""Create the argparse action with WriteArg-specific defaults."""
160161
if nargs is not None:
161-
raise ValueError("nargs for WriteArgAction must not be set.")
162+
msg = "nargs for WriteArgAction must not be set."
163+
raise ValueError(msg)
162164
if const is not None:
163-
raise ValueError("const for WriteArgAction must not be set.")
165+
msg = "const for WriteArgAction must not be set."
166+
raise ValueError(msg)
164167
super().__init__(
165168
option_strings=option_strings,
166169
dest=dest,
@@ -589,9 +592,8 @@ def get_config(arguments: list[str]) -> Options:
589592
)
590593

591594
if not options.project_dir or not os.path.exists(options.project_dir):
592-
raise RuntimeError(
593-
f"Failed to determine a valid project_dir: {options.project_dir}",
594-
)
595+
msg = f"Failed to determine a valid project_dir: {options.project_dir}"
596+
raise RuntimeError(msg)
595597

596598
# Compute final verbosity level by subtracting -q counter.
597599
options.verbosity -= options.quiet

src/ansiblelint/config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,8 @@ def get_rule_config(rule_id: str) -> dict[str, Any]:
168168
"""Get configurations for the rule ``rule_id``."""
169169
rule_config = options.rules.get(rule_id, {})
170170
if not isinstance(rule_config, dict): # pragma: no branch
171-
raise RuntimeError(f"Invalid rule config for {rule_id}: {rule_config}")
171+
msg = f"Invalid rule config for {rule_id}: {rule_config}"
172+
raise RuntimeError(msg)
172173
return rule_config
173174

174175

src/ansiblelint/errors.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,22 +57,18 @@ def __init__(
5757
super().__init__(message)
5858

5959
if rule.__class__ is RuntimeErrorRule and not message:
60-
raise TypeError(
61-
f"{self.__class__.__name__}() missing a "
62-
"required argument: one of 'message' or 'rule'",
63-
)
60+
msg = f"{self.__class__.__name__}() missing a required argument: one of 'message' or 'rule'"
61+
raise TypeError(msg)
6462

6563
self.message = str(message or getattr(rule, "shortdesc", ""))
6664

6765
# Safety measure to ensure we do not end-up with incorrect indexes
6866
if lineno == 0: # pragma: no cover
69-
raise RuntimeError(
70-
"MatchError called incorrectly as line numbers start with 1",
71-
)
67+
msg = "MatchError called incorrectly as line numbers start with 1"
68+
raise RuntimeError(msg)
7269
if column == 0: # pragma: no cover
73-
raise RuntimeError(
74-
"MatchError called incorrectly as column numbers start with 1",
75-
)
70+
msg = "MatchError called incorrectly as column numbers start with 1"
71+
raise RuntimeError(msg)
7672

7773
self.lineno = lineno
7874
self.column = column

src/ansiblelint/file_utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,8 @@ def content(self, value: str) -> None:
309309
has not already been populated.
310310
"""
311311
if not isinstance(value, str):
312-
raise TypeError(f"Expected str but got {type(value)}")
312+
msg = f"Expected str but got {type(value)}"
313+
raise TypeError(msg)
313314
if self._original_content is None:
314315
if self._content is not None:
315316
self._original_content = self._content

src/ansiblelint/formatters/__init__.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,8 @@ class CodeclimateJSONFormatter(BaseFormatter[Any]):
137137
def format_result(self, matches: list[MatchError]) -> str:
138138
"""Format a list of match errors as a JSON string."""
139139
if not isinstance(matches, list):
140-
raise RuntimeError(
141-
f"The {self.__class__} was expecting a list of MatchError.",
142-
)
140+
msg = f"The {self.__class__} was expecting a list of MatchError."
141+
raise RuntimeError(msg)
143142

144143
result = []
145144
for match in matches:
@@ -205,9 +204,8 @@ class SarifFormatter(BaseFormatter[Any]):
205204
def format_result(self, matches: list[MatchError]) -> str:
206205
"""Format a list of match errors as a JSON string."""
207206
if not isinstance(matches, list):
208-
raise RuntimeError(
209-
f"The {self.__class__} was expecting a list of MatchError.",
210-
)
207+
msg = f"The {self.__class__} was expecting a list of MatchError."
208+
raise RuntimeError(msg)
211209

212210
root_path = Path(str(self._base_dir)).as_uri()
213211
root_path = root_path + "/" if not root_path.endswith("/") else root_path

src/ansiblelint/generate_docs.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,8 @@ def rules_as_md(rules: RulesCollection) -> str:
4646

4747
if rule.help:
4848
if not rule.help.startswith(f"# {rule.id}"): # pragma: no cover
49-
raise RuntimeError(
50-
f"Rule {rule.__class__} markdown help does not start with `# {rule.id}` header.\n{rule.help}",
51-
)
49+
msg = f"Rule {rule.__class__} markdown help does not start with `# {rule.id}` header.\n{rule.help}"
50+
raise RuntimeError(msg)
5251
result += f"\n\n{rule.help}"
5352
else:
5453
description = rule.description

src/ansiblelint/loaders.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,8 @@ def load_ignore_txt(filepath: Path | None = None) -> dict[str, set[str]]:
5656
try:
5757
path, rule = entry.split()
5858
except ValueError as exc:
59-
raise RuntimeError(
60-
f"Unable to parse line '{line}' from {ignore_file} file.",
61-
) from exc
59+
msg = f"Unable to parse line '{line}' from {ignore_file} file."
60+
raise RuntimeError(msg) from exc
6261
result[path].add(rule)
6362

6463
return result

src/ansiblelint/rules/galaxy.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ def _coerce(other: object) -> Version:
152152
other = Version(str(other))
153153
if isinstance(other, Version):
154154
return other
155-
raise NotImplementedError(f"Unable to coerce object type {type(other)} to Version")
155+
msg = f"Unable to coerce object type {type(other)} to Version"
156+
raise NotImplementedError(msg)
156157

157158

158159
if "pytest" in sys.modules:

0 commit comments

Comments
 (0)