Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into no-dupe-keys
Browse files Browse the repository at this point in the history
* upstream/main: (45 commits)
  website(docs): set `color-scheme` on the root element (rome#3721)
  feat(rome_analyze): add a warning for unused suppression comments (rome#3718)
  feat(rome_js_analyze): Implement prefer-numeric-literals lint (rome#3558)
  feat(rome_js_formatter): jestEach template literals rome#3308 (rome#3582)
  doc(website): Add context about Romes philosophy (rome#3714)
  fix(rome_js_formatter): Single-line comment below a JSX prop triggers… (rome#3641)
  test(rome_js_formatter): update prettier tests (rome#3684)
  fix(rome_js_parser): improve await handling in non-async context (rome#3573)
  fix(rome_js_parser): improve yield parsing in non generator function (rome#3622)
  More playground polish
  Fix backgrounds
  Fix height
  Align docs.rome.tools with rome.tools
  Reenable compression
  Add missing width
  website(docs): More playground IDE features (rome#3711)
  fix(rome_js_formatter): new expression attribute (rome#3686)
  docs(website): added checkbox to toggle linter in playground (rome#3699)
  website(docs): More website tweaks (rome#3707)
  website(docs): Add default layout property (rome#3705)
  ...
  • Loading branch information
jeysal committed Nov 14, 2022
2 parents 09adebb + 501dbe9 commit 1b0f6fa
Show file tree
Hide file tree
Showing 765 changed files with 29,785 additions and 12,164 deletions.
94 changes: 0 additions & 94 deletions .github/workflows/deploy_playground.yml

This file was deleted.

50 changes: 0 additions & 50 deletions .github/workflows/deploy_playground_on_main.yml

This file was deleted.

8 changes: 4 additions & 4 deletions .github/workflows/pull_request_js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ jobs:
with:
version: 7
- name: Build WASM module for the web
run: wasm-pack build --out-dir ../../npm/wasm-web --target web --release --scope rometools crates/rome_wasm
run: wasm-pack build --out-dir ../../npm/wasm-web --target web --scope rometools crates/rome_wasm
- name: Install libraries
working-directory: website/playground
working-directory: website
run: pnpm i
- name: Build JS
working-directory: website/playground
working-directory: website
run: pnpm build:js
- name: Type check
working-directory: website/playground
working-directory: website
run: pnpm tsc
1 change: 1 addition & 0 deletions Cargo.lock

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

59 changes: 46 additions & 13 deletions crates/rome_analyze/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,27 @@ where
}
}

for suppression in line_suppressions {
if suppression.did_suppress_signal {
continue;
}

let signal = DiagnosticSignal::new(|| {
let diag = SuppressionDiagnostic::new(
ctx.file_id,
category!("suppressions/unused"),
suppression.comment_span,
"Suppression comment is not being used",
);

AnalyzerDiagnostic::from_error(diag.into())
});

if let ControlFlow::Break(br) = (emit_signal)(&signal) {
return Some(br);
}
}

None
}
}
Expand Down Expand Up @@ -203,6 +224,8 @@ struct PhaseRunner<'analyzer, 'phase, L: Language, Matcher, Break> {
struct LineSuppression {
/// Line index this comment is suppressing lint rules for
line_index: usize,
/// Range of source text covered by the suppression comment
comment_span: TextRange,
/// Range of source text this comment is suppressing lint rules for
text_range: TextRange,
/// Set to true if this comment has set the `suppress_all` flag to true
Expand All @@ -211,6 +234,9 @@ struct LineSuppression {
/// List of all the rules this comment has started suppressing (must be
/// removed from the suppressed set on expiration)
suppressed_rules: Vec<RuleFilter<'static>>,
/// Set to `true` when a signal matching this suppression was emitted and
/// suppressed
did_suppress_signal: bool,
}

impl<'a, 'phase, L, Matcher, Break> PhaseRunner<'a, 'phase, L, Matcher, Break>
Expand Down Expand Up @@ -344,14 +370,14 @@ where
// if it matchs the current line index, otherwise perform a binary
// search over all the previously seen suppressions to find one
// with a matching range
let suppression = self
.line_suppressions
.last()
.filter(|suppression| {
suppression.line_index == *self.line_index
&& suppression.text_range.start() <= start
})
.or_else(|| {
let suppression = self.line_suppressions.last_mut().filter(|suppression| {
suppression.line_index == *self.line_index
&& suppression.text_range.start() <= start
});

let suppression = match suppression {
Some(suppression) => Some(suppression),
None => {
let index = self.line_suppressions.binary_search_by(|suppression| {
if suppression.text_range.end() < entry.text_range.start() {
Ordering::Less
Expand All @@ -362,21 +388,26 @@ where
}
});

Some(&self.line_suppressions[index.ok()?])
});
index.ok().map(|index| &mut self.line_suppressions[index])
}
};

let is_suppressed = suppression.map_or(false, |suppression| {
let suppression = suppression.filter(|suppression| {
if suppression.suppress_all {
return true;
}

suppression
.suppressed_rules
.iter()
.any(|filter| *filter == entry.rule)
});

// Emit the signal if the rule that created it is not currently being suppressed
if !is_suppressed {
// If the signal is being suppressed mark the line suppression as
// hit, otherwise emit the signal
if let Some(suppression) = suppression {
suppression.did_suppress_signal = true;
} else {
(self.emit_signal)(&*entry.signal)?;
}

Expand Down Expand Up @@ -479,9 +510,11 @@ where

let entry = LineSuppression {
line_index,
comment_span: range,
text_range: range,
suppress_all,
suppressed_rules: suppressions,
did_suppress_signal: false,
};

self.line_suppressions.push(entry);
Expand Down
16 changes: 15 additions & 1 deletion crates/rome_analyze/src/matcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ mod tests {
let mut builder = RawSyntaxTreeBuilder::new();

builder.start_node(RawLanguageKind::ROOT);
builder.start_node(RawLanguageKind::EXPRESSION_LIST);
builder.start_node(RawLanguageKind::SEPARATED_EXPRESSION_LIST);

builder.start_node(RawLanguageKind::LITERAL_EXPRESSION);
builder.token_with_trivia(
Expand Down Expand Up @@ -289,6 +289,16 @@ mod tests {
&[TriviaPiece::new(TriviaPieceKind::Newline, 1)],
);

builder.token_with_trivia(
RawLanguageKind::SEMICOLON_TOKEN,
"//group/rule\n;\n",
&[
TriviaPiece::new(TriviaPieceKind::SingleLineComment, 12),
TriviaPiece::new(TriviaPieceKind::Newline, 1),
],
&[TriviaPiece::new(TriviaPieceKind::Newline, 1)],
);

builder.finish_node();
builder.finish_node();

Expand Down Expand Up @@ -356,6 +366,10 @@ mod tests {
category!("args/fileNotFound"),
TextRange::new(TextSize::from(97), TextSize::from(108))
),
(
category!("suppressions/unused"),
TextRange::new(TextSize::from(110), TextSize::from(122))
),
]
);
}
Expand Down
2 changes: 2 additions & 0 deletions crates/rome_diagnostics_categories/src/categories.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ define_dategories! {
"lint/nursery/useCamelCase": "https://docs.rome.tools/lint/rules/useCamelCase",
"lint/nursery/useExhaustiveDependencies": "https://docs.rome.tools/lint/rules/useExhaustiveDependencies",
"lint/nursery/useFlatMap": "https://docs.rome.tools/lint/rules/useFlatMap",
"lint/nursery/useNumericLiterals": "https://docs.rome.tools/lint/rules/useNumericLiterals",
"lint/nursery/useValidForDirection": "https://docs.rome.tools/lint/rules/useValidForDirection",

;
Expand All @@ -100,6 +101,7 @@ define_dategories! {

"suppressions/unknownGroup",
"suppressions/unknownRule",
"suppressions/unused",
// Used in tests and examples
"args/fileNotFound",
"flags/invalid",
Expand Down
Loading

0 comments on commit 1b0f6fa

Please sign in to comment.