eslint-plugin-lube 0.1.7 → 0.2.0
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/README.md +2 -1
- package/index.js +53 -1
- package/node-type.text +71 -0
- package/package.json +26 -27
- package/private.d.ts +106 -19
- package/rules/pretty-imports.js +110 -0
- package/rules/svelte-naming-convention.js +11 -13
- package/test/pretty-imports/check_exports.js +85 -0
- package/test/pretty-imports/check_imports.js +85 -0
- package/test/pretty-imports.js +19 -0
- package/test/svelte-naming-convention/case_by_identifier.js +1 -34
package/README.md
CHANGED
|
@@ -2,4 +2,5 @@
|
|
|
2
2
|
|
|
3
3
|
| Rule | Code | Test |
|
|
4
4
|
|---|---|---|
|
|
5
|
-
| svelte-naming-convention | [code](https://github.com/Artxe2/lube-series/blob/master/packages/eslint-plugin-lube/rules/svelte-naming-convention.js) | [test](https://github.com/Artxe2/lube-series/blob/master/packages/eslint-plugin-lube/test/svelte-naming-convention
|
|
5
|
+
| svelte-naming-convention | [code](https://github.com/Artxe2/lube-series/blob/master/packages/eslint-plugin-lube/rules/svelte-naming-convention.js) | [test](https://github.com/Artxe2/lube-series/blob/master/packages/eslint-plugin-lube/test/svelte-naming-convention) |
|
|
6
|
+
| pretty-imports | [code](https://github.com/Artxe2/lube-series/blob/master/packages/eslint-plugin-lube/rules/pretty-imports.js) | [test](https://github.com/Artxe2/lube-series/blob/master/packages/eslint-plugin-lube/test/pretty-imports) |
|
package/index.js
CHANGED
|
@@ -1 +1,53 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @type {import("eslint").ESLint.Plugin & {
|
|
3
|
+
* configs: Record<string, import("eslint").ESLint.ConfigData|{}>
|
|
4
|
+
* }}
|
|
5
|
+
*/
|
|
6
|
+
module.exports = {
|
|
7
|
+
configs: {
|
|
8
|
+
recommended: {
|
|
9
|
+
extends: ["eslint:recommended"],
|
|
10
|
+
plugins: ["lube"],
|
|
11
|
+
rules: {
|
|
12
|
+
"arrow-spacing": "error",
|
|
13
|
+
"comma-spacing": "error",
|
|
14
|
+
"dot-location": ["error", "property"],
|
|
15
|
+
"for-direction": "error",
|
|
16
|
+
"getter-return": "error",
|
|
17
|
+
"indent": ["error", "tab"],
|
|
18
|
+
"keyword-spacing": ["error", {
|
|
19
|
+
"after": true,
|
|
20
|
+
"before": true
|
|
21
|
+
}],
|
|
22
|
+
"lube/svelte-naming-convention": "error",
|
|
23
|
+
"lube/pretty-imports": "error",
|
|
24
|
+
"max-len": ["warn", 120],
|
|
25
|
+
"max-nested-callbacks": ["error", 3],
|
|
26
|
+
"no-console": "warn",
|
|
27
|
+
"no-duplicate-imports": "error",
|
|
28
|
+
"no-empty-pattern": "error",
|
|
29
|
+
"no-multi-spaces": "error",
|
|
30
|
+
"object-curly-spacing": ["error", "always"],
|
|
31
|
+
"prefer-const": "warn",
|
|
32
|
+
"quotes": ["error", "double"],
|
|
33
|
+
"semi": ["error", "never"],
|
|
34
|
+
"semi-spacing": ["error", {
|
|
35
|
+
"after": true,
|
|
36
|
+
"before": false
|
|
37
|
+
}],
|
|
38
|
+
"space-before-function-paren": ["error", {
|
|
39
|
+
"anonymous": "never",
|
|
40
|
+
"asyncArrow": "always",
|
|
41
|
+
"named": "never"
|
|
42
|
+
}],
|
|
43
|
+
"space-in-parens": ["error", "never"],
|
|
44
|
+
"space-infix-ops": "error",
|
|
45
|
+
"space-unary-ops": "error"
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
rules: {
|
|
50
|
+
"pretty-imports": require("./rules/pretty-imports"),
|
|
51
|
+
"svelte-naming-convention": require("./rules/svelte-naming-convention")
|
|
52
|
+
}
|
|
53
|
+
}
|
package/node-type.text
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/* ArrayExpression */
|
|
2
|
+
/* ArrayPattern */
|
|
3
|
+
/* ArrowFunctionExpression */
|
|
4
|
+
/* AssignmentExpression */
|
|
5
|
+
/* AssignmentPattern */
|
|
6
|
+
/* AwaitExpression */
|
|
7
|
+
/* BinaryExpression */
|
|
8
|
+
/* BlockStatement */
|
|
9
|
+
/* BreakStatement */
|
|
10
|
+
/* CallExpression */
|
|
11
|
+
/* CatchClause */
|
|
12
|
+
/* ChainExpression */
|
|
13
|
+
/* ClassBody */
|
|
14
|
+
/* ClassDeclaration */
|
|
15
|
+
/* ClassExpression */
|
|
16
|
+
/* ConditionalExpression */
|
|
17
|
+
/* ContinueStatement */
|
|
18
|
+
/* DebuggerStatement */
|
|
19
|
+
/* DoWhileStatement */
|
|
20
|
+
/* EmptyStatement */
|
|
21
|
+
/* ExportAllDeclaration */
|
|
22
|
+
/* ExportDefaultDeclaration */
|
|
23
|
+
/* ExportNamedDeclaration */
|
|
24
|
+
/* ExportSpecifier */
|
|
25
|
+
/* ExpressionStatement */
|
|
26
|
+
/* ForInStatement */
|
|
27
|
+
/* ForOfStatement */
|
|
28
|
+
/* ForStatement */
|
|
29
|
+
/* FunctionDeclaration */
|
|
30
|
+
/* FunctionExpression */
|
|
31
|
+
/* Identifier */
|
|
32
|
+
/* IfStatement */
|
|
33
|
+
/* ImportDeclaration */
|
|
34
|
+
/* ImportDefaultSpecifier */
|
|
35
|
+
/* ImportExpression */
|
|
36
|
+
/* ImportNamespaceSpecifier */
|
|
37
|
+
/* ImportSpecifier */
|
|
38
|
+
/* LabeledStatement */
|
|
39
|
+
/* Literal */
|
|
40
|
+
/* LogicalExpression */
|
|
41
|
+
/* MemberExpression */
|
|
42
|
+
/* MetaProperty */
|
|
43
|
+
/* MethodDefinition */
|
|
44
|
+
/* NewExpression */
|
|
45
|
+
/* ObjectExpression */
|
|
46
|
+
/* ObjectPattern */
|
|
47
|
+
/* PrivateIdentifier */
|
|
48
|
+
/* Program */
|
|
49
|
+
/* Property */
|
|
50
|
+
/* PropertyDefinition */
|
|
51
|
+
/* RestElement */
|
|
52
|
+
/* ReturnStatement */
|
|
53
|
+
/* SequenceExpression */
|
|
54
|
+
/* SpreadElement */
|
|
55
|
+
/* StaticBlock */
|
|
56
|
+
/* Super */
|
|
57
|
+
/* SwitchCase */
|
|
58
|
+
/* SwitchStatement */
|
|
59
|
+
/* TaggedTemplateExpression */
|
|
60
|
+
/* TemplateElement */
|
|
61
|
+
/* TemplateLiteral */
|
|
62
|
+
/* ThisExpression */
|
|
63
|
+
/* ThrowStatement */
|
|
64
|
+
/* TryStatement */
|
|
65
|
+
/* UnaryExpression */
|
|
66
|
+
/* UpdateExpression */
|
|
67
|
+
/* VariableDeclaration */
|
|
68
|
+
/* VariableDeclarator */
|
|
69
|
+
/* WhileStatement */
|
|
70
|
+
/* WithStatement */
|
|
71
|
+
/* YieldExpression */
|
package/package.json
CHANGED
|
@@ -1,27 +1,26 @@
|
|
|
1
|
-
{
|
|
2
|
-
"author": "artxe2",
|
|
3
|
-
"bugs": {
|
|
4
|
-
"url": "https://github.com/Artxe2/lube-series/issues"
|
|
5
|
-
},
|
|
6
|
-
"
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
"
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
"
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"author": "artxe2",
|
|
3
|
+
"bugs": {
|
|
4
|
+
"url": "https://github.com/Artxe2/lube-series/issues"
|
|
5
|
+
},
|
|
6
|
+
"description": "Eslint rules expand options",
|
|
7
|
+
"devDependencies": {
|
|
8
|
+
"@types/eslint": "^8.44.2",
|
|
9
|
+
"@types/estree": "^1.0.1",
|
|
10
|
+
"@typescript-eslint/parser": "^6.3.0",
|
|
11
|
+
"eslint": "^8.47.0",
|
|
12
|
+
"mocha": "^10.2.0"
|
|
13
|
+
},
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"name": "eslint-plugin-lube",
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "https://github.com/Artxe2/lube-series",
|
|
19
|
+
"directory": "packages/eslint-plugin-lube"
|
|
20
|
+
},
|
|
21
|
+
"scripts": {
|
|
22
|
+
"test": "mocha"
|
|
23
|
+
},
|
|
24
|
+
"type": "commonjs",
|
|
25
|
+
"version": "0.2.0"
|
|
26
|
+
}
|
package/private.d.ts
CHANGED
|
@@ -1,22 +1,109 @@
|
|
|
1
|
-
import
|
|
2
|
-
Node,
|
|
3
|
-
Pattern
|
|
4
|
-
} from "estree"
|
|
1
|
+
import * as estree from "estree"
|
|
5
2
|
|
|
6
|
-
|
|
7
|
-
computed: boolean
|
|
8
|
-
id: ASTNode
|
|
9
|
-
imported: ASTNode
|
|
10
|
-
key: ASTNode
|
|
11
|
-
left: ASTNode
|
|
12
|
-
local: ASTNode
|
|
13
|
-
name: string
|
|
14
|
-
object: ASTNode
|
|
3
|
+
export type ASTNode = {
|
|
15
4
|
parent: ASTNode
|
|
16
|
-
property: ASTNode
|
|
17
5
|
range: [number, number]
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
6
|
+
} & (
|
|
7
|
+
estree.ArrayExpression & {
|
|
8
|
+
elements: ASTNode[]
|
|
9
|
+
}
|
|
10
|
+
| estree.ArrayPattern & {
|
|
11
|
+
elements: ASTNode[]
|
|
12
|
+
}
|
|
13
|
+
| estree.ArrowFunctionExpression & {
|
|
14
|
+
body: ASTNode
|
|
15
|
+
params: ASTNode[]
|
|
16
|
+
}
|
|
17
|
+
| estree.AssignmentExpression
|
|
18
|
+
| estree.AssignmentPattern
|
|
19
|
+
| estree.AwaitExpression
|
|
20
|
+
| estree.BinaryExpression
|
|
21
|
+
| estree.BlockStatement
|
|
22
|
+
| estree.BreakStatement
|
|
23
|
+
| estree.CallExpression
|
|
24
|
+
| estree.CatchClause
|
|
25
|
+
| estree.ChainExpression
|
|
26
|
+
| estree.ClassBody
|
|
27
|
+
| estree.ClassDeclaration
|
|
28
|
+
| estree.ClassExpression
|
|
29
|
+
| estree.ConditionalExpression
|
|
30
|
+
| estree.ContinueStatement
|
|
31
|
+
| estree.DebuggerStatement
|
|
32
|
+
| estree.DoWhileStatement
|
|
33
|
+
| estree.EmptyStatement
|
|
34
|
+
| estree.ExportAllDeclaration
|
|
35
|
+
| estree.ExportDefaultDeclaration
|
|
36
|
+
| estree.ExportNamedDeclaration & {
|
|
37
|
+
source: estree.SimpleLiteral & {
|
|
38
|
+
range: [number, number]
|
|
39
|
+
raw: string
|
|
40
|
+
value: string
|
|
41
|
+
}
|
|
42
|
+
specifiers: ASTNode[]
|
|
43
|
+
}
|
|
44
|
+
| estree.ExportSpecifier
|
|
45
|
+
| estree.ExpressionStatement
|
|
46
|
+
| estree.ForInStatement
|
|
47
|
+
| estree.ForOfStatement
|
|
48
|
+
| estree.ForStatement
|
|
49
|
+
| estree.FunctionDeclaration & {
|
|
50
|
+
body: ASTNode
|
|
51
|
+
params: ASTNode[]
|
|
52
|
+
}
|
|
53
|
+
| estree.FunctionExpression & {
|
|
54
|
+
body: ASTNode
|
|
55
|
+
params: ASTNode[]
|
|
56
|
+
}
|
|
57
|
+
| estree.Identifier
|
|
58
|
+
| estree.IfStatement
|
|
59
|
+
| estree.ImportDeclaration & {
|
|
60
|
+
source: estree.SimpleLiteral & {
|
|
61
|
+
range: [number, number]
|
|
62
|
+
raw: string
|
|
63
|
+
value: string
|
|
64
|
+
}
|
|
65
|
+
specifiers: ASTNode[]
|
|
66
|
+
}
|
|
67
|
+
| estree.ImportDefaultSpecifier
|
|
68
|
+
| estree.ImportExpression
|
|
69
|
+
| estree.ImportNamespaceSpecifier
|
|
70
|
+
| estree.ImportSpecifier
|
|
71
|
+
| estree.LabeledStatement
|
|
72
|
+
| estree.Literal
|
|
73
|
+
| estree.LogicalExpression
|
|
74
|
+
| estree.MemberExpression
|
|
75
|
+
| estree.MetaProperty
|
|
76
|
+
| estree.MethodDefinition
|
|
77
|
+
| estree.NewExpression
|
|
78
|
+
| estree.ObjectExpression & {
|
|
79
|
+
properties: ASTNode[]
|
|
80
|
+
}
|
|
81
|
+
| estree.ObjectPattern & {
|
|
82
|
+
properties: ASTNode[]
|
|
83
|
+
}
|
|
84
|
+
| estree.PrivateIdentifier
|
|
85
|
+
| estree.Program
|
|
86
|
+
| estree.Property & { key: estree.Identifier }
|
|
87
|
+
| estree.PropertyDefinition
|
|
88
|
+
| estree.RestElement
|
|
89
|
+
| estree.ReturnStatement
|
|
90
|
+
| estree.SequenceExpression
|
|
91
|
+
| estree.SpreadElement
|
|
92
|
+
| estree.StaticBlock
|
|
93
|
+
| estree.Super
|
|
94
|
+
| estree.SwitchCase
|
|
95
|
+
| estree.SwitchStatement
|
|
96
|
+
| estree.TaggedTemplateExpression
|
|
97
|
+
| estree.TemplateElement
|
|
98
|
+
| estree.TemplateLiteral
|
|
99
|
+
| estree.ThisExpression
|
|
100
|
+
| estree.ThrowStatement
|
|
101
|
+
| estree.TryStatement
|
|
102
|
+
| estree.UnaryExpression
|
|
103
|
+
| estree.UpdateExpression
|
|
104
|
+
| estree.VariableDeclaration
|
|
105
|
+
| estree.VariableDeclarator
|
|
106
|
+
| estree.WhileStatement
|
|
107
|
+
| estree.WithStatement
|
|
108
|
+
| estree.YieldExpression
|
|
109
|
+
)
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict"
|
|
2
|
+
/** @type {import("eslint").Rule.RuleModule} */
|
|
3
|
+
module.exports = {
|
|
4
|
+
meta: {
|
|
5
|
+
docs: {
|
|
6
|
+
description: "Enforces pretty imports.",
|
|
7
|
+
recommended: true,
|
|
8
|
+
url: "https://github.com/Artxe2/lube-series/blob/master/packages/eslint-plugin-lube/test/pretty-imports"
|
|
9
|
+
},
|
|
10
|
+
fixable: "code",
|
|
11
|
+
messages: {
|
|
12
|
+
not_match: "This imports is not pretty"
|
|
13
|
+
},
|
|
14
|
+
schema: [{
|
|
15
|
+
properties: {
|
|
16
|
+
checkExports: {
|
|
17
|
+
type: "boolean",
|
|
18
|
+
default: true
|
|
19
|
+
},
|
|
20
|
+
checkImports: {
|
|
21
|
+
type: "boolean",
|
|
22
|
+
default: true
|
|
23
|
+
},
|
|
24
|
+
indent: {
|
|
25
|
+
type: "string",
|
|
26
|
+
default: "\t"
|
|
27
|
+
},
|
|
28
|
+
maxLength: {
|
|
29
|
+
type: "number",
|
|
30
|
+
default: 30
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
type: "object"
|
|
34
|
+
}],
|
|
35
|
+
type: "suggestion"
|
|
36
|
+
},
|
|
37
|
+
create(context) {
|
|
38
|
+
const check_exports = /** @type {boolean} */ (context.options[0]?.checkExports) ?? true
|
|
39
|
+
const check_imports = /** @type {boolean} */ (context.options[0]?.checkImports) ?? true
|
|
40
|
+
const indent = /** @type {string} */ (context.options[0]?.indent) ?? "\t"
|
|
41
|
+
const max_length = /** @type {number} */ (context.options[0]?.maxLength) ?? 30
|
|
42
|
+
const source_code = context.sourceCode
|
|
43
|
+
const text = source_code.text
|
|
44
|
+
|
|
45
|
+
const indent_regex = /[ \t]*(?=[^\n]*$)/
|
|
46
|
+
/** @param {number} index */
|
|
47
|
+
function get_indent(index) {
|
|
48
|
+
return text.slice(0, index).match(indent_regex)?.[0] || ""
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @param {import("../private").ASTNode} node
|
|
53
|
+
* @param {string} corrected_text
|
|
54
|
+
*/
|
|
55
|
+
function report(node, corrected_text) {
|
|
56
|
+
context.report({
|
|
57
|
+
fix(fixer) {
|
|
58
|
+
return fixer.replaceText(node, corrected_text)
|
|
59
|
+
},
|
|
60
|
+
messageId: "not_match",
|
|
61
|
+
node: /** @type {import("estree").Node} */(node)
|
|
62
|
+
})
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return {
|
|
66
|
+
/** @param {import("../private").ASTNode & import("estree").ExportNamedDeclaration} node */
|
|
67
|
+
ExportNamedDeclaration(node) {
|
|
68
|
+
if (check_exports && node.specifiers[0]?.type == "ExportSpecifier") {
|
|
69
|
+
const line_indent = get_indent(node.range[0])
|
|
70
|
+
let length = 0
|
|
71
|
+
for (const s of node.specifiers) {
|
|
72
|
+
length += s.range[1] - s.range[0]
|
|
73
|
+
}
|
|
74
|
+
const corrected_text = length > max_length
|
|
75
|
+
? `export {\n${line_indent + indent}${
|
|
76
|
+
/** @type {import("../private").ASTNode[]} v */
|
|
77
|
+
(node.specifiers).map(v => text.slice(v.range[0], v.range[1]))
|
|
78
|
+
.join(",\n" + line_indent + indent)
|
|
79
|
+
}\n${line_indent}} from ${text.slice(node.source.range[0], node.range[1])}`
|
|
80
|
+
: `export { ${
|
|
81
|
+
/** @type {import("../private").ASTNode[]} v */
|
|
82
|
+
(node.specifiers).map(v => text.slice(v.range[0], v.range[1])).join(", ")
|
|
83
|
+
} } from ${text.slice(node.source.range[0], node.range[1])}`
|
|
84
|
+
if (corrected_text != text.slice(node.range[0], node.range[1])) report(node, corrected_text)
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
/** @param {import("../private").ASTNode & import("estree").ImportDeclaration} node */
|
|
88
|
+
ImportDeclaration(node) {
|
|
89
|
+
if (check_imports && node.specifiers[0]?.type == "ImportSpecifier") {
|
|
90
|
+
const line_indent = get_indent(node.range[0])
|
|
91
|
+
let length = 0
|
|
92
|
+
for (const s of node.specifiers) {
|
|
93
|
+
length += s.range[1] - s.range[0]
|
|
94
|
+
}
|
|
95
|
+
const corrected_text = length > max_length
|
|
96
|
+
? `import {\n${line_indent + indent}${
|
|
97
|
+
/** @type {import("../private").ASTNode[]} v */
|
|
98
|
+
(node.specifiers).map(v => text.slice(v.range[0], v.range[1]))
|
|
99
|
+
.join(",\n" + line_indent + indent)
|
|
100
|
+
}\n${line_indent}} from ${text.slice(node.source.range[0], node.range[1])}`
|
|
101
|
+
: `import { ${
|
|
102
|
+
/** @type {import("../private").ASTNode[]} v */
|
|
103
|
+
(node.specifiers).map(v => text.slice(v.range[0], v.range[1])).join(", ")
|
|
104
|
+
} } from ${text.slice(node.source.range[0], node.range[1])}`
|
|
105
|
+
if (corrected_text != text.slice(node.range[0], node.range[1])) report(node, corrected_text)
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
@@ -15,7 +15,7 @@ module.exports = {
|
|
|
15
15
|
properties: {
|
|
16
16
|
fixSameNames: {
|
|
17
17
|
type: "boolean",
|
|
18
|
-
default:
|
|
18
|
+
default: true
|
|
19
19
|
},
|
|
20
20
|
},
|
|
21
21
|
type: "object"
|
|
@@ -23,13 +23,13 @@ module.exports = {
|
|
|
23
23
|
type: "suggestion"
|
|
24
24
|
},
|
|
25
25
|
create(context) {
|
|
26
|
-
const fix_same_names = /** @type {boolean} */ (context.options[0]?.fixSameNames)
|
|
26
|
+
const fix_same_names = /** @type {boolean} */ (context.options[0]?.fixSameNames) ?? true
|
|
27
27
|
|
|
28
28
|
// let name | const name | class name
|
|
29
|
-
const allow_regex = /^[_$]?[_$]?(?:[
|
|
30
|
-
const fixable_name_regex = /^[_$]?[_$]?(?:[
|
|
31
|
-
const fix_regex = /([
|
|
32
|
-
const camel_case_regex = /^[
|
|
29
|
+
const allow_regex = /^[_$]?[_$]?(?:[\da-z]+(?:_[\da-z]+)*\$?\$?)?$|^[A-Z][\dA-Z_]*$|^(?:[\dA-Z][\da-z]*)+$/
|
|
30
|
+
const fixable_name_regex = /^[_$]?[_$]?(?:[\dA-Za-z]+(?:_[\dA-Za-z]+)*\$?\$?)?$/
|
|
31
|
+
const fix_regex = /([\da-z]?)([A-Z][\dA-Z]*)/g
|
|
32
|
+
const camel_case_regex = /^[\da-z]+([A-Z][\da-z]*)*$/
|
|
33
33
|
|
|
34
34
|
/**
|
|
35
35
|
* @param {string} _
|
|
@@ -47,7 +47,7 @@ module.exports = {
|
|
|
47
47
|
/** @type {Set<import("../private").ASTNode>} */
|
|
48
48
|
const shortand_properties = new Set()
|
|
49
49
|
|
|
50
|
-
/** @param {import("../private").ASTNode} node */
|
|
50
|
+
/** @param {import("../private").ASTNode & import("estree").Identifier} node */
|
|
51
51
|
function defer(node) {
|
|
52
52
|
if (fix_same_names) {
|
|
53
53
|
const name = node.name
|
|
@@ -63,7 +63,7 @@ module.exports = {
|
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
/** @param {import("../private").ASTNode} node */
|
|
66
|
+
/** @param {import("../private").ASTNode & import("estree").Identifier} node */
|
|
67
67
|
function report(node) {
|
|
68
68
|
const name = node.name
|
|
69
69
|
context.report({
|
|
@@ -78,15 +78,13 @@ module.exports = {
|
|
|
78
78
|
}
|
|
79
79
|
return null
|
|
80
80
|
},
|
|
81
|
-
messageId:
|
|
82
|
-
? "not_match_private"
|
|
83
|
-
: "not_match",
|
|
81
|
+
messageId: "not_match",
|
|
84
82
|
node: /** @type {import("estree").Node} */(node)
|
|
85
83
|
})
|
|
86
84
|
if (fix_same_names) {
|
|
87
85
|
const usages = pending_usages.get(name)
|
|
88
86
|
while (usages?.length) {
|
|
89
|
-
report(/** @type {import("../private").ASTNode} */(
|
|
87
|
+
report(/** @type {import("../private").ASTNode & import("estree").Identifier} */(
|
|
90
88
|
usages.pop()
|
|
91
89
|
))
|
|
92
90
|
}
|
|
@@ -95,7 +93,7 @@ module.exports = {
|
|
|
95
93
|
}
|
|
96
94
|
|
|
97
95
|
return {
|
|
98
|
-
/** @param {import("../private").ASTNode} node */
|
|
96
|
+
/** @param {import("../private").ASTNode & import("estree").Identifier} node */
|
|
99
97
|
Identifier(node) {
|
|
100
98
|
const name = node.name
|
|
101
99
|
if (allow_regex.test(name)) return
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {import("eslint").RuleTester.ValidTestCase[]} valid
|
|
3
|
+
* @param {import("eslint").RuleTester.InvalidTestCase[]} invalid
|
|
4
|
+
*/
|
|
5
|
+
exports.module = (valid, invalid) => {
|
|
6
|
+
valid.push({
|
|
7
|
+
code: `
|
|
8
|
+
|
|
9
|
+
export { a, b as c, d } from 'module' ;
|
|
10
|
+
export { fff, ggg, hhh, iii, jjj, kkk, lll } from 'module/2'
|
|
11
|
+
`,
|
|
12
|
+
options: [{ maxLength: 30 }],
|
|
13
|
+
parserOptions: {
|
|
14
|
+
ecmaVersion: "latest",
|
|
15
|
+
sourceType: "module"
|
|
16
|
+
}
|
|
17
|
+
})
|
|
18
|
+
invalid.push(
|
|
19
|
+
{
|
|
20
|
+
code: `
|
|
21
|
+
|
|
22
|
+
export { a, b as c, d } from 'module' ;
|
|
23
|
+
export { fff, ggg, hhh, iii, jjj, kkk, lll } from 'module/2'
|
|
24
|
+
`,
|
|
25
|
+
errors: [{
|
|
26
|
+
messageId: "not_match",
|
|
27
|
+
type: "ExportNamedDeclaration",
|
|
28
|
+
line: 4,
|
|
29
|
+
column: 7
|
|
30
|
+
}],
|
|
31
|
+
options: [{ maxLength: 10 }],
|
|
32
|
+
output: `
|
|
33
|
+
|
|
34
|
+
export { a, b as c, d } from 'module' ;
|
|
35
|
+
export {
|
|
36
|
+
fff,
|
|
37
|
+
ggg,
|
|
38
|
+
hhh,
|
|
39
|
+
iii,
|
|
40
|
+
jjj,
|
|
41
|
+
kkk,
|
|
42
|
+
lll
|
|
43
|
+
} from 'module/2'
|
|
44
|
+
`,
|
|
45
|
+
parserOptions: {
|
|
46
|
+
ecmaVersion: "latest",
|
|
47
|
+
sourceType: "module"
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
code: `
|
|
52
|
+
|
|
53
|
+
export { a, b as c, d } from 'module' ;
|
|
54
|
+
export { fff, ggg, hhh, iii, jjj, kkk, lll } from 'module/2'
|
|
55
|
+
`,
|
|
56
|
+
errors: [{
|
|
57
|
+
messageId: "not_match",
|
|
58
|
+
type: "ExportNamedDeclaration",
|
|
59
|
+
line: 4,
|
|
60
|
+
column: 7
|
|
61
|
+
}],
|
|
62
|
+
options: [{
|
|
63
|
+
indent: " ",
|
|
64
|
+
maxLength: 10
|
|
65
|
+
}],
|
|
66
|
+
output: `
|
|
67
|
+
|
|
68
|
+
export { a, b as c, d } from 'module' ;
|
|
69
|
+
export {
|
|
70
|
+
fff,
|
|
71
|
+
ggg,
|
|
72
|
+
hhh,
|
|
73
|
+
iii,
|
|
74
|
+
jjj,
|
|
75
|
+
kkk,
|
|
76
|
+
lll
|
|
77
|
+
} from 'module/2'
|
|
78
|
+
`,
|
|
79
|
+
parserOptions: {
|
|
80
|
+
ecmaVersion: "latest",
|
|
81
|
+
sourceType: "module"
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
)
|
|
85
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {import("eslint").RuleTester.ValidTestCase[]} valid
|
|
3
|
+
* @param {import("eslint").RuleTester.InvalidTestCase[]} invalid
|
|
4
|
+
*/
|
|
5
|
+
exports.module = (valid, invalid) => {
|
|
6
|
+
valid.push({
|
|
7
|
+
code: `
|
|
8
|
+
|
|
9
|
+
import { a, b as c, d } from 'module' ;
|
|
10
|
+
import { fff, ggg, hhh, iii, jjj, kkk, lll } from 'module/2'
|
|
11
|
+
`,
|
|
12
|
+
options: [{ maxLength: 30 }],
|
|
13
|
+
parserOptions: {
|
|
14
|
+
ecmaVersion: "latest",
|
|
15
|
+
sourceType: "module"
|
|
16
|
+
}
|
|
17
|
+
})
|
|
18
|
+
invalid.push(
|
|
19
|
+
{
|
|
20
|
+
code: `
|
|
21
|
+
|
|
22
|
+
import { a, b as c, d } from 'module' ;
|
|
23
|
+
import { fff, ggg, hhh, iii, jjj, kkk, lll } from 'module/2'
|
|
24
|
+
`,
|
|
25
|
+
errors: [{
|
|
26
|
+
messageId: "not_match",
|
|
27
|
+
type: "ImportDeclaration",
|
|
28
|
+
line: 4,
|
|
29
|
+
column: 7
|
|
30
|
+
}],
|
|
31
|
+
options: [{ maxLength: 10 }],
|
|
32
|
+
output: `
|
|
33
|
+
|
|
34
|
+
import { a, b as c, d } from 'module' ;
|
|
35
|
+
import {
|
|
36
|
+
fff,
|
|
37
|
+
ggg,
|
|
38
|
+
hhh,
|
|
39
|
+
iii,
|
|
40
|
+
jjj,
|
|
41
|
+
kkk,
|
|
42
|
+
lll
|
|
43
|
+
} from 'module/2'
|
|
44
|
+
`,
|
|
45
|
+
parserOptions: {
|
|
46
|
+
ecmaVersion: "latest",
|
|
47
|
+
sourceType: "module"
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
code: `
|
|
52
|
+
|
|
53
|
+
import { a, b as c, d } from 'module' ;
|
|
54
|
+
import { fff, ggg, hhh, iii, jjj, kkk, lll } from 'module/2'
|
|
55
|
+
`,
|
|
56
|
+
errors: [{
|
|
57
|
+
messageId: "not_match",
|
|
58
|
+
type: "ImportDeclaration",
|
|
59
|
+
line: 4,
|
|
60
|
+
column: 7
|
|
61
|
+
}],
|
|
62
|
+
options: [{
|
|
63
|
+
indent: " ",
|
|
64
|
+
maxLength: 10
|
|
65
|
+
}],
|
|
66
|
+
output: `
|
|
67
|
+
|
|
68
|
+
import { a, b as c, d } from 'module' ;
|
|
69
|
+
import {
|
|
70
|
+
fff,
|
|
71
|
+
ggg,
|
|
72
|
+
hhh,
|
|
73
|
+
iii,
|
|
74
|
+
jjj,
|
|
75
|
+
kkk,
|
|
76
|
+
lll
|
|
77
|
+
} from 'module/2'
|
|
78
|
+
`,
|
|
79
|
+
parserOptions: {
|
|
80
|
+
ecmaVersion: "latest",
|
|
81
|
+
sourceType: "module"
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
)
|
|
85
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict"
|
|
2
|
+
const { RuleTester } = require("eslint")
|
|
3
|
+
|
|
4
|
+
/** @type {RuleTester.ValidTestCase[]} */
|
|
5
|
+
const valid = []
|
|
6
|
+
/** @type {RuleTester.InvalidTestCase[]} */
|
|
7
|
+
const invalid = []
|
|
8
|
+
|
|
9
|
+
require("./pretty-imports/check_exports").module(valid, invalid)
|
|
10
|
+
require("./pretty-imports/check_imports").module(valid, invalid)
|
|
11
|
+
|
|
12
|
+
new RuleTester().run(
|
|
13
|
+
"pretty-imports",
|
|
14
|
+
require("../rules/pretty-imports"),
|
|
15
|
+
{
|
|
16
|
+
valid,
|
|
17
|
+
invalid
|
|
18
|
+
}
|
|
19
|
+
)
|
|
@@ -33,7 +33,6 @@ exports.module = (valid, invalid) => {
|
|
|
33
33
|
column: 18
|
|
34
34
|
}
|
|
35
35
|
],
|
|
36
|
-
options: [{ fixSameNames: true }],
|
|
37
36
|
output: `
|
|
38
37
|
var value = [ deferA ]
|
|
39
38
|
var value = [ pending_a ]
|
|
@@ -104,7 +103,6 @@ exports.module = (valid, invalid) => {
|
|
|
104
103
|
column: 15
|
|
105
104
|
}
|
|
106
105
|
],
|
|
107
|
-
options: [{ fixSameNames: true }],
|
|
108
106
|
output: `
|
|
109
107
|
deferA = deferB
|
|
110
108
|
pending_a = pending_b
|
|
@@ -144,7 +142,6 @@ exports.module = (valid, invalid) => {
|
|
|
144
142
|
column: 18
|
|
145
143
|
}
|
|
146
144
|
],
|
|
147
|
-
options: [{ fixSameNames: true }],
|
|
148
145
|
output: `
|
|
149
146
|
(camel_case = deferA) => {}
|
|
150
147
|
(snake_case = pending_a) => {}
|
|
@@ -178,7 +175,6 @@ exports.module = (valid, invalid) => {
|
|
|
178
175
|
column: 10
|
|
179
176
|
}
|
|
180
177
|
],
|
|
181
|
-
options: [{ fixSameNames: true }],
|
|
182
178
|
output: `
|
|
183
179
|
await deferA
|
|
184
180
|
await pending_a
|
|
@@ -230,7 +226,6 @@ exports.module = (valid, invalid) => {
|
|
|
230
226
|
column: 15
|
|
231
227
|
}
|
|
232
228
|
],
|
|
233
|
-
options: [{ fixSameNames: true }],
|
|
234
229
|
output: `
|
|
235
230
|
deferA = deferB
|
|
236
231
|
pending_a - pending_b
|
|
@@ -263,7 +258,6 @@ exports.module = (valid, invalid) => {
|
|
|
263
258
|
column: 4
|
|
264
259
|
}
|
|
265
260
|
],
|
|
266
|
-
options: [{ fixSameNames: true }],
|
|
267
261
|
output: `
|
|
268
262
|
deferA()
|
|
269
263
|
pending_a()
|
|
@@ -322,7 +316,6 @@ exports.module = (valid, invalid) => {
|
|
|
322
316
|
column: 22
|
|
323
317
|
}
|
|
324
318
|
],
|
|
325
|
-
options: [{ fixSameNames: true }],
|
|
326
319
|
output: `
|
|
327
320
|
test ? deferA : deferB
|
|
328
321
|
test ? pending_a : pending_b
|
|
@@ -341,7 +334,6 @@ exports.module = (valid, invalid) => {
|
|
|
341
334
|
line: 3,
|
|
342
335
|
column: 8
|
|
343
336
|
}],
|
|
344
|
-
options: [{ fixSameNames: true }],
|
|
345
337
|
output: `
|
|
346
338
|
export * as camelCase from "module"
|
|
347
339
|
var camel_case
|
|
@@ -362,6 +354,7 @@ exports.module = (valid, invalid) => {
|
|
|
362
354
|
line: 3,
|
|
363
355
|
column: 8
|
|
364
356
|
}],
|
|
357
|
+
options: [{ fixSameNames: false }],
|
|
365
358
|
output: `
|
|
366
359
|
export default camelCase
|
|
367
360
|
var camel_case
|
|
@@ -388,7 +381,6 @@ exports.module = (valid, invalid) => {
|
|
|
388
381
|
column: 8
|
|
389
382
|
},
|
|
390
383
|
],
|
|
391
|
-
options: [{ fixSameNames: true }],
|
|
392
384
|
output: `
|
|
393
385
|
export default camel_case
|
|
394
386
|
var camel_case
|
|
@@ -416,7 +408,6 @@ exports.module = (valid, invalid) => {
|
|
|
416
408
|
column: 19
|
|
417
409
|
},
|
|
418
410
|
],
|
|
419
|
-
options: [{ fixSameNames: true }],
|
|
420
411
|
output: `
|
|
421
412
|
export { default as camelCase, camelCase2 } from 'module'
|
|
422
413
|
var camel_case, camel_case2
|
|
@@ -451,7 +442,6 @@ exports.module = (valid, invalid) => {
|
|
|
451
442
|
column: 4
|
|
452
443
|
}
|
|
453
444
|
],
|
|
454
|
-
options: [{ fixSameNames: true }],
|
|
455
445
|
output: `
|
|
456
446
|
deferA
|
|
457
447
|
pending_a
|
|
@@ -489,7 +479,6 @@ exports.module = (valid, invalid) => {
|
|
|
489
479
|
column: 23
|
|
490
480
|
}
|
|
491
481
|
],
|
|
492
|
-
options: [{ fixSameNames: true }],
|
|
493
482
|
output: `
|
|
494
483
|
for (camel_case in deferA) {}
|
|
495
484
|
for (snake_case in pending_a) {}
|
|
@@ -553,7 +542,6 @@ exports.module = (valid, invalid) => {
|
|
|
553
542
|
column: 29
|
|
554
543
|
}
|
|
555
544
|
],
|
|
556
|
-
options: [{ fixSameNames: true }],
|
|
557
545
|
output: `
|
|
558
546
|
for (deferA; deferB; deferC) {}
|
|
559
547
|
for (pending_a; pending_b; pending_c) {}
|
|
@@ -616,7 +604,6 @@ exports.module = (valid, invalid) => {
|
|
|
616
604
|
column: 8
|
|
617
605
|
}
|
|
618
606
|
],
|
|
619
|
-
options: [{ fixSameNames: true }],
|
|
620
607
|
output: `
|
|
621
608
|
if (deferA) {}
|
|
622
609
|
if (pending_a) {}
|
|
@@ -671,7 +658,6 @@ exports.module = (valid, invalid) => {
|
|
|
671
658
|
column: 4
|
|
672
659
|
}
|
|
673
660
|
],
|
|
674
|
-
options: [{ fixSameNames: true }],
|
|
675
661
|
output: `
|
|
676
662
|
import { imported as camel_case, camelCase2, camelCase3 } from "module"
|
|
677
663
|
camel_case
|
|
@@ -722,7 +708,6 @@ exports.module = (valid, invalid) => {
|
|
|
722
708
|
column: 16
|
|
723
709
|
}
|
|
724
710
|
],
|
|
725
|
-
options: [{ fixSameNames: true }],
|
|
726
711
|
output: `
|
|
727
712
|
deferA && deferB
|
|
728
713
|
pending_a || pending_b
|
|
@@ -775,7 +760,6 @@ exports.module = (valid, invalid) => {
|
|
|
775
760
|
column: 11
|
|
776
761
|
}
|
|
777
762
|
],
|
|
778
|
-
options: [{ fixSameNames: true }],
|
|
779
763
|
output: `
|
|
780
764
|
deferA.camelCase
|
|
781
765
|
pending_a.camelCase
|
|
@@ -829,7 +813,6 @@ exports.module = (valid, invalid) => {
|
|
|
829
813
|
column: 8
|
|
830
814
|
}
|
|
831
815
|
],
|
|
832
|
-
options: [{ fixSameNames: true }],
|
|
833
816
|
output: `
|
|
834
817
|
new deferA
|
|
835
818
|
new pending_a
|
|
@@ -868,7 +851,6 @@ exports.module = (valid, invalid) => {
|
|
|
868
851
|
column: 18
|
|
869
852
|
}
|
|
870
853
|
],
|
|
871
|
-
options: [{ fixSameNames: true }],
|
|
872
854
|
output: `
|
|
873
855
|
var value = { camelCase: deferA }
|
|
874
856
|
var value = { key: pending_a }
|
|
@@ -896,7 +878,6 @@ exports.module = (valid, invalid) => {
|
|
|
896
878
|
column: 19
|
|
897
879
|
}
|
|
898
880
|
],
|
|
899
|
-
options: [{ fixSameNames: true }],
|
|
900
881
|
output: `
|
|
901
882
|
class ObjectB { camelCase = camelCase2 }
|
|
902
883
|
var camel_case, camel_case2
|
|
@@ -921,7 +902,6 @@ exports.module = (valid, invalid) => {
|
|
|
921
902
|
column: 13
|
|
922
903
|
}
|
|
923
904
|
],
|
|
924
|
-
options: [{ fixSameNames: true }],
|
|
925
905
|
output: `
|
|
926
906
|
var [ ...camel_case_a ] = value
|
|
927
907
|
var { ...camel_case_b } = value
|
|
@@ -953,7 +933,6 @@ exports.module = (valid, invalid) => {
|
|
|
953
933
|
column: 31
|
|
954
934
|
}
|
|
955
935
|
],
|
|
956
|
-
options: [{ fixSameNames: true }],
|
|
957
936
|
output: `
|
|
958
937
|
function func_a() { return deferA }
|
|
959
938
|
function func_b() { return pending_a }
|
|
@@ -986,7 +965,6 @@ exports.module = (valid, invalid) => {
|
|
|
986
965
|
column: 10
|
|
987
966
|
}
|
|
988
967
|
],
|
|
989
|
-
options: [{ fixSameNames: true }],
|
|
990
968
|
output: `
|
|
991
969
|
a, b, deferA
|
|
992
970
|
a, b, pending_a
|
|
@@ -1034,7 +1012,6 @@ exports.module = (valid, invalid) => {
|
|
|
1034
1012
|
column: 31
|
|
1035
1013
|
}
|
|
1036
1014
|
],
|
|
1037
|
-
options: [{ fixSameNames: true }],
|
|
1038
1015
|
output: `
|
|
1039
1016
|
var value = [ ...deferA, deferB ]
|
|
1040
1017
|
var value = [ ...pending_a, pending_b ]
|
|
@@ -1068,7 +1045,6 @@ exports.module = (valid, invalid) => {
|
|
|
1068
1045
|
column: 12
|
|
1069
1046
|
}
|
|
1070
1047
|
],
|
|
1071
|
-
options: [{ fixSameNames: true }],
|
|
1072
1048
|
output: `
|
|
1073
1049
|
switch (deferA) {}
|
|
1074
1050
|
switch (pending_a) {}
|
|
@@ -1101,7 +1077,6 @@ exports.module = (valid, invalid) => {
|
|
|
1101
1077
|
column: 25
|
|
1102
1078
|
}
|
|
1103
1079
|
],
|
|
1104
|
-
options: [{ fixSameNames: true }],
|
|
1105
1080
|
output: `
|
|
1106
1081
|
switch (cond) { case deferA: break }
|
|
1107
1082
|
switch (cond) { case pending_a: break }
|
|
@@ -1134,7 +1109,6 @@ exports.module = (valid, invalid) => {
|
|
|
1134
1109
|
column: 4
|
|
1135
1110
|
}
|
|
1136
1111
|
],
|
|
1137
|
-
options: [{ fixSameNames: true }],
|
|
1138
1112
|
output: `
|
|
1139
1113
|
deferA\`quasis\${expression}quasis\`
|
|
1140
1114
|
pending_a\`quasis\${expression}quasis\`
|
|
@@ -1168,7 +1142,6 @@ exports.module = (valid, invalid) => {
|
|
|
1168
1142
|
column: 10
|
|
1169
1143
|
}
|
|
1170
1144
|
],
|
|
1171
|
-
options: [{ fixSameNames: true }],
|
|
1172
1145
|
output: `
|
|
1173
1146
|
throw deferA
|
|
1174
1147
|
throw pending_a
|
|
@@ -1201,7 +1174,6 @@ exports.module = (valid, invalid) => {
|
|
|
1201
1174
|
column: 5
|
|
1202
1175
|
}
|
|
1203
1176
|
],
|
|
1204
|
-
options: [{ fixSameNames: true }],
|
|
1205
1177
|
output: `
|
|
1206
1178
|
+deferA
|
|
1207
1179
|
-pending_a
|
|
@@ -1234,7 +1206,6 @@ exports.module = (valid, invalid) => {
|
|
|
1234
1206
|
column: 4
|
|
1235
1207
|
}
|
|
1236
1208
|
],
|
|
1237
|
-
options: [{ fixSameNames: true }],
|
|
1238
1209
|
output: `
|
|
1239
1210
|
++deferA
|
|
1240
1211
|
--pending_a
|
|
@@ -1279,7 +1250,6 @@ exports.module = (valid, invalid) => {
|
|
|
1279
1250
|
column: 15
|
|
1280
1251
|
}
|
|
1281
1252
|
],
|
|
1282
|
-
options: [{ fixSameNames: true }],
|
|
1283
1253
|
output: `
|
|
1284
1254
|
var camel_case = deferA
|
|
1285
1255
|
var snake_case = pending_a
|
|
@@ -1318,7 +1288,6 @@ exports.module = (valid, invalid) => {
|
|
|
1318
1288
|
column: 11
|
|
1319
1289
|
}
|
|
1320
1290
|
],
|
|
1321
|
-
options: [{ fixSameNames: true }],
|
|
1322
1291
|
output: `
|
|
1323
1292
|
while (deferA) {}
|
|
1324
1293
|
while (pending_a) {}
|
|
@@ -1351,7 +1320,6 @@ exports.module = (valid, invalid) => {
|
|
|
1351
1320
|
column: 10
|
|
1352
1321
|
}
|
|
1353
1322
|
],
|
|
1354
|
-
options: [{ fixSameNames: true }],
|
|
1355
1323
|
output: `
|
|
1356
1324
|
with (deferA) {}
|
|
1357
1325
|
with (pending_a) {}
|
|
@@ -1384,7 +1352,6 @@ exports.module = (valid, invalid) => {
|
|
|
1384
1352
|
column: 31
|
|
1385
1353
|
}
|
|
1386
1354
|
],
|
|
1387
|
-
options: [{ fixSameNames: true }],
|
|
1388
1355
|
output: `
|
|
1389
1356
|
function* func_a() { yield deferA }
|
|
1390
1357
|
function* func_b() { yield pending_a }
|