Skip to content

Commit

Permalink
fix: eslint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
AndyOGo committed Feb 15, 2023
1 parent b525d61 commit 5639937
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 158 deletions.
2 changes: 1 addition & 1 deletion lint-staged.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = {
'(src|test)/**/*.[tj]s': (filenames) => [
`eslint --fix ${filenames.join(' ')}`,
'node --require babel-register-ts test',
'jest',
],
'(README).md': ["doctoc --title '**Table of Contents**'"],
};
1 change: 1 addition & 0 deletions test/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"globals": {
"testRule": "readonly",
"testOptions": "readonly"
},
"rules": {
"import/no-extraneous-dependencies": ["error", {
Expand Down
301 changes: 144 additions & 157 deletions test/auto-fix-func.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,171 +3,158 @@ import autoFixFunc from './helpers/auto-fix-func';
import autoFixFuncWithThrow from './helpers/auto-fix-func-with-throw';

// works if autofix is omitted
testRule(
{
ruleName,

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,
},
],
}
);
testRule({
ruleName,

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(
{
skip: true,
ruleName,
fix: true,

config: [
['color', 'font-size', 'display'],
{
autoFixFunc: autoFixFuncWithThrow,
},
],

reject: [
{
code: '.foo { color: #fff; }',
fixed: '.foo { color: $color-white; }',
message: `Expected variable or function for "#fff" of "color" (scale-unlimited/declaration-strict-value)`,
},
{
code: '.foo { color: red; }',
fixed: '.foo { color: $color-red; }',
message: `Expected variable or function for "red" of "color" (scale-unlimited/declaration-strict-value)`,
},
{
code: '.foo { font-size: 16px; }',
unfixable: true,
// message: `"font-size" is not a color property (${ruleName})`,
message: `Expected variable or function for "16px" of "font-size" (${ruleName})`,
line: 1,
column: 8,
},
{
code: '.foo { color: blue; }',
unfixable: true,
// message: `Can't fix color "blue" (${ruleName})`,
message: `Expected variable or function for "blue" of "color" (scale-unlimited/declaration-strict-value)`,
line: 1,
column: 8,
},
{
code: '.foo { display: block; }',
unfixable: true,
// message: `Property "display" with value "block" can't be autofixed (${ruleName})`,
message: `Expected variable or function for "block" of "display" (scale-unlimited/declaration-strict-value)`,
line: 1,
column: 8,
},
],
}
);
testRule({
skip: true,
ruleName,
fix: true,

config: [
['color', 'font-size', 'display'],
{
autoFixFunc: autoFixFuncWithThrow,
},
],

reject: [
{
code: '.foo { color: #fff; }',
fixed: '.foo { color: $color-white; }',
message: `Expected variable or function for "#fff" of "color" (scale-unlimited/declaration-strict-value)`,
},
{
code: '.foo { color: red; }',
fixed: '.foo { color: $color-red; }',
message: `Expected variable or function for "red" of "color" (scale-unlimited/declaration-strict-value)`,
},
{
code: '.foo { font-size: 16px; }',
unfixable: true,
// message: `"font-size" is not a color property (${ruleName})`,
message: `Expected variable or function for "16px" of "font-size" (${ruleName})`,
line: 1,
column: 8,
},
{
code: '.foo { color: blue; }',
unfixable: true,
// message: `Can't fix color "blue" (${ruleName})`,
message: `Expected variable or function for "blue" of "color" (scale-unlimited/declaration-strict-value)`,
line: 1,
column: 8,
},
{
code: '.foo { display: block; }',
unfixable: true,
// message: `Property "display" with value "block" can't be autofixed (${ruleName})`,
message: `Expected variable or function for "block" of "display" (scale-unlimited/declaration-strict-value)`,
line: 1,
column: 8,
},
],
});

// autofix by function property disabled
testRule(
{
skip: true,
ruleName,
fix: true,

config: [
'color',
{
autoFixFunc,
disableFix: true,
},
],

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

config: [
'color',
{
autoFixFunc,
disableFix: true,
},
],

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

// autofix by file exporting function
testRule(
{
skip: true,
ruleName,
fix: true,

config: [
'color',
{
autoFixFunc: './test/helpers/auto-fix-func.js',
},
],

accept: [
{ code: '.foo { color: #fff; }' },
{ code: '.foo { color: red; }' },
],
}
);
testRule({
skip: true,
ruleName,
fix: true,

config: [
'color',
{
autoFixFunc: './test/helpers/auto-fix-func.js',
},
],

accept: [{ code: '.foo { color: #fff; }' }, { code: '.foo { color: red; }' }],
});

// autofix by file exporting function disabled
testRule(
{
ruleName,
fix: true,

config: [
'color',
{
autoFixFunc: './test/helpers/auto-fix-func.js',
disableFix: true,
},
],

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

config: [
'color',
{
autoFixFunc: './test/helpers/auto-fix-func.js',
disableFix: true,
},
],

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

testOptions({
skip: true,
Expand Down

0 comments on commit 5639937

Please sign in to comment.