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

Commit

Permalink
fix(rome_js_analyze): noRedundantUseStrict check only 'use strict' di…
Browse files Browse the repository at this point in the history
…rective (#4591)

* fix: noRedundantUseStrict check only 'use strict' directive

* docs: update changelog

* docs: update
  • Loading branch information
nissy-dev authored Jun 18, 2023
1 parent 292e1f2 commit 201172c
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ parameter decorators:
}
```

- [noRedundantUseStrict](https://docs.rome.tools/lint/rules/noredundantusestrict/) check only `'use strict'` directive to resolve false positive diagnostics.

React introduce new directives, "use client" and "use server".
The rule raises false positive errors about these directives.

### Parser

### VSCode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ impl Rule for NoRedundantUseStrict {

fn run(ctx: &RuleContext<Self>) -> Self::Signals {
let node = ctx.query();
if node.inner_string_text().ok()? != "use strict" {
return None;
}
let mut outer_most: Option<AnyJsStrictModeNode> = None;
let root = ctx.root();
match root {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use client'

import { useState } from "react"

export default function Counter() {
const [count, setCount] = useState(0)

return (
<div>
<p>You clicked {count} times</p>
<button type="button" onClick={() => setCount(count + 1)}>Click me</button>
</div>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
source: crates/rome_js_analyze/tests/spec_tests.rs
expression: validReactDirectives.tsx
---
# Input
```js
'use client'

import { useState } from "react"

export default function Counter() {
const [count, setCount] = useState(0)

return (
<div>
<p>You clicked {count} times</p>
<button type="button" onClick={() => setCount(count + 1)}>Click me</button>
</div>
)
}

```


0 comments on commit 201172c

Please sign in to comment.