eslint-plugin-lube 0.2.2 → 0.2.4
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
package/rules/pretty-imports.js
CHANGED
|
@@ -49,11 +49,33 @@ module.exports = {
|
|
|
49
49
|
const text = source_code.text
|
|
50
50
|
|
|
51
51
|
const indent_regex = /[ \t]*(?=[^\n]*$)/
|
|
52
|
+
const _r_regex = /\r/g
|
|
52
53
|
/** @param {number} index */
|
|
53
54
|
function get_indent(index) {
|
|
54
55
|
return text.slice(0, index).match(indent_regex)?.[0] || ""
|
|
55
56
|
}
|
|
56
57
|
|
|
58
|
+
/**
|
|
59
|
+
* @overload
|
|
60
|
+
* @param {number} start
|
|
61
|
+
* @param {number} end
|
|
62
|
+
* @returns {string}
|
|
63
|
+
*//**
|
|
64
|
+
* @overload
|
|
65
|
+
* @param {import("../private").ASTNode} node
|
|
66
|
+
* @returns {string}
|
|
67
|
+
*//**
|
|
68
|
+
* @param {import("../private").ASTNode|number} node_or_start
|
|
69
|
+
* @param {number} [end]
|
|
70
|
+
* @returns {string}
|
|
71
|
+
*/
|
|
72
|
+
function get_text(node_or_start, end) {
|
|
73
|
+
const substr = typeof node_or_start == "number"
|
|
74
|
+
? text.slice(node_or_start, end)
|
|
75
|
+
: text.slice(node_or_start.range[0], node_or_start.range[1])
|
|
76
|
+
return substr.replace(_r_regex, "")
|
|
77
|
+
}
|
|
78
|
+
|
|
57
79
|
/**
|
|
58
80
|
* @param {import("../private").ASTNode} node
|
|
59
81
|
* @param {string} corrected_text
|
|
@@ -80,12 +102,12 @@ module.exports = {
|
|
|
80
102
|
let corrected_text = length > max_length
|
|
81
103
|
? `export {\n${line_indent + indent}${
|
|
82
104
|
/** @type {import("../private").ASTNode[]} v */
|
|
83
|
-
(node.specifiers).map(
|
|
105
|
+
(node.specifiers).map(get_text)
|
|
84
106
|
.join(",\n" + line_indent + indent)
|
|
85
107
|
}\n${line_indent}}`
|
|
86
108
|
: `export { ${
|
|
87
109
|
/** @type {import("../private").ASTNode[]} v */
|
|
88
|
-
(node.specifiers).map(
|
|
110
|
+
(node.specifiers).map(get_text).join(", ")
|
|
89
111
|
} }`
|
|
90
112
|
if (node.source) {
|
|
91
113
|
corrected_text += " from " + node.source.raw
|
|
@@ -107,17 +129,17 @@ module.exports = {
|
|
|
107
129
|
let corrected_text = length > max_length
|
|
108
130
|
? `import {\n${line_indent + indent}${
|
|
109
131
|
/** @type {import("../private").ASTNode[]} v */
|
|
110
|
-
(node.specifiers).map(
|
|
132
|
+
(node.specifiers).map(get_text)
|
|
111
133
|
.join(",\n" + line_indent + indent)
|
|
112
134
|
}\n${line_indent}} from ${node.source.raw}`
|
|
113
135
|
: `import { ${
|
|
114
136
|
/** @type {import("../private").ASTNode[]} v */
|
|
115
|
-
(node.specifiers).map(
|
|
137
|
+
(node.specifiers).map(get_text).join(", ")
|
|
116
138
|
} } from ${node.source.raw}`
|
|
117
139
|
if (semicolon) {
|
|
118
140
|
corrected_text += ";"
|
|
119
141
|
}
|
|
120
|
-
if (corrected_text !=
|
|
142
|
+
if (corrected_text != get_text(node)) report(node, corrected_text)
|
|
121
143
|
}
|
|
122
144
|
}
|
|
123
145
|
}
|
|
@@ -26,7 +26,7 @@ module.exports = {
|
|
|
26
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 = /^[_$]?[_$]?(?:[\da-z]+(?:_[\da-z]+)*\$?\$?)?$|^[A-Z][\dA-
|
|
29
|
+
const allow_regex = /^[_$]?[_$]?(?:[\da-z]+(?:_[\da-z]+)*\$?\$?)?$|^[A-Z](?:_?[\dA-Z]+)*$|^(?:[\dA-Z][\da-z]*)+$/
|
|
30
30
|
const fixable_name_regex = /^[_$]?[_$]?(?:[\dA-Za-z]+(?:_[\dA-Za-z]+)*\$?\$?)?$/
|
|
31
31
|
const fix_regex = /([\da-z]?)([A-Z][\dA-Z]*)/g
|
|
32
32
|
const camel_case_regex = /^[\da-z]+([A-Z][\da-z]*)*$/
|
|
@@ -30,5 +30,23 @@ exports.module = (valid, invalid) => {
|
|
|
30
30
|
}],
|
|
31
31
|
output: "var camel_case = 'Hello'"
|
|
32
32
|
},
|
|
33
|
+
{
|
|
34
|
+
code: "var NO_SNAKE__CASE = 'Hello'",
|
|
35
|
+
errors: [{
|
|
36
|
+
...error,
|
|
37
|
+
line: 1,
|
|
38
|
+
column: 5
|
|
39
|
+
}],
|
|
40
|
+
output: "var NO_SNAKE__CASE = 'Hello'"
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
code: "var NO_SNAKE_CASE_ = 'Hello'",
|
|
44
|
+
errors: [{
|
|
45
|
+
...error,
|
|
46
|
+
line: 1,
|
|
47
|
+
column: 5
|
|
48
|
+
}],
|
|
49
|
+
output: "var NO_SNAKE_CASE_ = 'Hello'"
|
|
50
|
+
},
|
|
33
51
|
)
|
|
34
52
|
}
|