epiphany/node_modules/@ronilaukkarinen/stylelint-a11y/dist/rules/content-property-no-static-value/index.js
2023-12-09 22:48:07 -08:00

72 lines
No EOL
2.4 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/content-property-no-static-value';
exports.ruleName = ruleName;
var messages = _stylelint.utils.ruleMessages(ruleName, {
expected: function expected(selector) {
return "Unexpected using \"content\" property in ".concat(selector);
}
});
exports.messages = messages;
var isContentPropertyUsedCorrectly = function isContentPropertyUsedCorrectly(selectors) {
return selectors.every(function (selector) {
return /:before|:after/.test(selector);
});
};
var checkNodesForContentProperty = function checkNodesForContentProperty(node) {
return node.nodes.filter(function (node) {
return node.prop;
}).some(function (node) {
return node.prop.toLowerCase() === 'content';
});
};
function check(node) {
if (node.type !== 'rule' || !checkNodesForContentProperty(node) || !node.first) {
return true;
}
return node.nodes.some(function (o) {
return o.type === 'decl' && o.prop.toLowerCase() === 'content' && isContentPropertyUsedCorrectly(o.parent.selectors) && (o.value.toLowerCase() === "''" || o.value.toLowerCase() === '""' || o.value.toLowerCase() === 'attr(aria-label)');
});
}
function _default(actual) {
return function (root, result) {
var validOptions = _stylelint.utils.validateOptions(result, ruleName, {
actual: actual
});
if (!validOptions || !actual) {
return;
}
root.walk(function (node) {
var selector = null;
if (node.type === 'rule') {
if (!(0, _isStandardSyntaxRule["default"])(node)) {
return;
}
selector = node.selector;
} else if (node.type === 'atrule' && node.name.toLowerCase() === 'page' && node.params) {
selector = node.params;
}
if (!selector) {
return;
}
var isAccepted = check(node);
if (!isAccepted) {
_stylelint.utils.report({
index: node.lastEach,
message: messages.expected(selector),
node: node,
ruleName: ruleName,
result: result
});
}
});
};
}