Skip to content

Commit bcf0df5

Browse files
feat: limit namespace import identifier in id-length rule (#18849)
* feat: limit namespace import identifier in id-length rule * test: add tests for valid case in 'id-length' rule * refactor: Sort order, Change variable name to semantic name * Update lib/rules/id-length.js Co-authored-by: Tanuj Kanti <[email protected]> * Update tests/lib/rules/id-length.js Co-authored-by: Tanuj Kanti <[email protected]> * Update tests/lib/rules/id-length.js Co-authored-by: Tanuj Kanti <[email protected]> * test: add test for shows that ImportSpecifiers are allowed even with default 2 and with max option --------- Co-authored-by: Tanuj Kanti <[email protected]>
1 parent 45c18e1 commit bcf0df5

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

lib/rules/id-length.js

+1
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ module.exports = {
117117
return properties && !parent.computed && parent.key.name === node.name;
118118
},
119119
ImportDefaultSpecifier: true,
120+
ImportNamespaceSpecifier: true,
120121
RestElement: true,
121122
FunctionExpression: true,
122123
ArrowFunctionExpression: true,

tests/lib/rules/id-length.js

+17
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ ruleTester.run("id-length", rule, {
6464
{ code: "({ a: obj.x.y.z } = {});", options: [{ properties: "never" }], languageOptions: { ecmaVersion: 6 } },
6565
{ code: "import something from 'y';", languageOptions: { ecmaVersion: 6, sourceType: "module" } },
6666
{ code: "export var num = 0;", languageOptions: { ecmaVersion: 6, sourceType: "module" } },
67+
{ code: "import * as something from 'y';", languageOptions: { ecmaVersion: 6, sourceType: "module" } },
68+
{ code: "import { x } from 'y';", languageOptions: { ecmaVersion: 6, sourceType: "module" } },
69+
{ code: "import { longName } from 'y';", options: [{ max: 5 }], languageOptions: { ecmaVersion: 6, sourceType: "module" } },
6770
{ code: "({ prop: obj.x.y.something } = {});", languageOptions: { ecmaVersion: 6 } },
6871
{ code: "({ prop: obj.longName } = {});", languageOptions: { ecmaVersion: 6 } },
6972
{ code: "var obj = { a: 1, bc: 2 };", options: [{ properties: "never" }] },
@@ -246,6 +249,20 @@ ruleTester.run("id-length", rule, {
246249
{ code: "var [i] = arr;", languageOptions: { ecmaVersion: 6 }, errors: [tooShortError] },
247250
{ code: "var [,i,a] = arr;", languageOptions: { ecmaVersion: 6 }, errors: [tooShortError, tooShortError] },
248251
{ code: "function foo([a]) {}", languageOptions: { ecmaVersion: 6 }, errors: [tooShortError] },
252+
{ code: "import x from 'module';", languageOptions: { ecmaVersion: 6 }, errors: [tooShortError] },
253+
{ code: "import * as x from 'module';", languageOptions: { ecmaVersion: 6 }, errors: [tooShortError] },
254+
{
255+
code: "import longName from 'module';",
256+
options: [{ max: 5 }],
257+
languageOptions: { ecmaVersion: 6 },
258+
errors: [tooLongError]
259+
},
260+
{
261+
code: "import * as longName from 'module';",
262+
options: [{ max: 5 }],
263+
languageOptions: { ecmaVersion: 6 },
264+
errors: [tooLongError]
265+
},
249266
{
250267
code: "var _$xt_$ = Foo(42)",
251268
options: [{ min: 2, max: 4 }],

0 commit comments

Comments
 (0)