This repository has been archived by the owner on Aug 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 660
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rome_js_analyze): add module and classes support for noRedundant…
…UseStrict (#3955) Co-authored-by: Micha Reiser <[email protected]>
- Loading branch information
1 parent
287fcf9
commit 63409a8
Showing
17 changed files
with
680 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
crates/rome_js_analyze/tests/specs/nursery/noRedundantUseStrict/invalid.cjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
"use strict"; | ||
"use strict"; | ||
|
||
function test() { | ||
"use strict"; | ||
function inner_a() { | ||
"use strict"; // redundant directive | ||
} | ||
function inner_b() { | ||
function inner_inner() { | ||
"use strict"; // additional redundant directive | ||
} | ||
} | ||
} |
149 changes: 149 additions & 0 deletions
149
crates/rome_js_analyze/tests/specs/nursery/noRedundantUseStrict/invalid.cjs.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
--- | ||
source: crates/rome_js_analyze/tests/spec_tests.rs | ||
assertion_line: 86 | ||
expression: invalid.cjs | ||
--- | ||
# Input | ||
```js | ||
"use strict"; | ||
"use strict"; | ||
|
||
function test() { | ||
"use strict"; | ||
function inner_a() { | ||
"use strict"; // redundant directive | ||
} | ||
function inner_b() { | ||
function inner_inner() { | ||
"use strict"; // additional redundant directive | ||
} | ||
} | ||
} | ||
|
||
``` | ||
|
||
# Diagnostics | ||
``` | ||
invalid.cjs:2:1 lint/nursery/noRedundantUseStrict FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ | ||
! Redundant use strict directive. | ||
1 │ "use strict"; | ||
> 2 │ "use strict"; | ||
│ ^^^^^^^^^^^^^ | ||
3 │ | ||
4 │ function test() { | ||
i This outer use strict directive already enables strict mode. | ||
> 1 │ "use strict"; | ||
│ ^^^^^^^^^^^^^ | ||
2 │ "use strict"; | ||
3 │ | ||
i Safe fix: Remove the redundant "use strict" directive | ||
1 1 │ "use strict"; | ||
2 │ - "use·strict"; | ||
3 2 │ | ||
4 3 │ function test() { | ||
``` | ||
|
||
``` | ||
invalid.cjs:5:2 lint/nursery/noRedundantUseStrict FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ | ||
! Redundant use strict directive. | ||
4 │ function test() { | ||
> 5 │ "use strict"; | ||
│ ^^^^^^^^^^^^^ | ||
6 │ function inner_a() { | ||
7 │ "use strict"; // redundant directive | ||
i This outer use strict directive already enables strict mode. | ||
> 1 │ "use strict"; | ||
│ ^^^^^^^^^^^^^ | ||
2 │ "use strict"; | ||
3 │ | ||
i Safe fix: Remove the redundant "use strict" directive | ||
3 3 │ | ||
4 4 │ function test() { | ||
5 │ - → "use·strict"; | ||
6 │ - → function·inner_a()·{ | ||
5 │ + → function·inner_a()·{ | ||
7 6 │ "use strict"; // redundant directive | ||
8 7 │ } | ||
``` | ||
|
||
``` | ||
invalid.cjs:7:3 lint/nursery/noRedundantUseStrict FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ | ||
! Redundant use strict directive. | ||
5 │ "use strict"; | ||
6 │ function inner_a() { | ||
> 7 │ "use strict"; // redundant directive | ||
│ ^^^^^^^^^^^^^ | ||
8 │ } | ||
9 │ function inner_b() { | ||
i This outer use strict directive already enables strict mode. | ||
> 1 │ "use strict"; | ||
│ ^^^^^^^^^^^^^ | ||
2 │ "use strict"; | ||
3 │ | ||
i Safe fix: Remove the redundant "use strict" directive | ||
5 5 │ "use strict"; | ||
6 6 │ function inner_a() { | ||
7 │ - → → "use·strict";·//·redundant·directive | ||
8 │ - → } | ||
7 │ + → } | ||
9 8 │ function inner_b() { | ||
10 9 │ function inner_inner() { | ||
``` | ||
|
||
``` | ||
invalid.cjs:11:4 lint/nursery/noRedundantUseStrict FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ | ||
! Redundant use strict directive. | ||
9 │ function inner_b() { | ||
10 │ function inner_inner() { | ||
> 11 │ "use strict"; // additional redundant directive | ||
│ ^^^^^^^^^^^^^ | ||
12 │ } | ||
13 │ } | ||
i This outer use strict directive already enables strict mode. | ||
> 1 │ "use strict"; | ||
│ ^^^^^^^^^^^^^ | ||
2 │ "use strict"; | ||
3 │ | ||
i Safe fix: Remove the redundant "use strict" directive | ||
9 9 │ function inner_b() { | ||
10 10 │ function inner_inner() { | ||
11 │ - → → → "use·strict";·//·additional·redundant·directive | ||
12 │ - → → } | ||
11 │ + → → } | ||
13 12 │ } | ||
14 13 │ } | ||
``` | ||
|
||
|
24 changes: 15 additions & 9 deletions
24
crates/rome_js_analyze/tests/specs/nursery/noRedundantUseStrict/invalid.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,20 @@ | ||
"use strict"; | ||
// js module | ||
"use strict"; | ||
|
||
function test() { | ||
function foo() { | ||
"use strict"; | ||
function inner_a() { | ||
"use strict"; // redundant directive | ||
} | ||
function inner_b() { | ||
function inner_inner() { | ||
"use strict"; // additional redundant directive | ||
} | ||
} | ||
|
||
class C1 { | ||
// All code here is evaluated in strict mode | ||
test() { | ||
"use strict"; | ||
} | ||
} | ||
|
||
const C2 = class { | ||
// All code here is evaluated in strict mode | ||
test() { | ||
"use strict"; | ||
} | ||
}; |
Oops, something went wrong.