epiphany/node_modules/@ronilaukkarinen/stylelint-a11y/dist/rules/no-spread-text/index.js
2023-12-09 22:48:07 -08:00

60 lines
No EOL
2 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = _default;
exports.ruleName = exports.messages = void 0;
var _stylelint = require("stylelint");
var _isStandardSyntaxRule = _interopRequireDefault(require("stylelint/lib/utils/isStandardSyntaxRule"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
var ruleName = 'a11y/no-spread-text';
exports.ruleName = ruleName;
var messages = _stylelint.utils.ruleMessages(ruleName, {
expected: function expected(selector) {
return "Unexpected max-width in ".concat(selector);
}
});
exports.messages = messages;
var textStyles = ['text-decoration', 'text-align', 'text-transform', 'text-indent', 'letter-spacing', 'line-height', 'direction', 'word-spacing', 'text-shadow', 'text-overflow', 'color'];
var nodesProbablyForText = function nodesProbablyForText(nodes) {
return nodes.map(function (node) {
return node.prop;
}).filter(Boolean).map(function (prop) {
return prop.toLowerCase();
}).some(function (prop) {
return textStyles.includes(prop);
});
};
function _default(actual) {
return function (root, result) {
var validOptions = _stylelint.utils.validateOptions(result, ruleName, {
actual: actual
});
if (!validOptions || !actual) {
return;
}
root.walkRules(function (rule) {
var selector = null;
if (!(0, _isStandardSyntaxRule["default"])(rule)) {
return;
}
selector = rule.selector;
if (!selector) {
return;
}
var isRejected = nodesProbablyForText(rule.nodes) && rule.nodes.some(function (o) {
return o.type === 'decl' && o.prop.toLowerCase() === 'max-width' && o.value.toLowerCase().endsWith('ch') && (parseFloat(o.value) < 45 || parseFloat(o.value) > 80);
});
if (isRejected) {
_stylelint.utils.report({
index: rule.lastEach,
message: messages.expected(selector),
node: rule,
ruleName: ruleName,
result: result
});
}
});
};
}