Skip to content

Commit

Permalink
Add ignoreSelectors: [] to property-case
Browse files Browse the repository at this point in the history
  • Loading branch information
godested authored and Illia Zaitsev committed Jan 10, 2022
1 parent ab6ee66 commit ee704b4
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
12 changes: 12 additions & 0 deletions lib/rules/property-case/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -812,3 +812,15 @@ testRule({
},
],
});

testRule({
ruleName,
config: ['lower', { ignoreSelectors: [':exports'] }],
fix: true,

accept: [
{
code: ':exports { camelCasedColorVariable: blue }',
}
]
});
27 changes: 23 additions & 4 deletions lib/rules/property-case/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const isStandardSyntaxProperty = require('../../utils/isStandardSyntaxProperty')
const report = require('../../utils/report');
const ruleMessages = require('../../utils/ruleMessages');
const validateOptions = require('../../utils/validateOptions');
const optionsMatches = require('../../utils/optionsMatches');
const { isRegExp, isString } = require('../../utils/validateTypes');

const ruleName = 'property-case';

Expand All @@ -16,10 +18,21 @@ const messages = ruleMessages(ruleName, {

function rule(expectation, options, context) {
return (root, result) => {
const validOptions = validateOptions(result, ruleName, {
actual: expectation,
possible: ['lower', 'upper'],
});
const validOptions = validateOptions(
result,
ruleName,
{
actual: expectation,
possible: ['lower', 'upper'],
},
{
actual: options,
possible: {
ignoreSelectors: [isString, isRegExp],
},
optional: true,
}
);

if (!validOptions) {
return;
Expand All @@ -36,6 +49,12 @@ function rule(expectation, options, context) {
return;
}

const { selector } = decl.parent;

if (selector && optionsMatches(options, 'ignoreSelectors', selector)) {
return;
}

const expectedProp = expectation === 'lower' ? prop.toLowerCase() : prop.toUpperCase();

if (prop === expectedProp) {
Expand Down

0 comments on commit ee704b4

Please sign in to comment.