12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- 'use strict';
- const report = require('../../utils/report');
- const ruleMessages = require('../../utils/ruleMessages');
- const validateOptions = require('../../utils/validateOptions');
- const { isRegExp, isString } = require('../../utils/validateTypes');
- const ruleName = 'comment-pattern';
- const messages = ruleMessages(ruleName, {
- expected: (pattern) => `Expected comment to match pattern "${pattern}"`,
- });
- const meta = {
- url: 'https://stylelint.io/user-guide/rules/list/comment-pattern',
- };
- /** @type {import('stylelint').Rule} */
- const rule = (primary) => {
- return (root, result) => {
- const validOptions = validateOptions(result, ruleName, {
- actual: primary,
- possible: [isRegExp, isString],
- });
- if (!validOptions) {
- return;
- }
- const normalizedPattern = isString(primary) ? new RegExp(primary) : primary;
- root.walkComments((comment) => {
- const text = comment.text;
- if (normalizedPattern.test(text)) {
- return;
- }
- report({
- message: messages.expected(primary),
- node: comment,
- result,
- ruleName,
- });
- });
- };
- };
- rule.ruleName = ruleName;
- rule.messages = messages;
- rule.meta = meta;
- module.exports = rule;
|