diff --git a/.changeset/giant-pillows-shave.md b/.changeset/giant-pillows-shave.md
new file mode 100644
index 000000000..de240de65
--- /dev/null
+++ b/.changeset/giant-pillows-shave.md
@@ -0,0 +1,5 @@
+---
+"eslint-plugin-svelte": patch
+---
+
+feat(block-lang): added support for multiple modules of the same type
diff --git a/src/rules/block-lang.ts b/src/rules/block-lang.ts
index d526ef16b..0ed70e0d1 100644
--- a/src/rules/block-lang.ts
+++ b/src/rules/block-lang.ts
@@ -72,29 +72,37 @@ export default createRule("block-lang", {
const allowedScriptLangs: (string | null)[] = Array.isArray(scriptOption)
? scriptOption
: [scriptOption]
- let scriptLang: string | null = null
- let scriptNode: SvelteScriptElement | undefined = undefined
+ const scriptNodes: SvelteScriptElement[] = []
const styleOption: string | null | (string | null)[] =
context.options[0]?.style ?? null
const allowedStyleLangs: (string | null)[] = Array.isArray(styleOption)
? styleOption
: [styleOption]
- let styleLang: string | null = null
- let styleNode: SvelteStyleElement | undefined = undefined
+ const styleNodes: SvelteStyleElement[] = []
return {
SvelteScriptElement(node) {
- scriptNode = node
- scriptLang = getLangValue(node)?.toLowerCase() ?? null
+ scriptNodes.push(node)
},
SvelteStyleElement(node) {
- styleNode = node
- styleLang = 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
+
+
diff --git a/tests/fixtures/rules/block-lang/invalid/script/module-context/js01-errors.yaml b/tests/fixtures/rules/block-lang/invalid/script/module-context/js01-errors.yaml
new file mode 100644
index 000000000..b42a142cf
--- /dev/null
+++ b/tests/fixtures/rules/block-lang/invalid/script/module-context/js01-errors.yaml
@@ -0,0 +1,4 @@
+- message: The lang attribute of the
+
+
diff --git a/tests/fixtures/rules/block-lang/invalid/script/module-context/null01-errors.yaml b/tests/fixtures/rules/block-lang/invalid/script/module-context/null01-errors.yaml
new file mode 100644
index 000000000..b42a142cf
--- /dev/null
+++ b/tests/fixtures/rules/block-lang/invalid/script/module-context/null01-errors.yaml
@@ -0,0 +1,4 @@
+- message: The lang attribute of the
+
+
diff --git a/tests/fixtures/rules/block-lang/invalid/script/module-context/ts-as-style-lang01-errors.yaml b/tests/fixtures/rules/block-lang/invalid/script/module-context/ts-as-style-lang01-errors.yaml
new file mode 100644
index 000000000..b42a142cf
--- /dev/null
+++ b/tests/fixtures/rules/block-lang/invalid/script/module-context/ts-as-style-lang01-errors.yaml
@@ -0,0 +1,4 @@
+- message: The lang attribute of the
+
+
+
+
diff --git a/tests/fixtures/rules/block-lang/invalid/script/module-context/typescript01-errors.yaml b/tests/fixtures/rules/block-lang/invalid/script/module-context/typescript01-errors.yaml
new file mode 100644
index 000000000..b42a142cf
--- /dev/null
+++ b/tests/fixtures/rules/block-lang/invalid/script/module-context/typescript01-errors.yaml
@@ -0,0 +1,4 @@
+- message: The lang attribute of the
+
+