[X] Have you checked to see if your issue still exists on the master branch? See the docs for instructions on how to setup a local build of Refurb.
[X] Have you looked at the open/closed issues to see if anyone has already reported your issue?
[x] If reporting a false positive/incorrect suggestion, have you double checked that the suggested fix changes the code semantics?
The Bug
I found the issue where only the first error is taken into consideration from the amend section.
In my case, I want to disable all checks for a single path, so I specified a list of all possible checks as ignore values for a single directory.
I checked the code (the same code is on master) and probably found the issue:
def is_ignored_via_amend(error: Error, settings: Settings) -> bool:
assert error.filename
path = Path(error.filename).resolve()
error_code = ErrorCode.from_error(type(error))
config_root = Path(settings.config_file).parent if settings.config_file else Path()
for ignore in settings.ignore:
if ignore.path:
ignore_path = (config_root / ignore.path).resolve()
if path.is_relative_to(ignore_path):
if isinstance(ignore, ErrorCode):
return str(ignore) == str(error_code)
return ignore.value in error.categories
return False
The loop always ends on the first iteration if the path is relative to the ignore path, the error code is never checked there. There are not UTs for that function, probably that's why it was missed.
The solution below worked for me, so I'm creating MR for that. Please review.
def is_ignored_via_amend(error: Error, settings: Settings) -> bool:
assert error.filename
path = Path(error.filename).resolve()
error_code = str(ErrorCode.from_error(type(error)))
config_root = Path(settings.config_file).parent if settings.config_file else Path()
errors_to_ignore = []
categories_to_ignore = []
for ignore in settings.ignore:
if ignore.path:
ignore_path = (config_root / ignore.path).resolve()
if path.is_relative_to(ignore_path):
if isinstance(ignore, ErrorCode):
errors_to_ignore.append(str(ignore))
else:
categories_to_ignore.append(ignore.value)
return error_code in errors_to_ignore or any(category in categories_to_ignore for category in error.categories)
Has your issue already been fixed?
master
branch? See the docs for instructions on how to setup a local build of Refurb.The Bug
I found the issue where only the first error is taken into consideration from the amend section.
In my case, I want to disable all checks for a single path, so I specified a list of all possible checks as ignore values for a single directory.
I checked the code (the same code is on master) and probably found the issue:
The loop always ends on the first iteration if the path is relative to the ignore path, the error code is never checked there. There are not UTs for that function, probably that's why it was missed.
The solution below worked for me, so I'm creating MR for that. Please review.
Version Info
Python Version
3.11
Config File
Extra Info
None