Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit492eb8f

Browse files
feat: limit the name given toImportSpecifier inid-length (#18861)
* feat: report name given to ImportSpecifier* update code* no error on same local name* add more tests
1 parent2de5742 commit492eb8f

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

‎lib/rules/id-length.js‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//------------------------------------------------------------------------------
1212

1313
const{ getGraphemeCount}=require("../shared/string-utils");
14+
const{ getModuleExportName}=require("./utils/ast-utils");
1415

1516
//------------------------------------------------------------------------------
1617
// Rule Definition
@@ -116,6 +117,12 @@ module.exports = {
116117
}
117118
returnproperties&&!parent.computed&&parent.key.name===node.name;
118119
},
120+
ImportSpecifier(parent,node){
121+
return(
122+
parent.local===node&&
123+
getModuleExportName(parent.imported)!==getModuleExportName(parent.local)
124+
);
125+
},
119126
ImportDefaultSpecifier:true,
120127
ImportNamespaceSpecifier:true,
121128
RestElement:true,

‎tests/lib/rules/id-length.js‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,11 @@ ruleTester.run("id-length", rule, {
6666
{code:"export var num = 0;",languageOptions:{ecmaVersion:6,sourceType:"module"}},
6767
{code:"import * as something from 'y';",languageOptions:{ecmaVersion:6,sourceType:"module"}},
6868
{code:"import { x } from 'y';",languageOptions:{ecmaVersion:6,sourceType:"module"}},
69+
{code:"import { x as x } from 'y';",languageOptions:{ecmaVersion:6,sourceType:"module"}},
70+
{code:"import { 'x' as x } from 'y';",languageOptions:{ecmaVersion:2022,sourceType:"module"}},
71+
{code:"import { x as foo } from 'y';",languageOptions:{ecmaVersion:6,sourceType:"module"}},
6972
{code:"import { longName } from 'y';",options:[{max:5}],languageOptions:{ecmaVersion:6,sourceType:"module"}},
73+
{code:"import { x as bar } from 'y';",options:[{max:5}],languageOptions:{ecmaVersion:6,sourceType:"module"}},
7074
{code:"({ prop: obj.x.y.something } = {});",languageOptions:{ecmaVersion:6}},
7175
{code:"({ prop: obj.longName } = {});",languageOptions:{ecmaVersion:6}},
7276
{code:"var obj = { a: 1, bc: 2 };",options:[{properties:"never"}]},
@@ -250,6 +254,9 @@ ruleTester.run("id-length", rule, {
250254
{code:"var [,i,a] = arr;",languageOptions:{ecmaVersion:6},errors:[tooShortError,tooShortError]},
251255
{code:"function foo([a]) {}",languageOptions:{ecmaVersion:6},errors:[tooShortError]},
252256
{code:"import x from 'module';",languageOptions:{ecmaVersion:6},errors:[tooShortError]},
257+
{code:"import { x as z } from 'module';",languageOptions:{ecmaVersion:6},errors:[{ ...tooShortError,column:15}]},
258+
{code:"import { foo as z } from 'module';",languageOptions:{ecmaVersion:6},errors:[{ ...tooShortError,column:17}]},
259+
{code:"import { 'foo' as z } from 'module';",languageOptions:{ecmaVersion:2022},errors:[{ ...tooShortError,column:19}]},
253260
{code:"import * as x from 'module';",languageOptions:{ecmaVersion:6},errors:[tooShortError]},
254261
{
255262
code:"import longName from 'module';",
@@ -263,6 +270,12 @@ ruleTester.run("id-length", rule, {
263270
languageOptions:{ecmaVersion:6},
264271
errors:[tooLongError]
265272
},
273+
{
274+
code:"import { foo as longName } from 'module';",
275+
options:[{max:5}],
276+
languageOptions:{ecmaVersion:6},
277+
errors:[{ ...tooLongError,column:17}]
278+
},
266279
{
267280
code:"var _$xt_$ = Foo(42)",
268281
options:[{min:2,max:4}],

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp