Skip to content

Files

Latest commit

 

History

History
61 lines (47 loc) · 1.99 KB

block-lang.md

File metadata and controls

61 lines (47 loc) · 1.99 KB

Pattern: Use of unexpected language

Issue: -

Description

This rule enforces all svelte components to use the same set of languages for their scripts and styles.

<!-- ✓ GOOD -->
<script lang="ts">
  /* eslint svelte/block-lang: ["error", { "script": "ts" }] */
</script>
<!-- ✓ GOOD -->
<script>
  /* eslint svelte/block-lang: ["error", { "script": ["ts", null], "style": "scss" }] */
</script>

<style lang="scss">
</style>
<!-- ✗ BAD -->
<script>
  /* eslint svelte/block-lang: ["error", { "script": ["ts"] }] */
</script>

🔧 Options

{
  "svelte/block-lang": [
    "error",
    {
      "enforceScriptPresent": true,
      "enforceStylePresent": false,
      "script": ["ts", null], // a list of languages or null to signify no language specified
      "style": "scss" // same as for script, a single value can be used instead of an array.
    }
  ]
}
  • enforceScriptPresent ... Whether to enforce the presence of a <script> block with one of the given languages. This may be useful as for example TypeScript checks some uses of a component if it is defined as being TypeScript. Default false.
  • enforceStylePresent ... Whether to enforce the presence of a <style> block with one of the given languages. Default false.
  • script ... A list of languages allowed for the <script> block. If null is included, no lang attribute is also allowed. A plain string or null can be used instead of one-item array. Default null.
  • style ... A list of languages allowed for the <style> block. If null is included, no lang attribute is also allowed. A plain string or null can be used instead of one-item array. Default null.

🚀 Version

This rule was introduced in eslint-plugin-svelte v2.18.0

🔍 Implementation