1
0
mirror of https://github.com/thangisme/notes.git synced 2024-11-01 08:17:34 -04:00
notes/node_modules/stylelint/lib/rules/declaration-block-single-line-max-declarations/index.js
Patrick Marsceill b7b0d0d7bf
Initial commit
2017-03-09 13:16:08 -05:00

55 lines
1.4 KiB
JavaScript

"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