eslint-plugin-code-style 1.9.4 → 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.
Files changed (3) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/index.js +31 -3
  3. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -7,6 +7,17 @@ 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
+
10
21
  ## [1.9.4] - 2026-02-03
11
22
 
12
23
  ### Enhanced
@@ -1299,6 +1310,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1299
1310
 
1300
1311
  ---
1301
1312
 
1313
+ [1.9.5]: https://github.com/Mohamed-Elhawary/eslint-plugin-code-style/compare/v1.9.4...v1.9.5
1302
1314
  [1.9.4]: https://github.com/Mohamed-Elhawary/eslint-plugin-code-style/compare/v1.9.3...v1.9.4
1303
1315
  [1.9.3]: https://github.com/Mohamed-Elhawary/eslint-plugin-code-style/compare/v1.9.2...v1.9.3
1304
1316
  [1.9.2]: https://github.com/Mohamed-Elhawary/eslint-plugin-code-style/compare/v1.9.1...v1.9.2
package/index.js CHANGED
@@ -14421,8 +14421,11 @@ const noHardcodedStrings = {
14421
14421
  // Check if string is in an object that looks like constants definition
14422
14422
  const isInConstantsObjectHandler = (node) => {
14423
14423
  let current = node.parent;
14424
+ let depth = 0;
14424
14425
 
14425
14426
  while (current) {
14427
+ depth++;
14428
+
14426
14429
  if (current.type === "VariableDeclarator") {
14427
14430
  const varName = current.id && current.id.name;
14428
14431
 
@@ -14440,9 +14443,34 @@ const noHardcodedStrings = {
14440
14443
  }
14441
14444
  }
14442
14445
 
14443
- // Check for export const CONSTANT_NAME = "value"
14444
- if (current.type === "ExportNamedDeclaration") {
14445
- return true;
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;
14446
14474
  }
14447
14475
 
14448
14476
  current = current.parent;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-code-style",
3
- "version": "1.9.4",
3
+ "version": "1.9.5",
4
4
  "description": "A custom ESLint plugin for enforcing consistent code formatting and style rules in React/JSX projects",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",