|
| 1 | +/** |
| 2 | + * @author Yosuke Ota <https://github.com/ota-meshi> |
| 3 | + * See LICENSE file in root directory for full license. |
| 4 | + */ |
| 5 | +'use strict' |
| 6 | + |
| 7 | +const Linter = require('eslint').Linter |
| 8 | +const chai = require('chai') |
| 9 | + |
| 10 | +const rules = require('../..').rules |
| 11 | + |
| 12 | +const assert = chai.assert |
| 13 | + |
| 14 | +const baseConfig = { |
| 15 | + parser: 'vue-eslint-parser', |
| 16 | + parserOptions: { |
| 17 | + ecmaVersion: 2018, |
| 18 | + sourceType: 'module', |
| 19 | + ecmaFeatures: { |
| 20 | + jsx: true |
| 21 | + } |
| 22 | + } |
| 23 | +} |
| 24 | + |
| 25 | +describe('Complex autofix test cases', () => { |
| 26 | + const linter = new Linter() |
| 27 | + for (const key of Object.keys(rules)) { |
| 28 | + const ruleId = `vue/${key}` |
| 29 | + linter.defineRule(ruleId, rules[key]) |
| 30 | + } |
| 31 | + |
| 32 | + // https://github.com/vuejs/eslint-plugin-vue/issues/554 |
| 33 | + describe('Autofix of `html-self-closing` and `component-name-in-template-casing` should not conflict.', () => { |
| 34 | + const kebabConfig = Object.assign({}, baseConfig, { 'rules': { |
| 35 | + 'vue/html-self-closing': ['error', { |
| 36 | + 'html': { |
| 37 | + 'component': 'never' |
| 38 | + } |
| 39 | + }], |
| 40 | + 'vue/component-name-in-template-casing': ['error', 'kebab-case'] |
| 41 | + }}) |
| 42 | + const pascalConfig = Object.assign({}, baseConfig, { 'rules': { |
| 43 | + 'vue/html-self-closing': ['error', { |
| 44 | + 'html': { |
| 45 | + 'component': 'never' |
| 46 | + } |
| 47 | + }], |
| 48 | + 'vue/component-name-in-template-casing': ['error'] |
| 49 | + }}) |
| 50 | + it('Even if set kebab-case, the output should be as expected.', () => { |
| 51 | + const code = ` |
| 52 | + <template> |
| 53 | + <VueComponent /> |
| 54 | + </template>` |
| 55 | + const output = ` |
| 56 | + <template> |
| 57 | + <vue-component ></vue-component> |
| 58 | + </template>` |
| 59 | + |
| 60 | + assert.equal( |
| 61 | + linter.verifyAndFix(code, kebabConfig, 'test.vue').output, |
| 62 | + output |
| 63 | + ) |
| 64 | + }) |
| 65 | + it('Even if set PascalCase, the output should be as expected.', () => { |
| 66 | + const code = ` |
| 67 | + <template> |
| 68 | + <vue-component /> |
| 69 | + </template>` |
| 70 | + const output = ` |
| 71 | + <template> |
| 72 | + <VueComponent ></VueComponent> |
| 73 | + </template>` |
| 74 | + |
| 75 | + assert.equal( |
| 76 | + linter.verifyAndFix(code, pascalConfig, 'test.vue').output, |
| 77 | + output |
| 78 | + ) |
| 79 | + }) |
| 80 | + it('Even if element have an attributes, the output should be as expected.', () => { |
| 81 | + const code = ` |
| 82 | + <template> |
| 83 | + <vue-component attr |
| 84 | + id="item1" /> |
| 85 | + </template>` |
| 86 | + const output = ` |
| 87 | + <template> |
| 88 | + <VueComponent attr |
| 89 | + id="item1" ></VueComponent> |
| 90 | + </template>` |
| 91 | + |
| 92 | + assert.equal( |
| 93 | + linter.verifyAndFix(code, pascalConfig, 'test.vue').output, |
| 94 | + output |
| 95 | + ) |
| 96 | + }) |
| 97 | + }) |
| 98 | +}) |
0 commit comments