eslint-plugin-code-style 1.6.1 → 1.6.4
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 +27 -0
- package/index.js +44 -16
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,30 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
---
|
|
9
9
|
|
|
10
|
+
## [1.6.4] - 2026-02-01
|
|
11
|
+
|
|
12
|
+
### Enhanced
|
|
13
|
+
|
|
14
|
+
- **`function-object-destructure`** - Add more module paths: apis, configs, utilities, routes
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## [1.6.3] - 2026-02-01
|
|
19
|
+
|
|
20
|
+
### Fixed
|
|
21
|
+
|
|
22
|
+
- **`component-props-destructure`** - Preserve TypeScript type annotation when auto-fixing
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## [1.6.2] - 2026-02-01
|
|
27
|
+
|
|
28
|
+
### Enhanced
|
|
29
|
+
|
|
30
|
+
- **`function-object-destructure`** - Expand to check more module paths (services, constants, config, api, utils, helpers, lib) for dot notation enforcement
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
10
34
|
## [1.6.1] - 2026-02-01
|
|
11
35
|
|
|
12
36
|
### Enhanced
|
|
@@ -987,6 +1011,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
987
1011
|
|
|
988
1012
|
---
|
|
989
1013
|
|
|
1014
|
+
[1.6.4]: https://github.com/Mohamed-Elhawary/eslint-plugin-code-style/compare/v1.6.3...v1.6.4
|
|
1015
|
+
[1.6.3]: https://github.com/Mohamed-Elhawary/eslint-plugin-code-style/compare/v1.6.2...v1.6.3
|
|
1016
|
+
[1.6.2]: https://github.com/Mohamed-Elhawary/eslint-plugin-code-style/compare/v1.6.1...v1.6.2
|
|
990
1017
|
[1.6.1]: https://github.com/Mohamed-Elhawary/eslint-plugin-code-style/compare/v1.6.0...v1.6.1
|
|
991
1018
|
[1.6.0]: https://github.com/Mohamed-Elhawary/eslint-plugin-code-style/compare/v1.5.2...v1.6.0
|
|
992
1019
|
[1.5.2]: https://github.com/Mohamed-Elhawary/eslint-plugin-code-style/compare/v1.5.1...v1.5.2
|
package/index.js
CHANGED
|
@@ -12414,15 +12414,32 @@ const functionObjectDestructure = {
|
|
|
12414
12414
|
create(context) {
|
|
12415
12415
|
const sourceCode = context.sourceCode || context.getSourceCode();
|
|
12416
12416
|
|
|
12417
|
-
// Track imports from
|
|
12418
|
-
|
|
12419
|
-
|
|
12420
|
-
|
|
12421
|
-
|
|
12422
|
-
|
|
12423
|
-
|
|
12424
|
-
|
|
12425
|
-
|
|
12417
|
+
// Track imports from module paths that should use dot notation, not destructure
|
|
12418
|
+
// This improves searchability: api.loginHandler is easier to find than loginHandler
|
|
12419
|
+
const moduleImports = new Set();
|
|
12420
|
+
|
|
12421
|
+
// Folders that contain modules which should be accessed via dot notation
|
|
12422
|
+
const modulePathPatterns = [
|
|
12423
|
+
"api",
|
|
12424
|
+
"apis",
|
|
12425
|
+
"config",
|
|
12426
|
+
"configs",
|
|
12427
|
+
"constants",
|
|
12428
|
+
"data",
|
|
12429
|
+
"helpers",
|
|
12430
|
+
"lib",
|
|
12431
|
+
"routes",
|
|
12432
|
+
"services",
|
|
12433
|
+
"utils",
|
|
12434
|
+
"utilities",
|
|
12435
|
+
];
|
|
12436
|
+
|
|
12437
|
+
const isModuleImportPath = (importPath) => {
|
|
12438
|
+
// Match paths like @/services, @/constants, ./data, ../config, etc.
|
|
12439
|
+
return modulePathPatterns.some((pattern) => importPath === `@/${pattern}`
|
|
12440
|
+
|| importPath.endsWith(`/${pattern}`)
|
|
12441
|
+
|| importPath.includes(`/${pattern}/`)
|
|
12442
|
+
|| new RegExp(`^\\.?\\.?/${pattern}$`).test(importPath));
|
|
12426
12443
|
};
|
|
12427
12444
|
|
|
12428
12445
|
const checkImportHandler = (node) => {
|
|
@@ -12430,13 +12447,13 @@ const functionObjectDestructure = {
|
|
|
12430
12447
|
|
|
12431
12448
|
const importPath = node.source.value;
|
|
12432
12449
|
|
|
12433
|
-
if (
|
|
12434
|
-
// Track all imported specifiers from
|
|
12450
|
+
if (isModuleImportPath(importPath)) {
|
|
12451
|
+
// Track all imported specifiers from module paths
|
|
12435
12452
|
node.specifiers.forEach((spec) => {
|
|
12436
12453
|
if (spec.type === "ImportSpecifier" && spec.local && spec.local.name) {
|
|
12437
|
-
|
|
12454
|
+
moduleImports.add(spec.local.name);
|
|
12438
12455
|
} else if (spec.type === "ImportDefaultSpecifier" && spec.local && spec.local.name) {
|
|
12439
|
-
|
|
12456
|
+
moduleImports.add(spec.local.name);
|
|
12440
12457
|
}
|
|
12441
12458
|
});
|
|
12442
12459
|
}
|
|
@@ -12467,7 +12484,7 @@ const functionObjectDestructure = {
|
|
|
12467
12484
|
}
|
|
12468
12485
|
}
|
|
12469
12486
|
|
|
12470
|
-
if (sourceVarName &&
|
|
12487
|
+
if (sourceVarName && moduleImports.has(sourceVarName)) {
|
|
12471
12488
|
const destructuredProps = decl.id.properties
|
|
12472
12489
|
.filter((p) => p.type === "Property" && p.key && p.key.name)
|
|
12473
12490
|
.map((p) => p.key.name);
|
|
@@ -12475,7 +12492,7 @@ const functionObjectDestructure = {
|
|
|
12475
12492
|
const sourceText = sourceCode.getText(decl.init);
|
|
12476
12493
|
|
|
12477
12494
|
context.report({
|
|
12478
|
-
message: `Do not destructure
|
|
12495
|
+
message: `Do not destructure module imports. Use dot notation for searchability: "${sourceText}.${destructuredProps[0]}" instead of destructuring`,
|
|
12479
12496
|
node: decl.id,
|
|
12480
12497
|
});
|
|
12481
12498
|
}
|
|
@@ -13301,8 +13318,19 @@ const componentPropsDestructure = {
|
|
|
13301
13318
|
? (fixer) => {
|
|
13302
13319
|
const fixes = [];
|
|
13303
13320
|
|
|
13321
|
+
// Build destructured pattern, preserving type annotation if present
|
|
13322
|
+
const destructuredPattern = `{ ${accessedProps.join(", ")} }`;
|
|
13323
|
+
let replacement = destructuredPattern;
|
|
13324
|
+
|
|
13325
|
+
// Preserve TypeScript type annotation if present
|
|
13326
|
+
if (firstParam.typeAnnotation) {
|
|
13327
|
+
const typeText = sourceCode.getText(firstParam.typeAnnotation);
|
|
13328
|
+
|
|
13329
|
+
replacement = `${destructuredPattern}${typeText}`;
|
|
13330
|
+
}
|
|
13331
|
+
|
|
13304
13332
|
// Replace param with destructured pattern
|
|
13305
|
-
fixes.push(fixer.replaceText(firstParam,
|
|
13333
|
+
fixes.push(fixer.replaceText(firstParam, replacement));
|
|
13306
13334
|
|
|
13307
13335
|
// Replace all props.x with just x
|
|
13308
13336
|
accesses.forEach((access) => {
|
package/package.json
CHANGED