-
-
Notifications
You must be signed in to change notification settings - Fork 681
/
Copy pathblock-lang.md
95 lines (67 loc) · 2.28 KB
/
block-lang.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
---
pageClass: rule-details
sidebarDepth: 0
title: vue/block-lang
description: disallow use other than available `lang`
since: v7.15.0
---
# vue/block-lang
> disallow use other than available `lang`
## :book: Rule Details
This rule disallows the use of languages other than those available in the your application for the lang attribute of block elements.
## :wrench: Options
```json
{
"vue/block-lang": ["error",
{
"script": {
"lang": "ts"
}
}
]
}
```
<eslint-code-block :rules="{'vue/block-lang': ['error', { script: { lang: 'ts' } }]}">
```vue
<!-- ✓ GOOD -->
<script lang="ts">
</script>
```
</eslint-code-block>
<eslint-code-block :rules="{'vue/block-lang': ['error', { script: { lang: 'ts' } }]}">
```vue
<!-- ✗ BAD -->
<script>
</script>
```
</eslint-code-block>
Specify the block name for the key of the option object.
You can use the object as a value and use the following properties:
- `lang` ... Specifies the available value for the `lang` attribute of the block. If multiple languages are available, specify them as an array. If you do not specify it, will disallow any language.
- `allowNoLang` ... If `true`, allows the `lang` attribute not to be specified (allows the use of the default language of block).
::: warning Note
If the default language is specified for `lang` option of `<template>`, `<style>` and `<script>`, it will be enforced to not specify `lang` attribute.
This is to prevent unintended problems with [Vetur](https://vuejs.github.io/vetur/).
See also [Vetur - Syntax Highlighting](https://vuejs.github.io/vetur/guide/highlighting.html).
:::
### `{ script: { lang: 'js' } }`
Same as `{ script: { allowNoLang: true } }`.
<eslint-code-block :rules="{'vue/block-lang': ['error', { script: { lang: 'js' } }]}">
```vue
<!-- ✓ GOOD -->
<script>
</script>
```
</eslint-code-block>
<eslint-code-block :rules="{'vue/block-lang': ['error', { script: { lang: 'js' } }]}">
```vue
<!-- ✗ BAD -->
<script lang="js">
</script>
```
</eslint-code-block>
## :rocket: Version
This rule was introduced in eslint-plugin-vue v7.15.0
## :mag: Implementation
- [Rule source](https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/block-lang.js)
- [Test source](https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/block-lang.js)