From bcf2ff4ba99cc9ee44510c95f718582cba695803 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Fri, 2 Nov 2018 20:24:41 +0900 Subject: [PATCH 1/6] Added no-duplicate-attr-inheritence rule --- docs/rules/no-duplicate-attr-inheritence.md | 38 +++++++ lib/rules/no-duplicate-attr-inheritence.js | 51 +++++++++ .../rules/no-duplicate-attr-inheritence.js | 104 ++++++++++++++++++ 3 files changed, 193 insertions(+) create mode 100644 docs/rules/no-duplicate-attr-inheritence.md create mode 100644 lib/rules/no-duplicate-attr-inheritence.js create mode 100644 tests/lib/rules/no-duplicate-attr-inheritence.js diff --git a/docs/rules/no-duplicate-attr-inheritence.md b/docs/rules/no-duplicate-attr-inheritence.md new file mode 100644 index 000000000..ca52272ac --- /dev/null +++ b/docs/rules/no-duplicate-attr-inheritence.md @@ -0,0 +1,38 @@ +# Disable inheritAttrs when using v-bind="$attrs" (vue/no-duplicate-attr-inheritence) + +- :gear: This rule is included in `"plugin:vue/recommended"`. + +Please describe the origin of the rule here. + + +## Rule Details + +This rule aims to... + +Examples of **incorrect** code for this rule: + +```js + +// fill me in + +``` + +Examples of **correct** code for this rule: + +```js + +// fill me in + +``` + +### Options + +If there are any options, describe them here. Otherwise, delete this section. + +## When Not To Use It + +Give a short description of when it would be appropriate to turn off this rule. + +## Further Reading + +If there are other links that describe the issue this rule addresses, please include them here in a bulleted list. diff --git a/lib/rules/no-duplicate-attr-inheritence.js b/lib/rules/no-duplicate-attr-inheritence.js new file mode 100644 index 000000000..9bc17ae07 --- /dev/null +++ b/lib/rules/no-duplicate-attr-inheritence.js @@ -0,0 +1,51 @@ +/** + * @fileoverview Disable inheritAttrs when using v-bind="$attrs" + * @author Hiroki Osame + */ +'use strict' + +const utils = require('../utils') + +// ------------------------------------------------------------------------------ +// Rule Definition +// ------------------------------------------------------------------------------ + +module.exports = { + meta: { + docs: { + description: 'enforce inheritAttrs: false when using v-bind="$attrs"', + category: 'recommended', + recommended: false, + url: 'https://github.com/vuejs/eslint-plugin-vue/blob/v5.0.0-beta.3/docs/rules/no-duplicate-attr-inheritence.md' + }, + fixable: null, + schema: [ + // fill in your schema + ] + }, + + create (context) { + let inheritsAttrs = true + + return { + ...utils.executeOnVue(context, (node) => { + const inheritAttrsProp = node.properties.find(prop => (prop.type === 'Property' && prop.key.type === 'Identifier' && prop.key.name === 'inheritAttrs')) + + if (inheritAttrsProp && inheritAttrsProp.value.type === 'Literal') { + inheritsAttrs = inheritAttrsProp.value.value + } + }), + + ...utils.defineTemplateBodyVisitor(context, { + "VAttribute[directive=true][key.name='bind'][value.expression.name='$attrs']" (node) { + if (inheritsAttrs) { + context.report({ + node, + message: 'Set "inheritAttrs" to false.' + }) + } + } + }) + } + } +} diff --git a/tests/lib/rules/no-duplicate-attr-inheritence.js b/tests/lib/rules/no-duplicate-attr-inheritence.js new file mode 100644 index 000000000..02ffc33a1 --- /dev/null +++ b/tests/lib/rules/no-duplicate-attr-inheritence.js @@ -0,0 +1,104 @@ +/** + * @fileoverview Disable inheritAttrs when using v-bind="$attrs" + * @author Hiroki Osame + */ +'use strict' + +// ------------------------------------------------------------------------------ +// Requirements +// ------------------------------------------------------------------------------ + +var rule = require('../../../lib/rules/no-duplicate-attr-inheritence') + +var RuleTester = require('eslint').RuleTester + +// ------------------------------------------------------------------------------ +// Tests +// ------------------------------------------------------------------------------ + +var ruleTester = new RuleTester({ + parser: 'vue-eslint-parser', + parserOptions: { + ecmaVersion: 2018, + sourceType: 'module' + } +}) +ruleTester.run('no-duplicate-attr-inheritence', rule, { + + valid: [ + { + filename: 'test.vue', + code: '' + }, + { + filename: 'test.vue', + code: ` + + + ` + }, + { + filename: 'test.vue', + code: ` + + + ` + }, + { + filename: 'test.vue', + code: ` + + + ` + }, + { + filename: 'test.vue', + code: ` + + + ` + }, + { + filename: 'test.vue', + code: ` + + + ` + } + ], + + invalid: [ + { + filename: 'test.vue', + code: '', + errors: ['Set "inheritAttrs" to false.'] + }, + { + filename: 'test.vue', + code: ` + + + `, + errors: ['Set "inheritAttrs" to false.'] + } + ] +}) From af060be7aa7f993060fd4553abb25d801a829035 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Fri, 2 Nov 2018 20:32:18 +0900 Subject: [PATCH 2/6] New rule no-duplicate-attr-inheritance --- docs/rules/no-duplicate-attr-inheritence.md | 38 ------- lib/rules/no-duplicate-attr-inheritence.js | 51 --------- .../rules/no-duplicate-attr-inheritence.js | 104 ------------------ 3 files changed, 193 deletions(-) delete mode 100644 docs/rules/no-duplicate-attr-inheritence.md delete mode 100644 lib/rules/no-duplicate-attr-inheritence.js delete mode 100644 tests/lib/rules/no-duplicate-attr-inheritence.js diff --git a/docs/rules/no-duplicate-attr-inheritence.md b/docs/rules/no-duplicate-attr-inheritence.md deleted file mode 100644 index ca52272ac..000000000 --- a/docs/rules/no-duplicate-attr-inheritence.md +++ /dev/null @@ -1,38 +0,0 @@ -# Disable inheritAttrs when using v-bind="$attrs" (vue/no-duplicate-attr-inheritence) - -- :gear: This rule is included in `"plugin:vue/recommended"`. - -Please describe the origin of the rule here. - - -## Rule Details - -This rule aims to... - -Examples of **incorrect** code for this rule: - -```js - -// fill me in - -``` - -Examples of **correct** code for this rule: - -```js - -// fill me in - -``` - -### Options - -If there are any options, describe them here. Otherwise, delete this section. - -## When Not To Use It - -Give a short description of when it would be appropriate to turn off this rule. - -## Further Reading - -If there are other links that describe the issue this rule addresses, please include them here in a bulleted list. diff --git a/lib/rules/no-duplicate-attr-inheritence.js b/lib/rules/no-duplicate-attr-inheritence.js deleted file mode 100644 index 9bc17ae07..000000000 --- a/lib/rules/no-duplicate-attr-inheritence.js +++ /dev/null @@ -1,51 +0,0 @@ -/** - * @fileoverview Disable inheritAttrs when using v-bind="$attrs" - * @author Hiroki Osame - */ -'use strict' - -const utils = require('../utils') - -// ------------------------------------------------------------------------------ -// Rule Definition -// ------------------------------------------------------------------------------ - -module.exports = { - meta: { - docs: { - description: 'enforce inheritAttrs: false when using v-bind="$attrs"', - category: 'recommended', - recommended: false, - url: 'https://github.com/vuejs/eslint-plugin-vue/blob/v5.0.0-beta.3/docs/rules/no-duplicate-attr-inheritence.md' - }, - fixable: null, - schema: [ - // fill in your schema - ] - }, - - create (context) { - let inheritsAttrs = true - - return { - ...utils.executeOnVue(context, (node) => { - const inheritAttrsProp = node.properties.find(prop => (prop.type === 'Property' && prop.key.type === 'Identifier' && prop.key.name === 'inheritAttrs')) - - if (inheritAttrsProp && inheritAttrsProp.value.type === 'Literal') { - inheritsAttrs = inheritAttrsProp.value.value - } - }), - - ...utils.defineTemplateBodyVisitor(context, { - "VAttribute[directive=true][key.name='bind'][value.expression.name='$attrs']" (node) { - if (inheritsAttrs) { - context.report({ - node, - message: 'Set "inheritAttrs" to false.' - }) - } - } - }) - } - } -} diff --git a/tests/lib/rules/no-duplicate-attr-inheritence.js b/tests/lib/rules/no-duplicate-attr-inheritence.js deleted file mode 100644 index 02ffc33a1..000000000 --- a/tests/lib/rules/no-duplicate-attr-inheritence.js +++ /dev/null @@ -1,104 +0,0 @@ -/** - * @fileoverview Disable inheritAttrs when using v-bind="$attrs" - * @author Hiroki Osame - */ -'use strict' - -// ------------------------------------------------------------------------------ -// Requirements -// ------------------------------------------------------------------------------ - -var rule = require('../../../lib/rules/no-duplicate-attr-inheritence') - -var RuleTester = require('eslint').RuleTester - -// ------------------------------------------------------------------------------ -// Tests -// ------------------------------------------------------------------------------ - -var ruleTester = new RuleTester({ - parser: 'vue-eslint-parser', - parserOptions: { - ecmaVersion: 2018, - sourceType: 'module' - } -}) -ruleTester.run('no-duplicate-attr-inheritence', rule, { - - valid: [ - { - filename: 'test.vue', - code: '' - }, - { - filename: 'test.vue', - code: ` - - - ` - }, - { - filename: 'test.vue', - code: ` - - - ` - }, - { - filename: 'test.vue', - code: ` - - - ` - }, - { - filename: 'test.vue', - code: ` - - - ` - }, - { - filename: 'test.vue', - code: ` - - - ` - } - ], - - invalid: [ - { - filename: 'test.vue', - code: '', - errors: ['Set "inheritAttrs" to false.'] - }, - { - filename: 'test.vue', - code: ` - - - `, - errors: ['Set "inheritAttrs" to false.'] - } - ] -}) From 8da0e26c29a600c20c15765ee4a4f8b76bc406b7 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Fri, 2 Nov 2018 20:33:55 +0900 Subject: [PATCH 3/6] New rule no-duplicate-attr-inheritance --- docs/rules/no-duplicate-attr-inheritance.md | 38 +++++++ lib/rules/no-duplicate-attr-inheritance.js | 51 +++++++++ .../rules/no-duplicate-attr-inheritance.js | 104 ++++++++++++++++++ 3 files changed, 193 insertions(+) create mode 100644 docs/rules/no-duplicate-attr-inheritance.md create mode 100644 lib/rules/no-duplicate-attr-inheritance.js create mode 100644 tests/lib/rules/no-duplicate-attr-inheritance.js diff --git a/docs/rules/no-duplicate-attr-inheritance.md b/docs/rules/no-duplicate-attr-inheritance.md new file mode 100644 index 000000000..8cac68c04 --- /dev/null +++ b/docs/rules/no-duplicate-attr-inheritance.md @@ -0,0 +1,38 @@ +# Disable inheritAttrs when using v-bind="$attrs" (vue/no-duplicate-attr-inheritance) + +- :gear: This rule is included in `"plugin:vue/recommended"`. + +Please describe the origin of the rule here. + + +## Rule Details + +This rule aims to... + +Examples of **incorrect** code for this rule: + +```js + +// fill me in + +``` + +Examples of **correct** code for this rule: + +```js + +// fill me in + +``` + +### Options + +If there are any options, describe them here. Otherwise, delete this section. + +## When Not To Use It + +Give a short description of when it would be appropriate to turn off this rule. + +## Further Reading + +If there are other links that describe the issue this rule addresses, please include them here in a bulleted list. diff --git a/lib/rules/no-duplicate-attr-inheritance.js b/lib/rules/no-duplicate-attr-inheritance.js new file mode 100644 index 000000000..6be34211b --- /dev/null +++ b/lib/rules/no-duplicate-attr-inheritance.js @@ -0,0 +1,51 @@ +/** + * @fileoverview Disable inheritAttrs when using v-bind="$attrs" + * @author Hiroki Osame + */ +'use strict' + +const utils = require('../utils') + +// ------------------------------------------------------------------------------ +// Rule Definition +// ------------------------------------------------------------------------------ + +module.exports = { + meta: { + docs: { + description: 'enforce inheritAttrs: false when using v-bind="$attrs"', + category: 'recommended', + recommended: false, + url: 'https://github.com/vuejs/eslint-plugin-vue/blob/v5.0.0-beta.3/docs/rules/no-duplicate-attr-inheritance.md' + }, + fixable: null, + schema: [ + // fill in your schema + ] + }, + + create (context) { + let inheritsAttrs = true + + return { + ...utils.executeOnVue(context, (node) => { + const inheritAttrsProp = node.properties.find(prop => (prop.type === 'Property' && prop.key.type === 'Identifier' && prop.key.name === 'inheritAttrs')) + + if (inheritAttrsProp && inheritAttrsProp.value.type === 'Literal') { + inheritsAttrs = inheritAttrsProp.value.value + } + }), + + ...utils.defineTemplateBodyVisitor(context, { + "VAttribute[directive=true][key.name='bind'][value.expression.name='$attrs']" (node) { + if (inheritsAttrs) { + context.report({ + node, + message: 'Set "inheritAttrs" to false.' + }) + } + } + }) + } + } +} diff --git a/tests/lib/rules/no-duplicate-attr-inheritance.js b/tests/lib/rules/no-duplicate-attr-inheritance.js new file mode 100644 index 000000000..e6a47b99d --- /dev/null +++ b/tests/lib/rules/no-duplicate-attr-inheritance.js @@ -0,0 +1,104 @@ +/** + * @fileoverview Disable inheritAttrs when using v-bind="$attrs" + * @author Hiroki Osame + */ +'use strict' + +// ------------------------------------------------------------------------------ +// Requirements +// ------------------------------------------------------------------------------ + +var rule = require('../../../lib/rules/no-duplicate-attr-inheritance') + +var RuleTester = require('eslint').RuleTester + +// ------------------------------------------------------------------------------ +// Tests +// ------------------------------------------------------------------------------ + +var ruleTester = new RuleTester({ + parser: 'vue-eslint-parser', + parserOptions: { + ecmaVersion: 2018, + sourceType: 'module' + } +}) +ruleTester.run('no-duplicate-attr-inheritance', rule, { + + valid: [ + { + filename: 'test.vue', + code: '' + }, + { + filename: 'test.vue', + code: ` + + + ` + }, + { + filename: 'test.vue', + code: ` + + + ` + }, + { + filename: 'test.vue', + code: ` + + + ` + }, + { + filename: 'test.vue', + code: ` + + + ` + }, + { + filename: 'test.vue', + code: ` + + + ` + } + ], + + invalid: [ + { + filename: 'test.vue', + code: '', + errors: ['Set "inheritAttrs" to false.'] + }, + { + filename: 'test.vue', + code: ` + + + `, + errors: ['Set "inheritAttrs" to false.'] + } + ] +}) From 5ae1f6e28d7248c52a9c66fdd994a4ad812bac0b Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Fri, 2 Nov 2018 20:49:35 +0900 Subject: [PATCH 4/6] Code to work with Node v6.14.4 --- lib/rules/no-duplicate-attr-inheritance.js | 9 ++++----- tests/lib/utils/index.js | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/rules/no-duplicate-attr-inheritance.js b/lib/rules/no-duplicate-attr-inheritance.js index 6be34211b..8dc160ba5 100644 --- a/lib/rules/no-duplicate-attr-inheritance.js +++ b/lib/rules/no-duplicate-attr-inheritance.js @@ -27,16 +27,15 @@ module.exports = { create (context) { let inheritsAttrs = true - return { - ...utils.executeOnVue(context, (node) => { + return Object.assign( + utils.executeOnVue(context, (node) => { const inheritAttrsProp = node.properties.find(prop => (prop.type === 'Property' && prop.key.type === 'Identifier' && prop.key.name === 'inheritAttrs')) if (inheritAttrsProp && inheritAttrsProp.value.type === 'Literal') { inheritsAttrs = inheritAttrsProp.value.value } }), - - ...utils.defineTemplateBodyVisitor(context, { + utils.defineTemplateBodyVisitor(context, { "VAttribute[directive=true][key.name='bind'][value.expression.name='$attrs']" (node) { if (inheritsAttrs) { context.report({ @@ -46,6 +45,6 @@ module.exports = { } } }) - } + ) } } diff --git a/tests/lib/utils/index.js b/tests/lib/utils/index.js index f698a98ef..940c346e7 100644 --- a/tests/lib/utils/index.js +++ b/tests/lib/utils/index.js @@ -243,7 +243,7 @@ describe('getRegisteredComponents', () => { assert.deepEqual( utils.getRegisteredComponents(node).map(c => c.name), - ['PrimaryButton', 'secondaryButton', 'the-modal', 'the_dropdown', 'the_input', 'SomeComponent'], + ['PrimaryButton', 'secondaryButton', 'the-modal', 'the_dropdown', 'the_input', 'SomeComponent'] ) }) From 80077951df8a688ec600cb0fb3538ebeb3416ab1 Mon Sep 17 00:00:00 2001 From: Armano Date: Tue, 6 Nov 2018 15:01:23 +0900 Subject: [PATCH 5/6] Remove category Co-Authored-By: hirokiosame --- lib/rules/no-duplicate-attr-inheritance.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/rules/no-duplicate-attr-inheritance.js b/lib/rules/no-duplicate-attr-inheritance.js index 8dc160ba5..f4e9222f6 100644 --- a/lib/rules/no-duplicate-attr-inheritance.js +++ b/lib/rules/no-duplicate-attr-inheritance.js @@ -14,7 +14,7 @@ module.exports = { meta: { docs: { description: 'enforce inheritAttrs: false when using v-bind="$attrs"', - category: 'recommended', + category: undefined, recommended: false, url: 'https://github.com/vuejs/eslint-plugin-vue/blob/v5.0.0-beta.3/docs/rules/no-duplicate-attr-inheritance.md' }, From 31116164efb0362b0f5c151005e779126a90ec6b Mon Sep 17 00:00:00 2001 From: yosuke ota Date: Tue, 19 May 2020 16:20:37 +0900 Subject: [PATCH 6/6] Update --- docs/rules/README.md | 1 + docs/rules/no-duplicate-attr-inheritance.md | 70 ++++++++++++------- lib/index.js | 1 + lib/rules/no-duplicate-attr-inheritance.js | 26 +++++-- .../rules/no-duplicate-attr-inheritance.js | 11 ++- tests/lib/utils/index.js | 2 +- 6 files changed, 76 insertions(+), 35 deletions(-) diff --git a/docs/rules/README.md b/docs/rules/README.md index 83eda5692..b89debd60 100644 --- a/docs/rules/README.md +++ b/docs/rules/README.md @@ -282,6 +282,7 @@ For example: | [vue/match-component-file-name](./match-component-file-name.md) | require component name property to match its file name | | | [vue/max-len](./max-len.md) | enforce a maximum line length | | | [vue/no-boolean-default](./no-boolean-default.md) | disallow boolean defaults | :wrench: | +| [vue/no-duplicate-attr-inheritance](./no-duplicate-attr-inheritance.md) | enforce `inheritAttrs` to be set to `false` when using `v-bind="$attrs"` | | | [vue/no-empty-pattern](./no-empty-pattern.md) | disallow empty destructuring patterns | | | [vue/no-irregular-whitespace](./no-irregular-whitespace.md) | disallow irregular whitespace | | | [vue/no-reserved-component-names](./no-reserved-component-names.md) | disallow the use of reserved names in component definitions | | diff --git a/docs/rules/no-duplicate-attr-inheritance.md b/docs/rules/no-duplicate-attr-inheritance.md index 8cac68c04..959124e48 100644 --- a/docs/rules/no-duplicate-attr-inheritance.md +++ b/docs/rules/no-duplicate-attr-inheritance.md @@ -1,38 +1,56 @@ -# Disable inheritAttrs when using v-bind="$attrs" (vue/no-duplicate-attr-inheritance) - -- :gear: This rule is included in `"plugin:vue/recommended"`. - -Please describe the origin of the rule here. - - -## Rule Details - -This rule aims to... - -Examples of **incorrect** code for this rule: - -```js - -// fill me in - +--- +pageClass: rule-details +sidebarDepth: 0 +title: vue/no-duplicate-attr-inheritance +description: enforce `inheritAttrs` to be set to `false` when using `v-bind="$attrs"` +--- +# vue/no-duplicate-attr-inheritance +> enforce `inheritAttrs` to be set to `false` when using `v-bind="$attrs"` + +## :book: Rule Details + +This rule aims to prevent duplicated attribute inheritance. +This rule to warn to apply `inheritAttrs: false` when it detects `v-bind="$attrs"` being used. + + + +```vue + + ` + }, + { + filename: 'test.vue', + code: ` + + + ` } ], diff --git a/tests/lib/utils/index.js b/tests/lib/utils/index.js index 940c346e7..f698a98ef 100644 --- a/tests/lib/utils/index.js +++ b/tests/lib/utils/index.js @@ -243,7 +243,7 @@ describe('getRegisteredComponents', () => { assert.deepEqual( utils.getRegisteredComponents(node).map(c => c.name), - ['PrimaryButton', 'secondaryButton', 'the-modal', 'the_dropdown', 'the_input', 'SomeComponent'] + ['PrimaryButton', 'secondaryButton', 'the-modal', 'the_dropdown', 'the_input', 'SomeComponent'], ) })