Skip to content

Commit

Permalink
Add ignore: ["keyframe-selectors"] to selector-disallowed-list
Browse files Browse the repository at this point in the history
  • Loading branch information
mattxwang committed Dec 19, 2023
1 parent ef766cd commit 60fb3e6
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/sixty-lamps-type.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"stylelint": minor
---

Added: `ignore: ["keyframe-selectors"]` to `selector-disallowed-list`
47 changes: 47 additions & 0 deletions lib/rules/selector-disallowed-list/__tests__/index.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import rule from '../index.mjs';
import { stripIndent } from 'common-tags';

const { messages, ruleName } = rule;

testRule({
Expand Down Expand Up @@ -220,3 +222,48 @@ testRule({
},
],
});

testRule({
ruleName,
config: [/from/, { ignore: ['keyframe-selectors'] }],

accept: [
{
code: stripIndent(`
@keyframes fade-in {
from {
opacity: 0;
}
}
`),
},
],

reject: [
{
code: '.from {}',
message: messages.rejected('.from'),
line: 1,
column: 1,
endLine: 1,
endColumn: 6,
},
],
});

testRule({
ruleName,
config: [/from/, { ignore: ['keyframe-selectors'], splitList: true }],

accept: [
{
code: stripIndent(`
@keyframes fade-in {
from, to {
opacity: 0;
}
}
`),
},
],
});
13 changes: 12 additions & 1 deletion lib/rules/selector-disallowed-list/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const optionsMatches = require('../../utils/optionsMatches.cjs');
const report = require('../../utils/report.cjs');
const ruleMessages = require('../../utils/ruleMessages.cjs');
const validateOptions = require('../../utils/validateOptions.cjs');
const isKeyframeSelector = require('../../utils/isKeyframeSelector.cjs');

const ruleName = 'selector-disallowed-list';

Expand All @@ -33,7 +34,7 @@ const rule = (primary, secondaryOptions) => {
{
actual: secondaryOptions,
possible: {
ignore: ['inside-block'],
ignore: ['inside-block', 'keyframe-selectors'],
splitList: [validateTypes.isBoolean],
},
optional: true,
Expand All @@ -45,6 +46,8 @@ const rule = (primary, secondaryOptions) => {
}

const ignoreInsideBlock = optionsMatches(secondaryOptions, 'ignore', 'inside-block');
const ignoreKeyframeSelectors = optionsMatches(secondaryOptions, 'ignore', 'keyframe-selectors');

const splitList = secondaryOptions && secondaryOptions.splitList;

root.walkRules((ruleNode) => {
Expand All @@ -63,6 +66,10 @@ const rule = (primary, secondaryOptions) => {

if (splitList) {
ruleNode.selectors.forEach((selector) => {
if (ignoreKeyframeSelectors && isKeyframeSelector(selector)) {
return;
}

if (matchesStringOrRegExp(selector, primary)) {
report({
result,
Expand All @@ -77,6 +84,10 @@ const rule = (primary, secondaryOptions) => {
} else {
const { selector, raws } = ruleNode;

if (ignoreKeyframeSelectors && isKeyframeSelector(selector)) {
return;
}

if (matchesStringOrRegExp(selector, primary)) {
const word = (raws.selector && raws.selector.raw) || selector;

Expand Down
17 changes: 16 additions & 1 deletion lib/rules/selector-disallowed-list/index.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { isBoolean, isRegExp, isString } from '../../utils/validateTypes.mjs';
import isKeyframeSelector from '../../utils/isKeyframeSelector.mjs';
import isStandardSyntaxRule from '../../utils/isStandardSyntaxRule.mjs';
import matchesStringOrRegExp from '../../utils/matchesStringOrRegExp.mjs';
import optionsMatches from '../../utils/optionsMatches.mjs';
Expand Down Expand Up @@ -29,7 +30,7 @@ const rule = (primary, secondaryOptions) => {
{
actual: secondaryOptions,
possible: {
ignore: ['inside-block'],
ignore: ['inside-block', 'keyframe-selectors'],
splitList: [isBoolean],
},
optional: true,
Expand All @@ -41,6 +42,12 @@ const rule = (primary, secondaryOptions) => {
}

const ignoreInsideBlock = optionsMatches(secondaryOptions, 'ignore', 'inside-block');
const ignoreKeyframeSelectors = optionsMatches(
secondaryOptions,
'ignore',
'keyframe-selectors',
);

const splitList = secondaryOptions && secondaryOptions.splitList;

root.walkRules((ruleNode) => {
Expand All @@ -59,6 +66,10 @@ const rule = (primary, secondaryOptions) => {

if (splitList) {
ruleNode.selectors.forEach((selector) => {
if (ignoreKeyframeSelectors && isKeyframeSelector(selector)) {
return;
}

if (matchesStringOrRegExp(selector, primary)) {
report({
result,
Expand All @@ -73,6 +84,10 @@ const rule = (primary, secondaryOptions) => {
} else {
const { selector, raws } = ruleNode;

if (ignoreKeyframeSelectors && isKeyframeSelector(selector)) {
return;
}

if (matchesStringOrRegExp(selector, primary)) {
const word = (raws.selector && raws.selector.raw) || selector;

Expand Down

0 comments on commit 60fb3e6

Please sign in to comment.