eslint-plugin-lube 0.4.3 → 0.5.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/index.js +126 -125
- package/package.json +39 -31
- package/rules/pretty-imports.js +15 -15
- package/rules/pretty-jsdoc-casting.js +37 -29
- package/rules/pretty-sequence.js +61 -52
- package/rules/svelte-naming-convention.js +19 -19
- package/test/pretty-imports/ExportNamedDeclaration.js +32 -24
- package/test/pretty-imports/ImportDeclaration.js +32 -24
- package/test/pretty-imports.js +3 -3
- package/test/pretty-jsdoc-casting/case_by_expression.js +73 -25
- package/test/pretty-jsdoc-casting/various_situations.js +31 -11
- package/test/pretty-jsdoc-casting.js +3 -3
- package/test/pretty-sequence/case_by_node_type.js +62 -30
- package/test/pretty-sequence/case_by_option.js +31 -15
- package/test/pretty-sequence/various_situations.js +34 -9
- package/test/pretty-sequence.js +3 -3
- package/test/svelte-naming-convention/basic_snake_case.js +21 -8
- package/test/svelte-naming-convention/case_by_identifier.js +761 -195
- package/test/svelte-naming-convention/snake_case_with_symbols.js +28 -7
- package/test/svelte-naming-convention.js +3 -3
- package/tsconfig.json +10 -2
- package/types/index.d.ts +15 -0
- package/types/index.d.ts.map +1 -0
- package/types/rules/pretty-imports.d.ts +3 -0
- package/types/rules/pretty-imports.d.ts.map +1 -0
- package/types/rules/pretty-jsdoc-casting.d.ts +3 -0
- package/types/rules/pretty-jsdoc-casting.d.ts.map +1 -0
- package/types/rules/pretty-sequence.d.ts +3 -0
- package/types/rules/pretty-sequence.d.ts.map +1 -0
- package/types/rules/svelte-naming-convention.d.ts +3 -0
- package/types/rules/svelte-naming-convention.d.ts.map +1 -0
- package/types/test/pretty-imports/ExportNamedDeclaration.d.ts +2 -0
- package/types/test/pretty-imports/ExportNamedDeclaration.d.ts.map +1 -0
- package/types/test/pretty-imports/ImportDeclaration.d.ts +2 -0
- package/types/test/pretty-imports/ImportDeclaration.d.ts.map +1 -0
- package/types/test/pretty-imports.d.ts +2 -0
- package/types/test/pretty-imports.d.ts.map +1 -0
- package/types/test/pretty-jsdoc-casting/case_by_expression.d.ts +2 -0
- package/types/test/pretty-jsdoc-casting/case_by_expression.d.ts.map +1 -0
- package/types/test/pretty-jsdoc-casting/various_situations.d.ts +2 -0
- package/types/test/pretty-jsdoc-casting/various_situations.d.ts.map +1 -0
- package/types/test/pretty-jsdoc-casting.d.ts +2 -0
- package/types/test/pretty-jsdoc-casting.d.ts.map +1 -0
- package/types/test/pretty-sequence/case_by_node_type.d.ts +2 -0
- package/types/test/pretty-sequence/case_by_node_type.d.ts.map +1 -0
- package/types/test/pretty-sequence/case_by_option.d.ts +2 -0
- package/types/test/pretty-sequence/case_by_option.d.ts.map +1 -0
- package/types/test/pretty-sequence/various_situations.d.ts +2 -0
- package/types/test/pretty-sequence/various_situations.d.ts.map +1 -0
- package/types/test/pretty-sequence.d.ts +2 -0
- package/types/test/pretty-sequence.d.ts.map +1 -0
- package/types/test/svelte-naming-convention/basic_snake_case.d.ts +2 -0
- package/types/test/svelte-naming-convention/basic_snake_case.d.ts.map +1 -0
- package/types/test/svelte-naming-convention/case_by_identifier.d.ts +2 -0
- package/types/test/svelte-naming-convention/case_by_identifier.d.ts.map +1 -0
- package/types/test/svelte-naming-convention/snake_case_with_symbols.d.ts +2 -0
- package/types/test/svelte-naming-convention/snake_case_with_symbols.d.ts.map +1 -0
- package/types/test/svelte-naming-convention.d.ts +2 -0
- package/types/test/svelte-naming-convention.d.ts.map +1 -0
package/index.js
CHANGED
|
@@ -1,125 +1,126 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
"
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
"
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
"
|
|
113
|
-
"
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
1
|
+
const plugin = {
|
|
2
|
+
configs: { plugins: {}, rules: {} },
|
|
3
|
+
meta: { name: "eslint-plugin-lube" },
|
|
4
|
+
rules: {
|
|
5
|
+
"pretty-imports": require("./rules/pretty-imports"),
|
|
6
|
+
"pretty-jsdoc-casting": require("./rules/pretty-jsdoc-casting"),
|
|
7
|
+
"pretty-sequence": require("./rules/pretty-sequence"),
|
|
8
|
+
"svelte-naming-convention": require(
|
|
9
|
+
"./rules/svelte-naming-convention"
|
|
10
|
+
)
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
Object.assign(
|
|
15
|
+
plugin.configs,
|
|
16
|
+
{
|
|
17
|
+
plugins: { lube: plugin },
|
|
18
|
+
rules: {
|
|
19
|
+
"array-bracket-newline": [ "error", "consistent" ],
|
|
20
|
+
"array-element-newline": [ "error", "consistent" ],
|
|
21
|
+
"arrow-parens": [ "error", "as-needed" ],
|
|
22
|
+
"arrow-spacing": [
|
|
23
|
+
"error",
|
|
24
|
+
{ "after": true, "before": true }
|
|
25
|
+
],
|
|
26
|
+
"block-spacing": [ "error", "always" ],
|
|
27
|
+
"brace-style": [ "error", "1tbs" ],
|
|
28
|
+
"comma-dangle": [ "error", "never" ],
|
|
29
|
+
"comma-spacing": [
|
|
30
|
+
"error",
|
|
31
|
+
{ "after": true, "before": false }
|
|
32
|
+
],
|
|
33
|
+
"comma-style": [ "error", "last" ],
|
|
34
|
+
"computed-property-spacing": [ "error", "never" ],
|
|
35
|
+
"dot-location": [ "error", "property" ],
|
|
36
|
+
"eol-last": [ "error", "never" ],
|
|
37
|
+
"func-call-spacing": [ "error", "never" ],
|
|
38
|
+
"function-call-argument-newline": [ "error", "consistent" ],
|
|
39
|
+
"generator-star-spacing": [ "error", "after" ],
|
|
40
|
+
"indent": [ "error", "tab" ],
|
|
41
|
+
"jsx-quotes": [ "error", "prefer-double" ],
|
|
42
|
+
"key-spacing": [
|
|
43
|
+
"error",
|
|
44
|
+
{
|
|
45
|
+
"afterColon": true,
|
|
46
|
+
"beforeColon": false
|
|
47
|
+
}
|
|
48
|
+
],
|
|
49
|
+
"keyword-spacing": [
|
|
50
|
+
"error",
|
|
51
|
+
{ "after": true, "before": true }
|
|
52
|
+
],
|
|
53
|
+
"lube/pretty-imports": "error",
|
|
54
|
+
"lube/pretty-jsdoc-casting": "error",
|
|
55
|
+
"lube/pretty-sequence": "error",
|
|
56
|
+
"lube/svelte-naming-convention": "error",
|
|
57
|
+
"max-len": [ "warn", 120 ],
|
|
58
|
+
"max-statements-per-line": [ "error", { "max": 1 } ],
|
|
59
|
+
"multiline-ternary": [ "error", "always-multiline" ],
|
|
60
|
+
"newline-per-chained-call": [
|
|
61
|
+
"error",
|
|
62
|
+
{ "ignoreChainWithDepth": 2 }
|
|
63
|
+
],
|
|
64
|
+
"no-await-in-loop": "warn",
|
|
65
|
+
"no-case-declarations": "off",
|
|
66
|
+
"no-console": "warn",
|
|
67
|
+
"no-duplicate-imports": "error",
|
|
68
|
+
"no-lonely-if": "error",
|
|
69
|
+
"no-multi-spaces": "error",
|
|
70
|
+
"no-new-native-nonconstructor": "error",
|
|
71
|
+
"no-self-compare": "error",
|
|
72
|
+
"no-shadow": "error",
|
|
73
|
+
"no-shadow-restricted-names": "error",
|
|
74
|
+
"no-trailing-spaces": [
|
|
75
|
+
"error",
|
|
76
|
+
{
|
|
77
|
+
"ignoreComments": false,
|
|
78
|
+
"skipBlankLines": false
|
|
79
|
+
}
|
|
80
|
+
],
|
|
81
|
+
"object-curly-newline": [ "error", { "consistent": true } ],
|
|
82
|
+
"object-curly-spacing": [ "error", "always" ],
|
|
83
|
+
"one-var": [ "error", "never" ],
|
|
84
|
+
"operator-linebreak": [ "error", "before" ],
|
|
85
|
+
"prefer-const": [
|
|
86
|
+
"warn",
|
|
87
|
+
{
|
|
88
|
+
"destructuring": "all",
|
|
89
|
+
"ignoreReadBeforeAssign": false
|
|
90
|
+
}
|
|
91
|
+
],
|
|
92
|
+
"quotes": [ "error", "double" ],
|
|
93
|
+
"rest-spread-spacing": [ "error", "never" ],
|
|
94
|
+
"semi": [ "error", "never" ],
|
|
95
|
+
"semi-spacing": [
|
|
96
|
+
"error",
|
|
97
|
+
{ "after": true, "before": false }
|
|
98
|
+
],
|
|
99
|
+
"semi-style": [ "error", "first" ],
|
|
100
|
+
"space-before-blocks": [ "error", "always" ],
|
|
101
|
+
"space-before-function-paren": [
|
|
102
|
+
"error",
|
|
103
|
+
{
|
|
104
|
+
"anonymous": "never",
|
|
105
|
+
"asyncArrow": "always",
|
|
106
|
+
"named": "never"
|
|
107
|
+
}
|
|
108
|
+
],
|
|
109
|
+
"space-in-parens": [ "error", "never" ],
|
|
110
|
+
"space-infix-ops": [ "error", { "int32Hint": true } ],
|
|
111
|
+
"space-unary-ops": [
|
|
112
|
+
"error",
|
|
113
|
+
{ "nonwords": false, "words": true }
|
|
114
|
+
],
|
|
115
|
+
"switch-colon-spacing": [
|
|
116
|
+
"error",
|
|
117
|
+
{ "after": true, "before": false }
|
|
118
|
+
],
|
|
119
|
+
"template-curly-spacing": [ "error", "never" ],
|
|
120
|
+
"template-tag-spacing": [ "error", "never" ],
|
|
121
|
+
"yield-star-spacing": [ "error", "after" ]
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
)
|
|
125
|
+
|
|
126
|
+
module.exports = plugin
|
package/package.json
CHANGED
|
@@ -1,32 +1,40 @@
|
|
|
1
|
-
{
|
|
2
|
-
"author": "artxe2",
|
|
3
|
-
"bugs": {
|
|
4
|
-
"url": "https://github.com/Artxe2/lube-series/issues"
|
|
5
|
-
},
|
|
6
|
-
"description": "Full fixable rules for auto-formatting with ESLint only without Prettier",
|
|
7
|
-
"devDependencies": {
|
|
8
|
-
"@types/eslint": "^
|
|
9
|
-
"@types/estree": "^1.0.
|
|
10
|
-
"@typescript-eslint/parser": "^
|
|
11
|
-
"eslint": "^
|
|
12
|
-
"mocha": "^
|
|
13
|
-
"typescript": "^5.
|
|
14
|
-
},
|
|
15
|
-
"keywords": [
|
|
16
|
-
"eslint-plugin",
|
|
17
|
-
"lube",
|
|
18
|
-
"eslint-plugin-lube",
|
|
19
|
-
"prettier",
|
|
20
|
-
"jsdoc"
|
|
21
|
-
],
|
|
22
|
-
"license": "MIT",
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
|
|
26
|
-
"
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
1
|
+
{
|
|
2
|
+
"author": "artxe2",
|
|
3
|
+
"bugs": {
|
|
4
|
+
"url": "https://github.com/Artxe2/lube-series/issues"
|
|
5
|
+
},
|
|
6
|
+
"description": "Full fixable rules for auto-formatting with ESLint only without Prettier",
|
|
7
|
+
"devDependencies": {
|
|
8
|
+
"@types/eslint": "^9.6.1",
|
|
9
|
+
"@types/estree": "^1.0.8",
|
|
10
|
+
"@typescript-eslint/parser": "^8.35.0",
|
|
11
|
+
"eslint": "^9.29.0",
|
|
12
|
+
"mocha": "^11.7.0",
|
|
13
|
+
"typescript": "^5.8.3"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"eslint-plugin",
|
|
17
|
+
"lube",
|
|
18
|
+
"eslint-plugin-lube",
|
|
19
|
+
"prettier",
|
|
20
|
+
"jsdoc"
|
|
21
|
+
],
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"main": "index.js",
|
|
24
|
+
"name": "eslint-plugin-lube",
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"eslint": ">=9.0.0"
|
|
27
|
+
},
|
|
28
|
+
"repository": {
|
|
29
|
+
"directory": "packages/eslint-plugin-lube",
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "https://github.com/Artxe2/lube-series"
|
|
32
|
+
},
|
|
33
|
+
"scripts": {
|
|
34
|
+
"dts": "node ../../scripts/tsc_with_clean.js eslint-plugin-lube",
|
|
35
|
+
"test": "mocha"
|
|
36
|
+
},
|
|
37
|
+
"type": "commonjs",
|
|
38
|
+
"types": "types/index.d.ts",
|
|
39
|
+
"version": "0.5.1"
|
|
32
40
|
}
|
package/rules/pretty-imports.js
CHANGED
|
@@ -28,17 +28,17 @@ module.exports = {
|
|
|
28
28
|
},
|
|
29
29
|
create(context) {
|
|
30
30
|
/** @type {import("../private").RuleOptions["pretty-imports"]} */
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
31
|
+
const option = context.options[0]
|
|
32
|
+
const check_exports = option?.checkExports ?? true
|
|
33
|
+
const check_imports = option?.checkImports ?? true
|
|
34
|
+
const indent = option?.indent ?? "\t"
|
|
35
|
+
const max_length = option?.maxLength ?? 30
|
|
36
|
+
const semicolon = option?.semicolon ?? false
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
38
|
+
const source_code = context.sourceCode
|
|
39
|
+
const text = source_code.text
|
|
40
|
+
const indent_regex = /[ \t]*(?=[^\n]*$)/
|
|
41
|
+
const _r_regex = /\r/g
|
|
42
42
|
|
|
43
43
|
/**
|
|
44
44
|
* @param {number} index
|
|
@@ -62,7 +62,7 @@ module.exports = {
|
|
|
62
62
|
* @returns {string}
|
|
63
63
|
*/
|
|
64
64
|
function get_text(node_or_start, end) {
|
|
65
|
-
|
|
65
|
+
const substr = typeof node_or_start == "number"
|
|
66
66
|
? text.slice(node_or_start, end)
|
|
67
67
|
: text.slice(
|
|
68
68
|
node_or_start.range[0],
|
|
@@ -95,9 +95,9 @@ module.exports = {
|
|
|
95
95
|
*/
|
|
96
96
|
ExportNamedDeclaration(node) {
|
|
97
97
|
if (check_exports && node.specifiers[0]?.type == "ExportSpecifier") {
|
|
98
|
-
|
|
98
|
+
const line_indent = get_indent(node.range[0])
|
|
99
99
|
let length = 0
|
|
100
|
-
for (
|
|
100
|
+
for (const s of node.specifiers) {
|
|
101
101
|
length += s.range[1] - s.range[0]
|
|
102
102
|
}
|
|
103
103
|
let corrected_text = length > max_length
|
|
@@ -123,9 +123,9 @@ module.exports = {
|
|
|
123
123
|
*/
|
|
124
124
|
ImportDeclaration(node) {
|
|
125
125
|
if (check_imports && node.specifiers[0]?.type == "ImportSpecifier") {
|
|
126
|
-
|
|
126
|
+
const line_indent = get_indent(node.range[0])
|
|
127
127
|
let length = 0
|
|
128
|
-
for (
|
|
128
|
+
for (const s of node.specifiers) {
|
|
129
129
|
length += s.range[1] - s.range[0]
|
|
130
130
|
}
|
|
131
131
|
let corrected_text = length > max_length
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
"use strict"
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
const left_space_regex = /\s+$/
|
|
4
|
+
const right_space_regex = /^\s+/
|
|
5
|
+
const type_regex = /(?<=(?:^|.*\s*)@type\s*\{).+(?=\}.*?$)/
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* @param {number} length
|
|
9
9
|
* @returns {number[]}
|
|
10
10
|
*/
|
|
11
11
|
function get_indexed_array(length) {
|
|
12
|
-
|
|
12
|
+
const array = []
|
|
13
13
|
while (length) array[--length] = length
|
|
14
14
|
return array
|
|
15
15
|
}
|
|
@@ -29,21 +29,21 @@ module.exports = {
|
|
|
29
29
|
type: "layout"
|
|
30
30
|
},
|
|
31
31
|
create(context) {
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
const source_code = context.sourceCode
|
|
33
|
+
const origin_text = source_code.text
|
|
34
34
|
let fixed_text = origin_text
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
const text_length = fixed_text.length + 1
|
|
36
|
+
const text_indexes = get_indexed_array(text_length)
|
|
37
37
|
/** @type {import("../private").Comment[]} */
|
|
38
|
-
|
|
39
|
-
for (
|
|
38
|
+
const comments = []
|
|
39
|
+
for (const comment of /** @type {import("../private").Comment[]} */(source_code.getAllComments())/**/) {
|
|
40
40
|
let [ start, end ] = comment.range
|
|
41
41
|
while (start < end) comments[start++] = comment
|
|
42
42
|
}
|
|
43
43
|
/** @type {import("../private").AstNode[] & import("estree").Expression[]} */
|
|
44
|
-
|
|
44
|
+
const expressions = []
|
|
45
45
|
/** @type {Set<string>} */
|
|
46
|
-
|
|
46
|
+
const node_ranges = new Set
|
|
47
47
|
|
|
48
48
|
/**
|
|
49
49
|
* @param {import("../private").AstNode} node
|
|
@@ -51,11 +51,11 @@ module.exports = {
|
|
|
51
51
|
*/
|
|
52
52
|
function verify_correct(node) {
|
|
53
53
|
let temp_text = fixed_text
|
|
54
|
-
|
|
54
|
+
const temp_indexes = [ ...text_indexes ]
|
|
55
55
|
/** @type {(string | undefined)[]} */
|
|
56
|
-
|
|
56
|
+
const types = []
|
|
57
57
|
/** @type {true[]} */
|
|
58
|
-
|
|
58
|
+
const extras = []
|
|
59
59
|
/**
|
|
60
60
|
* @param {number} start
|
|
61
61
|
* @param {number} end
|
|
@@ -63,41 +63,45 @@ module.exports = {
|
|
|
63
63
|
* @returns {void}
|
|
64
64
|
*/
|
|
65
65
|
function temp_text_changes(start, end, insert = "") {
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
const s = temp_indexes[start]
|
|
67
|
+
const e = temp_indexes[end]
|
|
68
|
+
if (s == null || e == null) return
|
|
69
|
+
const gap = insert.length + s - e
|
|
70
|
+
temp_text = temp_text.slice(0, s) + insert + temp_text.slice(e)
|
|
68
71
|
if (gap) {
|
|
69
72
|
while (end < text_length) {
|
|
70
73
|
temp_indexes[end++] += gap
|
|
71
74
|
}
|
|
72
75
|
}
|
|
73
76
|
}
|
|
77
|
+
let comment
|
|
74
78
|
let open = 0
|
|
75
79
|
let close = 0
|
|
76
80
|
let prev_open = 0
|
|
77
81
|
let prev_close = 0
|
|
78
82
|
let [ left, right ] = node.range
|
|
79
83
|
W: while (left > 0) {
|
|
80
|
-
|
|
81
|
-
|
|
84
|
+
comment = comments[left - 1]
|
|
85
|
+
if (comment) {
|
|
82
86
|
left = comment.range[0]
|
|
83
87
|
if (open && !types[open - 1]) {
|
|
84
|
-
|
|
88
|
+
const type = comment.type == "Block" && type_regex.exec(comment.value)?.[0]
|
|
85
89
|
if (type) {
|
|
86
90
|
types[open - 1] = type
|
|
87
91
|
temp_text_changes(...comment.range)
|
|
88
92
|
}
|
|
89
93
|
}
|
|
90
94
|
} else {
|
|
91
|
-
|
|
95
|
+
const left_space = left_space_regex.exec(origin_text.slice(0, left))?.[0].length
|
|
92
96
|
if (left_space) {
|
|
93
97
|
left -= left_space
|
|
94
98
|
} else if (origin_text[left - 1] == "(") {
|
|
95
99
|
while (right < text_length) {
|
|
96
|
-
|
|
97
|
-
|
|
100
|
+
comment = comments[right]
|
|
101
|
+
if (comment) {
|
|
98
102
|
right = comment.range[1]
|
|
99
103
|
} else {
|
|
100
|
-
|
|
104
|
+
const right_space = right_space_regex.exec(origin_text.slice(right))?.[0].length
|
|
101
105
|
if (right_space) {
|
|
102
106
|
right += right_space
|
|
103
107
|
} else {
|
|
@@ -132,8 +136,9 @@ module.exports = {
|
|
|
132
136
|
temp_text_changes(prev_open, prev_open, "(")
|
|
133
137
|
temp_text_changes(prev_close, prev_close, ")")
|
|
134
138
|
}
|
|
135
|
-
|
|
139
|
+
const start = temp_indexes[node.range[0]]
|
|
136
140
|
let end = temp_indexes[node.range[1]]
|
|
141
|
+
if (!end) return
|
|
137
142
|
if (extras[end] || open && temp_text.slice(end, end + 4) == "/**/") {
|
|
138
143
|
end += 4
|
|
139
144
|
}
|
|
@@ -161,8 +166,11 @@ module.exports = {
|
|
|
161
166
|
* @returns {void}
|
|
162
167
|
*/
|
|
163
168
|
function report(node, start, end, corrected_text) {
|
|
164
|
-
|
|
165
|
-
|
|
169
|
+
const s = text_indexes[start]
|
|
170
|
+
const e = text_indexes[end]
|
|
171
|
+
if (s == null || e == null) return
|
|
172
|
+
fixed_text = fixed_text.slice(0, s) + corrected_text + fixed_text.slice(e)
|
|
173
|
+
const gap = corrected_text.length + s - e
|
|
166
174
|
if (gap) {
|
|
167
175
|
for (let i = end; i < text_length; i++) {
|
|
168
176
|
text_indexes[i] += gap
|
|
@@ -187,14 +195,14 @@ module.exports = {
|
|
|
187
195
|
* @returns {void}
|
|
188
196
|
*/
|
|
189
197
|
function push_to_reverse(node) {
|
|
190
|
-
|
|
198
|
+
const range = `${node.range[0]} ${node.range[1]}`
|
|
191
199
|
if (node_ranges.has(range)) return
|
|
192
200
|
node_ranges.add(range)
|
|
193
201
|
expressions.push(node)
|
|
194
202
|
}
|
|
195
203
|
return {
|
|
196
204
|
"Program:exit": () => {
|
|
197
|
-
for (
|
|
205
|
+
for (const node of expressions.reverse()) {
|
|
198
206
|
verify_correct(node)
|
|
199
207
|
}
|
|
200
208
|
},
|