Skip to content

Avoid E275 if keyword followed by comma#12136

Merged
dhruvmanila merged 1 commit intomainfrom
dhruv/infinite-autofix
Jul 1, 2024
Merged

Avoid E275 if keyword followed by comma#12136
dhruvmanila merged 1 commit intomainfrom
dhruv/infinite-autofix

Conversation

@dhruvmanila
Copy link
Member

Summary

Use the following to reproduce this:

$ cargo run -- check --select=E275,E203 --preview --no-cache ~/playground/ruff/src/play.py --fix
debug error: Failed to converge after 100 iterations in `/Users/dhruv/playground/ruff/src/play.py` with rule codes E275:---
yield,x

---
/Users/dhruv/playground/ruff/src/play.py:1:1: E275 Missing whitespace after keyword
  |
1 | yield,x
  | ^^^^^ E275
  |
  = help: Added missing whitespace after keyword

Found 101 errors (100 fixed, 1 remaining).
[*] 1 fixable with the `--fix` option.

Test Plan

Add a test case and run cargo insta test.

@dhruvmanila dhruvmanila added bug Something isn't working fuzzer Surfaced via fuzzing. labels Jul 1, 2024
@github-actions
Copy link
Contributor

github-actions bot commented Jul 1, 2024

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

ℹ️ ecosystem check encountered linter errors. (no lint changes; 1 project error)

demisto/content (error)

ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview

warning: The top-level linter settings are deprecated in favour of their counterparts in the `lint` section. Please update the following options in `pyproject.toml`:
  - 'ignore' -> 'lint.ignore'
  - 'select' -> 'lint.select'
  - 'unfixable' -> 'lint.unfixable'
  - 'per-file-ignores' -> 'lint.per-file-ignores'
warning: `PGH001` has been remapped to `S307`.
warning: `PGH002` has been remapped to `G010`.
warning: `PLR1701` has been remapped to `SIM101`.
ruff failed
  Cause: Selection of deprecated rule `E999` is not allowed when preview is enabled.

@dhruvmanila dhruvmanila merged commit 3f25561 into main Jul 1, 2024
@dhruvmanila dhruvmanila deleted the dhruv/infinite-autofix branch July 1, 2024 12:34
dhruvmanila added a commit that referenced this pull request Jul 2, 2024
## Summary

This PR updates Ruff to **not** generate auto-fixes if the source code
contains syntax errors as determined by the parser.

The main motivation behind this is to avoid infinite autofix loop when
the token-based rules are run over any source with syntax errors in
#11950.

Although even after this, it's not certain that there won't be an
infinite autofix loop because the logic might be incorrect. For example,
#12094 and
#12136.

This requires updating the test infrastructure to not validate for fix
availability status when the source contained syntax errors. This is
required because otherwise the fuzzer might fail as it uses the test
function to run the linter and validate the source code.

resolves: #11455 

## Test Plan

`cargo insta test`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working fuzzer Surfaced via fuzzing.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants