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): #3261
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico committed Sep 21, 2022
1 parent de1392c commit 4caeb45
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 5 deletions.
6 changes: 3 additions & 3 deletions crates/rome_js_analyze/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ mod tests {
#[test]
fn quick_test() {
const SOURCE: &str = r#"
React.createElement('button', {
"type": "bar"
});
function Component() {}
const f = <Component>ff</Component>;
f()
"#;

let parsed = parse(SOURCE, FileId::zero(), SourceType::jsx());
Expand Down
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 @@ -118,8 +118,14 @@ impl Rule for UseCamelCase {
let is_exported_function = binding
.parent::<JsFunctionExportDefaultDeclaration>()
.is_some();
let is_jsx_component = model.all_reads(binding).any(|reference| {
JsxReferenceIdentifier::can_cast(reference.node().kind())
});

if is_variable || is_parameter || is_function || is_exported_function {
if is_jsx_component {
None
} else if is_variable || is_parameter || is_function || is_exported_function
{
let name = binding.name_token().ok()?;
check_is_camel(name.text_trimmed())
} else {
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 4caeb45

Please sign in to comment.