X-Git-Url: https://git.josue.xyz/?a=blobdiff_plain;f=.config%2Fcoc%2Fextensions%2Fnode_modules%2Fcoc-prettier%2Fnode_modules%2Fstylelint%2Flib%2Frules%2Fvalue-list-max-empty-lines%2Findex.js;fp=.config%2Fcoc%2Fextensions%2Fnode_modules%2Fcoc-prettier%2Fnode_modules%2Fstylelint%2Flib%2Frules%2Fvalue-list-max-empty-lines%2Findex.js;h=c007254dcf8b9adaedab96049981593676358eae;hb=3aba54c891969552833dbc350b3139e944e17a97;hp=0000000000000000000000000000000000000000;hpb=1def8ecce8e6f3aa32e6978d0ba7846a99b8de34;p=dotfiles%2F.git diff --git a/.config/coc/extensions/node_modules/coc-prettier/node_modules/stylelint/lib/rules/value-list-max-empty-lines/index.js b/.config/coc/extensions/node_modules/coc-prettier/node_modules/stylelint/lib/rules/value-list-max-empty-lines/index.js new file mode 100644 index 00000000..c007254d --- /dev/null +++ b/.config/coc/extensions/node_modules/coc-prettier/node_modules/stylelint/lib/rules/value-list-max-empty-lines/index.js @@ -0,0 +1,61 @@ +"use strict"; + +const _ = require("lodash"); +const report = require("../../utils/report"); +const ruleMessages = require("../../utils/ruleMessages"); +const styleSearch = require("style-search"); +const validateOptions = require("../../utils/validateOptions"); + +const ruleName = "value-list-max-empty-lines"; + +const messages = ruleMessages(ruleName, { + expected: max => + `Expected no more than ${max} empty ${max === 1 ? "line" : "lines"}` +}); + +const rule = function(max) { + const maxAdjacentNewlines = max + 1; + + return (root, result) => { + const validOptions = validateOptions(result, ruleName, { + actual: max, + possible: _.isNumber + }); + if (!validOptions) { + return; + } + + root.walkDecls(decl => { + const value = decl.value; + const repeatLFNewLines = _.repeat("\n", maxAdjacentNewlines); + const repeatCRLFNewLines = _.repeat("\r\n", maxAdjacentNewlines); + + styleSearch({ source: value, target: "\n" }, match => { + if ( + value.substr(match.startIndex + 1, maxAdjacentNewlines) === + repeatLFNewLines || + value.substr(match.startIndex + 1, maxAdjacentNewlines * 2) === + repeatCRLFNewLines + ) { + // Put index at `\r` if it's CRLF, otherwise leave it at `\n` + let index = match.startIndex; + if (value[index - 1] === "\r") { + index -= 1; + } + + report({ + message: messages.expected(max), + node: decl, + index, + result, + ruleName + }); + } + }); + }); + }; +}; + +rule.ruleName = ruleName; +rule.messages = messages; +module.exports = rule;