From c5ada108eab0203b024c7d9801f537d42e40d15b Mon Sep 17 00:00:00 2001 From: Yosuke Ota Date: Fri, 30 Jul 2021 16:03:34 +0900 Subject: [PATCH] Add `vue/block-lang` rule. (#1586) --- docs/rules/README.md | 3 +- docs/rules/block-lang.md | 91 ++++++++++++++ lib/index.js | 1 + lib/rules/block-lang.js | 224 ++++++++++++++++++++++++++++++++++ lib/utils/index.js | 12 ++ tests/lib/rules/block-lang.js | 181 +++++++++++++++++++++++++++ 6 files changed, 511 insertions(+), 1 deletion(-) create mode 100644 docs/rules/block-lang.md create mode 100644 lib/rules/block-lang.js create mode 100644 tests/lib/rules/block-lang.js diff --git a/docs/rules/README.md b/docs/rules/README.md index 0cc9bf16f..f7a2e01d5 100644 --- a/docs/rules/README.md +++ b/docs/rules/README.md @@ -279,13 +279,14 @@ For example: ```json { "rules": { - "vue/block-tag-newline": "error" + "vue/block-lang": "error" } } ``` | Rule ID | Description | | |:--------|:------------|:---| +| [vue/block-lang](./block-lang.md) | disallow use other than available `lang` | | | [vue/block-tag-newline](./block-tag-newline.md) | enforce line breaks after opening and before closing block-level tags | :wrench: | | [vue/component-name-in-template-casing](./component-name-in-template-casing.md) | enforce specific casing for the component naming style in template | :wrench: | | [vue/custom-event-name-casing](./custom-event-name-casing.md) | enforce specific casing for custom event name | | diff --git a/docs/rules/block-lang.md b/docs/rules/block-lang.md new file mode 100644 index 000000000..9b342c0b2 --- /dev/null +++ b/docs/rules/block-lang.md @@ -0,0 +1,91 @@ +--- +pageClass: rule-details +sidebarDepth: 0 +title: vue/block-lang +description: disallow use other than available `lang` +--- +# vue/block-lang + +> disallow use other than available `lang` + +- :exclamation: ***This rule has not been released yet.*** + +## :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" + } + } + ] +} +``` + + + +```vue + + +``` + + + + + +```vue + + +``` + + + +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 `