-
-
Notifications
You must be signed in to change notification settings - Fork 649
/
html-closing-bracket-spacing.js
96 lines (90 loc) · 3.38 KB
/
html-closing-bracket-spacing.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
/**
* @author Toru Nagashima <https://github.com/mysticatea>
*/
'use strict'
// -----------------------------------------------------------------------------
// Requirements
// -----------------------------------------------------------------------------
const RuleTester = require('eslint').RuleTester
const rule = require('../../../lib/rules/html-closing-bracket-spacing')
// -----------------------------------------------------------------------------
// Tests
// -----------------------------------------------------------------------------
var ruleTester = new RuleTester({
parser: require.resolve('vue-eslint-parser'),
parserOptions: {
ecmaVersion: 2015
}
})
ruleTester.run('html-closing-bracket-spacing', rule, {
valid: [
'',
'<template><div></div><div /></template>',
'<template><div foo></div><div foo /></template>',
'<template><div foo=a></div><div foo=a /></template>',
'<template><div foo="a"></div><div foo="a" /></template>',
{
code: '<template ><div ></div><div /></template>',
options: [{ startTag: 'always' }]
},
{
code: '<template><div></div ><div /></template >',
options: [{ endTag: 'always' }]
},
{
code: '<template><div></div><div/></template>',
options: [{ selfClosingTag: 'never' }]
},
'<template><div',
'<template><div></div',
{
code: '<template><div',
options: [{ startTag: 'never', endTag: 'never' }]
},
{
code: '<template><div></div',
options: [{ startTag: 'never', endTag: 'never' }]
}
],
invalid: [
{
code: '<template>\n <div >\n </div >\n <div/>\n</template>',
output: '<template>\n <div>\n </div>\n <div />\n</template>',
errors: [
{ message: "Expected no space before '>', but found.", line: 2, column: 7, endColumn: 9 },
{ message: "Expected no space before '>', but found.", line: 3, column: 8, endColumn: 10 },
{ message: "Expected a space before '/>', but not found.", line: 4, column: 7, endColumn: 9 }
]
},
{
code: '<template>\n <div foo ></div>\n <div foo/>\n</template>',
output: '<template>\n <div foo></div>\n <div foo />\n</template>',
errors: [
{ message: "Expected no space before '>', but found.", line: 2, column: 11, endColumn: 13 },
{ message: "Expected a space before '/>', but not found.", line: 3, column: 11, endColumn: 13 }
]
},
{
code: '<template>\n <div foo="1" ></div>\n <div foo="1"/>\n</template>',
output: '<template>\n <div foo="1"></div>\n <div foo="1" />\n</template>',
errors: [
{ message: "Expected no space before '>', but found.", line: 2, column: 15, endColumn: 17 },
{ message: "Expected a space before '/>', but not found.", line: 3, column: 15, endColumn: 17 }
]
},
{
code: '<template >\n <div>\n </div>\n <div />\n</template >',
output: '<template >\n <div >\n </div >\n <div/>\n</template >',
options: [{
startTag: 'always',
endTag: 'always',
selfClosingTag: 'never'
}],
errors: [
{ message: "Expected a space before '>', but not found.", line: 2, column: 7, endColumn: 8 },
{ message: "Expected a space before '>', but not found.", line: 3, column: 8, endColumn: 9 },
{ message: "Expected no space before '/>', but found.", line: 4, column: 7, endColumn: 10 }
]
}
]
})