eslint-plugin-lube 0.1.7 → 0.2.1

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 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.js) |
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
- module.exports = { rules: { "svelte-naming-convention": require("./rules/svelte-naming-convention") } }
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
@@ -3,12 +3,10 @@
3
3
  "bugs": {
4
4
  "url": "https://github.com/Artxe2/lube-series/issues"
5
5
  },
6
- "dependencies": {
7
- "@types/estree": "^1.0.1"
8
- },
9
6
  "description": "Eslint rules expand options",
10
7
  "devDependencies": {
11
8
  "@types/eslint": "^8.44.2",
9
+ "@types/estree": "^1.0.1",
12
10
  "@typescript-eslint/parser": "^6.3.0",
13
11
  "eslint": "^8.47.0",
14
12
  "mocha": "^10.2.0"
@@ -17,11 +15,12 @@
17
15
  "name": "eslint-plugin-lube",
18
16
  "repository": {
19
17
  "type": "git",
20
- "url": "https://github.com/Artxe2/lube-series"
18
+ "url": "https://github.com/Artxe2/lube-series",
19
+ "directory": "packages/eslint-plugin-lube"
21
20
  },
22
21
  "scripts": {
23
22
  "test": "mocha"
24
23
  },
25
24
  "type": "commonjs",
26
- "version": "0.1.7"
27
- }
25
+ "version": "0.2.1"
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
- interface ASTNode extends Node, Pattern {
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
- right: ASTNode
19
- shorthand: boolean
20
- type: string
21
- value: ASTNode
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,125 @@
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
+ semicolon: {
33
+ type: "boolean",
34
+ default: false
35
+ }
36
+ },
37
+ type: "object"
38
+ }],
39
+ type: "suggestion"
40
+ },
41
+ create(context) {
42
+ const check_exports = /** @type {boolean} */ (context.options[0]?.checkExports) ?? true
43
+ const check_imports = /** @type {boolean} */ (context.options[0]?.checkImports) ?? true
44
+ const indent = /** @type {string} */ (context.options[0]?.indent) ?? "\t"
45
+ const max_length = /** @type {number} */ (context.options[0]?.maxLength) ?? 30
46
+ const semicolon = /** @type {number} */ (context.options[0]?.semicolon) ?? false
47
+
48
+ const source_code = context.sourceCode
49
+ const text = source_code.text
50
+
51
+ const indent_regex = /[ \t]*(?=[^\n]*$)/
52
+ /** @param {number} index */
53
+ function get_indent(index) {
54
+ return text.slice(0, index).match(indent_regex)?.[0] || ""
55
+ }
56
+
57
+ /**
58
+ * @param {import("../private").ASTNode} node
59
+ * @param {string} corrected_text
60
+ */
61
+ function report(node, corrected_text) {
62
+ context.report({
63
+ fix(fixer) {
64
+ return fixer.replaceText(node, corrected_text)
65
+ },
66
+ messageId: "not_match",
67
+ node: /** @type {import("estree").Node} */(node)
68
+ })
69
+ }
70
+
71
+ return {
72
+ /** @param {import("../private").ASTNode & import("estree").ExportNamedDeclaration} node */
73
+ ExportNamedDeclaration(node) {
74
+ if (check_exports && node.specifiers[0]?.type == "ExportSpecifier") {
75
+ const line_indent = get_indent(node.range[0])
76
+ let length = 0
77
+ for (const s of node.specifiers) {
78
+ length += s.range[1] - s.range[0]
79
+ }
80
+ let corrected_text = length > max_length
81
+ ? `export {\n${line_indent + indent}${
82
+ /** @type {import("../private").ASTNode[]} v */
83
+ (node.specifiers).map(v => text.slice(v.range[0], v.range[1]))
84
+ .join(",\n" + line_indent + indent)
85
+ }\n${line_indent}}`
86
+ : `export { ${
87
+ /** @type {import("../private").ASTNode[]} v */
88
+ (node.specifiers).map(v => text.slice(v.range[0], v.range[1])).join(", ")
89
+ } }`
90
+ if (node.source) {
91
+ corrected_text += " from " + node.source.raw
92
+ }
93
+ if (semicolon) {
94
+ corrected_text += ";"
95
+ }
96
+ if (corrected_text != text.slice(node.range[0], node.range[1])) report(node, corrected_text)
97
+ }
98
+ },
99
+ /** @param {import("../private").ASTNode & import("estree").ImportDeclaration} node */
100
+ ImportDeclaration(node) {
101
+ if (check_imports && node.specifiers[0]?.type == "ImportSpecifier") {
102
+ const line_indent = get_indent(node.range[0])
103
+ let length = 0
104
+ for (const s of node.specifiers) {
105
+ length += s.range[1] - s.range[0]
106
+ }
107
+ let corrected_text = length > max_length
108
+ ? `import {\n${line_indent + indent}${
109
+ /** @type {import("../private").ASTNode[]} v */
110
+ (node.specifiers).map(v => text.slice(v.range[0], v.range[1]))
111
+ .join(",\n" + line_indent + indent)
112
+ }\n${line_indent}} from ${node.source.raw}`
113
+ : `import { ${
114
+ /** @type {import("../private").ASTNode[]} v */
115
+ (node.specifiers).map(v => text.slice(v.range[0], v.range[1])).join(", ")
116
+ } } from ${node.source.raw}`
117
+ if (semicolon) {
118
+ corrected_text += ";"
119
+ }
120
+ if (corrected_text != text.slice(node.range[0], node.range[1])) report(node, corrected_text)
121
+ }
122
+ }
123
+ }
124
+ }
125
+ }
@@ -15,7 +15,7 @@ module.exports = {
15
15
  properties: {
16
16
  fixSameNames: {
17
17
  type: "boolean",
18
- default: false
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 = /^[_$]?[_$]?(?:[0-9a-z]+(?:_[0-9a-z]+)*\$?\$?)?$|^[A-Z][0-9A-Z_]*$|^(?:[0-9A-Z][0-9a-z]*)+$/
30
- const fixable_name_regex = /^[_$]?[_$]?(?:[0-9A-Za-z]+(?:_[0-9A-Za-z]+)*\$?\$?)?$/
31
- const fix_regex = /([0-9a-z]?)([A-Z][0-9A-Z]*)/g
32
- const camel_case_regex = /^[0-9a-z]+([A-Z][0-9a-z]*)*$/
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: node.type == "PrivateIdentifier"
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,117 @@
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
+ {
8
+ code: `
9
+
10
+ export { a, b as c, d } from 'module'
11
+ export { fff, ggg, hhh, iii, jjj, kkk, lll } from 'module/2'
12
+ `,
13
+ options: [{ maxLength: 30 }],
14
+ parserOptions: {
15
+ ecmaVersion: "latest",
16
+ sourceType: "module"
17
+ }
18
+ },
19
+ {
20
+ code: `
21
+ var a, b, c
22
+ export { a, b, c };
23
+ `,
24
+ options: [{ semicolon: true }],
25
+ parserOptions: {
26
+ ecmaVersion: "latest",
27
+ sourceType: "module"
28
+ }
29
+ }
30
+ )
31
+ invalid.push(
32
+ {
33
+ code: `
34
+
35
+ export { a, b as c, d } from 'module'
36
+ export { fff, ggg, hhh, iii, jjj, kkk, lll } from 'module/2'
37
+ `,
38
+ errors: [
39
+ {
40
+ messageId: "not_match",
41
+ type: "ExportNamedDeclaration",
42
+ line: 3,
43
+ column: 4
44
+ },
45
+ {
46
+ messageId: "not_match",
47
+ type: "ExportNamedDeclaration",
48
+ line: 4,
49
+ column: 7
50
+ }
51
+ ],
52
+ options: [{
53
+ maxLength: 10,
54
+ semicolon: true
55
+ }],
56
+ output: `
57
+
58
+ export { a, b as c, d } from 'module';
59
+ export {
60
+ fff,
61
+ ggg,
62
+ hhh,
63
+ iii,
64
+ jjj,
65
+ kkk,
66
+ lll
67
+ } from 'module/2';
68
+ `,
69
+ parserOptions: {
70
+ ecmaVersion: "latest",
71
+ sourceType: "module"
72
+ }
73
+ },
74
+ {
75
+ code: `
76
+
77
+ export { a, b as c, d } from 'module' ;
78
+ export { fff, ggg, hhh, iii, jjj, kkk, lll } from 'module/2'
79
+ `,
80
+ errors: [
81
+ {
82
+ messageId: "not_match",
83
+ type: "ExportNamedDeclaration",
84
+ line: 3,
85
+ column: 4
86
+ },
87
+ {
88
+ messageId: "not_match",
89
+ type: "ExportNamedDeclaration",
90
+ line: 4,
91
+ column: 7
92
+ }
93
+ ],
94
+ options: [{
95
+ indent: " ",
96
+ maxLength: 10
97
+ }],
98
+ output: `
99
+
100
+ export { a, b as c, d } from 'module'
101
+ export {
102
+ fff,
103
+ ggg,
104
+ hhh,
105
+ iii,
106
+ jjj,
107
+ kkk,
108
+ lll
109
+ } from 'module/2'
110
+ `,
111
+ parserOptions: {
112
+ ecmaVersion: "latest",
113
+ sourceType: "module"
114
+ }
115
+ }
116
+ )
117
+ }
@@ -0,0 +1,119 @@
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
+ {
8
+ code: `
9
+
10
+ import { a, b as c, d } from 'module'
11
+ import { fff, ggg, hhh, iii, jjj, kkk, lll } from 'module/2'
12
+ `,
13
+ options: [{ maxLength: 30 }],
14
+ parserOptions: {
15
+ ecmaVersion: "latest",
16
+ sourceType: "module"
17
+ }
18
+ },
19
+ {
20
+ code: `
21
+ import {
22
+ aaaaa_bbbbb,
23
+ aaaaa_ccccc,
24
+ aaaaa_ddddd
25
+ } from "module";`,
26
+ options: [{ semicolon: true }],
27
+ parserOptions: {
28
+ ecmaVersion: "latest",
29
+ sourceType: "module"
30
+ }
31
+ }
32
+ )
33
+ invalid.push(
34
+ {
35
+ code: `
36
+
37
+ import { a, b as c, d } from 'module'
38
+ import { fff, ggg, hhh, iii, jjj, kkk, lll } from 'module/2'
39
+ `,
40
+ errors: [
41
+ {
42
+ messageId: "not_match",
43
+ type: "ImportDeclaration",
44
+ line: 3,
45
+ column: 4
46
+ },
47
+ {
48
+ messageId: "not_match",
49
+ type: "ImportDeclaration",
50
+ line: 4,
51
+ column: 7
52
+ }
53
+ ],
54
+ options: [{
55
+ maxLength: 10,
56
+ semicolon: true
57
+ }],
58
+ output: `
59
+
60
+ import { a, b as c, d } from 'module';
61
+ import {
62
+ fff,
63
+ ggg,
64
+ hhh,
65
+ iii,
66
+ jjj,
67
+ kkk,
68
+ lll
69
+ } from 'module/2';
70
+ `,
71
+ parserOptions: {
72
+ ecmaVersion: "latest",
73
+ sourceType: "module"
74
+ }
75
+ },
76
+ {
77
+ code: `
78
+
79
+ import { a, b as c, d } from 'module' ;
80
+ import { fff, ggg, hhh, iii, jjj, kkk, lll } from 'module/2'
81
+ `,
82
+ errors: [
83
+ {
84
+ messageId: "not_match",
85
+ type: "ImportDeclaration",
86
+ line: 3,
87
+ column: 4
88
+ },
89
+ {
90
+ messageId: "not_match",
91
+ type: "ImportDeclaration",
92
+ line: 4,
93
+ column: 7
94
+ }
95
+ ],
96
+ options: [{
97
+ indent: " ",
98
+ maxLength: 10
99
+ }],
100
+ output: `
101
+
102
+ import { a, b as c, d } from 'module'
103
+ import {
104
+ fff,
105
+ ggg,
106
+ hhh,
107
+ iii,
108
+ jjj,
109
+ kkk,
110
+ lll
111
+ } from 'module/2'
112
+ `,
113
+ parserOptions: {
114
+ ecmaVersion: "latest",
115
+ sourceType: "module"
116
+ }
117
+ }
118
+ )
119
+ }
@@ -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 }