eslint-plugin-lube 0.2.5 → 0.3.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # Eslint plugin lube
2
2
 
3
- | Rule | Code | Test |
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) |
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) |
3
+ | Rule | Docs | Code | Test |
4
+ |---|---|---|---|
5
+ | svelte-naming-convention | [docs](https://github.com/Artxe2/lube-series/blob/master/packages/eslint-plugin-lube/docs/svelte-naming-convention.md) | [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 | [docs](https://github.com/Artxe2/lube-series/blob/master/packages/eslint-plugin-lube/docs/pretty-imports.md) | [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) |
@@ -0,0 +1,73 @@
1
+ # pretty-imports
2
+ Enforces proper indentation for import and export statements.
3
+
4
+ ## options
5
+ ```js
6
+ schema: [{
7
+ properties: {
8
+ checkExports: {
9
+ type: "boolean",
10
+ default: true
11
+ },
12
+ checkImports: {
13
+ type: "boolean",
14
+ default: true
15
+ },
16
+ indent: {
17
+ type: "string",
18
+ default: "\t"
19
+ },
20
+ maxLength: {
21
+ type: "number",
22
+ default: 30
23
+ },
24
+ semicolon: {
25
+ type: "boolean",
26
+ default: false
27
+ }
28
+ },
29
+ type: "object"
30
+ }]
31
+ ```
32
+ ### checkExports
33
+ If it is `true`, it checks the export statement.
34
+ ### checkImports
35
+ If it is `true`, it checks the import statement.
36
+ ### indent
37
+ This is the character to be used for indentation.
38
+ ### maxLength
39
+ If the sum of the characters in the Specifier is greater than the set value, apply line breaks.
40
+ ```js
41
+ // If maxLength is less than or equal to 20, an error occurs.
42
+ export { fff, ggg, hhh, iii, jjj, kkk, lll } from 'module/2'
43
+ ```
44
+ ### semicolon
45
+ If it is `true`, insert a semicolon explicitly.
46
+
47
+ ## Valid
48
+ ```js
49
+ export { a, b as c, d } from 'module'
50
+ export { fff, ggg, hhh, iii, jjj, kkk, lll } from 'module/2'
51
+ import {
52
+ aaaaa_bbbbb,
53
+ aaaaa_ccccc,
54
+ aaaaa_ddddd
55
+ } from "module"
56
+ ```
57
+
58
+ ## Invalid
59
+ ```js
60
+ export { a, b as c, d } from 'module';
61
+ export {a, b as c, d} from 'module'
62
+ export {
63
+ a,
64
+ b as c,
65
+ d
66
+ } from 'module'
67
+ import { aaaaa_bbbbb, aaaaa_ccccc, aaaaa_ddddd } from "module"
68
+ import {
69
+ aaaaa_bbbbb,
70
+ aaaaa_ccccc,
71
+ aaaaa_ddddd
72
+ } from "module"
73
+ ```
@@ -0,0 +1,24 @@
1
+ # pretty-imports
2
+ Enforces proper indentation for import and export statements.
3
+
4
+ ## options
5
+ ```js
6
+ schema: undefined
7
+ ```
8
+
9
+ ## Valid
10
+ ```js
11
+ var v = func(
12
+ a
13
+ )
14
+ var v = /** @type {A} */(/** @type {B} */(/** @type {C} */(a)/**/)/**/)/**/
15
+ var v = /** @type {A} */(a)/**/()
16
+ var v = { b: /** @type {A} */(a)/**/ }
17
+ ```
18
+
19
+ ## Invalid
20
+ ```js
21
+ var v = /** @type {A} */( /** @type {B} */(/** @type {C} */((a))))
22
+ var v = { b: /** @type {A} */(a) }
23
+ var v = { b: /**@type {A}*/(a)/**/ }
24
+ ```
@@ -0,0 +1,48 @@
1
+ # svelte-naming-convention
2
+ Enforces snake_case with some symbols for variable declaration.
3
+ [svelte#code-conventions](https://github.com/sveltejs/svelte/blob/master/CONTRIBUTING.md#code-conventions)
4
+
5
+ ## options
6
+ ```js
7
+ schema: [{
8
+ properties: {
9
+ fixSameNames: {
10
+ type: "boolean",
11
+ default: true
12
+ },
13
+ },
14
+ type: "object"
15
+ }]
16
+ ```
17
+ ### fixSameNames
18
+ If set to `true`, an error will be returned if the variable name is the same, even in the case of function calls that are the target of `defer`.
19
+ ```js
20
+ myFunction() // Only in the case that fixSameNames is true, an error occurs.
21
+
22
+ // Identifier 'myFunction' does not match for svelte's naming conventions.
23
+ function myFunction() {
24
+
25
+ }
26
+ ```
27
+
28
+ ## Valid
29
+ ```js
30
+ var snake_case = 'Hello'
31
+ var snake1_2_3case_4 = 'Hello'
32
+ var SNAKE_CASE = 'Hello'
33
+ var SNAKE1_2_3CASE_4 = 'Hello'
34
+ var PascalCase = 'Hello'
35
+ var P1ascal2Case345 = 'Hello'
36
+ var __ = 'Hello'
37
+ var $$ = 'Hello'
38
+ var __snake_case$$ = 'Hello'
39
+ var $$snake_case$$ = 'Hello'
40
+ ```
41
+
42
+ ## Invalid
43
+ ```js
44
+ var camelCase = 'Hello'
45
+ var NO_SNAKE__CASE = 'Hello'
46
+ var NO_SNAKE_CASE_ = 'Hello'
47
+ var __camelCase$$ = 'Hello'
48
+ ```
package/index.js CHANGED
@@ -19,8 +19,6 @@ module.exports = {
19
19
  "after": true,
20
20
  "before": true
21
21
  }],
22
- "lube/svelte-naming-convention": "error",
23
- "lube/pretty-imports": "error",
24
22
  "max-len": ["warn", 120],
25
23
  "max-nested-callbacks": ["error", 3],
26
24
  "no-console": "warn",
@@ -42,12 +40,16 @@ module.exports = {
42
40
  }],
43
41
  "space-in-parens": ["error", "never"],
44
42
  "space-infix-ops": "error",
45
- "space-unary-ops": "error"
43
+ "space-unary-ops": "error",
44
+ "lube/pretty-imports": "error",
45
+ "lube/pretty-jsdoc-casting": "error",
46
+ "lube/svelte-naming-convention": "error",
46
47
  }
47
48
  }
48
49
  },
49
50
  rules: {
50
51
  "pretty-imports": require("./rules/pretty-imports"),
52
+ "pretty-jsdoc-casting": require("./rules/pretty-jsdoc-casting"),
51
53
  "svelte-naming-convention": require("./rules/svelte-naming-convention")
52
54
  }
53
55
  }
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.5"
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.6",
9
+ "@types/estree": "^1.0.3",
10
+ "@typescript-eslint/parser": "^6.8.0",
11
+ "eslint": "^8.52.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.3.0"
26
+ }
package/private.d.ts CHANGED
@@ -1,26 +1,34 @@
1
1
  import * as estree from "estree"
2
2
 
3
- export type ASTNode = {
4
- parent: ASTNode
3
+ export type BaseAstNode = {
4
+ parent: AstNode
5
5
  range: [number, number]
6
- } & (
6
+ }
7
+
8
+ export type AstNode = BaseAstNode & (
7
9
  estree.ArrayExpression & {
8
- elements: ASTNode[]
10
+ elements: AstNode[]
9
11
  }
10
12
  | estree.ArrayPattern & {
11
- elements: ASTNode[]
13
+ elements: AstNode[]
12
14
  }
13
15
  | estree.ArrowFunctionExpression & {
14
- body: ASTNode
15
- params: ASTNode[]
16
+ body: AstNode
17
+ params: AstNode[]
18
+ }
19
+ | estree.AssignmentExpression & {
20
+ left: AstNode
21
+ right: AstNode
16
22
  }
17
- | estree.AssignmentExpression
18
23
  | estree.AssignmentPattern
19
24
  | estree.AwaitExpression
20
25
  | estree.BinaryExpression
21
26
  | estree.BlockStatement
22
27
  | estree.BreakStatement
23
- | estree.CallExpression
28
+ | estree.CallExpression & {
29
+ callee: AstNode
30
+ arguments: AstNode[]
31
+ }
24
32
  | estree.CatchClause
25
33
  | estree.ChainExpression
26
34
  | estree.ClassBody
@@ -39,7 +47,7 @@ export type ASTNode = {
39
47
  raw: string
40
48
  value: string
41
49
  }
42
- specifiers: ASTNode[]
50
+ specifiers: AstNode[]
43
51
  }
44
52
  | estree.ExportSpecifier
45
53
  | estree.ExpressionStatement
@@ -47,12 +55,12 @@ export type ASTNode = {
47
55
  | estree.ForOfStatement
48
56
  | estree.ForStatement
49
57
  | estree.FunctionDeclaration & {
50
- body: ASTNode
51
- params: ASTNode[]
58
+ body: AstNode
59
+ params: AstNode[]
52
60
  }
53
61
  | estree.FunctionExpression & {
54
- body: ASTNode
55
- params: ASTNode[]
62
+ body: AstNode
63
+ params: AstNode[]
56
64
  }
57
65
  | estree.Identifier
58
66
  | estree.IfStatement
@@ -62,7 +70,7 @@ export type ASTNode = {
62
70
  raw: string
63
71
  value: string
64
72
  }
65
- specifiers: ASTNode[]
73
+ specifiers: AstNode[]
66
74
  }
67
75
  | estree.ImportDefaultSpecifier
68
76
  | estree.ImportExpression
@@ -74,21 +82,29 @@ export type ASTNode = {
74
82
  | estree.MemberExpression
75
83
  | estree.MetaProperty
76
84
  | estree.MethodDefinition
77
- | estree.NewExpression
85
+ | estree.NewExpression & {
86
+ callee: AstNode
87
+ arguments: AstNode[]
88
+ }
78
89
  | estree.ObjectExpression & {
79
- properties: ASTNode[]
90
+ properties: AstNode[]
80
91
  }
81
92
  | estree.ObjectPattern & {
82
- properties: ASTNode[]
93
+ properties: AstNode[]
83
94
  }
84
95
  | estree.PrivateIdentifier
85
96
  | estree.Program
86
- | estree.Property & { key: estree.Identifier }
97
+ | estree.Property & {
98
+ key: AstNode & estree.Identifier
99
+ value: AstNode
100
+ }
87
101
  | estree.PropertyDefinition
88
102
  | estree.RestElement
89
103
  | estree.ReturnStatement
90
104
  | estree.SequenceExpression
91
- | estree.SpreadElement
105
+ | estree.SpreadElement & {
106
+ argument: AstNode
107
+ }
92
108
  | estree.StaticBlock
93
109
  | estree.Super
94
110
  | estree.SwitchCase
@@ -102,8 +118,13 @@ export type ASTNode = {
102
118
  | estree.UnaryExpression
103
119
  | estree.UpdateExpression
104
120
  | estree.VariableDeclaration
105
- | estree.VariableDeclarator
121
+ | estree.VariableDeclarator & {
122
+ id: AstNode
123
+ init: AstNode
124
+ }
106
125
  | estree.WhileStatement
107
126
  | estree.WithStatement
108
127
  | estree.YieldExpression
109
- )
128
+ )
129
+
130
+ export type Comment = BaseAstNode & estree.Comment
@@ -3,13 +3,14 @@
3
3
  module.exports = {
4
4
  meta: {
5
5
  docs: {
6
- description: "Enforces pretty imports.",
6
+ description: "Enforces proper indentation for import and export statements.",
7
7
  recommended: true,
8
- url: "https://github.com/Artxe2/lube-series/blob/master/packages/eslint-plugin-lube/rules/pretty-imports.js"
8
+ url: "https://github.com/Artxe2/lube-series/blob/master/packages/eslint-plugin-lube/docs/pretty-imports.md"
9
9
  },
10
10
  fixable: "code",
11
11
  messages: {
12
- not_match: "This imports is not pretty"
12
+ exports: "This exports is not pretty",
13
+ imports: "This imports is not pretty"
13
14
  },
14
15
  schema: [{
15
16
  properties: {
@@ -36,21 +37,24 @@ module.exports = {
36
37
  },
37
38
  type: "object"
38
39
  }],
39
- type: "suggestion"
40
+ type: "layout"
40
41
  },
41
42
  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
43
+ const check_exports = /** @type {boolean} */(context.options[0]?.checkExports)/**/ ?? true
44
+ const check_imports = /** @type {boolean} */(context.options[0]?.checkImports)/**/ ?? true
45
+ const indent = /** @type {string} */(context.options[0]?.indent)/**/ ?? "\t"
46
+ const max_length = /** @type {number} */(context.options[0]?.maxLength)/**/ ?? 30
47
+ const semicolon = /** @type {number} */(context.options[0]?.semicolon)/**/ ?? false
47
48
 
48
49
  const source_code = context.sourceCode
49
50
  const text = source_code.text
50
51
 
51
52
  const indent_regex = /[ \t]*(?=[^\n]*$)/
52
53
  const _r_regex = /\r/g
53
- /** @param {number} index */
54
+ /**
55
+ * @param {number} index
56
+ * @returns {string}
57
+ */
54
58
  function get_indent(index) {
55
59
  return text.slice(0, index).match(indent_regex)?.[0] || ""
56
60
  }
@@ -62,11 +66,11 @@ module.exports = {
62
66
  * @returns {string}
63
67
  *//**
64
68
  * @overload
65
- * @param {import("../private").ASTNode} node
69
+ * @param {import("../private").AstNode} node
66
70
  * @returns {string}
67
71
  *//**
68
- * @param {import("../private").ASTNode|number} node_or_start
69
- * @param {number} [end]
72
+ * @param {import("../private").AstNode | number} node_or_start
73
+ * @param {number=} end
70
74
  * @returns {string}
71
75
  */
72
76
  function get_text(node_or_start, end) {
@@ -77,21 +81,26 @@ module.exports = {
77
81
  }
78
82
 
79
83
  /**
80
- * @param {import("../private").ASTNode} node
84
+ * @param {import("../private").AstNode} node
81
85
  * @param {string} corrected_text
86
+ * @param {"exports" | "imports"} message_id
87
+ * @returns {void}
82
88
  */
83
- function report(node, corrected_text) {
89
+ function report(node, corrected_text, message_id) {
84
90
  context.report({
85
91
  fix(fixer) {
86
92
  return fixer.replaceText(node, corrected_text)
87
93
  },
88
- messageId: "not_match",
89
- node: /** @type {import("estree").Node} */(node)
94
+ messageId: message_id,
95
+ node: /** @type {import("estree").Node} */(node)/**/
90
96
  })
91
97
  }
92
98
 
93
99
  return {
94
- /** @param {import("../private").ASTNode & import("estree").ExportNamedDeclaration} node */
100
+ /**
101
+ * @param {import("../private").AstNode & import("estree").ExportNamedDeclaration} node
102
+ * @returns {void}
103
+ */
95
104
  ExportNamedDeclaration(node) {
96
105
  if (check_exports && node.specifiers[0]?.type == "ExportSpecifier") {
97
106
  const line_indent = get_indent(node.range[0])
@@ -101,13 +110,13 @@ module.exports = {
101
110
  }
102
111
  let corrected_text = length > max_length
103
112
  ? `export {\n${line_indent + indent}${
104
- /** @type {import("../private").ASTNode[]} v */
105
- (node.specifiers).map(get_text)
113
+
114
+ /** @type {import("../private").AstNode[]} */(node.specifiers)/**/.map(get_text)
106
115
  .join(",\n" + line_indent + indent)
107
116
  }\n${line_indent}}`
108
117
  : `export { ${
109
- /** @type {import("../private").ASTNode[]} v */
110
- (node.specifiers).map(get_text).join(", ")
118
+
119
+ /** @type {import("../private").AstNode[]} */(node.specifiers)/**/.map(get_text).join(", ")
111
120
  } }`
112
121
  if (node.source) {
113
122
  corrected_text += " from " + node.source.raw
@@ -115,10 +124,13 @@ module.exports = {
115
124
  if (semicolon) {
116
125
  corrected_text += ";"
117
126
  }
118
- if (corrected_text != get_text(node)) report(node, corrected_text)
127
+ if (corrected_text != get_text(node)) report(node, corrected_text, "exports")
119
128
  }
120
129
  },
121
- /** @param {import("../private").ASTNode & import("estree").ImportDeclaration} node */
130
+ /**
131
+ * @param {import("../private").AstNode & import("estree").ImportDeclaration} node
132
+ * @returns {void}
133
+ */
122
134
  ImportDeclaration(node) {
123
135
  if (check_imports && node.specifiers[0]?.type == "ImportSpecifier") {
124
136
  const line_indent = get_indent(node.range[0])
@@ -128,18 +140,18 @@ module.exports = {
128
140
  }
129
141
  let corrected_text = length > max_length
130
142
  ? `import {\n${line_indent + indent}${
131
- /** @type {import("../private").ASTNode[]} v */
132
- (node.specifiers).map(get_text)
143
+
144
+ /** @type {import("../private").AstNode[]} */(node.specifiers)/**/.map(get_text)
133
145
  .join(",\n" + line_indent + indent)
134
146
  }\n${line_indent}} from ${node.source.raw}`
135
147
  : `import { ${
136
- /** @type {import("../private").ASTNode[]} v */
137
- (node.specifiers).map(get_text).join(", ")
148
+
149
+ /** @type {import("../private").AstNode[]} */(node.specifiers)/**/.map(get_text).join(", ")
138
150
  } } from ${node.source.raw}`
139
151
  if (semicolon) {
140
152
  corrected_text += ";"
141
153
  }
142
- if (corrected_text != get_text(node)) report(node, corrected_text)
154
+ if (corrected_text != get_text(node)) report(node, corrected_text, "imports")
143
155
  }
144
156
  }
145
157
  }