Skip to content

Commit

Permalink
fix: multiple diagnostic
Browse files Browse the repository at this point in the history
  • Loading branch information
t-shiratori committed May 6, 2024
1 parent f536251 commit 6f752ed
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,13 @@ declare_rule! {
impl Rule for NoInvalidPositionAtImportRule {
type Query = Ast<CssRuleList>;
type State = TextRange;
type Signals = Option<Self::State>;
type Signals = Vec<Self::State>;
type Options = ();

fn run(ctx: &RuleContext<Self>) -> Option<Self::State> {
fn run(ctx: &RuleContext<Self>) -> Vec<Self::State> {
let node = ctx.query();
let mut is_invalid_position = false;
let mut invalid_import_list = Vec::new();

for rule in node {
let any_css_at_rule = match rule {
Expand All @@ -60,7 +61,7 @@ impl Rule for NoInvalidPositionAtImportRule {
let import_rule = any_css_at_rule.as_css_import_at_rule();
if let Some(import_rule) = import_rule {
if is_invalid_position {
return Some(import_rule.range());
invalid_import_list.push(import_rule.range());
}
} else {
is_invalid_position = true;
Expand All @@ -69,8 +70,7 @@ impl Rule for NoInvalidPositionAtImportRule {
is_invalid_position = true;
}
}

None
invalid_import_list
}

fn diagnostic(_: &RuleContext<Self>, state: &Self::State) -> Option<RuleDiagnostic> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
a {}
@import 'foo.css';
@import 'bar.css';
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ expression: invalid.css
```css
a {}
@import 'foo.css';
@import 'bar.css';
```

Expand All @@ -18,7 +19,26 @@ invalid.css:2:2 lint/nursery/noInvalidPositionAtImportRule ━━━━━━━
1 │ a {}
> 2 │ @import 'foo.css';
│ ^^^^^^^^^^^^^^^^^
3 │
3 │ @import 'bar.css';
4 │
i Any @import rules must precede all other valid at-rules and style rules in a stylesheet (ignoring @charset and @layer), or else the @import rule is invalid.
i Consider moving import position.
```

```
invalid.css:3:2 lint/nursery/noInvalidPositionAtImportRule ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
! This @import is in the wrong position.
1 │ a {}
2 │ @import 'foo.css';
> 3 │ @import 'bar.css';
│ ^^^^^^^^^^^^^^^^^
4 │
i Any @import rules must precede all other valid at-rules and style rules in a stylesheet (ignoring @charset and @layer), or else the @import rule is invalid.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
@import 'foo.css';
a {}
@import 'bar.css';
@import 'bar1.css';
@import 'bar2.css';
a {}
@import 'bar3.css';
@import 'bar4.css';
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ expression: invalidBetweenImport.css
```css
@import 'foo.css';
a {}
@import 'bar.css';
@import 'bar1.css';
@import 'bar2.css';
a {}
@import 'bar3.css';
@import 'bar4.css';
```

Expand All @@ -18,9 +22,66 @@ invalidBetweenImport.css:3:2 lint/nursery/noInvalidPositionAtImportRule ━━
1 │ @import 'foo.css';
2 │ a {}
> 3 │ @import 'bar.css';
│ ^^^^^^^^^^^^^^^^^
4 │
> 3 │ @import 'bar1.css';
│ ^^^^^^^^^^^^^^^^^^
4 │ @import 'bar2.css';
5 │ a {}
i Any @import rules must precede all other valid at-rules and style rules in a stylesheet (ignoring @charset and @layer), or else the @import rule is invalid.
i Consider moving import position.
```

```
invalidBetweenImport.css:4:2 lint/nursery/noInvalidPositionAtImportRule ━━━━━━━━━━━━━━━━━━━━━━━━━━━━
! This @import is in the wrong position.
2 │ a {}
3 │ @import 'bar1.css';
> 4 │ @import 'bar2.css';
│ ^^^^^^^^^^^^^^^^^^
5 │ a {}
6 │ @import 'bar3.css';
i Any @import rules must precede all other valid at-rules and style rules in a stylesheet (ignoring @charset and @layer), or else the @import rule is invalid.
i Consider moving import position.
```

```
invalidBetweenImport.css:6:2 lint/nursery/noInvalidPositionAtImportRule ━━━━━━━━━━━━━━━━━━━━━━━━━━━━
! This @import is in the wrong position.
4 │ @import 'bar2.css';
5 │ a {}
> 6 │ @import 'bar3.css';
│ ^^^^^^^^^^^^^^^^^^
7 │ @import 'bar4.css';
8 │
i Any @import rules must precede all other valid at-rules and style rules in a stylesheet (ignoring @charset and @layer), or else the @import rule is invalid.
i Consider moving import position.
```

```
invalidBetweenImport.css:7:2 lint/nursery/noInvalidPositionAtImportRule ━━━━━━━━━━━━━━━━━━━━━━━━━━━━
! This @import is in the wrong position.
5 │ a {}
6 │ @import 'bar3.css';
> 7 │ @import 'bar4.css';
│ ^^^^^^^^^^^^^^^^^^
8 │
i Any @import rules must precede all other valid at-rules and style rules in a stylesheet (ignoring @charset and @layer), or else the @import rule is invalid.
Expand Down

0 comments on commit 6f752ed

Please sign in to comment.