mirror of
https://github.com/thangisme/notes.git
synced 2024-11-01 04:27:17 -04:00
50 lines
1008 B
JavaScript
50 lines
1008 B
JavaScript
"use strict"
|
|
|
|
const report = require("../../utils/report")
|
|
const ruleMessages = require("../../utils/ruleMessages")
|
|
const validateOptions = require("../../utils/validateOptions")
|
|
|
|
const ruleName = "comment-no-empty"
|
|
|
|
const messages = ruleMessages(ruleName, {
|
|
rejected: "Unexpected empty comment",
|
|
})
|
|
|
|
const rule = function (actual) {
|
|
return (root, result) => {
|
|
const validOptions = validateOptions(result, ruleName, { actual })
|
|
if (!validOptions) {
|
|
return
|
|
}
|
|
|
|
root.walkComments(comment => {
|
|
// To ignore inline SCSS comments
|
|
if (
|
|
comment.raws.inline
|
|
|| comment.inline
|
|
) {
|
|
return
|
|
}
|
|
|
|
// To ignore comments that are not empty
|
|
if (
|
|
comment.text
|
|
&& comment.text.length !== 0
|
|
) {
|
|
return
|
|
}
|
|
|
|
report({
|
|
message: messages.rejected,
|
|
node: comment,
|
|
result,
|
|
ruleName,
|
|
})
|
|
})
|
|
}
|
|
}
|
|
|
|
rule.ruleName = ruleName
|
|
rule.messages = messages
|
|
module.exports = rule
|