UNPKG

stylelint

Version:
70 lines (56 loc) 2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.messages = exports.ruleName = undefined; exports.default = function (max) { var maxAdjacentNewlines = max + 1; return function (root, result) { var validOptions = (0, _utils.validateOptions)(result, ruleName, { actual: max, possible: _lodash.isNumber }); if (!validOptions) { return; } root.walkDecls(function (decl) { if (decl.value.indexOf("(") === -1) { return; } var declString = decl.toString(); var repeatLFNewLines = (0, _lodash.repeat)("\n", maxAdjacentNewlines); var repeatCRLFNewLines = (0, _lodash.repeat)("\r\n", maxAdjacentNewlines); (0, _styleSearch2.default)({ source: declString, target: "\n", functionArguments: "only" }, function (match) { if (declString.substr(match.startIndex + 1, maxAdjacentNewlines) === repeatLFNewLines || declString.substr(match.startIndex + 1, maxAdjacentNewlines * 2) === repeatCRLFNewLines) { // Put index at `\r` if it's CRLF, otherwise leave it at `\n` var index = match.startIndex; if (declString[index - 1] === "\r") { index -= 1; } (0, _utils.report)({ message: messages.expected(max), node: decl, index: index, result: result, ruleName: ruleName }); } }); }); }; }; var _lodash = require("lodash"); var _utils = require("../../utils"); var _styleSearch = require("style-search"); var _styleSearch2 = _interopRequireDefault(_styleSearch); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var ruleName = exports.ruleName = "function-max-empty-lines"; var messages = exports.messages = (0, _utils.ruleMessages)(ruleName, { expected: function expected(max) { return "Expected no more than " + max + " empty line(s)"; } });