eslint-plugin-svelte 2.2.0 → 2.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 +3 -1
- package/lib/configs/prettier.d.ts +2 -0
- package/lib/configs/prettier.js +2 -0
- package/lib/index.d.ts +2 -0
- package/lib/rules/html-closing-bracket-spacing.d.ts +2 -0
- package/lib/rules/html-closing-bracket-spacing.js +92 -0
- package/lib/rules/no-spaces-around-equal-signs-in-attribute.d.ts +2 -0
- package/lib/rules/no-spaces-around-equal-signs-in-attribute.js +49 -0
- package/lib/utils/rules.js +4 -0
- package/package.json +16 -11
package/README.md
CHANGED
|
@@ -35,7 +35,7 @@ The [svelte-eslint-parser] and the `eslint-plugin-svelte` can not be used with t
|
|
|
35
35
|
|
|
36
36
|
## Migration Guide
|
|
37
37
|
|
|
38
|
-
To migrate from `eslint-plugin-svelte` v1, or `@ota-meshi/eslint-plugin-svelte
|
|
38
|
+
To migrate from `eslint-plugin-svelte` v1, or [`@ota-meshi/eslint-plugin-svelte`](https://www.npmjs.com/package/@ota-meshi/eslint-plugin-svelte), please refer to the [migration guide](https://ota-meshi.github.io/eslint-plugin-svelte/migration/).
|
|
39
39
|
|
|
40
40
|
## :book: Documentation
|
|
41
41
|
|
|
@@ -292,10 +292,12 @@ These rules relate to style guidelines, and are therefore quite subjective:
|
|
|
292
292
|
| Rule ID | Description | |
|
|
293
293
|
|:--------|:------------|:---|
|
|
294
294
|
| [svelte/first-attribute-linebreak](https://ota-meshi.github.io/eslint-plugin-svelte/rules/first-attribute-linebreak/) | enforce the location of first attribute | :wrench: |
|
|
295
|
+
| [svelte/html-closing-bracket-spacing](https://ota-meshi.github.io/eslint-plugin-svelte/rules/html-closing-bracket-spacing/) | require or disallow a space before tag's closing brackets | :wrench: |
|
|
295
296
|
| [svelte/html-quotes](https://ota-meshi.github.io/eslint-plugin-svelte/rules/html-quotes/) | enforce quotes style of HTML attributes | :wrench: |
|
|
296
297
|
| [svelte/indent](https://ota-meshi.github.io/eslint-plugin-svelte/rules/indent/) | enforce consistent indentation | :wrench: |
|
|
297
298
|
| [svelte/max-attributes-per-line](https://ota-meshi.github.io/eslint-plugin-svelte/rules/max-attributes-per-line/) | enforce the maximum number of attributes per line | :wrench: |
|
|
298
299
|
| [svelte/mustache-spacing](https://ota-meshi.github.io/eslint-plugin-svelte/rules/mustache-spacing/) | enforce unified spacing in mustache | :wrench: |
|
|
300
|
+
| [svelte/no-spaces-around-equal-signs-in-attribute](https://ota-meshi.github.io/eslint-plugin-svelte/rules/no-spaces-around-equal-signs-in-attribute/) | disallow spaces around equal signs in attribute | :wrench: |
|
|
299
301
|
| [svelte/prefer-class-directive](https://ota-meshi.github.io/eslint-plugin-svelte/rules/prefer-class-directive/) | require class directives instead of ternary expressions | :wrench: |
|
|
300
302
|
| [svelte/prefer-style-directive](https://ota-meshi.github.io/eslint-plugin-svelte/rules/prefer-style-directive/) | require style directives instead of style attribute | :wrench: |
|
|
301
303
|
| [svelte/shorthand-attribute](https://ota-meshi.github.io/eslint-plugin-svelte/rules/shorthand-attribute/) | enforce use of shorthand syntax in attribute | :wrench: |
|
|
@@ -2,10 +2,12 @@ declare const _default: {
|
|
|
2
2
|
extends: string[];
|
|
3
3
|
rules: {
|
|
4
4
|
"svelte/first-attribute-linebreak": string;
|
|
5
|
+
"svelte/html-closing-bracket-spacing": string;
|
|
5
6
|
"svelte/html-quotes": string;
|
|
6
7
|
"svelte/indent": string;
|
|
7
8
|
"svelte/max-attributes-per-line": string;
|
|
8
9
|
"svelte/mustache-spacing": string;
|
|
10
|
+
"svelte/no-spaces-around-equal-signs-in-attribute": string;
|
|
9
11
|
"svelte/shorthand-attribute": string;
|
|
10
12
|
"svelte/shorthand-directive": string;
|
|
11
13
|
};
|
package/lib/configs/prettier.js
CHANGED
|
@@ -9,10 +9,12 @@ module.exports = {
|
|
|
9
9
|
extends: [baseExtend],
|
|
10
10
|
rules: {
|
|
11
11
|
"svelte/first-attribute-linebreak": "off",
|
|
12
|
+
"svelte/html-closing-bracket-spacing": "off",
|
|
12
13
|
"svelte/html-quotes": "off",
|
|
13
14
|
"svelte/indent": "off",
|
|
14
15
|
"svelte/max-attributes-per-line": "off",
|
|
15
16
|
"svelte/mustache-spacing": "off",
|
|
17
|
+
"svelte/no-spaces-around-equal-signs-in-attribute": "off",
|
|
16
18
|
"svelte/shorthand-attribute": "off",
|
|
17
19
|
"svelte/shorthand-directive": "off",
|
|
18
20
|
},
|
package/lib/index.d.ts
CHANGED
|
@@ -37,10 +37,12 @@ declare const _default: {
|
|
|
37
37
|
extends: string[];
|
|
38
38
|
rules: {
|
|
39
39
|
"svelte/first-attribute-linebreak": string;
|
|
40
|
+
"svelte/html-closing-bracket-spacing": string;
|
|
40
41
|
"svelte/html-quotes": string;
|
|
41
42
|
"svelte/indent": string;
|
|
42
43
|
"svelte/max-attributes-per-line": string;
|
|
43
44
|
"svelte/mustache-spacing": string;
|
|
45
|
+
"svelte/no-spaces-around-equal-signs-in-attribute": string;
|
|
44
46
|
"svelte/shorthand-attribute": string;
|
|
45
47
|
"svelte/shorthand-directive": string;
|
|
46
48
|
};
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const utils_1 = require("../utils");
|
|
4
|
+
exports.default = (0, utils_1.createRule)("html-closing-bracket-spacing", {
|
|
5
|
+
meta: {
|
|
6
|
+
docs: {
|
|
7
|
+
description: "require or disallow a space before tag's closing brackets",
|
|
8
|
+
category: "Stylistic Issues",
|
|
9
|
+
conflictWithPrettier: true,
|
|
10
|
+
recommended: false,
|
|
11
|
+
},
|
|
12
|
+
schema: [
|
|
13
|
+
{
|
|
14
|
+
type: "object",
|
|
15
|
+
properties: {
|
|
16
|
+
startTag: {
|
|
17
|
+
enum: ["always", "never", "ignore"],
|
|
18
|
+
},
|
|
19
|
+
endTag: {
|
|
20
|
+
enum: ["always", "never", "ignore"],
|
|
21
|
+
},
|
|
22
|
+
selfClosingTag: {
|
|
23
|
+
enum: ["always", "never", "ignore"],
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
additionalProperties: false,
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
messages: {
|
|
30
|
+
expectedSpace: "Expected space before '>', but not found.",
|
|
31
|
+
unexpectedSpace: "Expected no space before '>', but found.",
|
|
32
|
+
},
|
|
33
|
+
fixable: "whitespace",
|
|
34
|
+
type: "layout",
|
|
35
|
+
},
|
|
36
|
+
create(ctx) {
|
|
37
|
+
const options = {
|
|
38
|
+
startTag: "never",
|
|
39
|
+
endTag: "never",
|
|
40
|
+
selfClosingTag: "always",
|
|
41
|
+
...ctx.options[0],
|
|
42
|
+
};
|
|
43
|
+
const src = ctx.getSourceCode();
|
|
44
|
+
function containsNewline(string) {
|
|
45
|
+
return string.includes("\n");
|
|
46
|
+
}
|
|
47
|
+
function report(node, shouldHave) {
|
|
48
|
+
const tagSrc = src.getText(node);
|
|
49
|
+
const match = /(\s*)\/?>$/.exec(tagSrc);
|
|
50
|
+
const end = node.range[1];
|
|
51
|
+
const start = node.range[1] - match[0].length;
|
|
52
|
+
const loc = {
|
|
53
|
+
start: src.getLocFromIndex(start),
|
|
54
|
+
end: src.getLocFromIndex(end),
|
|
55
|
+
};
|
|
56
|
+
ctx.report({
|
|
57
|
+
loc,
|
|
58
|
+
messageId: shouldHave ? "expectedSpace" : "unexpectedSpace",
|
|
59
|
+
*fix(fixer) {
|
|
60
|
+
if (shouldHave) {
|
|
61
|
+
yield fixer.insertTextBeforeRange([start, end], " ");
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
const spaces = match[1];
|
|
65
|
+
yield fixer.removeRange([start, start + spaces.length]);
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
return {
|
|
71
|
+
"SvelteStartTag, SvelteEndTag"(node) {
|
|
72
|
+
const tagType = node.type === "SvelteEndTag"
|
|
73
|
+
? "endTag"
|
|
74
|
+
: node.selfClosing
|
|
75
|
+
? "selfClosingTag"
|
|
76
|
+
: "startTag";
|
|
77
|
+
if (options[tagType] === "ignore")
|
|
78
|
+
return;
|
|
79
|
+
const tagSrc = src.getText(node);
|
|
80
|
+
const match = /(\s*)\/?>$/.exec(tagSrc);
|
|
81
|
+
if (containsNewline(match[1]))
|
|
82
|
+
return;
|
|
83
|
+
if (options[tagType] === "always" && !match[1]) {
|
|
84
|
+
report(node, true);
|
|
85
|
+
}
|
|
86
|
+
else if (options[tagType] === "never" && match[1]) {
|
|
87
|
+
report(node, false);
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
},
|
|
92
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const utils_1 = require("../utils");
|
|
4
|
+
exports.default = (0, utils_1.createRule)("no-spaces-around-equal-signs-in-attribute", {
|
|
5
|
+
meta: {
|
|
6
|
+
docs: {
|
|
7
|
+
description: "disallow spaces around equal signs in attribute",
|
|
8
|
+
category: "Stylistic Issues",
|
|
9
|
+
recommended: false,
|
|
10
|
+
conflictWithPrettier: true,
|
|
11
|
+
},
|
|
12
|
+
schema: {},
|
|
13
|
+
fixable: "whitespace",
|
|
14
|
+
messages: {
|
|
15
|
+
noSpaces: "Unexpected spaces found around equal signs.",
|
|
16
|
+
},
|
|
17
|
+
type: "layout",
|
|
18
|
+
},
|
|
19
|
+
create(ctx) {
|
|
20
|
+
const source = ctx.getSourceCode();
|
|
21
|
+
function getAttrEq(node) {
|
|
22
|
+
const keyRange = node.key.range;
|
|
23
|
+
const eqSource = /^[\s=]*/u.exec(source.text.slice(keyRange[1], node.range[1]))[0];
|
|
24
|
+
const valueStart = keyRange[1] + eqSource.length;
|
|
25
|
+
return [eqSource, [keyRange[1], valueStart]];
|
|
26
|
+
}
|
|
27
|
+
function containsWhitespace(string) {
|
|
28
|
+
return /\s/u.test(string);
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
"SvelteAttribute, SvelteDirective, SvelteStyleDirective, SvelteSpecialDirective"(node) {
|
|
32
|
+
const [eqSource, range] = getAttrEq(node);
|
|
33
|
+
if (!containsWhitespace(eqSource))
|
|
34
|
+
return;
|
|
35
|
+
const loc = {
|
|
36
|
+
start: source.getLocFromIndex(range[0]),
|
|
37
|
+
end: source.getLocFromIndex(range[1]),
|
|
38
|
+
};
|
|
39
|
+
ctx.report({
|
|
40
|
+
loc,
|
|
41
|
+
messageId: "noSpaces",
|
|
42
|
+
*fix(fixer) {
|
|
43
|
+
yield fixer.replaceTextRange(range, "=");
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
},
|
|
49
|
+
});
|
package/lib/utils/rules.js
CHANGED
|
@@ -7,6 +7,7 @@ exports.rules = void 0;
|
|
|
7
7
|
const button_has_type_1 = __importDefault(require("../rules/button-has-type"));
|
|
8
8
|
const comment_directive_1 = __importDefault(require("../rules/comment-directive"));
|
|
9
9
|
const first_attribute_linebreak_1 = __importDefault(require("../rules/first-attribute-linebreak"));
|
|
10
|
+
const html_closing_bracket_spacing_1 = __importDefault(require("../rules/html-closing-bracket-spacing"));
|
|
10
11
|
const html_quotes_1 = __importDefault(require("../rules/html-quotes"));
|
|
11
12
|
const indent_1 = __importDefault(require("../rules/indent"));
|
|
12
13
|
const max_attributes_per_line_1 = __importDefault(require("../rules/max-attributes-per-line"));
|
|
@@ -20,6 +21,7 @@ const no_inner_declarations_1 = __importDefault(require("../rules/no-inner-decla
|
|
|
20
21
|
const no_not_function_handler_1 = __importDefault(require("../rules/no-not-function-handler"));
|
|
21
22
|
const no_object_in_text_mustaches_1 = __importDefault(require("../rules/no-object-in-text-mustaches"));
|
|
22
23
|
const no_shorthand_style_property_overrides_1 = __importDefault(require("../rules/no-shorthand-style-property-overrides"));
|
|
24
|
+
const no_spaces_around_equal_signs_in_attribute_1 = __importDefault(require("../rules/no-spaces-around-equal-signs-in-attribute"));
|
|
23
25
|
const no_target_blank_1 = __importDefault(require("../rules/no-target-blank"));
|
|
24
26
|
const no_unknown_style_directive_property_1 = __importDefault(require("../rules/no-unknown-style-directive-property"));
|
|
25
27
|
const no_unused_svelte_ignore_1 = __importDefault(require("../rules/no-unused-svelte-ignore"));
|
|
@@ -36,6 +38,7 @@ exports.rules = [
|
|
|
36
38
|
button_has_type_1.default,
|
|
37
39
|
comment_directive_1.default,
|
|
38
40
|
first_attribute_linebreak_1.default,
|
|
41
|
+
html_closing_bracket_spacing_1.default,
|
|
39
42
|
html_quotes_1.default,
|
|
40
43
|
indent_1.default,
|
|
41
44
|
max_attributes_per_line_1.default,
|
|
@@ -49,6 +52,7 @@ exports.rules = [
|
|
|
49
52
|
no_not_function_handler_1.default,
|
|
50
53
|
no_object_in_text_mustaches_1.default,
|
|
51
54
|
no_shorthand_style_property_overrides_1.default,
|
|
55
|
+
no_spaces_around_equal_signs_in_attribute_1.default,
|
|
52
56
|
no_target_blank_1.default,
|
|
53
57
|
no_unknown_style_directive_property_1.default,
|
|
54
58
|
no_unused_svelte_ignore_1.default,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-svelte",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"description": "ESLint plugin for Svelte using AST",
|
|
5
5
|
"repository": "git+https://github.com/ota-meshi/eslint-plugin-svelte.git",
|
|
6
6
|
"homepage": "https://ota-meshi.github.io/eslint-plugin-svelte",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"prepublishOnly": "yarn clean && yarn build",
|
|
44
44
|
"pretest:base": "cross-env DEBUG=eslint-plugin-svelte*",
|
|
45
45
|
"preversion": "yarn test && git add .",
|
|
46
|
-
"svelte-kit": "node --experimental-loader ./svelte-kit-import-hook.mjs node_modules/vite/bin/vite.js
|
|
46
|
+
"svelte-kit": "node --experimental-loader ./svelte-kit-import-hook.mjs node_modules/vite/bin/vite.js",
|
|
47
47
|
"test": "yarn mocha \"tests/src/**/*.ts\" --reporter dot --timeout 60000",
|
|
48
48
|
"ts": "node -r esbuild-register",
|
|
49
49
|
"update": "yarn ts ./tools/update.ts && yarn format-for-gen-file",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"postcss-load-config": "^3.1.4",
|
|
67
67
|
"postcss-safe-parser": "^6.0.0",
|
|
68
68
|
"sourcemap-codec": "^1.4.8",
|
|
69
|
-
"svelte-eslint-parser": "^0.
|
|
69
|
+
"svelte-eslint-parser": "^0.17.0"
|
|
70
70
|
},
|
|
71
71
|
"devDependencies": {
|
|
72
72
|
"@babel/core": "^7.16.0",
|
|
@@ -74,19 +74,25 @@
|
|
|
74
74
|
"@babel/plugin-proposal-function-bind": "^7.16.7",
|
|
75
75
|
"@babel/types": "^7.16.0",
|
|
76
76
|
"@fontsource/fira-mono": "^4.5.0",
|
|
77
|
-
"@ota-meshi/eslint-plugin": "^0.11.
|
|
77
|
+
"@ota-meshi/eslint-plugin": "^0.11.3",
|
|
78
78
|
"@sindresorhus/slugify": "^2.1.0",
|
|
79
79
|
"@sveltejs/adapter-static": "^1.0.0-next.26",
|
|
80
80
|
"@sveltejs/kit": "^1.0.0-next.360",
|
|
81
81
|
"@types/babel__core": "^7.1.19",
|
|
82
|
+
"@types/cross-spawn": "^6.0.2",
|
|
83
|
+
"@types/escape-html": "^1.0.2",
|
|
82
84
|
"@types/eslint": "^8.0.0",
|
|
83
85
|
"@types/eslint-scope": "^3.7.0",
|
|
84
86
|
"@types/eslint-visitor-keys": "^1.0.0",
|
|
85
|
-
"@types/estree": "^0.0
|
|
87
|
+
"@types/estree": "^1.0.0",
|
|
86
88
|
"@types/less": "^3.0.3",
|
|
89
|
+
"@types/markdown-it": "^12.2.3",
|
|
90
|
+
"@types/markdown-it-container": "^2.0.5",
|
|
91
|
+
"@types/markdown-it-emoji": "^2.0.2",
|
|
87
92
|
"@types/mocha": "^9.0.0",
|
|
88
93
|
"@types/node": "^16.0.0",
|
|
89
94
|
"@types/postcss-safe-parser": "^5.0.1",
|
|
95
|
+
"@types/prismjs": "^1.26.0",
|
|
90
96
|
"@types/stylus": "^0.48.38",
|
|
91
97
|
"@typescript-eslint/eslint-plugin": "^5.4.0",
|
|
92
98
|
"@typescript-eslint/parser": "^5.4.1-0",
|
|
@@ -99,10 +105,10 @@
|
|
|
99
105
|
"eslint": "^8.0.0",
|
|
100
106
|
"eslint-config-prettier": "^8.3.0",
|
|
101
107
|
"eslint-plugin-eslint-comments": "^3.2.0",
|
|
102
|
-
"eslint-plugin-eslint-plugin": "^
|
|
103
|
-
"eslint-plugin-json-schema-validator": "^
|
|
108
|
+
"eslint-plugin-eslint-plugin": "^5.0.0",
|
|
109
|
+
"eslint-plugin-json-schema-validator": "^4.0.0",
|
|
104
110
|
"eslint-plugin-jsonc": "^2.0.0",
|
|
105
|
-
"eslint-plugin-markdown": "^
|
|
111
|
+
"eslint-plugin-markdown": "^3.0.0",
|
|
106
112
|
"eslint-plugin-node": "^11.1.0",
|
|
107
113
|
"eslint-plugin-node-dependencies": "^0.9.0",
|
|
108
114
|
"eslint-plugin-prettier": "^4.0.0",
|
|
@@ -119,7 +125,6 @@
|
|
|
119
125
|
"mocha": "^10.0.0",
|
|
120
126
|
"nyc": "^15.1.0",
|
|
121
127
|
"pako": "^2.0.3",
|
|
122
|
-
"pirates": "^4.0.1",
|
|
123
128
|
"postcss-nested": "^5.0.6",
|
|
124
129
|
"prettier": "^2.2.1",
|
|
125
130
|
"prettier-plugin-pkg": "^0.16.0",
|
|
@@ -134,8 +139,8 @@
|
|
|
134
139
|
"svelte": "^3.46.1",
|
|
135
140
|
"svelte-adapter-ghpages": "0.0.2",
|
|
136
141
|
"typescript": "^4.5.2",
|
|
137
|
-
"vite": "^
|
|
138
|
-
"vite-plugin-svelte-md": "^0.1.
|
|
142
|
+
"vite": "^3.0.0-0",
|
|
143
|
+
"vite-plugin-svelte-md": "^0.1.5"
|
|
139
144
|
},
|
|
140
145
|
"publishConfig": {
|
|
141
146
|
"access": "public"
|