Skip to content

Commit

Permalink
fix: only execute autofix func if it could be found
Browse files Browse the repository at this point in the history
  • Loading branch information
AndyOGo committed Apr 2, 2021
1 parent d71d199 commit f5b20e3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,8 +428,8 @@ const ruleFunction: StylelintRuleFunction = (
const types = getTypes(config, property);

// support auto fixing
if (context.fix && !disableFix) {
const fixedValue = autoFixFuncNormalized!(
if (context.fix && !disableFix && autoFixFuncNormalized) {
const fixedValue = autoFixFuncNormalized(
node,
{
validVar,
Expand Down
28 changes: 28 additions & 0 deletions test/auto-fix-func.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,34 @@ const { rule } = declarationStrictValue;
const ruleWithContext = (context) => (properties, options) =>
rule(properties, options, context);

// works if autofix is omitted
testRule(
ruleWithContext({
fix: true,
}),
{
ruleName,
skipBasicChecks: true,

config: ['color'],

reject: [
{
code: '.foo { color: #fff; }',
message: `Expected variable or function for "#fff" of "color" (${ruleName})`,
line: 1,
column: 8,
},
{
code: '.foo { color: red; }',
message: `Expected variable or function for "red" of "color" (${ruleName})`,
line: 1,
column: 8,
},
],
}
);

// autofix by function property
testRule(
ruleWithContext({
Expand Down

0 comments on commit f5b20e3

Please sign in to comment.