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): fix noShoutyConstants with empty string (#3868)
Browse files Browse the repository at this point in the history
Closes #3867
  • Loading branch information
rosslh authored Nov 28, 2022
1 parent 77261b3 commit 20e2ed0
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,12 @@ fn is_id_and_string_literal_inner_text_equal(
.as_js_string_literal_expression()?;
let literal_text = literal.inner_string_text().ok()?;

if id_text.len() != usize::from(literal_text.len()) {
return None;
}

for (from_id, from_literal) in id_text.chars().zip(literal_text.chars()) {
if from_id != from_literal {
return None;
}
if from_id.is_lowercase() || from_literal.is_lowercase() {
if from_id != from_literal || from_id.is_lowercase() {
return None;
}
}
Expand Down
17 changes: 16 additions & 1 deletion crates/rome_js_analyze/tests/specs/style/noShoutyConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,19 @@ export const d = {
const D ="D";
export const e = {
D
};
};

const Empty = "";
export const E = Empty;

const NotMatching = "DoesNotMatch";
export const F = NotMatching;

const matchingLowercase = "matchingLowercase";
export const G = matchingLowercase;

const AL = "ALPHA";
export const H = AL;

const ALPHA = "AL";
export const I = ALPHA;
18 changes: 18 additions & 0 deletions crates/rome_js_analyze/tests/specs/style/noShoutyConstants.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,22 @@ const D ="D";
export const e = {
D
};

const Empty = "";
export const E = Empty;

const NotMatching = "DoesNotMatch";
export const F = NotMatching;

const matchingLowercase = "matchingLowercase";
export const G = matchingLowercase;

const AL = "ALPHA";
export const H = AL;

const ALPHA = "AL";
export const I = ALPHA;

```

# Diagnostics
Expand Down Expand Up @@ -173,6 +189,7 @@ noShoutyConstants.js:26:7 lint/style/noShoutyConstants FIXABLE ━━━━━
> 28 │ D
│ ^
29 │ };
30 │
i You should avoid declaring constants with a string that's the same
value as the variable name. It introduces a level of unnecessary
Expand All @@ -189,6 +206,7 @@ noShoutyConstants.js:26:7 lint/style/noShoutyConstants FIXABLE ━━━━━
26 │ + →
27 │ + → D:"D"
29 28 │ };
30 29 │
```
Expand Down

0 comments on commit 20e2ed0

Please sign in to comment.