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

Commit

Permalink
chore: PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
kaioduarte committed Jan 4, 2023
1 parent 4e1f07d commit 48a9bb4
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 16 deletions.
6 changes: 4 additions & 2 deletions crates/rome_js_analyze/src/analyzers/nursery/use_yield.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ impl AnyFunctionLike {

#[derive(Default)]
struct MissingYieldVisitor {
/// Vector to hold a function node and a boolean indicating whether the function
/// contains an `yield` expression or not.
stack: Vec<(AnyFunctionLike, bool)>,
}

Expand Down Expand Up @@ -115,7 +117,7 @@ impl Visitor for MissingYieldVisitor {
// entry of the stack and the `has_yield` flag is `false`, emit a query match
if let Some(exit_node) = AnyFunctionLike::cast_ref(node) {
if let Some((enter_node, has_yield)) = self.stack.pop() {
assert_eq!(enter_node, exit_node);
debug_assert_eq!(enter_node, exit_node);
if !has_yield {
ctx.match_query(MissingYield(enter_node));
}
Expand Down Expand Up @@ -173,7 +175,7 @@ impl Rule for UseYield {
Some(RuleDiagnostic::new(
rule_category!(),
ctx.query().range(),
markup! {"This generator function does not have "<Emphasis>"yield"</Emphasis>"."},
markup! {"This generator function doesn't contain "<Emphasis>"yield"</Emphasis>"."},
))
}
}
18 changes: 9 additions & 9 deletions crates/rome_js_analyze/tests/specs/nursery/useYield.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ function* foo() {
```
useYield.js:37:1 lint/nursery/useYield ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
! This generator function does not have yield.
! This generator function doesn't contain yield.
36 │ // Invalid
> 37 │ function* foo() {
Expand All @@ -122,7 +122,7 @@ useYield.js:37:1 lint/nursery/useYield ━━━━━━━━━━━━━
```
useYield.js:41:2 lint/nursery/useYield ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
! This generator function does not have yield.
! This generator function doesn't contain yield.
39 │ }
40 │
Expand All @@ -140,7 +140,7 @@ useYield.js:41:2 lint/nursery/useYield ━━━━━━━━━━━━━
```
useYield.js:46:2 lint/nursery/useYield ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
! This generator function does not have yield.
! This generator function doesn't contain yield.
45 │ const obj = {
> 46 │ *foo() {
Expand All @@ -157,7 +157,7 @@ useYield.js:46:2 lint/nursery/useYield ━━━━━━━━━━━━━
```
useYield.js:52:2 lint/nursery/useYield ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
! This generator function does not have yield.
! This generator function doesn't contain yield.
51 │ class A {
> 52 │ *foo() {
Expand All @@ -174,7 +174,7 @@ useYield.js:52:2 lint/nursery/useYield ━━━━━━━━━━━━━
```
useYield.js:57:1 lint/nursery/useYield ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
! This generator function does not have yield.
! This generator function doesn't contain yield.
55 │ }
56 │
Expand All @@ -194,7 +194,7 @@ useYield.js:57:1 lint/nursery/useYield ━━━━━━━━━━━━━
```
useYield.js:64:2 lint/nursery/useYield ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
! This generator function does not have yield.
! This generator function doesn't contain yield.
63 │ function* foo() {
> 64 │ function* bar() {
Expand All @@ -211,7 +211,7 @@ useYield.js:64:2 lint/nursery/useYield ━━━━━━━━━━━━━
```
useYield.js:70:1 lint/nursery/useYield ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
! This generator function does not have yield.
! This generator function doesn't contain yield.
68 │ }
69 │
Expand All @@ -232,7 +232,7 @@ useYield.js:70:1 lint/nursery/useYield ━━━━━━━━━━━━━
```
useYield.js:79:3 lint/nursery/useYield ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
! This generator function does not have yield.
! This generator function doesn't contain yield.
77 │ function* foo() {
78 │ const obj = {
Expand All @@ -250,7 +250,7 @@ useYield.js:79:3 lint/nursery/useYield ━━━━━━━━━━━━━
```
useYield.js:85:3 lint/nursery/useYield ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
! This generator function does not have yield.
! This generator function doesn't contain yield.
84 │ class A {
> 85 │ *baz() {
Expand Down
9 changes: 5 additions & 4 deletions crates/rome_service/src/configuration/linter/rules.rs

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

6 changes: 6 additions & 0 deletions website/src/pages/lint/rules/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,12 @@ a superclass
Disallow control flow statements in finally blocks.
</section>
<section class="rule">
<h3 data-toc-exclude id="noUnusedLabels">
<a href="/lint/rules/noUnusedLabels">noUnusedLabels</a>
</h3>
Disallow unused labels.
</section>
<section class="rule">
<h3 data-toc-exclude id="noUselessSwitchCase">
<a href="/lint/rules/noUselessSwitchCase">noUselessSwitchCase</a>
</h3>
Expand Down
2 changes: 1 addition & 1 deletion website/src/pages/lint/rules/useYield.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function* foo() {

<pre class="language-text"><code class="language-text">nursery/useYield.js:1:1 <a href="https://docs.rome.tools/lint/rules/useYield">lint/nursery/useYield</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

<strong><span style="color: Tomato;"> </span></strong><strong><span style="color: Tomato;">✖</span></strong> <span style="color: Tomato;">This generator function does not have </span><span style="color: Tomato;"><strong>yield</strong></span><span style="color: Tomato;">.</span>
<strong><span style="color: Tomato;"> </span></strong><strong><span style="color: Tomato;">✖</span></strong> <span style="color: Tomato;">This generator function doesn't contain </span><span style="color: Tomato;"><strong>yield</strong></span><span style="color: Tomato;">.</span>

<strong><span style="color: Tomato;"> </span></strong><strong><span style="color: Tomato;">&gt;</span></strong> <strong>1 │ </strong>function* foo() {
<strong> │ </strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong>
Expand Down

0 comments on commit 48a9bb4

Please sign in to comment.