Skip to content
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

Upgrade annotation snippet #11618

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
19 changes: 5 additions & 14 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ red_knot_server = { path = "crates/red_knot_server" }
red_knot_workspace = { path = "crates/red_knot_workspace" }

aho-corasick = { version = "1.1.3" }
annotate-snippets = { version = "0.9.2", features = ["color"] }
annotate-snippets = { version = "0.11.4" }
anyhow = { version = "1.0.80" }
argfile = { version = "0.2.0" }
bincode = { version = "1.3.3" }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
---
source: crates/ruff/src/commands/check.rs
---
/home/ferris/project/code.py:1:1: E902 Permission denied (os error 13)
/home/ferris/project/notebook.ipynb:1:1: E902 Permission denied (os error 13)
/home/ferris/project/pyproject.toml:1:1: E902 Permission denied (os error 13)
error[E902]: /home/ferris/project/code.py:1:1: Permission denied (os error 13)

error[E902]: /home/ferris/project/notebook.ipynb:1:1: Permission denied (os error 13)

error[E902]: /home/ferris/project/pyproject.toml:1:1: Permission denied (os error 13)
93 changes: 62 additions & 31 deletions crates/ruff/tests/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,12 @@ inline-quotes = "single"
success: false
exit_code: 1
----- stdout -----
test.py:1:5: Q000 [*] Double quotes found but single quotes preferred
test.py:1:5: B005 Using `.strip()` with multi-character strings is misleading
test.py:1:19: Q000 [*] Double quotes found but single quotes preferred
error[Q000]: test.py:1:5: [*] Double quotes found but single quotes preferred
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not clear to me where and how we want to show the file name, location, and fixability


error[B005]: test.py:1:5: Using `.strip()` with multi-character strings is misleading

error[Q000]: test.py:1:19: [*] Double quotes found but single quotes preferred

Found 3 errors.
[*] 2 fixable with the `--fix` option.

Expand Down Expand Up @@ -88,9 +91,12 @@ inline-quotes = "single"
success: false
exit_code: 1
----- stdout -----
-:1:5: Q000 [*] Double quotes found but single quotes preferred
-:1:5: B005 Using `.strip()` with multi-character strings is misleading
-:1:19: Q000 [*] Double quotes found but single quotes preferred
error[Q000]: -:1:5: [*] Double quotes found but single quotes preferred

error[B005]: -:1:5: Using `.strip()` with multi-character strings is misleading

error[Q000]: -:1:19: [*] Double quotes found but single quotes preferred

Found 3 errors.
[*] 2 fixable with the `--fix` option.

Expand Down Expand Up @@ -128,9 +134,12 @@ inline-quotes = "single"
success: false
exit_code: 1
----- stdout -----
-:1:5: Q000 [*] Double quotes found but single quotes preferred
-:1:5: B005 Using `.strip()` with multi-character strings is misleading
-:1:19: Q000 [*] Double quotes found but single quotes preferred
error[Q000]: -:1:5: [*] Double quotes found but single quotes preferred

error[B005]: -:1:5: Using `.strip()` with multi-character strings is misleading

error[Q000]: -:1:19: [*] Double quotes found but single quotes preferred

Found 3 errors.
[*] 2 fixable with the `--fix` option.

Expand Down Expand Up @@ -174,9 +183,12 @@ inline-quotes = "single"
success: false
exit_code: 1
----- stdout -----
-:1:5: Q000 [*] Double quotes found but single quotes preferred
-:1:5: B005 Using `.strip()` with multi-character strings is misleading
-:1:19: Q000 [*] Double quotes found but single quotes preferred
error[Q000]: -:1:5: [*] Double quotes found but single quotes preferred

error[B005]: -:1:5: Using `.strip()` with multi-character strings is misleading

error[Q000]: -:1:19: [*] Double quotes found but single quotes preferred

Found 3 errors.
[*] 2 fixable with the `--fix` option.

Expand Down Expand Up @@ -255,9 +267,12 @@ OTHER = "OTHER"
success: false
exit_code: 1
----- stdout -----
main.py:4:16: Q000 [*] Double quotes found but single quotes preferred
main.py:5:12: Q000 [*] Double quotes found but single quotes preferred
test.py:3:15: Q000 [*] Double quotes found but single quotes preferred
error[Q000]: main.py:4:16: [*] Double quotes found but single quotes preferred

error[Q000]: main.py:5:12: [*] Double quotes found but single quotes preferred

error[Q000]: test.py:3:15: [*] Double quotes found but single quotes preferred

Found 3 errors.
[*] 3 fixable with the `--fix` option.

Expand Down Expand Up @@ -305,8 +320,10 @@ if __name__ == "__main__":
success: false
exit_code: 1
----- stdout -----
generated.py:4:16: Q000 [*] Double quotes found but single quotes preferred
generated.py:5:12: Q000 [*] Double quotes found but single quotes preferred
error[Q000]: generated.py:4:16: [*] Double quotes found but single quotes preferred

error[Q000]: generated.py:5:12: [*] Double quotes found but single quotes preferred

Found 2 errors.
[*] 2 fixable with the `--fix` option.

Expand Down Expand Up @@ -352,7 +369,8 @@ _ = "---------------------------------------------------------------------------
success: false
exit_code: 1
----- stdout -----
test.py:5:91: E501 Line too long (109 > 100)
error[E501]: test.py:5:91: Line too long (109 > 100)

Found 1 error.

----- stderr -----
Expand Down Expand Up @@ -400,7 +418,8 @@ if __name__ == "__main__":
success: false
exit_code: 1
----- stdout -----
generated.py:2:8: F401 [*] `os` imported but unused
error[F401]: generated.py:2:8: [*] `os` imported but unused

Found 1 error.
[*] 1 fixable with the `--fix` option.

Expand Down Expand Up @@ -448,7 +467,8 @@ if __name__ == "__main__":
success: false
exit_code: 1
----- stdout -----
generated.py:2:8: F401 [*] `os` imported but unused
error[F401]: generated.py:2:8: [*] `os` imported but unused

Found 1 error.
[*] 1 fixable with the `--fix` option.

Expand Down Expand Up @@ -684,8 +704,10 @@ x = "longer_than_90_charactersssssssssssssssssssssssssssssssssssssssssssssssssss
success: false
exit_code: 1
----- stdout -----
-:2:1: I001 [*] Import block is un-sorted or un-formatted
-:15:91: E501 Line too long (97 > 90)
error[I001]: -:2:1: [*] Import block is un-sorted or un-formatted

error[E501]: -:15:91: Line too long (97 > 90)

Found 2 errors.
[*] 1 fixable with the `--fix` option.

Expand Down Expand Up @@ -809,7 +831,8 @@ select=["E501"]
success: false
exit_code: 1
----- stdout -----
-:1:91: E501 Line too long (97 > 90)
error[E501]: -:1:91: Line too long (97 > 90)

Found 1 error.

----- stderr -----
Expand Down Expand Up @@ -851,7 +874,8 @@ fn deprecated_config_option_overridden_via_cli() {
success: false
exit_code: 1
----- stdout -----
-:1:7: N801 Class name `lowercase` should use CapWords convention
error[N801]: -:1:7: Class name `lowercase` should use CapWords convention

Found 1 error.

----- stderr -----
Expand Down Expand Up @@ -925,7 +949,8 @@ include = ["*.ipy"]
success: false
exit_code: 1
----- stdout -----
main.ipy:cell 1:1:8: F401 [*] `os` imported but unused
error[F401]: main.ipy:cell 1:1:8: [*] `os` imported but unused

Found 1 error.
[*] 1 fixable with the `--fix` option.

Expand Down Expand Up @@ -963,7 +988,8 @@ import os
success: false
exit_code: 1
----- stdout -----
-:3:8: F401 [*] `os` imported but unused
error[F401]: -:3:8: [*] `os` imported but unused

Found 1 error.
[*] 1 fixable with the `--fix` option.

Expand Down Expand Up @@ -1041,7 +1067,8 @@ import os
success: false
exit_code: 1
----- stdout -----
-:2:8: F401 [*] `os` imported but unused
error[F401]: -:2:8: [*] `os` imported but unused

Found 1 error.
[*] 1 fixable with the `--fix` option.

Expand Down Expand Up @@ -1118,7 +1145,8 @@ import os
success: false
exit_code: 1
----- stdout -----
-:2:8: F401 [*] `os` imported but unused
error[F401]: -:2:8: [*] `os` imported but unused

Found 1 error.
[*] 1 fixable with the `--fix` option.

Expand Down Expand Up @@ -1159,7 +1187,8 @@ def func():
success: false
exit_code: 1
----- stdout -----
-:2:8: F401 [*] `os` imported but unused
error[F401]: -:2:8: [*] `os` imported but unused

Found 1 error.
[*] 1 fixable with the `--fix` option.

Expand Down Expand Up @@ -1197,7 +1226,8 @@ fn negated_per_file_ignores() -> Result<()> {
success: false
exit_code: 1
----- stdout -----
selected.py:1:1: RUF901 [*] Hey this is a stable test rule with a safe fix.
error[RUF901]: selected.py:1:1: [*] Hey this is a stable test rule with a safe fix.

Found 1 error.
[*] 1 fixable with the `--fix` option.

Expand Down Expand Up @@ -1239,7 +1269,8 @@ fn negated_per_file_ignores_absolute() -> Result<()> {
success: false
exit_code: 1
----- stdout -----
src/selected.py:1:1: RUF901 [*] Hey this is a stable test rule with a safe fix.
error[RUF901]: src/selected.py:1:1: [*] Hey this is a stable test rule with a safe fix.

Found 1 error.
[*] 1 fixable with the `--fix` option.

Expand Down
2 changes: 1 addition & 1 deletion crates/ruff_linter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ ruff_source_file = { workspace = true, features = ["serde"] }
ruff_text_size = { workspace = true }

aho-corasick = { workspace = true }
annotate-snippets = { workspace = true, features = ["color"] }
annotate-snippets = { workspace = true }
anyhow = { workspace = true }
bitflags = { workspace = true }
chrono = { workspace = true }
Expand Down
22 changes: 11 additions & 11 deletions crates/ruff_linter/src/message/grouped.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use ruff_source_file::OneIndexed;

use crate::fs::relativize_path;
use crate::message::diff::calculate_print_width;
use crate::message::text::{MessageCodeFrame, RuleCodeAndBody};
use crate::message::text::RuleCodeAndBody;
use crate::message::{
group_messages_by_filename, Emitter, EmitterContext, Message, MessageWithLocation,
};
Expand Down Expand Up @@ -154,16 +154,16 @@ impl Display for DisplayGroupedMessage<'_> {
)?;

if self.show_source {
use std::fmt::Write;
let mut padded = PadAdapter::new(f);
writeln!(
padded,
"{}",
MessageCodeFrame {
message,
notebook_index: self.notebook_index
}
)?;
// use std::fmt::Write;
// let mut padded = PadAdapter::new(f);
// writeln!(
// padded,
// "{}",
// MessageCodeFrame {
// message,
// notebook_index: self.notebook_index
// }
// )?;
}

Ok(())
Expand Down
5 changes: 1 addition & 4 deletions crates/ruff_linter/src/message/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,7 @@ impl Message {
.map_or(TextSize::new(0), TextLen::text_len);

Message::SyntaxError(SyntaxErrorMessage {
message: format!(
"SyntaxError: {}",
DisplayParseErrorType::new(&parse_error.error)
),
message: DisplayParseErrorType::new(&parse_error.error).to_string(),
range: TextRange::at(parse_error.location.start(), len),
file,
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
source: crates/ruff_linter/src/message/azure.rs
expression: content
---
##vso[task.logissue type=error;sourcepath=syntax_errors.py;linenumber=1;columnnumber=15;]SyntaxError: Expected one or more symbol names after import
##vso[task.logissue type=error;sourcepath=syntax_errors.py;linenumber=3;columnnumber=12;]SyntaxError: Expected ')', found newline
##vso[task.logissue type=error;sourcepath=syntax_errors.py;linenumber=1;columnnumber=15;]Expected one or more symbol names after import
##vso[task.logissue type=error;sourcepath=syntax_errors.py;linenumber=3;columnnumber=12;]Expected ')', found newline
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
source: crates/ruff_linter/src/message/github.rs
expression: content
---
::error title=Ruff,file=syntax_errors.py,line=1,col=15,endLine=2,endColumn=1::syntax_errors.py:1:15: SyntaxError: Expected one or more symbol names after import
::error title=Ruff,file=syntax_errors.py,line=3,col=12,endLine=4,endColumn=1::syntax_errors.py:3:12: SyntaxError: Expected ')', found newline
::error title=Ruff,file=syntax_errors.py,line=1,col=15,endLine=2,endColumn=1::syntax_errors.py:1:15: Expected one or more symbol names after import
::error title=Ruff,file=syntax_errors.py,line=3,col=12,endLine=4,endColumn=1::syntax_errors.py:3:12: Expected ')', found newline
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ expression: redact_fingerprint(&content)
---
[
{
"description": "SyntaxError: Expected one or more symbol names after import",
"description": "Expected one or more symbol names after import",
"fingerprint": "<redacted>",
"location": {
"lines": {
Expand All @@ -16,7 +16,7 @@ expression: redact_fingerprint(&content)
"severity": "major"
},
{
"description": "SyntaxError: Expected ')', found newline",
"description": "Expected ')', found newline",
"fingerprint": "<redacted>",
"location": {
"lines": {
Expand Down
Loading
Loading