Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

Commit

Permalink
refactor(rome_diagnostics): port the display of code frames over from…
Browse files Browse the repository at this point in the history
… Rome JS (#3280)

* refactor(rome_diagnostics): port the display of code frames over from Rome JS

* fix the alignment of tab characters

* Update crates/rome_diagnostics/src/v2/display/frame.rs

Co-authored-by: Emanuele Stoppa <[email protected]>

* update snapshots

Co-authored-by: Emanuele Stoppa <[email protected]>
  • Loading branch information
leops and ematipico authored Sep 30, 2022
1 parent 1f66e37 commit 34530e7
Show file tree
Hide file tree
Showing 502 changed files with 14,842 additions and 12,852 deletions.
6 changes: 4 additions & 2 deletions crates/rome_analyze/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#![deny(rustdoc::broken_intra_doc_links)]

use rome_console::codespan::Severity;
use rome_diagnostics::v2::{category, Category};
use std::cmp::Ordering;
use std::collections::{BTreeMap, BinaryHeap};
use std::ops;
Expand Down Expand Up @@ -36,6 +34,10 @@ pub use crate::syntax::SyntaxVisitor;
pub use crate::visitor::{NodeVisitor, Visitor, VisitorContext, VisitorFinishContext};
use rome_console::markup;
use rome_diagnostics::file::{FileId, FileSpan};
use rome_diagnostics::{
v2::{category, Category},
Severity,
};
use rome_diagnostics::{Diagnostic, SubDiagnostic};
use rome_rowan::{
AstNode, Direction, Language, SyntaxElement, SyntaxToken, TextRange, TextSize, TriviaPieceKind,
Expand Down
3 changes: 1 addition & 2 deletions crates/rome_analyze/src/matcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,7 @@ where

#[cfg(test)]
mod tests {
use rome_console::codespan::Severity;
use rome_diagnostics::{file::FileId, v2::category, Diagnostic};
use rome_diagnostics::{file::FileId, v2::category, Diagnostic, Severity};
use rome_rowan::{
raw_language::{RawLanguage, RawLanguageKind, RawLanguageRoot, RawSyntaxTreeBuilder},
AstNode, TextRange, TextSize, TriviaPiece, TriviaPieceKind,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,8 @@ file.js:1:1 lint/correctness/noDebugger FIXABLE ━━━━━━━━━━
! This is an unexpected use of the debugger statement.
┌─ file.js:1:1
1 │ debugger;
│ ^^^^^^^^^
> 1 │ debugger;
│ ^^^^^^^^^
i Suggested fix: Remove debugger statement
Expand Down
14 changes: 6 additions & 8 deletions crates/rome_cli/tests/snapshots/main_check/lint_error.snap
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ check.js:1:1 lint/correctness/useBlockStatements FIXABLE ━━━━━━━
× Block statements are preferred in this position.
┌─ check.js:1:1
1 │ for(;true;);
│ ^^^^^^^^^^^^
> 1 │ for(;true;);
│ ^^^^^^^^^^^^
2 │
i Suggested fix: Wrap the statement with a `JsBlockStatement`
Expand All @@ -41,10 +40,9 @@ check.js:1:1 lint/correctness/useWhile FIXABLE ━━━━━━━━━━
× Use while loops instead of for loops.
┌─ check.js:1:1
1 │ for(;true;);
│ ^^^^^^^^^^^
> 1 │ for(;true;);
│ ^^^^^^^^^^^
2 │
i Suggested fix: Use a while loop
Expand Down
168 changes: 88 additions & 80 deletions crates/rome_cli/tests/snapshots/main_check/maximum_diagnostics.snap
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ check.js:2:1 lint/correctness/useBlockStatements FIXABLE ━━━━━━━
× Block statements are preferred in this position.
┌─ check.js:2:1
2 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
│ ^^^^^^^^^^^^
> 2 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
│ ^^^^^^^^^^^^
3 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
4 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
i Suggested fix: Wrap the statement with a `JsBlockStatement`
Expand All @@ -53,10 +53,10 @@ check.js:2:1 lint/correctness/useWhile FIXABLE ━━━━━━━━━━
× Use while loops instead of for loops.
┌─ check.js:2:1
2 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
│ ^^^^^^^^^^^
> 2 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
│ ^^^^^^^^^^^
3 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
4 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
i Suggested fix: Use a while loop
Expand All @@ -76,10 +76,10 @@ check.js:2:13 lint/correctness/useBlockStatements FIXABLE ━━━━━━
× Block statements are preferred in this position.
┌─ check.js:2:13
2 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
│ ^^^^^^^^^^^^
> 2 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
│ ^^^^^^^^^^^^
3 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
4 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
i Suggested fix: Wrap the statement with a `JsBlockStatement`
Expand All @@ -99,10 +99,10 @@ check.js:2:13 lint/correctness/useWhile FIXABLE ━━━━━━━━━━
× Use while loops instead of for loops.
┌─ check.js:2:13
2 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
│ ^^^^^^^^^^^
> 2 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
│ ^^^^^^^^^^^
3 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
4 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
i Suggested fix: Use a while loop
Expand All @@ -122,10 +122,10 @@ check.js:2:25 lint/correctness/useBlockStatements FIXABLE ━━━━━━
× Block statements are preferred in this position.
┌─ check.js:2:25
2 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
│ ^^^^^^^^^^^^
> 2 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
│ ^^^^^^^^^^^^
3 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
4 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
i Suggested fix: Wrap the statement with a `JsBlockStatement`
Expand All @@ -145,10 +145,10 @@ check.js:2:25 lint/correctness/useWhile FIXABLE ━━━━━━━━━━
× Use while loops instead of for loops.
┌─ check.js:2:25
2 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
│ ^^^^^^^^^^^
> 2 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
│ ^^^^^^^^^^^
3 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
4 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
i Suggested fix: Use a while loop
Expand All @@ -168,10 +168,10 @@ check.js:2:37 lint/correctness/useBlockStatements FIXABLE ━━━━━━
× Block statements are preferred in this position.
┌─ check.js:2:37
2 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
│ ^^^^^^^^^^^^
> 2 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
│ ^^^^^^^^^^^^
3 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
4 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
i Suggested fix: Wrap the statement with a `JsBlockStatement`
Expand All @@ -191,10 +191,10 @@ check.js:2:37 lint/correctness/useWhile FIXABLE ━━━━━━━━━━
× Use while loops instead of for loops.
┌─ check.js:2:37
2 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
│ ^^^^^^^^^^^
> 2 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
│ ^^^^^^^^^^^
3 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
4 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
i Suggested fix: Use a while loop
Expand All @@ -214,10 +214,10 @@ check.js:2:49 lint/correctness/useBlockStatements FIXABLE ━━━━━━
× Block statements are preferred in this position.
┌─ check.js:2:49
2 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
│ ^^^^^^^^^^^^
> 2 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
│ ^^^^^^^^^^^^
3 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
4 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
i Suggested fix: Wrap the statement with a `JsBlockStatement`
Expand All @@ -237,10 +237,10 @@ check.js:2:49 lint/correctness/useWhile FIXABLE ━━━━━━━━━━
× Use while loops instead of for loops.
┌─ check.js:2:49
2 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
│ ^^^^^^^^^^^
> 2 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
│ ^^^^^^^^^^^
3 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
4 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
i Suggested fix: Use a while loop
Expand All @@ -260,10 +260,10 @@ check.js:2:61 lint/correctness/useBlockStatements FIXABLE ━━━━━━
× Block statements are preferred in this position.
┌─ check.js:2:61
2 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
│ ^^^^^^^^^^^^
> 2 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
│ ^^^^^^^^^^^^
3 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
4 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
i Suggested fix: Wrap the statement with a `JsBlockStatement`
Expand All @@ -283,10 +283,10 @@ check.js:2:61 lint/correctness/useWhile FIXABLE ━━━━━━━━━━
× Use while loops instead of for loops.
┌─ check.js:2:61
2 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
│ ^^^^^^^^^^^
> 2 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
│ ^^^^^^^^^^^
3 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
4 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
i Suggested fix: Use a while loop
Expand All @@ -306,10 +306,11 @@ check.js:3:1 lint/correctness/useBlockStatements FIXABLE ━━━━━━━
× Block statements are preferred in this position.
┌─ check.js:3:1
3 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
│ ^^^^^^^^^^^^
2 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
> 3 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
│ ^^^^^^^^^^^^
4 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
5 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
i Suggested fix: Wrap the statement with a `JsBlockStatement`
Expand All @@ -330,10 +331,11 @@ check.js:3:1 lint/correctness/useWhile FIXABLE ━━━━━━━━━━
× Use while loops instead of for loops.
┌─ check.js:3:1
3 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
│ ^^^^^^^^^^^
2 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
> 3 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
│ ^^^^^^^^^^^
4 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
5 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
i Suggested fix: Use a while loop
Expand All @@ -354,10 +356,11 @@ check.js:3:13 lint/correctness/useBlockStatements FIXABLE ━━━━━━
× Block statements are preferred in this position.
┌─ check.js:3:13
3 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
│ ^^^^^^^^^^^^
2 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
> 3 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
│ ^^^^^^^^^^^^
4 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
5 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
i Suggested fix: Wrap the statement with a `JsBlockStatement`
Expand All @@ -378,10 +381,11 @@ check.js:3:13 lint/correctness/useWhile FIXABLE ━━━━━━━━━━
× Use while loops instead of for loops.
┌─ check.js:3:13
3 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
│ ^^^^^^^^^^^
2 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
> 3 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
│ ^^^^^^^^^^^
4 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
5 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
i Suggested fix: Use a while loop
Expand All @@ -402,10 +406,11 @@ check.js:3:25 lint/correctness/useBlockStatements FIXABLE ━━━━━━
× Block statements are preferred in this position.
┌─ check.js:3:25
3 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
│ ^^^^^^^^^^^^
2 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
> 3 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
│ ^^^^^^^^^^^^
4 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
5 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
i Suggested fix: Wrap the statement with a `JsBlockStatement`
Expand All @@ -426,10 +431,11 @@ check.js:3:25 lint/correctness/useWhile FIXABLE ━━━━━━━━━━
× Use while loops instead of for loops.
┌─ check.js:3:25
3 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
│ ^^^^^^^^^^^
2 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
> 3 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
│ ^^^^^^^^^^^
4 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
5 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
i Suggested fix: Use a while loop
Expand All @@ -450,10 +456,11 @@ check.js:3:37 lint/correctness/useBlockStatements FIXABLE ━━━━━━
× Block statements are preferred in this position.
┌─ check.js:3:37
3 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
│ ^^^^^^^^^^^^
2 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
> 3 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
│ ^^^^^^^^^^^^
4 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
5 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
i Suggested fix: Wrap the statement with a `JsBlockStatement`
Expand All @@ -474,10 +481,11 @@ check.js:3:37 lint/correctness/useWhile FIXABLE ━━━━━━━━━━
× Use while loops instead of for loops.
┌─ check.js:3:37
3 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
│ ^^^^^^^^^^^
2 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
> 3 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
│ ^^^^^^^^^^^
4 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
5 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);
i Suggested fix: Use a while loop
Expand Down
7 changes: 3 additions & 4 deletions crates/rome_cli/tests/snapshots/main_check/parse_error.snap
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@ check.js:2:1 parse ━━━━━━━━━━━━━━━━━━━━
× the file ends here
┌─ check.js:2:1
2 │
│ ^
1 │ if
> 2 │
```
Expand Down
Loading

0 comments on commit 34530e7

Please sign in to comment.