UNPKG

stylelint

Version:
68 lines (56 loc) 1.86 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.messages = exports.ruleName = undefined; exports.default = function (on, options) { return function (root, result) { var validOptions = (0, _utils.validateOptions)(result, ruleName, { actual: on }, { optional: true, actual: options, possible: { ignore: ["empty-lines"] } }); if (!validOptions) { return; } var rootString = root.toString(); (0, _styleSearch2.default)({ source: rootString, target: ["\n", "\r"], comments: "check" }, function (match) { // If the character before newline is not whitespace, ignore if (!whitespacesToReject.has(rootString[match.startIndex - 1])) { return; } if ((0, _utils.optionsMatches)(options, "ignore", "empty-lines")) { // If there is only whitespace between the previous newline and // this newline, ignore var lineBefore = rootString.substring(match.startIndex + 1, rootString.lastIndexOf("\n", match.startIndex - 1)); if ((0, _utils.isOnlyWhitespace)(lineBefore)) { return; } } (0, _utils.report)({ message: messages.rejected, node: root, index: match.startIndex - 1, result: result, ruleName: ruleName }); }); }; }; 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 = "no-eol-whitespace"; var messages = exports.messages = (0, _utils.ruleMessages)(ruleName, { rejected: "Unexpected whitespace at end of line" }); var whitespacesToReject = new Set([" ", "\t"]);