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

fix(rome_js_analyze): fix noShoutyConstants with empty string #3868

Merged
merged 6 commits into from
Nov 28, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()) {
MichaReiser marked this conversation as resolved.
Show resolved Hide resolved
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