Skip to content

Commit 5de72f9

Browse files
committed
fix: use esutils
1 parent 2306947 commit 5de72f9

File tree

5 files changed

+13
-69
lines changed

5 files changed

+13
-69
lines changed

docs-svelte-kit/src/lib/eslint/ESLintEditor.svelte

+2-1
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,11 @@
219219
edits: [
220220
{
221221
resource: model.uri,
222-
edit: {
222+
textEdit: {
223223
range: editRange,
224224
text: fix.text,
225225
},
226+
versionId: model.getVersionId(),
226227
},
227228
],
228229
},

docs-svelte-kit/src/lib/eslint/MonacoEditor.svelte

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
monaco.languages.registerCodeActionProvider(language, {
5959
provideCodeActions(model, range, context) {
6060
const editor = getLeftEditor?.()
61-
if (editor?.getModel().url !== model.url) {
61+
if (editor?.getModel().uri !== model.uri) {
6262
return {
6363
actions: [],
6464
dispose() {

docs/rules/prefer-destructured-store-props.md

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ An example of the improvements can be see in this [REPL](https://svelte.dev/repl
2525
```svelte
2626
<script>
2727
/* eslint svelte/prefer-destructured-store-props: "error" */
28+
import store from "./store.js"
2829
$: ({ foo } = $store)
2930
</script>
3031

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
"dependencies": {
6868
"debug": "^4.3.1",
6969
"eslint-utils": "^3.0.0",
70+
"esutils": "^2.0.3",
7071
"known-css-properties": "^0.25.0",
7172
"postcss": "^8.4.5",
7273
"postcss-load-config": "^3.1.4",
@@ -100,6 +101,7 @@
100101
"@types/eslint-utils": "^3.0.1",
101102
"@types/eslint-visitor-keys": "^1.0.0",
102103
"@types/estree": "^1.0.0",
104+
"@types/esutils": "^2.0.0",
103105
"@types/less": "^3.0.3",
104106
"@types/markdown-it": "^12.2.3",
105107
"@types/markdown-it-container": "^2.0.5",
@@ -172,7 +174,7 @@
172174
"access": "public"
173175
},
174176
"typeCoverage": {
175-
"atLeast": 98.69,
177+
"atLeast": 98.71,
176178
"cache": true,
177179
"detail": true,
178180
"ignoreAsAssertion": true,

src/rules/prefer-destructured-store-props.ts

+6-66
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { TSESTree } from "@typescript-eslint/types"
22
import { getPropertyName } from "eslint-utils"
33
import type { AST } from "svelte-eslint-parser"
4+
import { keyword } from "esutils"
45
import type { SuggestionReportDescriptor } from "../types"
56
import { createRule } from "../utils"
67
import {
@@ -13,71 +14,6 @@ type StoreMemberExpression = TSESTree.MemberExpression & {
1314
object: TSESTree.Identifier & { name: string }
1415
}
1516

16-
const keywords = new Set([
17-
"abstract",
18-
"arguments",
19-
"boolean",
20-
"break",
21-
"byte",
22-
"case",
23-
"catch",
24-
"char",
25-
"class",
26-
"const",
27-
"continue",
28-
"debugger",
29-
"default",
30-
"delete",
31-
"do",
32-
"double",
33-
"else",
34-
"enum",
35-
"eval",
36-
"export",
37-
"extends",
38-
"false",
39-
"final",
40-
"finally",
41-
"float",
42-
"for",
43-
"function",
44-
"goto",
45-
"if",
46-
"implements",
47-
"import",
48-
"in",
49-
"instanceof",
50-
"int",
51-
"interface",
52-
"let",
53-
"long",
54-
"native",
55-
"new",
56-
"null",
57-
"package",
58-
"private",
59-
"protected",
60-
"public",
61-
"return",
62-
"short",
63-
"static",
64-
"super",
65-
"switch",
66-
"synchronized",
67-
"this",
68-
"throw",
69-
"throws",
70-
"transient",
71-
"true",
72-
"try",
73-
"typeof",
74-
"var",
75-
"void",
76-
"volatile",
77-
"while",
78-
"with",
79-
"yield",
80-
])
8117
export default createRule("prefer-destructured-store-props", {
8218
meta: {
8319
docs: {
@@ -134,6 +70,7 @@ export default createRule("prefer-destructured-store-props", {
13470
getPropertyName(prop) === propName,
13571
)
13672
if (prop) {
73+
// $: ({prop: target} = $store)
13774
yield prop.value
13875
}
13976
}
@@ -297,7 +234,10 @@ export default createRule("prefer-destructured-store-props", {
297234
}
298235
const baseName = varName
299236
let suffix = 0
300-
if (keywords.has(varName)) {
237+
if (
238+
keyword.isReservedWordES6(varName, true) ||
239+
keyword.isRestrictedWord(varName)
240+
) {
301241
varName = `${baseName}${++suffix}`
302242
}
303243
while (hasTopLevelVariable(varName)) {

0 commit comments

Comments
 (0)