From 802791616c8a311f9e128100854182df5371c848 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sat, 14 Jul 2018 09:21:55 -0400 Subject: [PATCH] Fix attribute-hyphenation ignore lists (#513) * tests: attribute-hyphenation: Fix the ignore-list test The test introduced in f9e1eee3fe711b9dfedc037fe25aa5570370296e didn't actually test what it meant to test for. It attempts to verify that the ignore list is obeyed; but its subject is an element that is ignored in its entirety! The code under test was never triggered! Fix this by changing
for in the test case, and also add the same test-case without the `ignore` config, in order to verify that it actually has something to ignore. * attribute-hyphenation: Work correctly when ignore has != 1 item Currently, the "ignore" options array only works correctly with exactly 1 item. Adjust it to work with 0 and with >1 items. * attribute-hyphenation: Fix spelling mistakes - hypen -> hyphen - cann't -> can't * Update test suite for attribute-hyphenation --- lib/rules/attribute-hyphenation.js | 6 +- tests/lib/rules/attribute-hyphenation.js | 93 ++++++++++++++++++++++-- 2 files changed, 91 insertions(+), 8 deletions(-) diff --git a/lib/rules/attribute-hyphenation.js b/lib/rules/attribute-hyphenation.js index ea7306d4b..5514ac2d2 100644 --- a/lib/rules/attribute-hyphenation.js +++ b/lib/rules/attribute-hyphenation.js @@ -49,10 +49,10 @@ module.exports = { const option = context.options[0] const optionsPayload = context.options[1] const useHyphenated = option !== 'never' - const ignoredAttributes = ['data-', 'aria-', 'slot-scope'] + let ignoredAttributes = ['data-', 'aria-', 'slot-scope'] if (optionsPayload && optionsPayload.ignore) { - ignoredAttributes.push(optionsPayload.ignore) + ignoredAttributes = ignoredAttributes.concat(optionsPayload.ignore) } const caseConverter = casing.getConverter(useHyphenated ? 'kebab-case' : 'camelCase') @@ -63,7 +63,7 @@ module.exports = { context.report({ node: node.key, loc: node.loc, - message: useHyphenated ? "Attribute '{{text}}' must be hyphenated." : "Attribute '{{text}}' cann't be hyphenated.", + message: useHyphenated ? "Attribute '{{text}}' must be hyphenated." : "Attribute '{{text}}' can't be hyphenated.", data: { text }, diff --git a/tests/lib/rules/attribute-hyphenation.js b/tests/lib/rules/attribute-hyphenation.js index 340bd32d6..c1f9b57bc 100644 --- a/tests/lib/rules/attribute-hyphenation.js +++ b/tests/lib/rules/attribute-hyphenation.js @@ -45,8 +45,8 @@ ruleTester.run('attribute-hyphenation', rule, { }, { filename: 'test.vue', - code: '', - options: ['never', { 'ignore': ['custom-hypen'] }] + code: '', + options: ['never', { 'ignore': ['custom-hyphen', 'second-custom'] }] } ], @@ -57,7 +57,7 @@ ruleTester.run('attribute-hyphenation', rule, { output: '', options: ['never'], errors: [{ - message: "Attribute 'my-prop' cann't be hyphenated.", + message: "Attribute 'my-prop' can't be hyphenated.", type: 'VIdentifier', line: 1 }] @@ -79,7 +79,7 @@ ruleTester.run('attribute-hyphenation', rule, { output: '', options: ['never'], errors: [{ - message: "Attribute ':my-prop' cann't be hyphenated.", + message: "Attribute ':my-prop' can't be hyphenated.", type: 'VDirectiveKey', line: 1 }] @@ -101,7 +101,7 @@ ruleTester.run('attribute-hyphenation', rule, { output: '', options: ['never'], errors: [{ - message: "Attribute 'v-bind:my-prop' cann't be hyphenated.", + message: "Attribute 'v-bind:my-prop' can't be hyphenated.", type: 'VDirectiveKey', line: 1 }] @@ -116,6 +116,89 @@ ruleTester.run('attribute-hyphenation', rule, { type: 'VDirectiveKey', line: 1 }] + }, + { + filename: 'test.vue', + code: '', + output: '', + options: ['always', { 'ignore': [] }], + errors: [{ + message: "Attribute 'v-bind:MyProp' must be hyphenated.", + type: 'VDirectiveKey', + line: 1 + }] + }, + { + filename: 'test.vue', + code: '', + output: '', + options: ['never', { ignore: ['my-prop'] }], + errors: [{ + message: "Attribute ':second-prop' can't be hyphenated.", + type: 'VDirectiveKey', + line: 1 + }] + }, + { + filename: 'test.vue', + code: '', + output: '', + options: ['always', { ignore: ['secondProp'] }], + errors: [{ + message: "Attribute 'v-bind:myProp' must be hyphenated.", + type: 'VDirectiveKey', + line: 1 + }] + }, + { + filename: 'test.vue', + code: ` + + `, + output: ` + + `, + options: ['never', { 'ignore': ['custom-hyphen', 'second-custom'] }], + errors: [{ + message: "Attribute 'third-custom' can't be hyphenated.", + type: 'VIdentifier', + line: 3 + }] + }, + { + filename: 'test.vue', + code: ` + + `, + output: ` + + `, + options: ['never'], + errors: [{ + message: "Attribute 'custom-hyphen' can't be hyphenated.", + type: 'VIdentifier', + line: 3 + }, { + message: "Attribute 'second-custom' can't be hyphenated.", + type: 'VIdentifier', + line: 3 + }] } ] })