eslint-plugin-svelte 2.19.2 → 2.20.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/README.md +1 -0
- package/lib/rules/block-lang.d.ts +2 -0
- package/lib/rules/block-lang.js +130 -0
- package/lib/utils/rules.js +2 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -330,6 +330,7 @@ These rules relate to better ways of doing things to help you avoid problems:
|
|
|
330
330
|
|
|
331
331
|
| Rule ID | Description | |
|
|
332
332
|
|:--------|:------------|:---|
|
|
333
|
+
| [svelte/block-lang](https://ota-meshi.github.io/eslint-plugin-svelte/rules/block-lang/) | disallows the use of languages other than those specified in the configuration for the lang attribute of `<script>` and `<style>` blocks. | |
|
|
333
334
|
| [svelte/button-has-type](https://ota-meshi.github.io/eslint-plugin-svelte/rules/button-has-type/) | disallow usage of button without an explicit type attribute | |
|
|
334
335
|
| [svelte/no-at-debug-tags](https://ota-meshi.github.io/eslint-plugin-svelte/rules/no-at-debug-tags/) | disallow the use of `{@debug}` | :star: |
|
|
335
336
|
| [svelte/no-reactive-functions](https://ota-meshi.github.io/eslint-plugin-svelte/rules/no-reactive-functions/) | it's not necessary to define functions in reactive statements | :bulb: |
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const utils_1 = require("../utils");
|
|
4
|
+
const ast_utils_1 = require("../utils/ast-utils");
|
|
5
|
+
exports.default = (0, utils_1.createRule)("block-lang", {
|
|
6
|
+
meta: {
|
|
7
|
+
docs: {
|
|
8
|
+
description: "disallows the use of languages other than those specified in the configuration for the lang attribute of `<script>` and `<style>` blocks.",
|
|
9
|
+
category: "Best Practices",
|
|
10
|
+
recommended: false,
|
|
11
|
+
},
|
|
12
|
+
schema: [
|
|
13
|
+
{
|
|
14
|
+
type: "object",
|
|
15
|
+
properties: {
|
|
16
|
+
enforceScriptPresent: {
|
|
17
|
+
type: "boolean",
|
|
18
|
+
},
|
|
19
|
+
enforceStylePresent: {
|
|
20
|
+
type: "boolean",
|
|
21
|
+
},
|
|
22
|
+
script: {
|
|
23
|
+
oneOf: [
|
|
24
|
+
{
|
|
25
|
+
type: ["string", "null"],
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
type: "array",
|
|
29
|
+
items: {
|
|
30
|
+
type: ["string", "null"],
|
|
31
|
+
},
|
|
32
|
+
minItems: 1,
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
},
|
|
36
|
+
style: {
|
|
37
|
+
oneOf: [
|
|
38
|
+
{
|
|
39
|
+
type: ["string", "null"],
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
type: "array",
|
|
43
|
+
items: {
|
|
44
|
+
type: ["string", "null"],
|
|
45
|
+
},
|
|
46
|
+
minItems: 1,
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
additionalProperties: false,
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
messages: {},
|
|
55
|
+
type: "suggestion",
|
|
56
|
+
},
|
|
57
|
+
create(context) {
|
|
58
|
+
if (!context.parserServices.isSvelte) {
|
|
59
|
+
return {};
|
|
60
|
+
}
|
|
61
|
+
const enforceScriptPresent = context.options[0]?.enforceScriptPresent ?? false;
|
|
62
|
+
const enforceStylePresent = context.options[0]?.enforceStylePresent ?? false;
|
|
63
|
+
const scriptOption = context.options[0]?.script ?? null;
|
|
64
|
+
const allowedScriptLangs = Array.isArray(scriptOption)
|
|
65
|
+
? scriptOption
|
|
66
|
+
: [scriptOption];
|
|
67
|
+
let scriptLang = null;
|
|
68
|
+
let scriptNode = undefined;
|
|
69
|
+
const styleOption = context.options[0]?.style ?? null;
|
|
70
|
+
const allowedStyleLangs = Array.isArray(styleOption)
|
|
71
|
+
? styleOption
|
|
72
|
+
: [styleOption];
|
|
73
|
+
let styleLang = null;
|
|
74
|
+
let styleNode = undefined;
|
|
75
|
+
return {
|
|
76
|
+
SvelteScriptElement(node) {
|
|
77
|
+
scriptNode = node;
|
|
78
|
+
scriptLang = (0, ast_utils_1.getLangValue)(node)?.toLowerCase() ?? null;
|
|
79
|
+
},
|
|
80
|
+
SvelteStyleElement(node) {
|
|
81
|
+
styleNode = node;
|
|
82
|
+
styleLang = (0, ast_utils_1.getLangValue)(node)?.toLowerCase() ?? null;
|
|
83
|
+
},
|
|
84
|
+
"Program:exit"() {
|
|
85
|
+
if (!allowedScriptLangs.includes(scriptLang)) {
|
|
86
|
+
if (scriptNode !== undefined) {
|
|
87
|
+
context.report({
|
|
88
|
+
node: scriptNode,
|
|
89
|
+
message: `The lang attribute of the <script> block should be ${prettyPrintLangs(allowedScriptLangs)}.`,
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
if (scriptNode === undefined && enforceScriptPresent) {
|
|
94
|
+
context.report({
|
|
95
|
+
loc: { line: 1, column: 1 },
|
|
96
|
+
message: `The <script> block should be present and its lang attribute should be ${prettyPrintLangs(allowedScriptLangs)}.`,
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
if (!allowedStyleLangs.includes(styleLang)) {
|
|
100
|
+
if (styleNode !== undefined) {
|
|
101
|
+
context.report({
|
|
102
|
+
node: styleNode,
|
|
103
|
+
message: `The lang attribute of the <style> block should be ${prettyPrintLangs(allowedStyleLangs)}.`,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if (styleNode === undefined && enforceStylePresent) {
|
|
108
|
+
context.report({
|
|
109
|
+
loc: { line: 1, column: 1 },
|
|
110
|
+
message: `The <style> block should be present and its lang attribute should be ${prettyPrintLangs(allowedStyleLangs)}.`,
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
},
|
|
116
|
+
});
|
|
117
|
+
function prettyPrintLangs(langs) {
|
|
118
|
+
const hasNull = langs.includes(null);
|
|
119
|
+
const nonNullLangs = langs
|
|
120
|
+
.filter((lang) => lang !== null)
|
|
121
|
+
.map((lang) => `"${lang}"`);
|
|
122
|
+
if (nonNullLangs.length === 0) {
|
|
123
|
+
return "omitted";
|
|
124
|
+
}
|
|
125
|
+
const hasNullText = hasNull ? "either omitted or " : "";
|
|
126
|
+
const nonNullText = nonNullLangs.length === 1
|
|
127
|
+
? nonNullLangs[0]
|
|
128
|
+
: `one of ${nonNullLangs.join(", ")}`;
|
|
129
|
+
return hasNullText + nonNullText;
|
|
130
|
+
}
|
package/lib/utils/rules.js
CHANGED
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.rules = void 0;
|
|
7
7
|
const no_unnecessary_condition_1 = __importDefault(require("../rules/@typescript-eslint/no-unnecessary-condition"));
|
|
8
|
+
const block_lang_1 = __importDefault(require("../rules/block-lang"));
|
|
8
9
|
const button_has_type_1 = __importDefault(require("../rules/button-has-type"));
|
|
9
10
|
const comment_directive_1 = __importDefault(require("../rules/comment-directive"));
|
|
10
11
|
const derived_has_same_inputs_outputs_1 = __importDefault(require("../rules/derived-has-same-inputs-outputs"));
|
|
@@ -58,6 +59,7 @@ const valid_compile_1 = __importDefault(require("../rules/valid-compile"));
|
|
|
58
59
|
const valid_prop_names_in_kit_pages_1 = __importDefault(require("../rules/valid-prop-names-in-kit-pages"));
|
|
59
60
|
exports.rules = [
|
|
60
61
|
no_unnecessary_condition_1.default,
|
|
62
|
+
block_lang_1.default,
|
|
61
63
|
button_has_type_1.default,
|
|
62
64
|
comment_directive_1.default,
|
|
63
65
|
derived_has_same_inputs_outputs_1.default,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-svelte",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.20.1",
|
|
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",
|