-
Notifications
You must be signed in to change notification settings - Fork 653
feat(rome_js_analyze): better JS suppressions #3855
Conversation
✅ Deploy Preview for docs-rometools canceled.
|
7a7f060
to
73993c4
Compare
Parser conformance results on ubuntu-latestjs/262
jsx/babel
symbols/microsoft
ts/babel
ts/microsoft
|
Comparing feat(rome_js_analyze): better JS suppressions Snapshot #16 to median since last deploy of rome.tools.
1 page tested
|
Chrome Desktop | iPhone, 4G LTE | Motorola Moto G Power, 3G connection |
---|---|---|
Most significant changes
27 other significant changes: JS Parse & Compile on Chrome Desktop, Total Blocking Time on Chrome Desktop, Largest Contentful Paint on Motorola Moto G Power, 3G connection, First Contentful Paint on Motorola Moto G Power, 3G connection, Time to Interactive on Motorola Moto G Power, 3G connection, Total Page Size in Bytes on Chrome Desktop, Total Page Size in Bytes on iPhone, 4G LTE, Total Page Size in Bytes on Motorola Moto G Power, 3G connection, Total CSS Size in Bytes on Chrome Desktop, Total CSS Size in Bytes on iPhone, 4G LTE, Total CSS Size in Bytes on Motorola Moto G Power, 3G connection, Time to Interactive on Chrome Desktop, Number of Requests on Motorola Moto G Power, 3G connection, Number of Requests on Chrome Desktop, Number of Requests on iPhone, 4G LTE, Largest Contentful Paint on Chrome Desktop, First Contentful Paint on Chrome Desktop, Speed Index on Motorola Moto G Power, 3G connection, Time to Interactive on iPhone, 4G LTE, Largest Contentful Paint on iPhone, 4G LTE, First Contentful Paint on iPhone, 4G LTE, Speed Index on Chrome Desktop, Total HTML Size in Bytes on Chrome Desktop, Total HTML Size in Bytes on iPhone, 4G LTE, Total HTML Size in Bytes on Motorola Moto G Power, 3G connection, Lighthouse Performance Score on Motorola Moto G Power, 3G connection, Lighthouse Performance Score on Chrome Desktop
Calibre: Site dashboard | View this PR | Edit settings | View documentation
6c95f2b
to
12224ec
Compare
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.
Does this support inserting suppressions in multiline templates, eg.
const foo = `
text
${a == b}
`;
If so can we add a test case for this ?
@@ -91,7 +106,12 @@ fn write_analysis_to_snapshot( | |||
rome_js_analyze::analyze(FileId::zero(), &root, filter, &options, |event| { | |||
if let Some(mut diag) = event.diagnostic() { | |||
for action in event.actions() { | |||
if !action.is_suppression() { | |||
if check_action_type.is_suppression() { |
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: this can be collapsed to a single if
with the condition !action.is_suppression() || check_action_type.is_suppression()
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.
Doing so will add the suggested actions to the snapshot of the suppressions, which is what I wanted to avoid
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.
Sorry I messed up factorizing the logic expression, I think it's actually check_action_type.is_suppression() == action.is_suppression()
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.
Same result 😅
8e62bc2
to
e251685
Compare
/// use rome_rowan::raw_language::{RawLanguageKind, RawSyntaxTreeBuilder}; | ||
/// use rome_rowan::{chain_pieces, TriviaPiece, TriviaPieceKind}; | ||
/// let mut builder = RawSyntaxTreeBuilder::new(); | ||
/// | ||
/// let mut node = RawSyntaxTreeBuilder::wrap_with_node(RawLanguageKind::ROOT, |builder| { | ||
/// builder.token_with_trivia( | ||
/// RawLanguageKind::LET_TOKEN, | ||
/// "\n\t let \t\t", | ||
/// &[TriviaPiece::whitespace(3)], | ||
/// &[TriviaPiece::whitespace(3)], | ||
/// ); | ||
/// builder.token(RawLanguageKind::STRING_TOKEN, "a"); | ||
/// builder.token_with_trivia( | ||
/// RawLanguageKind::SEMICOLON_TOKEN, | ||
/// "; \t\t", | ||
/// &[TriviaPiece::whitespace(1)], | ||
/// &[TriviaPiece::whitespace(1)], | ||
/// ); | ||
/// }); | ||
/// let mut tokens = node.tokens(); | ||
/// let first_token = tokens.next().unwrap(); | ||
/// let second_token = tokens.next().unwrap(); | ||
/// let third_token = tokens.next().unwrap(); | ||
/// | ||
/// let leading_trivia = chain_pieces( | ||
/// first_token.leading_trivia().pieces(), | ||
/// third_token.leading_trivia().pieces() | ||
/// ); | ||
/// | ||
/// let new_first_token = first_token.with_leading_trivia_pieces(leading_trivia); | ||
/// | ||
/// let new_token = format!("{:?}", new_first_token); | ||
/// assert_eq!(new_token, "LET_TOKEN@0..10 \"let\" [Whitespace(\"\\n\\t \"), Whitespace(\";\")] [Whitespace(\" \\t\\t\")]") |
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.
Using unwrap
in doctests is discouraged because readers may end up copying the code including the unwrap
calls. That's why it is recommended to wrap the test in a main
function and hide these lines by prefixing them with #
.
/// use rome_rowan::raw_language::{RawLanguageKind, RawSyntaxTreeBuilder}; | |
/// use rome_rowan::{chain_pieces, TriviaPiece, TriviaPieceKind}; | |
/// let mut builder = RawSyntaxTreeBuilder::new(); | |
/// | |
/// let mut node = RawSyntaxTreeBuilder::wrap_with_node(RawLanguageKind::ROOT, |builder| { | |
/// builder.token_with_trivia( | |
/// RawLanguageKind::LET_TOKEN, | |
/// "\n\t let \t\t", | |
/// &[TriviaPiece::whitespace(3)], | |
/// &[TriviaPiece::whitespace(3)], | |
/// ); | |
/// builder.token(RawLanguageKind::STRING_TOKEN, "a"); | |
/// builder.token_with_trivia( | |
/// RawLanguageKind::SEMICOLON_TOKEN, | |
/// "; \t\t", | |
/// &[TriviaPiece::whitespace(1)], | |
/// &[TriviaPiece::whitespace(1)], | |
/// ); | |
/// }); | |
/// let mut tokens = node.tokens(); | |
/// let first_token = tokens.next().unwrap(); | |
/// let second_token = tokens.next().unwrap(); | |
/// let third_token = tokens.next().unwrap(); | |
/// | |
/// let leading_trivia = chain_pieces( | |
/// first_token.leading_trivia().pieces(), | |
/// third_token.leading_trivia().pieces() | |
/// ); | |
/// | |
/// let new_first_token = first_token.with_leading_trivia_pieces(leading_trivia); | |
/// | |
/// let new_token = format!("{:?}", new_first_token); | |
/// assert_eq!(new_token, "LET_TOKEN@0..10 \"let\" [Whitespace(\"\\n\\t \"), Whitespace(\";\")] [Whitespace(\" \\t\\t\")]") | |
/// # use rome_rowan::raw_language::{RawLanguageKind, RawSyntaxTreeBuilder}; | |
/// # use rome_rowan::{chain_pieces, TriviaPiece, TriviaPieceKind, SyntaxResult}; | |
/// | |
/// # fn main() -> SyntaxResult<()> { | |
/// let mut builder = RawSyntaxTreeBuilder::new(); | |
/// | |
/// let mut node = RawSyntaxTreeBuilder::wrap_with_node(RawLanguageKind::ROOT, |builder| { | |
/// builder.token_with_trivia( | |
/// RawLanguageKind::LET_TOKEN, | |
/// "\n\t let \t\t", | |
/// &[TriviaPiece::whitespace(3)], | |
/// &[TriviaPiece::whitespace(3)], | |
/// ); | |
/// builder.token(RawLanguageKind::STRING_TOKEN, "a"); | |
/// builder.token_with_trivia( | |
/// RawLanguageKind::SEMICOLON_TOKEN, | |
/// "; \t\t", | |
/// &[TriviaPiece::whitespace(1)], | |
/// &[TriviaPiece::whitespace(1)], | |
/// ); | |
/// }); | |
/// let mut tokens = node.tokens(); | |
/// let first_token = tokens.next()?; | |
/// let second_token = tokens.next()?; | |
/// let third_token = tokens.next()?; | |
/// | |
/// let leading_trivia = chain_pieces( | |
/// first_token.leading_trivia().pieces(), | |
/// third_token.leading_trivia().pieces() | |
/// ); | |
/// | |
/// let new_first_token = first_token.with_leading_trivia_pieces(leading_trivia); | |
/// | |
/// let new_token = format!("{:?}", new_first_token); | |
/// assert_eq!(new_token, "LET_TOKEN@0..10 \"let\" [Whitespace(\"\\n\\t \"), Whitespace(\";\")] [Whitespace(\" \\t\\t\")]") | |
/// # Ok(()) | |
/// # } |
&mut self, | ||
after_element: &AnyJsxChild, | ||
new_element: &AnyJsxChild, | ||
new_element: &[AnyJsxChild], |
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: new_elements
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.
new_element: &[AnyJsxChild], | |
new_elements: &[AnyJsxChild], |
crates/rome_js_analyze/tests/suppression/correctness/noUndeclaredVariables.ts.snap
Outdated
Show resolved
Hide resolved
crates/rome_js_analyze/tests/suppression/correctness/noArrayIndexKey.jsx.snap
Show resolved
Hide resolved
crates/rome_js_analyze/tests/suppression/correctness/noArrayIndexKey.jsx.snap
Show resolved
Hide resolved
(TriviaPieceKind::Newline, "\n"), | ||
]) | ||
}; | ||
mutation.replace_token_transfer_trivia(first_token_with_newline, new_token); |
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.
The replace_token_transfer_trivia
implementation looks incorrect. Isn't it applying the trivia of the prev_token
(leading) and next_token
(trailing) twice
let leading_trivia: Vec<_> = prev_token
.leading_trivia()
.pieces()
.chain(prev_token.leading_trivia().pieces())
.map(|piece| TriviaPiece::new(piece.kind(), TextSize::of(piece.text())))
.collect();
let trailing_trivia: Vec<_> = next_token
.trailing_trivia()
.pieces()
.chain(next_token.trailing_trivia().pieces())
.map(|piece| TriviaPiece::new(piece.kind(), TextSize::of(piece.text())))
.collect();
Nit: replace_token_transfer_trivia can now use chain_trivia_pieces
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 done inside replace_token_transfer_trivia
function. I added some other test cases to show that.
Requesting changes because:
|
0b46100
to
82c6399
Compare
crates/rome_js_analyze/tests/suppression/a11y/useKeyWithClickEvents.jsx.snap
Show resolved
Hide resolved
e01b0fa
to
0f03d64
Compare
Summary
Closes #3445
This PR refines the heuristic of how a suppression comment should be applied inside a mutation action. I tried to comment on the heuristic.
I also took the opportunity to move the
chain_pieces
from the formatter to therome_rowan
crate, and added some doc tests (which is quite lengthy, but it should be enough I hope).Test Plan
I updated the test specs, to consider a new folder called
suppression
, which works the same as the current tests, but they extract only the suppression actions.I added some test cases, especially inside JSX, because I noticed they are the ones that caused more issues.
Plus, I run locally the suppression actions against
specs/
folder, printed the suppression actions, and checked locally that no strange code was emitted. This check was done manually and locally, I wasn't planning to update ALL the diagnostics.If you think there is some edge case that requires some attention, please paste some snippets and I will try to add them to the test suite.