eslint-plugin-svelte
Advanced tools
Comparing version 2.31.1 to 2.32.0
export declare const name: "eslint-plugin-svelte"; | ||
export declare const version: "2.31.1"; | ||
export declare const version: "2.32.0"; |
@@ -5,2 +5,2 @@ "use strict"; | ||
exports.name = "eslint-plugin-svelte"; | ||
exports.version = "2.31.1"; | ||
exports.version = "2.32.0"; |
@@ -67,4 +67,3 @@ "use strict"; | ||
: [scriptOption]; | ||
let scriptLang = null; | ||
let scriptNode = undefined; | ||
const scriptNodes = []; | ||
const styleOption = context.options[0]?.style ?? null; | ||
@@ -74,16 +73,19 @@ const allowedStyleLangs = Array.isArray(styleOption) | ||
: [styleOption]; | ||
let styleLang = null; | ||
let styleNode = undefined; | ||
const styleNodes = []; | ||
return { | ||
SvelteScriptElement(node) { | ||
scriptNode = node; | ||
scriptLang = (0, ast_utils_1.getLangValue)(node)?.toLowerCase() ?? null; | ||
scriptNodes.push(node); | ||
}, | ||
SvelteStyleElement(node) { | ||
styleNode = node; | ||
styleLang = (0, ast_utils_1.getLangValue)(node)?.toLowerCase() ?? null; | ||
styleNodes.push(node); | ||
}, | ||
"Program:exit"() { | ||
if (!allowedScriptLangs.includes(scriptLang)) { | ||
if (scriptNode !== undefined) { | ||
if (scriptNodes.length === 0 && enforceScriptPresent) { | ||
context.report({ | ||
loc: { line: 1, column: 1 }, | ||
message: `The <script> block should be present and its lang attribute should be ${prettyPrintLangs(allowedScriptLangs)}.`, | ||
}); | ||
} | ||
for (const scriptNode of scriptNodes) { | ||
if (!allowedScriptLangs.includes((0, ast_utils_1.getLangValue)(scriptNode)?.toLowerCase() ?? null)) { | ||
context.report({ | ||
@@ -95,10 +97,10 @@ node: scriptNode, | ||
} | ||
if (scriptNode === undefined && enforceScriptPresent) { | ||
if (styleNodes.length === 0 && enforceStylePresent) { | ||
context.report({ | ||
loc: { line: 1, column: 1 }, | ||
message: `The <script> block should be present and its lang attribute should be ${prettyPrintLangs(allowedScriptLangs)}.`, | ||
message: `The <style> block should be present and its lang attribute should be ${prettyPrintLangs(allowedStyleLangs)}.`, | ||
}); | ||
} | ||
if (!allowedStyleLangs.includes(styleLang)) { | ||
if (styleNode !== undefined) { | ||
for (const styleNode of styleNodes) { | ||
if (!allowedStyleLangs.includes((0, ast_utils_1.getLangValue)(styleNode)?.toLowerCase() ?? null)) { | ||
context.report({ | ||
@@ -110,8 +112,2 @@ node: styleNode, | ||
} | ||
if (styleNode === undefined && enforceStylePresent) { | ||
context.report({ | ||
loc: { line: 1, column: 1 }, | ||
message: `The <style> block should be present and its lang attribute should be ${prettyPrintLangs(allowedStyleLangs)}.`, | ||
}); | ||
} | ||
}, | ||
@@ -118,0 +114,0 @@ }; |
@@ -15,3 +15,16 @@ "use strict"; | ||
}, | ||
schema: [], | ||
schema: [ | ||
{ | ||
type: "object", | ||
properties: { | ||
allowedClassNames: { | ||
type: "array", | ||
items: { | ||
type: "string", | ||
}, | ||
}, | ||
}, | ||
additionalProperties: false, | ||
}, | ||
], | ||
messages: {}, | ||
@@ -24,2 +37,3 @@ type: "suggestion", | ||
} | ||
const allowedClassNames = context.options[0]?.allowedClassNames ?? []; | ||
const classesUsedInTemplate = {}; | ||
@@ -45,3 +59,4 @@ return { | ||
for (const className in classesUsedInTemplate) { | ||
if (!classesUsedInStyle.includes(className)) { | ||
if (!allowedClassNames.includes(className) && | ||
!classesUsedInStyle.includes(className)) { | ||
context.report({ | ||
@@ -48,0 +63,0 @@ loc: classesUsedInTemplate[className], |
{ | ||
"name": "eslint-plugin-svelte", | ||
"version": "2.31.1", | ||
"version": "2.32.0", | ||
"description": "ESLint plugin for Svelte using AST", | ||
@@ -30,3 +30,3 @@ "repository": "git+https://github.com/sveltejs/eslint-plugin-svelte.git", | ||
"eslint": "^7.0.0 || ^8.0.0-0", | ||
"svelte": "^3.37.0 || ^4.0.0-0" | ||
"svelte": "^3.37.0 || ^4.0.0" | ||
}, | ||
@@ -49,3 +49,3 @@ "peerDependenciesMeta": { | ||
"semver": "^7.5.3", | ||
"svelte-eslint-parser": "^0.31.0" | ||
"svelte-eslint-parser": "^0.32.0" | ||
}, | ||
@@ -138,3 +138,3 @@ "devDependencies": { | ||
"stylus": "^0.59.0", | ||
"svelte": "^4.0.0-0", | ||
"svelte": "^4.0.0", | ||
"svelte-adapter-ghpages": "0.1.0", | ||
@@ -141,0 +141,0 @@ "svelte-i18n": "^3.6.0", |
558076
12759
+ Addedsvelte-eslint-parser@0.32.2(transitive)
- Removedsvelte-eslint-parser@0.31.0(transitive)
Updatedsvelte-eslint-parser@^0.32.0