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