From a940da8dcba2d07ee4f2cfec4dd01b599b47102f Mon Sep 17 00:00:00 2001 From: Jonathan Santerre Date: Sat, 7 Dec 2019 14:27:25 -0500 Subject: [PATCH 1/7] New: vue/html-button-has-type rule (fixes #894) --- docs/rules/README.md | 1 + docs/rules/html-button-has-type.md | 62 ++++++++++ docs/rules/script-indent.md | 1 - lib/configs/recommended.js | 1 + lib/index.js | 1 + lib/rules/html-button-has-type.js | 96 +++++++++++++++ tests/lib/rules/html-button-has-type.js | 157 ++++++++++++++++++++++++ 7 files changed, 318 insertions(+), 1 deletion(-) create mode 100644 docs/rules/html-button-has-type.md create mode 100644 lib/rules/html-button-has-type.js create mode 100644 tests/lib/rules/html-button-has-type.js diff --git a/docs/rules/README.md b/docs/rules/README.md index e1c88ff56..cb573a90c 100644 --- a/docs/rules/README.md +++ b/docs/rules/README.md @@ -118,6 +118,7 @@ Enforce all the rules in this category, as well as all higher priority rules, wi | Rule ID | Description | | |:--------|:------------|:---| | [vue/attributes-order](./attributes-order.md) | enforce order of attributes | :wrench: | +| [vue/html-button-has-type](./html-button-has-type.md) | Prevent usage of button without an explicit type attribute | | | [vue/no-v-html](./no-v-html.md) | disallow use of v-html to prevent XSS attack | | | [vue/order-in-components](./order-in-components.md) | enforce order of properties in components | :wrench: | | [vue/this-in-template](./this-in-template.md) | disallow usage of `this` in template | | diff --git a/docs/rules/html-button-has-type.md b/docs/rules/html-button-has-type.md new file mode 100644 index 000000000..67a3c7dac --- /dev/null +++ b/docs/rules/html-button-has-type.md @@ -0,0 +1,62 @@ +--- +pageClass: rule-details +sidebarDepth: 0 +title: vue/html-button-has-type +description: Prevent usage of button without an explicit type attribute +--- +# vue/html-button-has-type +> Prevent usage of button without an explicit type attribute + +- :gear: This rule is included in `"plugin:vue/recommended"`. + +Forgetting the type attribute on a button defaults it to being a submit type. +This is nearly never what is intended, especially in your average one-page application. + +## :book: Rule Details + +This rule aims to warn if no type or an invalid type is used on a button type attribute. + + + +```vue + +``` + + + +## :wrench: Options + +```json +{ + "vue/html-button-has-type": ["error", { + "button": true, + "submit": true, + "reset": true + }] +} +``` + +- `button` ... `` + - `true` (default) ... allow value `button`. + - `false"` ... disallow value `button`. +- `sumbit` ... `` + - `true` (default) ... allow value `submit`. + - `false"` ... disallow value `submit`. +- `reset` ... `` + - `true` (default) ... allow value `reset`. + - `false"` ... disallow value `reset`. + +## :mag: Implementation + +- [Rule source](https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/html-button-has-type.js) +- [Test source](https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/html-button-has-type.js) diff --git a/docs/rules/script-indent.md b/docs/rules/script-indent.md index c28120b7d..59934faec 100644 --- a/docs/rules/script-indent.md +++ b/docs/rules/script-indent.md @@ -115,7 +115,6 @@ This rule only checks `.vue` files and does not interfere with other `.js` files - [indent](https://eslint.org/docs/rules/indent) - [vue/html-indent](./html-indent.md) -- [@typescript-eslint/indent](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/indent.md). The `vue/script-indent` rule does not understand TypeScript AST. Please use `@typescript-eslint/indent` rule instead of this one inside of `