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_analyzer): fix false positive #3261 (#3262)
Browse files Browse the repository at this point in the history
* fix(rome_js_analyzer): #3261

* chore: better refactor
  • Loading branch information
ematipico authored Sep 23, 2022
1 parent d0303d8 commit 35eba83
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use rome_js_syntax::{
JsFormalParameter, JsFunctionDeclaration, JsFunctionExportDefaultDeclaration,
JsGetterClassMember, JsIdentifierBinding, JsLiteralMemberName, JsMethodClassMember,
JsPrivateClassMemberName, JsPropertyClassMember, JsSetterClassMember, JsSyntaxKind,
JsVariableDeclaration, JsVariableDeclarator, JsVariableDeclaratorList,
JsVariableDeclaration, JsVariableDeclarator, JsVariableDeclaratorList, JsxReferenceIdentifier,
};
use rome_rowan::{declare_node_union, AstNode, BatchMutationExt};
use std::{borrow::Cow, iter::once};
Expand Down Expand Up @@ -121,10 +121,18 @@ impl Rule for UseCamelCase {

if is_variable || is_parameter || is_function || is_exported_function {
let name = binding.name_token().ok()?;
check_is_camel(name.text_trimmed())
} else {
None
let is_camel_case = check_is_camel(name.text_trimmed());
if is_camel_case.is_some() {
let is_jsx_component = model.all_reads(binding).any(|reference| {
JsxReferenceIdentifier::can_cast(reference.node().kind())
});
if !is_jsx_component {
return is_camel_case;
}
}
}

None
}
_ => None,
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// valid
function Component() {}
<Component>foo</Component>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
source: crates/rome_js_analyze/tests/spec_tests.rs
expression: useCamelCase.jsx
---
# Input
```js
// valid
function Component() {}
<Component>foo</Component>
```


0 comments on commit 35eba83

Please sign in to comment.