eslint-plugin-lube 0.4.2 → 0.5.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/index.js CHANGED
@@ -1,125 +1,125 @@
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
- "array-bracket-newline": [ "error", "consistent" ],
13
- "array-element-newline": [ "error", "consistent" ],
14
- "arrow-parens": [ "error", "as-needed" ],
15
- "arrow-spacing": [
16
- "error",
17
- { "before": true, "after": true }
18
- ],
19
- "block-spacing": [ "error", "always" ],
20
- "brace-style": [ "error", "1tbs" ],
21
- "comma-dangle": [ "error", "never" ],
22
- "comma-spacing": [
23
- "error",
24
- { "before": false, "after": true }
25
- ],
26
- "comma-style": [ "error", "last" ],
27
- "computed-property-spacing": [ "error", "never" ],
28
- "dot-location": [ "error", "property" ],
29
- "eol-last": [ "error", "never" ],
30
- "func-call-spacing": [ "error", "never" ],
31
- "function-call-argument-newline": [ "error", "consistent" ],
32
- "generator-star-spacing": [ "error", "after" ],
33
- "indent": [ "error", "tab" ],
34
- "jsx-quotes": [ "error", "prefer-double" ],
35
- "key-spacing": [
36
- "error",
37
- {
38
- "afterColon": true,
39
- "beforeColon": false
40
- }
41
- ],
42
- "keyword-spacing": [
43
- "error",
44
- { "after": true, "before": true }
45
- ],
46
- "max-len": [ "warn", 120 ],
47
- "max-statements-per-line": [ "error", { "max": 1 } ],
48
- "multiline-ternary": [ "error", "always-multiline" ],
49
- "newline-per-chained-call": [
50
- "error",
51
- { "ignoreChainWithDepth": 2 }
52
- ],
53
- "no-await-in-loop": "warn",
54
- "no-case-declarations": "off",
55
- "no-console": "warn",
56
- "no-duplicate-imports": "error",
57
- "no-lonely-if": "error",
58
- "no-multi-spaces": "error",
59
- "no-new-native-nonconstructor": "error",
60
- "no-self-compare": "error",
61
- "no-shadow": "error",
62
- "no-shadow-restricted-names": "error",
63
- "no-trailing-spaces": [
64
- "error",
65
- {
66
- "ignoreComments": false,
67
- "skipBlankLines": false
68
- }
69
- ],
70
- "object-curly-newline": [ "error", { "consistent": true } ],
71
- "object-curly-spacing": [ "error", "always" ],
72
- "operator-linebreak": [ "error", "before" ],
73
- "prefer-const": [
74
- "warn",
75
- {
76
- "destructuring": "all",
77
- "ignoreReadBeforeAssign": false
78
- }
79
- ],
80
- "quotes": [ "error", "double" ],
81
- "rest-spread-spacing": [ "error", "never" ],
82
- "semi": [ "error", "never" ],
83
- "semi-spacing": [
84
- "error",
85
- { "after": true, "before": false }
86
- ],
87
- "semi-style": [ "error", "first" ],
88
- "space-before-blocks": [ "error", "always" ],
89
- "space-before-function-paren": [
90
- "error",
91
- {
92
- "anonymous": "never",
93
- "asyncArrow": "always",
94
- "named": "never"
95
- }
96
- ],
97
- "space-in-parens": [ "error", "never" ],
98
- "space-infix-ops": [ "error", { "int32Hint": true } ],
99
- "space-unary-ops": [
100
- "error",
101
- { "words": true, "nonwords": false }
102
- ],
103
- "switch-colon-spacing": [
104
- "error",
105
- { "after": true, "before": false }
106
- ],
107
- "template-curly-spacing": [ "error", "never" ],
108
- "template-tag-spacing": [ "error", "never" ],
109
- "yield-star-spacing": [ "error", "after" ],
110
- "lube/pretty-imports": "error",
111
- "lube/pretty-jsdoc-casting": "error",
112
- "lube/pretty-sequence": "error",
113
- "lube/svelte-naming-convention": "error"
114
- }
115
- }
116
- },
117
- rules: {
118
- "pretty-imports": require("./rules/pretty-imports"),
119
- "pretty-jsdoc-casting": require("./rules/pretty-jsdoc-casting"),
120
- "pretty-sequence": require("./rules/pretty-sequence"),
121
- "svelte-naming-convention": require(
122
- "./rules/svelte-naming-convention"
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
+ { "before": true, "after": true }
25
+ ],
26
+ "block-spacing": [ "error", "always" ],
27
+ "brace-style": [ "error", "1tbs" ],
28
+ "comma-dangle": [ "error", "never" ],
29
+ "comma-spacing": [
30
+ "error",
31
+ { "before": false, "after": true }
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
+ "max-len": [ "warn", 120 ],
54
+ "max-statements-per-line": [ "error", { "max": 1 } ],
55
+ "multiline-ternary": [ "error", "always-multiline" ],
56
+ "newline-per-chained-call": [
57
+ "error",
58
+ { "ignoreChainWithDepth": 2 }
59
+ ],
60
+ "no-await-in-loop": "warn",
61
+ "no-case-declarations": "off",
62
+ "no-console": "warn",
63
+ "no-duplicate-imports": "error",
64
+ "no-lonely-if": "error",
65
+ "no-multi-spaces": "error",
66
+ "no-new-native-nonconstructor": "error",
67
+ "no-self-compare": "error",
68
+ "no-shadow": "error",
69
+ "no-shadow-restricted-names": "error",
70
+ "no-trailing-spaces": [
71
+ "error",
72
+ {
73
+ "ignoreComments": false,
74
+ "skipBlankLines": false
75
+ }
76
+ ],
77
+ "object-curly-newline": [ "error", { "consistent": true } ],
78
+ "object-curly-spacing": [ "error", "always" ],
79
+ "operator-linebreak": [ "error", "before" ],
80
+ "prefer-const": [
81
+ "warn",
82
+ {
83
+ "destructuring": "all",
84
+ "ignoreReadBeforeAssign": false
85
+ }
86
+ ],
87
+ "quotes": [ "error", "double" ],
88
+ "rest-spread-spacing": [ "error", "never" ],
89
+ "semi": [ "error", "never" ],
90
+ "semi-spacing": [
91
+ "error",
92
+ { "after": true, "before": false }
93
+ ],
94
+ "semi-style": [ "error", "first" ],
95
+ "space-before-blocks": [ "error", "always" ],
96
+ "space-before-function-paren": [
97
+ "error",
98
+ {
99
+ "anonymous": "never",
100
+ "asyncArrow": "always",
101
+ "named": "never"
102
+ }
103
+ ],
104
+ "space-in-parens": [ "error", "never" ],
105
+ "space-infix-ops": [ "error", { "int32Hint": true } ],
106
+ "space-unary-ops": [
107
+ "error",
108
+ { "words": true, "nonwords": false }
109
+ ],
110
+ "switch-colon-spacing": [
111
+ "error",
112
+ { "after": true, "before": false }
113
+ ],
114
+ "template-curly-spacing": [ "error", "never" ],
115
+ "template-tag-spacing": [ "error", "never" ],
116
+ "yield-star-spacing": [ "error", "after" ],
117
+ "lube/pretty-imports": "error",
118
+ "lube/pretty-jsdoc-casting": "error",
119
+ "lube/pretty-sequence": "error",
120
+ "lube/svelte-naming-convention": "error"
121
+ }
122
+ }
123
+ )
124
+
125
+ module.exports = plugin
package/package.json CHANGED
@@ -1,34 +1,38 @@
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": "^8.44.6",
9
- "@types/estree": "^1.0.3",
10
- "@typescript-eslint/parser": "^6.9.0",
11
- "eslint": "^8.52.0",
12
- "mocha": "^10.2.0"
13
- },
14
- "keywords": [
15
- "eslint-plugin",
16
- "lube",
17
- "eslint-plugin-lube",
18
- "prettier",
19
- "jsdoc"
20
- ],
21
- "license": "MIT",
22
- "name": "eslint-plugin-lube",
23
- "repository": {
24
- "directory": "packages/eslint-plugin-lube",
25
- "type": "git",
26
- "url": "https://github.com/Artxe2/lube-series"
27
- },
28
- "scripts": {
29
- "dts": "tsc",
30
- "test": "mocha"
31
- },
32
- "type": "commonjs",
33
- "version": "0.4.2"
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
+ "name": "eslint-plugin-lube",
24
+ "peerDependencies": {
25
+ "eslint": ">=9.0.0"
26
+ },
27
+ "repository": {
28
+ "directory": "packages/eslint-plugin-lube",
29
+ "type": "git",
30
+ "url": "https://github.com/Artxe2/lube-series"
31
+ },
32
+ "scripts": {
33
+ "dts": "tsc",
34
+ "test": "mocha"
35
+ },
36
+ "type": "commonjs",
37
+ "version": "0.5.0"
34
38
  }
package/private.d.ts CHANGED
@@ -52,7 +52,7 @@ export type AstNode = BaseAstNode & (
52
52
  | estree.ForStatement
53
53
  | {
54
54
  body: AstNode
55
- id: AstNode
55
+ id?: AstNode
56
56
  params: AstNode[]
57
57
  } & estree.FunctionDeclaration
58
58
  | {
@@ -63,22 +63,26 @@ module.exports = {
63
63
  * @returns {void}
64
64
  */
65
65
  function temp_text_changes(start, end, insert = "") {
66
- const gap = insert.length + temp_indexes[start] - temp_indexes[end]
67
- temp_text = temp_text.slice(0, temp_indexes[start]) + insert + temp_text.slice(temp_indexes[end])
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
- if (comments[left - 1]) {
81
- const comment = comments[left - 1]
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]
@@ -93,8 +97,8 @@ module.exports = {
93
97
  left -= left_space
94
98
  } else if (origin_text[left - 1] == "(") {
95
99
  while (right < text_length) {
96
- if (comments[right]) {
97
- const comment = comments[right]
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
@@ -134,6 +138,7 @@ module.exports = {
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
- fixed_text = fixed_text.slice(0, text_indexes[start]) + corrected_text + fixed_text.slice(text_indexes[end])
165
- const gap = corrected_text.length + text_indexes[start] - text_indexes[end]
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
@@ -87,9 +87,11 @@ module.exports = {
87
87
  function get_text(node, start, end, add_indentation) {
88
88
  let open_paren = false
89
89
  let [ left, right ] = node.range
90
+ let comment
90
91
  W: while (left > start) {
91
- if (comments[left - 1]) {
92
- left = comments[left - 1].range[0]
92
+ comment = comments[left - 1]
93
+ if (comment) {
94
+ left = comment.range[0]
93
95
  } else {
94
96
  const left_space = left_space_regex.exec(origin_text.slice(0, left))?.[0].length
95
97
  if (left_space) {
@@ -97,8 +99,8 @@ module.exports = {
97
99
  } else if (origin_text[left - 1] == "(") {
98
100
  open_paren = true
99
101
  while (right < end) {
100
- if (comments[right]) {
101
- const comment = comments[right]
102
+ comment = comments[right]
103
+ if (comment) {
102
104
  right = comment.range[1]
103
105
  } else {
104
106
  const right_space = right_space_regex.exec(origin_text.slice(right))?.[0].length
@@ -121,8 +123,8 @@ module.exports = {
121
123
  }
122
124
  }
123
125
  while (right < end) {
124
- if (comments[right]) {
125
- const comment = comments[right]
126
+ comment = comments[right]
127
+ if (comment) {
126
128
  right = comment.range[1]
127
129
  } else {
128
130
  const right_space = right_space_regex.exec(origin_text.slice(right))?.[0].length
@@ -162,8 +164,11 @@ module.exports = {
162
164
  * @returns {void}
163
165
  */
164
166
  function report(node, start, end, corrected_text) {
165
- fixed_text = fixed_text.slice(0, text_indexes[start]) + corrected_text + fixed_text.slice(text_indexes[end])
166
- const gap = corrected_text.length + text_indexes[start] - text_indexes[end]
167
+ const s = text_indexes[start]
168
+ const e = text_indexes[end]
169
+ if (s == null || e == null) return
170
+ fixed_text = fixed_text.slice(0, s) + corrected_text + fixed_text.slice(e)
171
+ const gap = corrected_text.length + s - e
167
172
  if (gap) {
168
173
  for (let i = end; i < text_length; i++) {
169
174
  text_indexes[i] += gap
@@ -202,7 +207,7 @@ module.exports = {
202
207
  let line_indent = get_indent(node.range[0])
203
208
  switch (node.type) {
204
209
  case "ArrayExpression":
205
- case "ArrayPattern":
210
+ case "ArrayPattern": {
206
211
  start = node.range[0] + 1
207
212
  end = node.range[1] - 1
208
213
  let null_anchor = start
@@ -239,37 +244,39 @@ module.exports = {
239
244
  elements.map(v => get_text(v, start, end)).join(", ")
240
245
  }${length && array_bracket_spacing ? " " : ""}`
241
246
  break
247
+ }
242
248
  case "ArrowFunctionExpression":
243
249
  case "FunctionDeclaration":
244
250
  case "FunctionExpression":
245
251
  if (node.type == "ArrowFunctionExpression") {
246
252
  if (
247
- node.params.length != 1
253
+ node.params.length > 1
248
254
  || origin_text.slice(
249
255
  node.range[0],
250
- node.params[0].range[0]
256
+ node.params[0]?.range[0]
251
257
  ).includes("(")
252
258
  ) {
253
259
  start = origin_text.indexOf("(", node.range[0]) + 1
254
260
  end = origin_text.indexOf(
255
261
  ")",
256
262
  node.params.length
257
- ? node.params[node.params.length - 1].range[1]
263
+ ? node.params[node.params.length - 1]?.range[1]
258
264
  : start
259
265
  )
260
266
  } else {
261
- [ start, end ] = node.params[0].range
267
+ const range = node.params[0]?.range
268
+ if (range) {
269
+ [ start, end ] = range
270
+ }
262
271
  }
263
272
  } else {
264
- start = node.type == "FunctionDeclaration"
273
+ start = node.id
265
274
  ? origin_text.indexOf("(", node.id.range[1]) + 1
266
- : node.id
267
- ? origin_text.indexOf("(", node.id.range[1]) + 1
268
- : origin_text.indexOf("(", node.range[0]) + 1
275
+ : origin_text.indexOf("(", node.range[0]) + 1
269
276
  end = origin_text.indexOf(
270
277
  ")",
271
278
  node.params.length
272
- ? node.params[node.params.length - 1].range[1]
279
+ ? node.params[node.params.length - 1]?.range[1]
273
280
  : start
274
281
  )
275
282
  }
@@ -387,7 +394,11 @@ module.exports = {
387
394
  return /** @type {import("../private").RuleListener} */({
388
395
  "Program:exit": () => {
389
396
  for (const node of nodes.reverse()) {
390
- verify_correct(node)
397
+ try {
398
+ verify_correct(node)
399
+ } catch (error) {
400
+ console.error(node.type, node, error)
401
+ }
391
402
  }
392
403
  },
393
404
  ArrayExpression: node => {
@@ -26,7 +26,7 @@ module.exports = {
26
26
  const option = context.options[0]
27
27
  const fix_same_names = option?.fixSameNames ?? true
28
28
 
29
- // let name | const name | class name
29
+ // let name | let name | class name
30
30
  const allow_regex = /^[_$]?[_$]?(?:[\da-z]+(?:_[\da-z]+)*\$?\$?)?$|^[A-Z](?:_?[\dA-Z]+)*$|^(?:[\dA-Z][\da-z]*)+$/
31
31
  const fixable_name_regex = /^[_$]?[_$]?(?:[\dA-Za-z]+(?:_[\dA-Za-z]+)*\$?\$?)?$/
32
32
  const fix_regex = /([\da-z]?)([A-Z][\dA-Z]*)/g
@@ -106,8 +106,7 @@ module.exports = {
106
106
  const name = node.name
107
107
  if (allow_regex.test(name)) return
108
108
  const parent = node.parent
109
- const type = parent.type
110
- switch (type) {
109
+ switch (parent.type) {
111
110
  case "ArrayExpression":
112
111
  // var value = [ camelCase ]
113
112
  defer(node)
@@ -228,7 +227,7 @@ module.exports = {
228
227
  break
229
228
  case "ImportSpecifier":
230
229
  // import { imported as local, local2 } from "module"
231
- if (parent.local == node && parent.imported.name != parent.local.name) {
230
+ if (parent.local == node && parent.imported.type == "Identifier" && parent.imported.name != parent.local.name) {
232
231
  // import { imported as camelCase } from "module"
233
232
  report(node)
234
233
  }
@@ -11,9 +11,11 @@ exports.module = (valid, invalid) => {
11
11
  export { fff, ggg, hhh, iii, jjj, kkk, lll } from 'module/2'
12
12
  `,
13
13
  options: [ { maxLength: 30 } ],
14
- parserOptions: {
15
- ecmaVersion: "latest",
16
- sourceType: "module"
14
+ languageOptions: {
15
+ parserOptions: {
16
+ ecmaVersion: "latest",
17
+ sourceType: "module"
18
+ }
17
19
  }
18
20
  },
19
21
  {
@@ -22,9 +24,11 @@ exports.module = (valid, invalid) => {
22
24
  export { a, b, c };
23
25
  `,
24
26
  options: [ { semicolon: true } ],
25
- parserOptions: {
26
- ecmaVersion: "latest",
27
- sourceType: "module"
27
+ languageOptions: {
28
+ parserOptions: {
29
+ ecmaVersion: "latest",
30
+ sourceType: "module"
31
+ }
28
32
  }
29
33
  }
30
34
  )
@@ -65,9 +69,11 @@ exports.module = (valid, invalid) => {
65
69
  lll
66
70
  } from 'module/2';
67
71
  `,
68
- parserOptions: {
69
- ecmaVersion: "latest",
70
- sourceType: "module"
72
+ languageOptions: {
73
+ parserOptions: {
74
+ ecmaVersion: "latest",
75
+ sourceType: "module"
76
+ }
71
77
  }
72
78
  },
73
79
  {
@@ -106,9 +112,11 @@ exports.module = (valid, invalid) => {
106
112
  lll
107
113
  } from 'module/2'
108
114
  `,
109
- parserOptions: {
110
- ecmaVersion: "latest",
111
- sourceType: "module"
115
+ languageOptions: {
116
+ parserOptions: {
117
+ ecmaVersion: "latest",
118
+ sourceType: "module"
119
+ }
112
120
  }
113
121
  }
114
122
  )
@@ -11,9 +11,11 @@ exports.module = (valid, invalid) => {
11
11
  import { fff, ggg, hhh, iii, jjj, kkk, lll } from 'module/2'
12
12
  `,
13
13
  options: [ { maxLength: 30 } ],
14
- parserOptions: {
15
- ecmaVersion: "latest",
16
- sourceType: "module"
14
+ languageOptions: {
15
+ parserOptions: {
16
+ ecmaVersion: "latest",
17
+ sourceType: "module"
18
+ }
17
19
  }
18
20
  },
19
21
  {
@@ -24,9 +26,11 @@ import {
24
26
  aaaaa_ddddd
25
27
  } from "module";`,
26
28
  options: [ { semicolon: true } ],
27
- parserOptions: {
28
- ecmaVersion: "latest",
29
- sourceType: "module"
29
+ languageOptions: {
30
+ parserOptions: {
31
+ ecmaVersion: "latest",
32
+ sourceType: "module"
33
+ }
30
34
  }
31
35
  }
32
36
  )
@@ -67,9 +71,11 @@ import {
67
71
  lll
68
72
  } from 'module/2';
69
73
  `,
70
- parserOptions: {
71
- ecmaVersion: "latest",
72
- sourceType: "module"
74
+ languageOptions: {
75
+ parserOptions: {
76
+ ecmaVersion: "latest",
77
+ sourceType: "module"
78
+ }
73
79
  }
74
80
  },
75
81
  {
@@ -108,9 +114,11 @@ import {
108
114
  lll
109
115
  } from 'module/2'
110
116
  `,
111
- parserOptions: {
112
- ecmaVersion: "latest",
113
- sourceType: "module"
117
+ languageOptions: {
118
+ parserOptions: {
119
+ ecmaVersion: "latest",
120
+ sourceType: "module"
121
+ }
114
122
  }
115
123
  }
116
124
  )
@@ -29,7 +29,9 @@ const test_case = (type, value) => ({
29
29
  var value = /** @type {D} */((${value}))/**/
30
30
  var value = ((/** @type {E} */(${value})/**/))
31
31
  `,
32
- parserOptions: { ecmaVersion: "latest" }
32
+ languageOptions: {
33
+ parserOptions: { ecmaVersion: "latest" }
34
+ }
33
35
  })
34
36
 
35
37
  /**
@@ -94,7 +96,9 @@ exports.module = (valid, invalid) => {
94
96
  ((/** @type {E} */(await b)/**/));
95
97
  }
96
98
  `,
97
- parserOptions: { ecmaVersion: "latest" }
99
+ languageOptions: {
100
+ parserOptions: { ecmaVersion: "latest" }
101
+ }
98
102
  },
99
103
  test_case("BinaryExpression", "a / b"),
100
104
  test_case("CallExpression", "a(b, c)"),
@@ -169,7 +173,9 @@ exports.module = (valid, invalid) => {
169
173
  ((/** @type {E} */(new.target)/**/));
170
174
  }
171
175
  `,
172
- parserOptions: { ecmaVersion: "latest" }
176
+ languageOptions: {
177
+ parserOptions: { ecmaVersion: "latest" }
178
+ }
173
179
  },
174
180
  test_case("NewExpression", "new a(b, c)"),
175
181
  test_case(
@@ -235,7 +241,9 @@ exports.module = (valid, invalid) => {
235
241
  ((/** @type {E} */(yield b)/**/));
236
242
  }
237
243
  `,
238
- parserOptions: { ecmaVersion: "latest" }
244
+ languageOptions: {
245
+ parserOptions: { ecmaVersion: "latest" }
246
+ }
239
247
  }
240
248
  )
241
249
  }
@@ -37,7 +37,9 @@ exports.module = (valid, invalid) => {
37
37
  .../** @type {X} */(x)/**/
38
38
  })/**/;
39
39
  /** @type {Y} */(y, /** @type {Z} */(z[/** @type {123} */(123)/**/])/**/)/**/`,
40
- parserOptions: { ecmaVersion: "latest" }
40
+ languageOptions: {
41
+ parserOptions: { ecmaVersion: "latest" }
42
+ }
41
43
  }
42
44
  )
43
45
  invalid.push(
@@ -85,7 +87,9 @@ exports.module = (valid, invalid) => {
85
87
  .../** @type {X} */(x)/**/
86
88
  })/**/;
87
89
  /** @type {Y} */(y, /** @type {Z} */(z[/** @type {123} */(123)/**/])/**/)/**/`,
88
- parserOptions: { ecmaVersion: "latest" }
90
+ languageOptions: {
91
+ parserOptions: { ecmaVersion: "latest" }
92
+ }
89
93
  }
90
94
  )
91
95
  }
@@ -59,7 +59,9 @@ exports.module = (valid, invalid) => {
59
59
  ] = value
60
60
  var [] = value
61
61
  `,
62
- parserOptions: { ecmaVersion: "latest" }
62
+ languageOptions: {
63
+ parserOptions: { ecmaVersion: "latest" }
64
+ }
63
65
  },
64
66
  {
65
67
  code: `
@@ -102,7 +104,9 @@ exports.module = (valid, invalid) => {
102
104
  var value = async a => b
103
105
  var value = async (a, b, c) => {}
104
106
  `,
105
- parserOptions: { ecmaVersion: "latest" }
107
+ languageOptions: {
108
+ parserOptions: { ecmaVersion: "latest" }
109
+ }
106
110
  },
107
111
  {
108
112
  code: `
@@ -141,7 +145,9 @@ exports.module = (valid, invalid) => {
141
145
  function func() {}
142
146
  async function func() {}
143
147
  `,
144
- parserOptions: { ecmaVersion: "latest" }
148
+ languageOptions: {
149
+ parserOptions: { ecmaVersion: "latest" }
150
+ }
145
151
  },
146
152
  {
147
153
  code: `
@@ -180,7 +186,9 @@ exports.module = (valid, invalid) => {
180
186
  var value = function () {}
181
187
  var value = async function () {}
182
188
  `,
183
- parserOptions: { ecmaVersion: "latest" }
189
+ languageOptions: {
190
+ parserOptions: { ecmaVersion: "latest" }
191
+ }
184
192
  },
185
193
  {
186
194
  code: `
@@ -265,7 +273,9 @@ exports.module = (valid, invalid) => {
265
273
  }
266
274
  var value = {}
267
275
  `,
268
- parserOptions: { ecmaVersion: "latest" }
276
+ languageOptions: {
277
+ parserOptions: { ecmaVersion: "latest" }
278
+ }
269
279
  },
270
280
  {
271
281
  code: `
@@ -294,7 +304,9 @@ exports.module = (valid, invalid) => {
294
304
  } = value
295
305
  var {} = value
296
306
  `,
297
- parserOptions: { ecmaVersion: "latest" }
307
+ languageOptions: {
308
+ parserOptions: { ecmaVersion: "latest" }
309
+ }
298
310
  },
299
311
  {
300
312
  code: `
@@ -19,7 +19,9 @@ exports.module = (valid, invalid) => {
19
19
  checkSequence: false
20
20
  }
21
21
  ],
22
- parserOptions: { ecmaVersion: "latest" }
22
+ languageOptions: {
23
+ parserOptions: { ecmaVersion: "latest" }
24
+ }
23
25
  },
24
26
  {
25
27
  code: `
@@ -28,14 +30,18 @@ exports.module = (valid, invalid) => {
28
30
  }
29
31
  `,
30
32
  options: [ { indent: " " } ],
31
- parserOptions: { ecmaVersion: "latest" }
33
+ languageOptions: {
34
+ parserOptions: { ecmaVersion: "latest" }
35
+ }
32
36
  },
33
37
  {
34
38
  code: `
35
39
  var value = { aaaaaaaaaa_aaaaaaaaaa_aaaaaaaaaa }
36
40
  `,
37
41
  options: [ { maxLength: 40 } ],
38
- parserOptions: { ecmaVersion: "latest" }
42
+ languageOptions: {
43
+ parserOptions: { ecmaVersion: "latest" }
44
+ }
39
45
  }
40
46
  )
41
47
  invalid.push(
@@ -70,7 +76,9 @@ exports.module = (valid, invalid) => {
70
76
  output: `
71
77
  var value = ( a, b, c ) => {}
72
78
  `,
73
- parserOptions: { ecmaVersion: "latest" }
79
+ languageOptions: {
80
+ parserOptions: { ecmaVersion: "latest" }
81
+ }
74
82
  },
75
83
  {
76
84
  code: `
@@ -81,7 +89,9 @@ exports.module = (valid, invalid) => {
81
89
  output: `
82
90
  var value = (a, b, c) => {}
83
91
  `,
84
- parserOptions: { ecmaVersion: "latest" }
92
+ languageOptions: {
93
+ parserOptions: { ecmaVersion: "latest" }
94
+ }
85
95
  }
86
96
  )
87
97
  invalid.push(
@@ -94,7 +104,9 @@ exports.module = (valid, invalid) => {
94
104
  output: `
95
105
  var value = { a, b, c }
96
106
  `,
97
- parserOptions: { ecmaVersion: "latest" }
107
+ languageOptions: {
108
+ parserOptions: { ecmaVersion: "latest" }
109
+ }
98
110
  },
99
111
  {
100
112
  code: `
@@ -105,7 +117,9 @@ exports.module = (valid, invalid) => {
105
117
  output: `
106
118
  var value = {a, b, c}
107
119
  `,
108
- parserOptions: { ecmaVersion: "latest" }
120
+ languageOptions: {
121
+ parserOptions: { ecmaVersion: "latest" }
122
+ }
109
123
  }
110
124
  )
111
125
  invalid.push(
@@ -120,7 +134,9 @@ exports.module = (valid, invalid) => {
120
134
  output: `
121
135
  var value = \`\${[ a, b, c ]}\`
122
136
  `,
123
- parserOptions: { ecmaVersion: "latest" }
137
+ languageOptions: {
138
+ parserOptions: { ecmaVersion: "latest" }
139
+ }
124
140
  }
125
141
  )
126
142
  }
@@ -10,7 +10,9 @@ exports.module = (valid, invalid) => {
10
10
  aaaaaaaaaa_aaaaaaaaaa_aaaaaaaaaa
11
11
  }
12
12
  `,
13
- parserOptions: { ecmaVersion: "latest" }
13
+ languageOptions: {
14
+ parserOptions: { ecmaVersion: "latest" }
15
+ }
14
16
  },
15
17
  {
16
18
  code: "func(a, /* a */(b)/* b */)"
@@ -24,11 +26,15 @@ exports.module = (valid, invalid) => {
24
26
  c
25
27
  }
26
28
  `,
27
- parserOptions: { ecmaVersion: "latest" }
29
+ languageOptions: {
30
+ parserOptions: { ecmaVersion: "latest" }
31
+ }
28
32
  },
29
33
  {
30
34
  code: "func(v => f(a, b, c))",
31
- parserOptions: { ecmaVersion: "latest" }
35
+ languageOptions: {
36
+ parserOptions: { ecmaVersion: "latest" }
37
+ }
32
38
  },
33
39
  {
34
40
  code: `
@@ -45,7 +51,22 @@ exports.module = (valid, invalid) => {
45
51
  aaaaaaaaaa_bbbbbbbbbb_cccccccccc
46
52
  )
47
53
  `,
48
- parserOptions: { ecmaVersion: "latest" }
54
+ languageOptions: {
55
+ parserOptions: { ecmaVersion: "latest" }
56
+ }
57
+ },
58
+ {
59
+ code: `
60
+ export default function(abc) {
61
+ return [ abc, abc ]
62
+ }
63
+ `,
64
+ languageOptions: {
65
+ parserOptions: {
66
+ ecmaVersion: "latest",
67
+ sourceType: "module"
68
+ }
69
+ }
49
70
  }
50
71
  )
51
72
  invalid.push(
@@ -102,7 +123,9 @@ exports.module = (valid, invalid) => {
102
123
  }
103
124
  }
104
125
  `,
105
- parserOptions: { ecmaVersion: "latest" }
126
+ languageOptions: {
127
+ parserOptions: { ecmaVersion: "latest" }
128
+ }
106
129
  },
107
130
  {
108
131
  code: `
@@ -162,7 +185,9 @@ exports.module = (valid, invalid) => {
162
185
  }
163
186
  }
164
187
  `,
165
- parserOptions: { ecmaVersion: "latest" }
188
+ languageOptions: {
189
+ parserOptions: { ecmaVersion: "latest" }
190
+ }
166
191
  }
167
192
  )
168
193
  }
@@ -29,14 +29,18 @@ exports.module = (valid, invalid) => {
29
29
  code: "var [ camelCase ] = value",
30
30
  errors: [ { line: 1, column: 7 } ],
31
31
  output: "var [ camel_case ] = value",
32
- parserOptions: { ecmaVersion: "latest" }
32
+ languageOptions: {
33
+ parserOptions: { ecmaVersion: "latest" }
34
+ }
33
35
  },
34
36
  // ArrowFunctionExpression
35
37
  {
36
38
  code: "(camelCase) => {}",
37
39
  errors: [ { line: 1, column: 2 } ],
38
40
  output: "(camel_case) => {}",
39
- parserOptions: { ecmaVersion: "latest" }
41
+ languageOptions: {
42
+ parserOptions: { ecmaVersion: "latest" }
43
+ }
40
44
  },
41
45
  // AssignmentExpression
42
46
  {
@@ -62,7 +66,9 @@ exports.module = (valid, invalid) => {
62
66
  pending_a = pending_b
63
67
  function func({ pendingA = 123 }) {}
64
68
  `,
65
- parserOptions: { ecmaVersion: "latest" }
69
+ languageOptions: {
70
+ parserOptions: { ecmaVersion: "latest" }
71
+ }
66
72
  },
67
73
  // AssignmentPattern
68
74
  {
@@ -84,7 +90,9 @@ exports.module = (valid, invalid) => {
84
90
  var pending_a
85
91
  (snake_case = pending_a) => {}
86
92
  `,
87
- parserOptions: { ecmaVersion: "latest" }
93
+ languageOptions: {
94
+ parserOptions: { ecmaVersion: "latest" }
95
+ }
88
96
  },
89
97
  // AwaitExpression
90
98
  {
@@ -105,9 +113,11 @@ exports.module = (valid, invalid) => {
105
113
  var pending_a
106
114
  await pending_a
107
115
  `,
108
- parserOptions: {
109
- ecmaVersion: "latest",
110
- sourceType: "module"
116
+ languageOptions: {
117
+ parserOptions: {
118
+ ecmaVersion: "latest",
119
+ sourceType: "module"
120
+ }
111
121
  }
112
122
  },
113
123
  // BinaryExpression
@@ -158,7 +168,9 @@ exports.module = (valid, invalid) => {
158
168
  code: "class camelCase {}",
159
169
  errors: [ { line: 1, column: 7 } ],
160
170
  output: "class camel_case {}",
161
- parserOptions: { ecmaVersion: "latest" }
171
+ languageOptions: {
172
+ parserOptions: { ecmaVersion: "latest" }
173
+ }
162
174
  },
163
175
  // ConditionalExpression
164
176
  {
@@ -194,9 +206,11 @@ exports.module = (valid, invalid) => {
194
206
  export * as camelCase from "module"
195
207
  var camel_case
196
208
  `,
197
- parserOptions: {
198
- ecmaVersion: "latest",
199
- sourceType: "module"
209
+ languageOptions: {
210
+ parserOptions: {
211
+ ecmaVersion: "latest",
212
+ sourceType: "module"
213
+ }
200
214
  }
201
215
  },
202
216
  // ExportDefaultDeclaration
@@ -211,9 +225,11 @@ exports.module = (valid, invalid) => {
211
225
  export default camelCase
212
226
  var camel_case
213
227
  `,
214
- parserOptions: {
215
- ecmaVersion: "latest",
216
- sourceType: "module"
228
+ languageOptions: {
229
+ parserOptions: {
230
+ ecmaVersion: "latest",
231
+ sourceType: "module"
232
+ }
217
233
  }
218
234
  },
219
235
  {
@@ -229,9 +245,11 @@ exports.module = (valid, invalid) => {
229
245
  export default camel_case
230
246
  var camel_case
231
247
  `,
232
- parserOptions: {
233
- ecmaVersion: "latest",
234
- sourceType: "module"
248
+ languageOptions: {
249
+ parserOptions: {
250
+ ecmaVersion: "latest",
251
+ sourceType: "module"
252
+ }
235
253
  }
236
254
  },
237
255
  // ExportSpecifier
@@ -248,9 +266,11 @@ exports.module = (valid, invalid) => {
248
266
  export { default as camelCase, camelCase2 } from 'module'
249
267
  var camel_case, camel_case2
250
268
  `,
251
- parserOptions: {
252
- ecmaVersion: "latest",
253
- sourceType: "module"
269
+ languageOptions: {
270
+ parserOptions: {
271
+ ecmaVersion: "latest",
272
+ sourceType: "module"
273
+ }
254
274
  }
255
275
  },
256
276
  // ExpressionStatement
@@ -293,7 +313,9 @@ exports.module = (valid, invalid) => {
293
313
  var pending_a
294
314
  for (snake_case in pending_a) {}
295
315
  `,
296
- parserOptions: { ecmaVersion: "latest" }
316
+ languageOptions: {
317
+ parserOptions: { ecmaVersion: "latest" }
318
+ }
297
319
  },
298
320
  // ForStatement
299
321
  {
@@ -320,7 +342,9 @@ exports.module = (valid, invalid) => {
320
342
  var pending_a, pending_b, pending_c
321
343
  for (pending_a; pending_b; pending_c) {}
322
344
  `,
323
- parserOptions: { ecmaVersion: "latest" }
345
+ languageOptions: {
346
+ parserOptions: { ecmaVersion: "latest" }
347
+ }
324
348
  },
325
349
  // FunctionDeclaration
326
350
  {
@@ -338,9 +362,11 @@ exports.module = (valid, invalid) => {
338
362
  export function camelCase2() {}
339
363
  export function camel_case$() {}
340
364
  `,
341
- parserOptions: {
342
- ecmaVersion: "latest",
343
- sourceType: "module"
365
+ languageOptions: {
366
+ parserOptions: {
367
+ ecmaVersion: "latest",
368
+ sourceType: "module"
369
+ }
344
370
  }
345
371
  },
346
372
  // IfStatement
@@ -368,9 +394,11 @@ exports.module = (valid, invalid) => {
368
394
  code: "import camelCase from 'module'",
369
395
  errors: [ { line: 1, column: 8 } ],
370
396
  output: "import camel_case from 'module'",
371
- parserOptions: {
372
- ecmaVersion: "latest",
373
- sourceType: "module"
397
+ languageOptions: {
398
+ parserOptions: {
399
+ ecmaVersion: "latest",
400
+ sourceType: "module"
401
+ }
374
402
  }
375
403
  },
376
404
  // ImportNamespaceSpecifier
@@ -378,9 +406,11 @@ exports.module = (valid, invalid) => {
378
406
  code: "import * as camelCase from 'module'",
379
407
  errors: [ { line: 1, column: 13 } ],
380
408
  output: "import * as camel_case from 'module'",
381
- parserOptions: {
382
- ecmaVersion: "latest",
383
- sourceType: "module"
409
+ languageOptions: {
410
+ parserOptions: {
411
+ ecmaVersion: "latest",
412
+ sourceType: "module"
413
+ }
384
414
  }
385
415
  },
386
416
  // ImportSpecifier
@@ -399,9 +429,11 @@ exports.module = (valid, invalid) => {
399
429
  camel_case
400
430
  camelCase2
401
431
  `,
402
- parserOptions: {
403
- ecmaVersion: "latest",
404
- sourceType: "module"
432
+ languageOptions: {
433
+ parserOptions: {
434
+ ecmaVersion: "latest",
435
+ sourceType: "module"
436
+ }
405
437
  }
406
438
  },
407
439
  // LogicalExpression
@@ -426,7 +458,9 @@ exports.module = (valid, invalid) => {
426
458
  var pending_a, pending_b
427
459
  pending_a ?? pending_b
428
460
  `,
429
- parserOptions: { ecmaVersion: "latest" }
461
+ languageOptions: {
462
+ parserOptions: { ecmaVersion: "latest" }
463
+ }
430
464
  },
431
465
  // MemberExpression
432
466
  {
@@ -470,7 +504,9 @@ exports.module = (valid, invalid) => {
470
504
  class ObjectB { camelCase() {} }
471
505
  var camel_case
472
506
  `,
473
- parserOptions: { ecmaVersion: "latest" }
507
+ languageOptions: {
508
+ parserOptions: { ecmaVersion: "latest" }
509
+ }
474
510
  },
475
511
  // NewExpression
476
512
  {
@@ -514,7 +550,9 @@ exports.module = (valid, invalid) => {
514
550
  var value = { key: pending_a }
515
551
  var value = { pendingA: pending_a }
516
552
  `,
517
- parserOptions: { ecmaVersion: "latest" }
553
+ languageOptions: {
554
+ parserOptions: { ecmaVersion: "latest" }
555
+ }
518
556
  },
519
557
  // PropertyDefinition
520
558
  {
@@ -530,7 +568,9 @@ exports.module = (valid, invalid) => {
530
568
  class ObjectB { camelCase = camelCase2 }
531
569
  var camel_case, camel_case2
532
570
  `,
533
- parserOptions: { ecmaVersion: "latest" }
571
+ languageOptions: {
572
+ parserOptions: { ecmaVersion: "latest" }
573
+ }
534
574
  },
535
575
  //RestElement
536
576
  {
@@ -546,7 +586,9 @@ exports.module = (valid, invalid) => {
546
586
  var [ ...camel_case_a ] = value
547
587
  var { ...camel_case_b } = value
548
588
  `,
549
- parserOptions: { ecmaVersion: "latest" }
589
+ languageOptions: {
590
+ parserOptions: { ecmaVersion: "latest" }
591
+ }
550
592
  },
551
593
  // ReturnStatement
552
594
  {
@@ -610,7 +652,9 @@ exports.module = (valid, invalid) => {
610
652
  var pending_a, pending_b
611
653
  var value = [ ...pending_a, pending_b ]
612
654
  `,
613
- parserOptions: { ecmaVersion: "latest" }
655
+ languageOptions: {
656
+ parserOptions: { ecmaVersion: "latest" }
657
+ }
614
658
  },
615
659
  // SwitchCase
616
660
  {
@@ -671,7 +715,9 @@ exports.module = (valid, invalid) => {
671
715
  var pending_a
672
716
  pending_a\`quasis\${expression}quasis\`
673
717
  `,
674
- parserOptions: { ecmaVersion: "latest" }
718
+ languageOptions: {
719
+ parserOptions: { ecmaVersion: "latest" }
720
+ }
675
721
  },
676
722
  // ThrowStatement
677
723
  {
@@ -758,9 +804,11 @@ exports.module = (valid, invalid) => {
758
804
  export var camelCase2
759
805
  export var camel_case$
760
806
  `,
761
- parserOptions: {
762
- ecmaVersion: "latest",
763
- sourceType: "module"
807
+ languageOptions: {
808
+ parserOptions: {
809
+ ecmaVersion: "latest",
810
+ sourceType: "module"
811
+ }
764
812
  }
765
813
  },
766
814
  // WhileStatement
@@ -822,7 +870,9 @@ exports.module = (valid, invalid) => {
822
870
  var pending_a
823
871
  function* func_c() { yield pending_a }
824
872
  `,
825
- parserOptions: { ecmaVersion: "latest" }
873
+ languageOptions: {
874
+ parserOptions: { ecmaVersion: "latest" }
875
+ }
826
876
  }
827
877
  )
828
878
  }
package/tsconfig.json CHANGED
@@ -3,9 +3,12 @@
3
3
  "allowJs": true,
4
4
  "allowSyntheticDefaultImports": true,
5
5
  "checkJs": true,
6
- "lib": ["ES2020", "DOM", "DOM.Iterable"],
6
+ "exactOptionalPropertyTypes": true,
7
+ "lib": [ "ES2020", "DOM", "DOM.Iterable" ],
7
8
  "module": "CommonJS",
8
9
  "noEmit": true,
10
+ "noPropertyAccessFromIndexSignature": true,
11
+ // "noUncheckedIndexedAccess": true,
9
12
  "skipLibCheck": true,
10
13
  "strict": true,
11
14
  "target": "ESNext"