eslint-plugin-lube 0.2.0 → 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/package.json CHANGED
@@ -1,26 +1,26 @@
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
- }
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.1"
26
+ }
package/private.d.ts CHANGED
@@ -34,7 +34,7 @@ export type ASTNode = {
34
34
  | estree.ExportAllDeclaration
35
35
  | estree.ExportDefaultDeclaration
36
36
  | estree.ExportNamedDeclaration & {
37
- source: estree.SimpleLiteral & {
37
+ source?: estree.SimpleLiteral & {
38
38
  range: [number, number]
39
39
  raw: string
40
40
  value: string
@@ -28,6 +28,10 @@ module.exports = {
28
28
  maxLength: {
29
29
  type: "number",
30
30
  default: 30
31
+ },
32
+ semicolon: {
33
+ type: "boolean",
34
+ default: false
31
35
  }
32
36
  },
33
37
  type: "object"
@@ -39,6 +43,8 @@ module.exports = {
39
43
  const check_imports = /** @type {boolean} */ (context.options[0]?.checkImports) ?? true
40
44
  const indent = /** @type {string} */ (context.options[0]?.indent) ?? "\t"
41
45
  const max_length = /** @type {number} */ (context.options[0]?.maxLength) ?? 30
46
+ const semicolon = /** @type {number} */ (context.options[0]?.semicolon) ?? false
47
+
42
48
  const source_code = context.sourceCode
43
49
  const text = source_code.text
44
50
 
@@ -71,16 +77,22 @@ module.exports = {
71
77
  for (const s of node.specifiers) {
72
78
  length += s.range[1] - s.range[0]
73
79
  }
74
- const corrected_text = length > max_length
80
+ let corrected_text = length > max_length
75
81
  ? `export {\n${line_indent + indent}${
76
82
  /** @type {import("../private").ASTNode[]} v */
77
83
  (node.specifiers).map(v => text.slice(v.range[0], v.range[1]))
78
84
  .join(",\n" + line_indent + indent)
79
- }\n${line_indent}} from ${text.slice(node.source.range[0], node.range[1])}`
85
+ }\n${line_indent}}`
80
86
  : `export { ${
81
87
  /** @type {import("../private").ASTNode[]} v */
82
88
  (node.specifiers).map(v => text.slice(v.range[0], v.range[1])).join(", ")
83
- } } from ${text.slice(node.source.range[0], node.range[1])}`
89
+ } }`
90
+ if (node.source) {
91
+ corrected_text += " from " + node.source.raw
92
+ }
93
+ if (semicolon) {
94
+ corrected_text += ";"
95
+ }
84
96
  if (corrected_text != text.slice(node.range[0], node.range[1])) report(node, corrected_text)
85
97
  }
86
98
  },
@@ -92,16 +104,19 @@ module.exports = {
92
104
  for (const s of node.specifiers) {
93
105
  length += s.range[1] - s.range[0]
94
106
  }
95
- const corrected_text = length > max_length
107
+ let corrected_text = length > max_length
96
108
  ? `import {\n${line_indent + indent}${
97
109
  /** @type {import("../private").ASTNode[]} v */
98
110
  (node.specifiers).map(v => text.slice(v.range[0], v.range[1]))
99
111
  .join(",\n" + line_indent + indent)
100
- }\n${line_indent}} from ${text.slice(node.source.range[0], node.range[1])}`
112
+ }\n${line_indent}} from ${node.source.raw}`
101
113
  : `import { ${
102
114
  /** @type {import("../private").ASTNode[]} v */
103
115
  (node.specifiers).map(v => text.slice(v.range[0], v.range[1])).join(", ")
104
- } } from ${text.slice(node.source.range[0], node.range[1])}`
116
+ } } from ${node.source.raw}`
117
+ if (semicolon) {
118
+ corrected_text += ";"
119
+ }
105
120
  if (corrected_text != text.slice(node.range[0], node.range[1])) report(node, corrected_text)
106
121
  }
107
122
  }
@@ -3,35 +3,59 @@
3
3
  * @param {import("eslint").RuleTester.InvalidTestCase[]} invalid
4
4
  */
5
5
  exports.module = (valid, invalid) => {
6
- valid.push({
7
- code: `
6
+ valid.push(
7
+ {
8
+ code: `
8
9
 
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"
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
+ }
16
29
  }
17
- })
30
+ )
18
31
  invalid.push(
19
32
  {
20
33
  code: `
21
34
 
22
- export { a, b as c, d } from 'module' ;
35
+ export { a, b as c, d } from 'module'
23
36
  export { fff, ggg, hhh, iii, jjj, kkk, lll } from 'module/2'
24
37
  `,
25
- errors: [{
26
- messageId: "not_match",
27
- type: "ExportNamedDeclaration",
28
- line: 4,
29
- column: 7
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
30
55
  }],
31
- options: [{ maxLength: 10 }],
32
56
  output: `
33
57
 
34
- export { a, b as c, d } from 'module' ;
58
+ export { a, b as c, d } from 'module';
35
59
  export {
36
60
  fff,
37
61
  ggg,
@@ -40,7 +64,7 @@ exports.module = (valid, invalid) => {
40
64
  jjj,
41
65
  kkk,
42
66
  lll
43
- } from 'module/2'
67
+ } from 'module/2';
44
68
  `,
45
69
  parserOptions: {
46
70
  ecmaVersion: "latest",
@@ -53,19 +77,27 @@ exports.module = (valid, invalid) => {
53
77
  export { a, b as c, d } from 'module' ;
54
78
  export { fff, ggg, hhh, iii, jjj, kkk, lll } from 'module/2'
55
79
  `,
56
- errors: [{
57
- messageId: "not_match",
58
- type: "ExportNamedDeclaration",
59
- line: 4,
60
- column: 7
61
- }],
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
+ ],
62
94
  options: [{
63
95
  indent: " ",
64
96
  maxLength: 10
65
97
  }],
66
98
  output: `
67
99
 
68
- export { a, b as c, d } from 'module' ;
100
+ export { a, b as c, d } from 'module'
69
101
  export {
70
102
  fff,
71
103
  ggg,
@@ -3,35 +3,61 @@
3
3
  * @param {import("eslint").RuleTester.InvalidTestCase[]} invalid
4
4
  */
5
5
  exports.module = (valid, invalid) => {
6
- valid.push({
7
- code: `
6
+ valid.push(
7
+ {
8
+ code: `
8
9
 
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"
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
+ }
16
31
  }
17
- })
32
+ )
18
33
  invalid.push(
19
34
  {
20
35
  code: `
21
36
 
22
- import { a, b as c, d } from 'module' ;
37
+ import { a, b as c, d } from 'module'
23
38
  import { fff, ggg, hhh, iii, jjj, kkk, lll } from 'module/2'
24
39
  `,
25
- errors: [{
26
- messageId: "not_match",
27
- type: "ImportDeclaration",
28
- line: 4,
29
- column: 7
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
30
57
  }],
31
- options: [{ maxLength: 10 }],
32
58
  output: `
33
59
 
34
- import { a, b as c, d } from 'module' ;
60
+ import { a, b as c, d } from 'module';
35
61
  import {
36
62
  fff,
37
63
  ggg,
@@ -40,7 +66,7 @@ exports.module = (valid, invalid) => {
40
66
  jjj,
41
67
  kkk,
42
68
  lll
43
- } from 'module/2'
69
+ } from 'module/2';
44
70
  `,
45
71
  parserOptions: {
46
72
  ecmaVersion: "latest",
@@ -53,19 +79,27 @@ exports.module = (valid, invalid) => {
53
79
  import { a, b as c, d } from 'module' ;
54
80
  import { fff, ggg, hhh, iii, jjj, kkk, lll } from 'module/2'
55
81
  `,
56
- errors: [{
57
- messageId: "not_match",
58
- type: "ImportDeclaration",
59
- line: 4,
60
- column: 7
61
- }],
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
+ ],
62
96
  options: [{
63
97
  indent: " ",
64
98
  maxLength: 10
65
99
  }],
66
100
  output: `
67
101
 
68
- import { a, b as c, d } from 'module' ;
102
+ import { a, b as c, d } from 'module'
69
103
  import {
70
104
  fff,
71
105
  ggg,