Instagram / Instagram/Fixit

`lint-fixme` comments not respected

Open
#405 3 comments 1 reaction 0 assignees View on GitHub
Dominant language
Python
Stars
714
Forks
72
PR merge metrics
No merged PRs in 30d

Description

`lint-fixme` comments on nodes in some cases are not respected.

## comprehensions

In the following file (`t.py`), we would expect the violation to be reported for the first function, but not for either of the other two.

```python
def f(l):
return [
i for i in l
if isinstance(i, int) or isinstance(i, float)
]

def g(l):
return [
i for i in l
# lint-fixme: CollapseIsinstanceChecks
if isinstance(i, int) or isinstance(i, float)
]

def h(l):
return [
i for i in l
if isinstance(i, int) or isinstance(i, float) # lint-fixme: CollapseIsinstanceChecks
]
```

However, the violation is reported for all three:

```console
$ fixit lint t.py
t.py@4:11 CollapseIsinstanceChecks: Multiple isinstance calls with the same target but different types can be collapsed into a single call with a tuple of types. (has autofix)
t.py@12:11 CollapseIsinstanceChecks: Multiple isinstance calls with the same target but different types can be collapsed into a single call with a tuple of types. (has autofix)
t.py@19:11 CollapseIsinstanceChecks: Multiple isinstance calls with the same target but different types can be collapsed into a single call with a tuple of types. (has autofix)
🛠️ 1 file checked, 1 file with errors, 3 auto-fixes available 🛠️
```

## lambdas

In the following file (`t.py`), we would expect the violation to be reported for the first list, but not for either of the other two.

```python
operators = [
int,
str,
lambda x: float(x),
]

operators = [
int,
str,
# lint-fixme: NoRedundantLambda
lambda x: float(x),
]

operators = [
int,
str,
lambda x: float(x), # lint-fixme: NoRedundantLambda
]
```

However, the violation is reported for all three:

```console
$ fixit lint t.py
t.py@4:4 NoRedundantLambda: The lambda that is wrapping float is redundant. It can unwrapped safely and used purely. (has autofix)
t.py@11:4 NoRedundantLambda: The lambda that is wrapping float is redundant. It can unwrapped safely and used purely. (has autofix)
t.py@17:4 NoRedundantLambda: The lambda that is wrapping float is redundant. It can unwrapped safely and used purely. (has autofix)
🛠️ 1 file checked, 1 file with errors, 3 auto-fixes available 🛠️
```

EDIT: the commit *is* respected if it is placed before the list:

```python
# lint-fixme: NoRedundantLambda
operators = [
int,
str,
lambda x: float(x),
]
```

```console
$ fixit lint t.py
🧼 1 file clean 🧼
```

This is not expected, though, and means that *multiple* lines will be ignored rather than just the desired one.

### methods

In the following file (`t.py`), we would expect the violation to be reported for the first class, but not for either of the other two.

```python
class foo:
@classmethod
def nm(self, a, b, c):
pass

class foo:
@classmethod
# lint-fixme: UseClsInClassmethod
def nm(self, a, b, c):
pass

class foo:
@classmethod
def nm(self, a, b, c): # lint-fixme: UseClsInClassmethod
pass
```

However, the violation is correctly silenced for the last case, but shown for the middle case that should be silenced:

```console
$ fixit lint t.py
t.py@3:4 UseClsInClassmethod: When using @classmethod, the first argument must be `cls`. (has autofix)
t.py@9:4 UseClsInClassmethod: When using @classmethod, the first argument must be `cls`. (has autofix)
🛠️ 1 file checked, 1 file with errors, 2 auto-fixes available 🛠️
```

## supporting information

```console
$ python --version
Python 3.11.5

$ fixit --version
fixit, version 2.1.0
```

I have also observed this behaviour on Python 3.10.11.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.