-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove E999
as a rule, disallow any disablement methods for syntax error
#11901
Conversation
96968ba
to
4dd412e
Compare
b8388f3
to
be1ab9f
Compare
## Summary This PR removes most of the syntax errors from the test cases. This would create noise when #11901 is complete. These syntax errors are also just noise for the test itself. ## Test Plan Update the snapshots and verify that they're still the same.
4dd412e
to
7b7e6b2
Compare
58fb82b
to
72b9853
Compare
|
code | total | + violation | - violation | + fix | - fix |
---|---|---|---|---|---|
E999 | 2 | 0 | 2 | 0 | 0 |
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.
1121283
to
80326bd
Compare
What happens if a user specifies |
I wonder if it still makes sense to model For example, I suspect that |
It shouldn't affect anything, the
Good point. Let me check. |
But we don't show a warning. I'm worried that this is confusing for users that would expect |
Yeah, that's correct. I guess that doesn't make sense since it, now, doesn't behave as a rule (as you mentioned). Although I wonder how would one go about configuring the fixable part if and when we introduce them. For some more context, Pyright doesn't seem to consider it as a rule either, at least that's what I'm inferring from the fact that there's no "rule" field in the JSON output: {
"file": "/Users/dhruv/playground/ruff/parser/_.py",
"severity": "error",
"message": "Expected expression to the right of \"=\"",
"range": {
"start": {
"line": 3,
"character": 17
},
"end": {
"line": 4,
"character": 0
}
}
} Vs the one with the "rule" field: {
"file": "/Users/dhruv/playground/ruff/src/lsp.py",
"severity": "error",
"message": "\"name\" is not defined",
"range": {
"start": {
"line": 9,
"character": 6
},
"end": {
"line": 9,
"character": 10
}
},
"rule": "reportUndefinedVariable"
} I'm not sure how does Biome does it but they have a separate |
Biome supports different |
I think we can just remove this code from the rule table so that it's not considered valid in config. But, that opens up another set of problems. |
What's the motivation for making it unsuppressable? |
There's some reasoning in the internal discord thread https://discord.com/channels/1039017663004942429/1082324250112823306/1250836504738267157 |
I don't see the motivation described in there, just more context on why it was added initially. |
Historically, I think the main motivation was because the parser didn't support new syntax which isn't the case with the new parser. We guarantee that the Ruff parser will always match the latest Python grammar. This means there's no need to suppress the syntax errors although there can be use cases in a test fixture for which the file should be exluded instead. This also means that we don't need to show the syntax errors as log messages in addition to the diagnostics. Other syntax errors: In the future, Ruff will also start providing syntax error diagnostics for unsupported syntax as per the target version or the ones raised by the compiler. Allowing to disable syntax errors means that Ruff won't be able to provide diagnostics for these kinds of syntax errors in case it's disabled. But, the syntax errors indicate that Python won't be able to run the code itself. Looking at the ecosystem, the following tools support ignoring syntax errors:
While, the following doesn't:
Searching for
tl;dr for the above search is that most usages are to include |
Some of these syntax errors emitted by the Python compiler are very subtle -- some have been the subject of several revisions at CPython (e.g. python/cpython#100581). From the perspective of Python users, these are all just |
I'll review the PR in detail in a minute, but I think we should wait to remove the The main reason is that we try to first deprecate a feature before completely removing it (gives users a nicer upgrade experience). |
Yeah, I just thought of that, I'm already on it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great! I'm also like that Message
is now an enum. I expect that we want to incorporate formatter errors in the future as well and it being an enum already moves in the right direction.
"code": message.kind.rule().noqa_code().to_string(), | ||
"url": message.kind.rule().url(), | ||
"message": message.kind.body, | ||
"code": message.rule().map(|rule| rule.noqa_code().to_string()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I'm inclined to add a code
and url
method to Message
that return Option<String>
and Option<Url>
to avoid the repetition in the different emitters.
// Try to create a non-empty range so that the diagnostic can print a caret at the right | ||
// position. This requires that we retrieve the next character, if any, and take its length | ||
// to maintain char-boundaries. | ||
let len = locator |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uh, our parse errors only have a start offset and not a range. That's funny.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I follow here. This is mainly a copy-paste from the existing logic :)
The only functionality that we "loose" when merging this PR is that it is no longer possible to disable Huh, RustRover's review feature isnt' there yet.... Submitting my review once would have been enough. |
It should be low effort if we want to add it to the new server. I don't think we should add any new "features" to Any suggestions for the config name?
|
|
I'm leaning towards a global option because we may want to always show (or not show) syntax error in the future even if linting is disabled. I'm leaning towards using
|
Makes sense. |
This would be useful if we want to provide more options apart from enabling / disabling. I'm not sure what they would be right now and don't know if there's any other functionality we could provide related to syntax errors (maybe "fix" enabled or not?). I'm leaning towards what Alex has suggested. |
f5d609a
to
7ef78bd
Compare
(I'm going to make the server changes in a follow-up PR.) |
7ef78bd
to
02b5c55
Compare
## Summary Follow-up to #11901 This PR avoids displaying the syntax errors as log message now that the `E999` diagnostic cannot be disabled. For context on why this was added, refer to #2505. Basically, we would allow ignoring the syntax error diagnostic because certain syntax feature weren't supported back then like `match` statement. And, if a user ignored `E999`, Ruff would give no feedback if the source code contained any syntax error. So, this log message was a way to indicate to the user even if `E999` was disabled. The current state of the parser is such that (a) it matches with the latest grammar and (b) it's easy to add support for any new syntax. **Note:** This PR doesn't remove the `DisplayParseError` struct because it's still being used by the formatter. ## Test Plan Update existing snapshots from the integration tests.
## Summary Follow-up to #11901 This PR avoids displaying the syntax errors as log message now that the `E999` diagnostic cannot be disabled. For context on why this was added, refer to #2505. Basically, we would allow ignoring the syntax error diagnostic because certain syntax feature weren't supported back then like `match` statement. And, if a user ignored `E999`, Ruff would give no feedback if the source code contained any syntax error. So, this log message was a way to indicate to the user even if `E999` was disabled. The current state of the parser is such that (a) it matches with the latest grammar and (b) it's easy to add support for any new syntax. **Note:** This PR doesn't remove the `DisplayParseError` struct because it's still being used by the formatter. ## Test Plan Update existing snapshots from the integration tests.
## Summary Follow-up from #11901 This PR adds a new server setting to show / hide syntax errors. ## Test Plan ### VS Code Using astral-sh/ruff-vscode#504 with the following config: ```json { "ruff.nativeServer": true, "ruff.path": ["/Users/dhruv/work/astral/ruff/target/debug/ruff"], "ruff.showSyntaxErrors": true } ``` First, set `ruff.showSyntaxErrors` to `true`: <img width="1177" alt="Screenshot 2024-06-27 at 08 34 58" src="https://github.com/astral-sh/ruff/assets/67177269/5d77547a-a908-4a00-8714-7c00784e8679"> And then set it to `false`: <img width="1185" alt="Screenshot 2024-06-27 at 08 35 19" src="https://github.com/astral-sh/ruff/assets/67177269/9720f089-f10c-420b-a2c1-2bbb2245be35"> ### Neovim Using the following Ruff server config: ```lua require('lspconfig').ruff.setup { init_options = { settings = { showSyntaxErrors = false, }, }, } ``` First, set `showSyntaxErrors` to `true`: <img width="1279" alt="Screenshot 2024-06-27 at 08 28 03" src="https://github.com/astral-sh/ruff/assets/67177269/e694e231-91ba-47f8-8e8a-ad2e82b85a45"> And then set it to `false`: <img width="1284" alt="Screenshot 2024-06-27 at 08 28 20" src="https://github.com/astral-sh/ruff/assets/67177269/25b86a57-02b1-44f7-9f65-cf5fdde93b0c">
…error (#11901) ## Summary This PR updates the way syntax errors are handled throughout the linter. The main change is that it's now not considered as a rule which involves the following changes: * Update `Message` to be an enum with two variants - one for diagnostic message and the other for syntax error message * Provide methods on the new message enum to query information required by downstream usages This means that the syntax errors cannot be hidden / disabled via any disablement methods. These are: 1. Configuration via `select`, `ignore`, `per-file-ignores`, and their `extend-*` variants ```console $ cargo run -- check ~/playground/ruff/src/lsp.py --extend-select=E999 --no-preview --no-cache Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.10s Running `target/debug/ruff check /Users/dhruv/playground/ruff/src/lsp.py --extend-select=E999 --no-preview --no-cache` warning: Rule `E999` is deprecated and will be removed in a future release. Syntax errors will always be shown regardless of whether this rule is selected or not. /Users/dhruv/playground/ruff/src/lsp.py:1:8: F401 [*] `abc` imported but unused | 1 | import abc | ^^^ F401 2 | from pathlib import Path 3 | import os | = help: Remove unused import: `abc` ``` 3. Command-line flags via `--select`, `--ignore`, `--per-file-ignores`, and their `--extend-*` variants ```console $ cargo run -- check ~/playground/ruff/src/lsp.py --no-cache --config=~/playground/ruff/pyproject.toml Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.11s Running `target/debug/ruff check /Users/dhruv/playground/ruff/src/lsp.py --no-cache --config=/Users/dhruv/playground/ruff/pyproject.toml` warning: Rule `E999` is deprecated and will be removed in a future release. Syntax errors will always be shown regardless of whether this rule is selected or not. /Users/dhruv/playground/ruff/src/lsp.py:1:8: F401 [*] `abc` imported but unused | 1 | import abc | ^^^ F401 2 | from pathlib import Path 3 | import os | = help: Remove unused import: `abc` ``` This also means that the **output format** needs to be updated: 1. The `code`, `noqa_row`, `url` fields in the JSON output is optional (`null` for syntax errors) 2. Other formats are changed accordingly For each format, a new test case specific to syntax errors have been added. Please refer to the snapshot output for the exact format for syntax error message. The output of the `--statistics` flag will have a blank entry for syntax errors: ``` 315 F821 [ ] undefined-name 119 [ ] syntax-error 103 F811 [ ] redefined-while-unused ``` The **language server** is updated to consider the syntax errors by convert them into LSP diagnostic format separately. ### Preview There are no quick fixes provided to disable syntax errors. This will automatically work for `ruff-lsp` because the `noqa_row` field will be `null` in that case. <img width="772" alt="Screenshot 2024-06-26 at 14 57 08" src="https://github.com/astral-sh/ruff/assets/67177269/aaac827e-4777-4ac8-8c68-eaf9f2c36774"> Even with `noqa` comment, the syntax error is displayed: <img width="763" alt="Screenshot 2024-06-26 at 14 59 51" src="https://github.com/astral-sh/ruff/assets/67177269/ba1afb68-7eaf-4b44-91af-6d93246475e2"> Rule documentation page: <img width="1371" alt="Screenshot 2024-06-26 at 16 48 07" src="https://github.com/astral-sh/ruff/assets/67177269/524f01df-d91f-4ac0-86cc-40e76b318b24"> ## Test Plan - [x] Disablement methods via config shows a warning - [x] `select`, `extend-select` - [ ] ~`ignore`~ _doesn't show any message_ - [ ] ~`per-file-ignores`, `extend-per-file-ignores`~ _doesn't show any message_ - [x] Disablement methods via command-line flag shows a warning - [x] `--select`, `--extend-select` - [ ] ~`--ignore`~ _doesn't show any message_ - [ ] ~`--per-file-ignores`, `--extend-per-file-ignores`~ _doesn't show any message_ - [x] File with syntax errors should exit with code 1 - [x] Language server - [x] Should show diagnostics for syntax errors - [x] Should not recommend a quick fix edit for adding `noqa` comment - [x] Same for `ruff-lsp` resolves: #8447
## Summary Follow-up to #11901 This PR avoids displaying the syntax errors as log message now that the `E999` diagnostic cannot be disabled. For context on why this was added, refer to #2505. Basically, we would allow ignoring the syntax error diagnostic because certain syntax feature weren't supported back then like `match` statement. And, if a user ignored `E999`, Ruff would give no feedback if the source code contained any syntax error. So, this log message was a way to indicate to the user even if `E999` was disabled. The current state of the parser is such that (a) it matches with the latest grammar and (b) it's easy to add support for any new syntax. **Note:** This PR doesn't remove the `DisplayParseError` struct because it's still being used by the formatter. ## Test Plan Update existing snapshots from the integration tests.
## Summary Follow-up from #11901 This PR adds a new server setting to show / hide syntax errors. ## Test Plan ### VS Code Using astral-sh/ruff-vscode#504 with the following config: ```json { "ruff.nativeServer": true, "ruff.path": ["/Users/dhruv/work/astral/ruff/target/debug/ruff"], "ruff.showSyntaxErrors": true } ``` First, set `ruff.showSyntaxErrors` to `true`: <img width="1177" alt="Screenshot 2024-06-27 at 08 34 58" src="https://github.com/astral-sh/ruff/assets/67177269/5d77547a-a908-4a00-8714-7c00784e8679"> And then set it to `false`: <img width="1185" alt="Screenshot 2024-06-27 at 08 35 19" src="https://github.com/astral-sh/ruff/assets/67177269/9720f089-f10c-420b-a2c1-2bbb2245be35"> ### Neovim Using the following Ruff server config: ```lua require('lspconfig').ruff.setup { init_options = { settings = { showSyntaxErrors = false, }, }, } ``` First, set `showSyntaxErrors` to `true`: <img width="1279" alt="Screenshot 2024-06-27 at 08 28 03" src="https://github.com/astral-sh/ruff/assets/67177269/e694e231-91ba-47f8-8e8a-ad2e82b85a45"> And then set it to `false`: <img width="1284" alt="Screenshot 2024-06-27 at 08 28 20" src="https://github.com/astral-sh/ruff/assets/67177269/25b86a57-02b1-44f7-9f65-cf5fdde93b0c">
…error (#11901) ## Summary This PR updates the way syntax errors are handled throughout the linter. The main change is that it's now not considered as a rule which involves the following changes: * Update `Message` to be an enum with two variants - one for diagnostic message and the other for syntax error message * Provide methods on the new message enum to query information required by downstream usages This means that the syntax errors cannot be hidden / disabled via any disablement methods. These are: 1. Configuration via `select`, `ignore`, `per-file-ignores`, and their `extend-*` variants ```console $ cargo run -- check ~/playground/ruff/src/lsp.py --extend-select=E999 --no-preview --no-cache Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.10s Running `target/debug/ruff check /Users/dhruv/playground/ruff/src/lsp.py --extend-select=E999 --no-preview --no-cache` warning: Rule `E999` is deprecated and will be removed in a future release. Syntax errors will always be shown regardless of whether this rule is selected or not. /Users/dhruv/playground/ruff/src/lsp.py:1:8: F401 [*] `abc` imported but unused | 1 | import abc | ^^^ F401 2 | from pathlib import Path 3 | import os | = help: Remove unused import: `abc` ``` 3. Command-line flags via `--select`, `--ignore`, `--per-file-ignores`, and their `--extend-*` variants ```console $ cargo run -- check ~/playground/ruff/src/lsp.py --no-cache --config=~/playground/ruff/pyproject.toml Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.11s Running `target/debug/ruff check /Users/dhruv/playground/ruff/src/lsp.py --no-cache --config=/Users/dhruv/playground/ruff/pyproject.toml` warning: Rule `E999` is deprecated and will be removed in a future release. Syntax errors will always be shown regardless of whether this rule is selected or not. /Users/dhruv/playground/ruff/src/lsp.py:1:8: F401 [*] `abc` imported but unused | 1 | import abc | ^^^ F401 2 | from pathlib import Path 3 | import os | = help: Remove unused import: `abc` ``` This also means that the **output format** needs to be updated: 1. The `code`, `noqa_row`, `url` fields in the JSON output is optional (`null` for syntax errors) 2. Other formats are changed accordingly For each format, a new test case specific to syntax errors have been added. Please refer to the snapshot output for the exact format for syntax error message. The output of the `--statistics` flag will have a blank entry for syntax errors: ``` 315 F821 [ ] undefined-name 119 [ ] syntax-error 103 F811 [ ] redefined-while-unused ``` The **language server** is updated to consider the syntax errors by convert them into LSP diagnostic format separately. ### Preview There are no quick fixes provided to disable syntax errors. This will automatically work for `ruff-lsp` because the `noqa_row` field will be `null` in that case. <img width="772" alt="Screenshot 2024-06-26 at 14 57 08" src="https://github.com/astral-sh/ruff/assets/67177269/aaac827e-4777-4ac8-8c68-eaf9f2c36774"> Even with `noqa` comment, the syntax error is displayed: <img width="763" alt="Screenshot 2024-06-26 at 14 59 51" src="https://github.com/astral-sh/ruff/assets/67177269/ba1afb68-7eaf-4b44-91af-6d93246475e2"> Rule documentation page: <img width="1371" alt="Screenshot 2024-06-26 at 16 48 07" src="https://github.com/astral-sh/ruff/assets/67177269/524f01df-d91f-4ac0-86cc-40e76b318b24"> ## Test Plan - [x] Disablement methods via config shows a warning - [x] `select`, `extend-select` - [ ] ~`ignore`~ _doesn't show any message_ - [ ] ~`per-file-ignores`, `extend-per-file-ignores`~ _doesn't show any message_ - [x] Disablement methods via command-line flag shows a warning - [x] `--select`, `--extend-select` - [ ] ~`--ignore`~ _doesn't show any message_ - [ ] ~`--per-file-ignores`, `--extend-per-file-ignores`~ _doesn't show any message_ - [x] File with syntax errors should exit with code 1 - [x] Language server - [x] Should show diagnostics for syntax errors - [x] Should not recommend a quick fix edit for adding `noqa` comment - [x] Same for `ruff-lsp` resolves: #8447
## Summary Follow-up to #11901 This PR avoids displaying the syntax errors as log message now that the `E999` diagnostic cannot be disabled. For context on why this was added, refer to #2505. Basically, we would allow ignoring the syntax error diagnostic because certain syntax feature weren't supported back then like `match` statement. And, if a user ignored `E999`, Ruff would give no feedback if the source code contained any syntax error. So, this log message was a way to indicate to the user even if `E999` was disabled. The current state of the parser is such that (a) it matches with the latest grammar and (b) it's easy to add support for any new syntax. **Note:** This PR doesn't remove the `DisplayParseError` struct because it's still being used by the formatter. ## Test Plan Update existing snapshots from the integration tests.
## Summary Follow-up from #11901 This PR adds a new server setting to show / hide syntax errors. ## Test Plan ### VS Code Using astral-sh/ruff-vscode#504 with the following config: ```json { "ruff.nativeServer": true, "ruff.path": ["/Users/dhruv/work/astral/ruff/target/debug/ruff"], "ruff.showSyntaxErrors": true } ``` First, set `ruff.showSyntaxErrors` to `true`: <img width="1177" alt="Screenshot 2024-06-27 at 08 34 58" src="https://github.com/astral-sh/ruff/assets/67177269/5d77547a-a908-4a00-8714-7c00784e8679"> And then set it to `false`: <img width="1185" alt="Screenshot 2024-06-27 at 08 35 19" src="https://github.com/astral-sh/ruff/assets/67177269/9720f089-f10c-420b-a2c1-2bbb2245be35"> ### Neovim Using the following Ruff server config: ```lua require('lspconfig').ruff.setup { init_options = { settings = { showSyntaxErrors = false, }, }, } ``` First, set `showSyntaxErrors` to `true`: <img width="1279" alt="Screenshot 2024-06-27 at 08 28 03" src="https://github.com/astral-sh/ruff/assets/67177269/e694e231-91ba-47f8-8e8a-ad2e82b85a45"> And then set it to `false`: <img width="1284" alt="Screenshot 2024-06-27 at 08 28 20" src="https://github.com/astral-sh/ruff/assets/67177269/25b86a57-02b1-44f7-9f65-cf5fdde93b0c">
Summary
This PR updates the way syntax errors are handled throughout the linter.
The main change is that it's now not considered as a rule which involves the following changes:
Message
to be an enum with two variants - one for diagnostic message and the other for syntax error messageThis means that the syntax errors cannot be hidden / disabled via any disablement methods. These are:
select
,ignore
,per-file-ignores
, and theirextend-*
variants--select
,--ignore
,--per-file-ignores
, and their--extend-*
variantsThis also means that the output format needs to be updated:
code
,noqa_row
,url
fields in the JSON output is optional (null
for syntax errors)For each format, a new test case specific to syntax errors have been added. Please refer to the snapshot output for the exact format for syntax error message.
The output of the
--statistics
flag will have a blank entry for syntax errors:The language server is updated to consider the syntax errors by convert them into LSP diagnostic format separately.
Preview
There are no quick fixes provided to disable syntax errors. This will automatically work for
ruff-lsp
because thenoqa_row
field will benull
in that case.Even with
noqa
comment, the syntax error is displayed:Rule documentation page:
Test Plan
select
,extend-select
doesn't show any messageignore
doesn't show any messageper-file-ignores
,extend-per-file-ignores
--select
,--extend-select
doesn't show any message--ignore
doesn't show any message--per-file-ignores
,--extend-per-file-ignores
noqa
commentruff-lsp
resolves: #8447