1
0
mirror of https://github.com/thangisme/notes.git synced 2024-11-01 06:37:17 -04:00
notes/node_modules/stylelint/lib/rules/declaration-block-single-line-max-declarations/index.js

55 lines
1.4 KiB
JavaScript
Raw Normal View History

2017-03-09 13:16:08 -05:00
"use strict"
const beforeBlockString = require("../../utils/beforeBlockString")
const blockString = require("../../utils/blockString")
const isSingleLineString = require("../../utils/isSingleLineString")
const report = require("../../utils/report")
const ruleMessages = require("../../utils/ruleMessages")
const validateOptions = require("../../utils/validateOptions")
const _ = require("lodash")
const ruleName = "declaration-block-single-line-max-declarations"
const messages = ruleMessages(ruleName, {
expected: quantity => `Expected no more than ${quantity} declaration(s)`,
})
const rule = function (quantity) {
return (root, result) => {
const validOptions = validateOptions(result, ruleName, {
actual: quantity,
possible: [_.isNumber],
})
if (!validOptions) {
return
}
root.walkRules(rule => {
if (!isSingleLineString(blockString(rule))) {
return
}
if (!rule.nodes) {
return
}
const decls = rule.nodes.filter(node => node.type === "decl")
if (decls.length <= quantity) {
return
}
report({
message: messages.expected(quantity),
node: rule,
index: beforeBlockString(rule, { noRawBefore: true }).length,
result,
ruleName,
})
})
}
}
rule.ruleName = ruleName
rule.messages = messages
module.exports = rule