eslint-plugin-code-style 1.9.3 → 1.9.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +24 -0
- package/index.js +40 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,28 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
---
|
|
9
9
|
|
|
10
|
+
## [1.9.5] - 2026-02-03
|
|
11
|
+
|
|
12
|
+
### Fixed
|
|
13
|
+
|
|
14
|
+
- **`no-hardcoded-strings`** - Fix bug where strings inside exported components were incorrectly skipped:
|
|
15
|
+
- Previously: `export const Component = () => { const name = "ahmed" }` was not detected
|
|
16
|
+
- Now: Strings inside functions are properly detected regardless of export status
|
|
17
|
+
- Only direct constant exports are skipped: `export const MESSAGE = "value"` or `export const DATA = { key: "value" }`
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## [1.9.4] - 2026-02-03
|
|
22
|
+
|
|
23
|
+
### Enhanced
|
|
24
|
+
|
|
25
|
+
- **`no-hardcoded-strings`** - Skip UI component patterns only in JSX attributes:
|
|
26
|
+
- In JSX attributes: `<Button variant="ghost" />` is now ignored
|
|
27
|
+
- In logic: `const status = "success"` or `setValue("primary")` is still detected
|
|
28
|
+
- UI patterns: `primary`, `secondary`, `ghost`, `outline`, `link`, `muted`, `danger`, `warning`, `success`, `error`, `sm`, `md`, `lg`, `xl`, `left`, `right`, `center`, `top`, `bottom`, `hover`, `focus`, `click`, etc.
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
10
32
|
## [1.9.3] - 2026-02-03
|
|
11
33
|
|
|
12
34
|
### Enhanced
|
|
@@ -1288,6 +1310,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
1288
1310
|
|
|
1289
1311
|
---
|
|
1290
1312
|
|
|
1313
|
+
[1.9.5]: https://github.com/Mohamed-Elhawary/eslint-plugin-code-style/compare/v1.9.4...v1.9.5
|
|
1314
|
+
[1.9.4]: https://github.com/Mohamed-Elhawary/eslint-plugin-code-style/compare/v1.9.3...v1.9.4
|
|
1291
1315
|
[1.9.3]: https://github.com/Mohamed-Elhawary/eslint-plugin-code-style/compare/v1.9.2...v1.9.3
|
|
1292
1316
|
[1.9.2]: https://github.com/Mohamed-Elhawary/eslint-plugin-code-style/compare/v1.9.1...v1.9.2
|
|
1293
1317
|
[1.9.1]: https://github.com/Mohamed-Elhawary/eslint-plugin-code-style/compare/v1.9.0...v1.9.1
|
package/index.js
CHANGED
|
@@ -14090,6 +14090,9 @@ const noHardcodedStrings = {
|
|
|
14090
14090
|
|
|
14091
14091
|
const allIgnorePatterns = [...technicalPatterns, ...extraIgnorePatterns];
|
|
14092
14092
|
|
|
14093
|
+
// UI component patterns - only ignored in JSX attributes, not in logic
|
|
14094
|
+
const uiComponentPattern = /^(primary|secondary|tertiary|ghost|outline|link|muted|danger|warning|info|success|error|default|subtle|solid|soft|plain|flat|elevated|filled|tonal|text|contained|standard|xs|sm|md|lg|xl|2xl|3xl|4xl|5xl|xxs|xxl|small|medium|large|tiny|huge|compact|comfortable|spacious|left|right|center|top|bottom|start|end|middle|baseline|stretch|between|around|evenly|horizontal|vertical|row|column|inline|block|flex|grid|auto|none|hidden|visible|static|relative|absolute|fixed|sticky|on|off|hover|focus|click|blur|always|never)$/;
|
|
14095
|
+
|
|
14093
14096
|
// HTTP status codes that should NOT be hardcoded (2xx, 4xx, and 5xx)
|
|
14094
14097
|
const httpStatusCodePattern = /^[245]\d{2}$/;
|
|
14095
14098
|
|
|
@@ -14418,8 +14421,11 @@ const noHardcodedStrings = {
|
|
|
14418
14421
|
// Check if string is in an object that looks like constants definition
|
|
14419
14422
|
const isInConstantsObjectHandler = (node) => {
|
|
14420
14423
|
let current = node.parent;
|
|
14424
|
+
let depth = 0;
|
|
14421
14425
|
|
|
14422
14426
|
while (current) {
|
|
14427
|
+
depth++;
|
|
14428
|
+
|
|
14423
14429
|
if (current.type === "VariableDeclarator") {
|
|
14424
14430
|
const varName = current.id && current.id.name;
|
|
14425
14431
|
|
|
@@ -14437,9 +14443,34 @@ const noHardcodedStrings = {
|
|
|
14437
14443
|
}
|
|
14438
14444
|
}
|
|
14439
14445
|
|
|
14440
|
-
// Check for export const CONSTANT_NAME = "value"
|
|
14441
|
-
|
|
14442
|
-
|
|
14446
|
+
// Check for export const CONSTANT_NAME = "value" - only direct assignments (depth <= 3)
|
|
14447
|
+
// e.g., export const X = "value" or export const X = { key: "value" }
|
|
14448
|
+
// But NOT strings inside exported functions like export const Component = () => { const x = "value" }
|
|
14449
|
+
if (current.type === "ExportNamedDeclaration" && depth <= 3) {
|
|
14450
|
+
// Only skip if the export is a direct literal or object, not a function
|
|
14451
|
+
const declaration = current.declaration;
|
|
14452
|
+
|
|
14453
|
+
if (declaration && declaration.type === "VariableDeclaration") {
|
|
14454
|
+
const declarator = declaration.declarations[0];
|
|
14455
|
+
|
|
14456
|
+
if (declarator && declarator.init) {
|
|
14457
|
+
const initType = declarator.init.type;
|
|
14458
|
+
|
|
14459
|
+
// Skip if it's a direct string, object, or array constant
|
|
14460
|
+
if (initType === "Literal" || initType === "ObjectExpression" || initType === "ArrayExpression") {
|
|
14461
|
+
return true;
|
|
14462
|
+
}
|
|
14463
|
+
}
|
|
14464
|
+
}
|
|
14465
|
+
}
|
|
14466
|
+
|
|
14467
|
+
// Stop traversing if we hit a function - strings inside functions should be checked
|
|
14468
|
+
if (
|
|
14469
|
+
current.type === "FunctionDeclaration"
|
|
14470
|
+
|| current.type === "FunctionExpression"
|
|
14471
|
+
|| current.type === "ArrowFunctionExpression"
|
|
14472
|
+
) {
|
|
14473
|
+
return false;
|
|
14443
14474
|
}
|
|
14444
14475
|
|
|
14445
14476
|
current = current.parent;
|
|
@@ -14545,6 +14576,9 @@ const noHardcodedStrings = {
|
|
|
14545
14576
|
if (node.value.type === "Literal" && typeof node.value.value === "string") {
|
|
14546
14577
|
const str = node.value.value;
|
|
14547
14578
|
|
|
14579
|
+
// Skip UI component patterns in JSX attributes (variant, size, position props)
|
|
14580
|
+
if (uiComponentPattern.test(str)) return;
|
|
14581
|
+
|
|
14548
14582
|
// Check if it's a flagged special string (status code, role name)
|
|
14549
14583
|
const isSpecialString = isFlaggedSpecialStringHandler(str);
|
|
14550
14584
|
|
|
@@ -14569,6 +14603,9 @@ const noHardcodedStrings = {
|
|
|
14569
14603
|
if (expression.type === "Literal" && typeof expression.value === "string") {
|
|
14570
14604
|
const str = expression.value;
|
|
14571
14605
|
|
|
14606
|
+
// Skip UI component patterns in JSX attributes (variant, size, position props)
|
|
14607
|
+
if (uiComponentPattern.test(str)) return;
|
|
14608
|
+
|
|
14572
14609
|
// Check if it's a flagged special string (status code, role name)
|
|
14573
14610
|
const isSpecialString = isFlaggedSpecialStringHandler(str);
|
|
14574
14611
|
|
package/package.json
CHANGED