Skip to content

Commit 7508003

Browse files
committed
update
1 parent 79eb091 commit 7508003

10 files changed

+167
-97
lines changed

docs/rules/html-comment-content-newline.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ This rule will enforce consistency of line break after the `<!--` and before the
6666
- This rule can also take a 2nd option, an object with the following key: `"exceptions"`.
6767
- The `"exceptions"` value is an array of string patterns which are considered exceptions to the rule.
6868

69-
```
69+
```json
7070
"vue/html-comment-content-newline": ["error", { ... }, { "exceptions": ["*"] }]
7171
```
7272

docs/rules/html-comment-content-spacing.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ Whitespace after the `<!--` and before the `-->` makes it easier to read text in
4646
```
4747

4848
- The first is a string which be either `"always"` or `"never"`. The default is `"always"`.
49-
- `"always"` ... there must be at least one whitespace at after the `<!--` and before the `-->`.
49+
- `"always"` (default) ... there must be at least one whitespace at after the `<!--` and before the `-->`.
5050
- `"never"` ... there should be no whitespace at after the `<!--` and before the `-->`.
5151

5252

5353
- This rule can also take a 2nd option, an object with the following key: `"exceptions"`.
5454
- The `"exceptions"` value is an array of string patterns which are considered exceptions to the rule.
5555
Please note that exceptions are ignored if the first argument is `"never"`.
5656

57-
```
57+
```json
5858
"vue/html-comment-content-spacing": ["error", "always", { "exceptions": ["*"] }]
5959
```
6060

lib/rules/html-comment-content-newline.js

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010

1111
const htmlComments = require('../utils/html-comments')
1212

13+
/**
14+
* @typedef { import('../utils/html-comments').HTMLComment } HTMLComment
15+
*/
16+
1317
// ------------------------------------------------------------------------------
1418
// Helpers
1519
// ------------------------------------------------------------------------------
@@ -37,7 +41,7 @@ module.exports = {
3741

3842
docs: {
3943
description: 'enforce unified line brake in HTML comments',
40-
category: undefined,
44+
categories: undefined,
4145
url: 'https://eslint.vuejs.org/rules/html-comment-content-newline.html'
4246
},
4347
fixable: 'whitespace',
@@ -82,98 +86,98 @@ module.exports = {
8286

8387
create (context) {
8488
const option = parseOption(context.options[0])
85-
return htmlComments.defineVisitor(context, context.options[1], (commentTokens) => {
86-
if (!commentTokens.value) {
89+
return htmlComments.defineVisitor(context, context.options[1], (comment) => {
90+
if (!comment.value) {
8791
return
8892
}
89-
const startLine = commentTokens.openDecoration
90-
? commentTokens.openDecoration.loc.end.line
91-
: commentTokens.value.loc.start.line
92-
const endLine = commentTokens.closeDecoration
93-
? commentTokens.closeDecoration.loc.start.line
94-
: commentTokens.value.loc.end.line
93+
const startLine = comment.openDecoration
94+
? comment.openDecoration.loc.end.line
95+
: comment.value.loc.start.line
96+
const endLine = comment.closeDecoration
97+
? comment.closeDecoration.loc.start.line
98+
: comment.value.loc.end.line
9599
const newlineType = startLine === endLine
96100
? option.singleline
97101
: option.multiline
98102
if (newlineType === 'ignore') {
99103
return
100104
}
101-
checkCommentOpen(commentTokens, newlineType !== 'never')
102-
checkCommentClose(commentTokens, newlineType !== 'never')
105+
checkCommentOpen(comment, newlineType !== 'never')
106+
checkCommentClose(comment, newlineType !== 'never')
103107
})
104108

105109
/**
106110
* Reports the newline before the contents of a given comment if it's invalid.
107-
* @param {string} commentTokens - comment tokens.
111+
* @param {HTMLComment} comment - comment data.
108112
* @param {boolean} requireNewline - `true` if line breaks are required.
109113
* @returns {void}
110114
*/
111-
function checkCommentOpen (commentTokens, requireNewline) {
112-
const beforeToken = commentTokens.openDecoration || commentTokens.open
115+
function checkCommentOpen (comment, requireNewline) {
116+
const beforeToken = comment.openDecoration || comment.open
113117

114118
if (requireNewline) {
115-
if (beforeToken.loc.end.line < commentTokens.value.loc.start.line) {
119+
if (beforeToken.loc.end.line < comment.value.loc.start.line) {
116120
// Is valid
117121
return
118122
}
119123
context.report({
120124
loc: {
121125
start: beforeToken.loc.end,
122-
end: commentTokens.value.loc.start
126+
end: comment.value.loc.start
123127
},
124-
messageId: commentTokens.openDecoration ? 'expectedAfterExceptionBlock' : 'expectedAfterHTMLCommentOpen',
125-
fix: commentTokens.openDecoration ? undefined : (fixer) => fixer.insertTextAfter(beforeToken, '\n')
128+
messageId: comment.openDecoration ? 'expectedAfterExceptionBlock' : 'expectedAfterHTMLCommentOpen',
129+
fix: comment.openDecoration ? undefined : (fixer) => fixer.insertTextAfter(beforeToken, '\n')
126130
})
127131
} else {
128-
if (beforeToken.loc.end.line === commentTokens.value.loc.start.line) {
132+
if (beforeToken.loc.end.line === comment.value.loc.start.line) {
129133
// Is valid
130134
return
131135
}
132136
context.report({
133137
loc: {
134138
start: beforeToken.loc.end,
135-
end: commentTokens.value.loc.start
139+
end: comment.value.loc.start
136140
},
137141
messageId: 'unexpectedAfterHTMLCommentOpen',
138-
fix: (fixer) => fixer.replaceTextRange([beforeToken.range[1], commentTokens.value.range[0]], ' ')
142+
fix: (fixer) => fixer.replaceTextRange([beforeToken.range[1], comment.value.range[0]], ' ')
139143
})
140144
}
141145
}
142146

143147
/**
144148
* Reports the space after the contents of a given comment if it's invalid.
145-
* @param {string} commentTokens - comment tokens.
149+
* @param {HTMLComment} comment - comment data.
146150
* @param {boolean} requireNewline - `true` if line breaks are required.
147151
* @returns {void}
148152
*/
149-
function checkCommentClose (commentTokens, requireNewline) {
150-
const afterToken = commentTokens.closeDecoration || commentTokens.close
153+
function checkCommentClose (comment, requireNewline) {
154+
const afterToken = comment.closeDecoration || comment.close
151155

152156
if (requireNewline) {
153-
if (commentTokens.value.loc.end.line < afterToken.loc.start.line) {
157+
if (comment.value.loc.end.line < afterToken.loc.start.line) {
154158
// Is valid
155159
return
156160
}
157161
context.report({
158162
loc: {
159-
start: commentTokens.value.loc.end,
163+
start: comment.value.loc.end,
160164
end: afterToken.loc.start
161165
},
162-
messageId: commentTokens.closeDecoration ? 'expectedBeforeExceptionBlock' : 'expectedBeforeHTMLCommentOpen',
163-
fix: commentTokens.closeDecoration ? undefined : (fixer) => fixer.insertTextBefore(afterToken, '\n')
166+
messageId: comment.closeDecoration ? 'expectedBeforeExceptionBlock' : 'expectedBeforeHTMLCommentOpen',
167+
fix: comment.closeDecoration ? undefined : (fixer) => fixer.insertTextBefore(afterToken, '\n')
164168
})
165169
} else {
166-
if (commentTokens.value.loc.end.line === afterToken.loc.start.line) {
170+
if (comment.value.loc.end.line === afterToken.loc.start.line) {
167171
// Is valid
168172
return
169173
}
170174
context.report({
171175
loc: {
172-
start: commentTokens.value.loc.end,
176+
start: comment.value.loc.end,
173177
end: afterToken.loc.start
174178
},
175179
messageId: 'unexpectedBeforeHTMLCommentOpen',
176-
fix: (fixer) => fixer.replaceTextRange([commentTokens.value.range[1], afterToken.range[0]], ' ')
180+
fix: (fixer) => fixer.replaceTextRange([comment.value.range[1], afterToken.range[0]], ' ')
177181
})
178182
}
179183
}

lib/rules/html-comment-content-spacing.js

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010

1111
const htmlComments = require('../utils/html-comments')
1212

13+
/**
14+
* @typedef { import('../utils/html-comments').HTMLComment } HTMLComment
15+
*/
16+
1317
// ------------------------------------------------------------------------------
1418
// Rule Definition
1519
// ------------------------------------------------------------------------------
@@ -20,7 +24,7 @@ module.exports = {
2024

2125
docs: {
2226
description: 'enforce unified spacing in HTML comments',
23-
category: undefined,
27+
categories: undefined,
2428
url: 'https://eslint.vuejs.org/rules/html-comment-content-spacing.html'
2529
},
2630
fixable: 'whitespace',
@@ -54,100 +58,100 @@ module.exports = {
5458
create (context) {
5559
// Unless the first option is never, require a space
5660
const requireSpace = context.options[0] !== 'never'
57-
return htmlComments.defineVisitor(context, context.options[1], (commentTokens) => {
58-
if (!commentTokens.value) {
61+
return htmlComments.defineVisitor(context, context.options[1], (comment) => {
62+
if (!comment.value) {
5963
return
6064
}
61-
checkCommentOpen(commentTokens)
62-
checkCommentClose(commentTokens)
65+
checkCommentOpen(comment)
66+
checkCommentClose(comment)
6367
}, { includeDirectives: true })
6468

6569
/**
6670
* Reports the space before the contents of a given comment if it's invalid.
67-
* @param {string} commentTokens - comment tokens.
71+
* @param {HTMLComment} comment - comment data.
6872
* @returns {void}
6973
*/
70-
function checkCommentOpen (commentTokens) {
71-
const beforeToken = commentTokens.openDecoration || commentTokens.open
72-
if (beforeToken.loc.end.line !== commentTokens.value.loc.start.line) {
74+
function checkCommentOpen (comment) {
75+
const beforeToken = comment.openDecoration || comment.open
76+
if (beforeToken.loc.end.line !== comment.value.loc.start.line) {
7377
// Ignore newline
7478
return
7579
}
7680

7781
if (requireSpace) {
78-
if (beforeToken.range[1] < commentTokens.value.range[0]) {
82+
if (beforeToken.range[1] < comment.value.range[0]) {
7983
// Is valid
8084
return
8185
}
8286
context.report({
8387
loc: {
8488
start: beforeToken.loc.end,
85-
end: commentTokens.value.loc.start
89+
end: comment.value.loc.start
8690
},
87-
messageId: commentTokens.openDecoration ? 'expectedAfterExceptionBlock' : 'expectedAfterHTMLCommentOpen',
88-
fix: commentTokens.openDecoration ? undefined : (fixer) => fixer.insertTextAfter(beforeToken, ' ')
91+
messageId: comment.openDecoration ? 'expectedAfterExceptionBlock' : 'expectedAfterHTMLCommentOpen',
92+
fix: comment.openDecoration ? undefined : (fixer) => fixer.insertTextAfter(beforeToken, ' ')
8993
})
9094
} else {
91-
if (commentTokens.openDecoration) {
95+
if (comment.openDecoration) {
9296
// Ignore expection block
9397
return
9498
}
95-
if (beforeToken.range[1] === commentTokens.value.range[0]) {
99+
if (beforeToken.range[1] === comment.value.range[0]) {
96100
// Is valid
97101
return
98102
}
99103
context.report({
100104
loc: {
101105
start: beforeToken.loc.end,
102-
end: commentTokens.value.loc.start
106+
end: comment.value.loc.start
103107
},
104108
messageId: 'unexpectedAfterHTMLCommentOpen',
105-
fix: (fixer) => fixer.removeRange([beforeToken.range[1], commentTokens.value.range[0]])
109+
fix: (fixer) => fixer.removeRange([beforeToken.range[1], comment.value.range[0]])
106110
})
107111
}
108112
}
109113

110114
/**
111115
* Reports the space after the contents of a given comment if it's invalid.
112-
* @param {string} commentTokens - comment tokens.
116+
* @param {HTMLComment} comment - comment data.
113117
* @returns {void}
114118
*/
115-
function checkCommentClose (commentTokens) {
116-
const afterToken = commentTokens.closeDecoration || commentTokens.close
117-
if (commentTokens.value.loc.end.line !== afterToken.loc.start.line) {
119+
function checkCommentClose (comment) {
120+
const afterToken = comment.closeDecoration || comment.close
121+
if (comment.value.loc.end.line !== afterToken.loc.start.line) {
118122
// Ignore newline
119123
return
120124
}
121125

122126
if (requireSpace) {
123-
if (commentTokens.value.range[1] < afterToken.range[0]) {
127+
if (comment.value.range[1] < afterToken.range[0]) {
124128
// Is valid
125129
return
126130
}
127131
context.report({
128132
loc: {
129-
start: commentTokens.value.loc.end,
133+
start: comment.value.loc.end,
130134
end: afterToken.loc.start
131135
},
132-
messageId: commentTokens.closeDecoration ? 'expectedBeforeExceptionBlock' : 'expectedBeforeHTMLCommentOpen',
133-
fix: commentTokens.closeDecoration ? undefined : (fixer) => fixer.insertTextBefore(afterToken, ' ')
136+
messageId: comment.closeDecoration ? 'expectedBeforeExceptionBlock' : 'expectedBeforeHTMLCommentOpen',
137+
fix: comment.closeDecoration ? undefined : (fixer) => fixer.insertTextBefore(afterToken, ' ')
134138
})
135139
} else {
136-
if (commentTokens.closeDecoration) {
140+
if (comment.closeDecoration) {
137141
// Ignore expection block
138142
return
139143
}
140-
if (commentTokens.value.range[1] === afterToken.range[0]) {
144+
if (comment.value.range[1] === afterToken.range[0]) {
141145
// Is valid
142146
return
143147
}
144148
context.report({
145149
loc: {
146-
start: commentTokens.value.loc.end,
150+
start: comment.value.loc.end,
147151
end: afterToken.loc.start
148152
},
149153
messageId: 'unexpectedBeforeHTMLCommentOpen',
150-
fix: (fixer) => fixer.removeRange([commentTokens.value.range[1], afterToken.range[0]])
154+
fix: (fixer) => fixer.removeRange([comment.value.range[1], afterToken.range[0]])
151155
})
152156
}
153157
}

lib/rules/html-comment-indent.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010

1111
const htmlComments = require('../utils/html-comments')
1212

13+
/**
14+
* @typedef { import('../utils/html-comments').HTMLComment } HTMLComment
15+
*/
16+
1317
// ------------------------------------------------------------------------------
1418
// Helpers
1519
// ------------------------------------------------------------------------------
@@ -70,7 +74,7 @@ module.exports = {
7074

7175
docs: {
7276
description: 'enforce consistent indentation in HTML comments',
73-
category: undefined,
77+
categories: undefined,
7478
url: 'https://eslint.vuejs.org/rules/html-comment-indent.html'
7579
},
7680
fixable: 'whitespace',
@@ -94,25 +98,25 @@ module.exports = {
9498
create (context) {
9599
const options = parseOptions(context.options[0])
96100
const sourceCode = context.getSourceCode()
97-
return htmlComments.defineVisitor(context, null, (commentTokens) => {
98-
const baseIndentText = getLineIndentText(commentTokens.open.loc.start.line)
101+
return htmlComments.defineVisitor(context, null, (comment) => {
102+
const baseIndentText = getLineIndentText(comment.open.loc.start.line)
99103
let endLine
100-
if (commentTokens.value) {
101-
const startLine = commentTokens.value.loc.start.line
102-
endLine = commentTokens.value.loc.end.line
104+
if (comment.value) {
105+
const startLine = comment.value.loc.start.line
106+
endLine = comment.value.loc.end.line
103107

104-
const checkStartLine = commentTokens.open.loc.end.line === startLine ? startLine + 1 : startLine
108+
const checkStartLine = comment.open.loc.end.line === startLine ? startLine + 1 : startLine
105109

106110
for (let line = checkStartLine; line <= endLine; line++) {
107111
validateIndentForLine(line, baseIndentText, 1)
108112
}
109113
} else {
110-
endLine = commentTokens.open.loc.end.line
114+
endLine = comment.open.loc.end.line
111115
}
112116

113-
if (endLine < commentTokens.close.loc.start.line) {
117+
if (endLine < comment.close.loc.start.line) {
114118
// `-->`
115-
validateIndentForLine(commentTokens.close.loc.start.line, baseIndentText, 0)
119+
validateIndentForLine(comment.close.loc.start.line, baseIndentText, 0)
116120
}
117121
}, { includeDirectives: true })
118122

0 commit comments

Comments
 (0)