Fix tests
This commit is contained in:
@ -17,7 +17,7 @@ const noHardcodedColorsRule = createRule({
|
|||||||
if (colorRegex.test(quasi.value.raw)) {
|
if (colorRegex.test(quasi.value.raw)) {
|
||||||
context.report({
|
context.report({
|
||||||
node,
|
node,
|
||||||
messageId: "avoidHardcodedColors",
|
messageId: "hardcodedColor",
|
||||||
data: {
|
data: {
|
||||||
color: quasi.value.raw,
|
color: quasi.value.raw,
|
||||||
},
|
},
|
||||||
@ -27,21 +27,21 @@ const noHardcodedColorsRule = createRule({
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
name: "avoid-hardcoded-colors",
|
name: "no-hardcoded-colors",
|
||||||
meta: {
|
meta: {
|
||||||
type: "suggestion",
|
|
||||||
docs: {
|
docs: {
|
||||||
description: "Avoid hardcoded RGBA or Hex colors, use colors from the theme file.",
|
description:
|
||||||
recommended: "recommended",
|
|
||||||
},
|
|
||||||
schema: [],
|
|
||||||
fixable: "code",
|
|
||||||
messages: {
|
|
||||||
avoidHardcodedColors:
|
|
||||||
"Do not use hardcoded RGBA or Hex colors. Please use a color from the theme file.",
|
"Do not use hardcoded RGBA or Hex colors. Please use a color from the theme file.",
|
||||||
},
|
},
|
||||||
|
messages: {
|
||||||
|
hardcodedColor:
|
||||||
|
"Hardcoded color {{ color }} found. Please use a color from the theme file.",
|
||||||
|
},
|
||||||
|
type: "suggestion",
|
||||||
|
schema: [],
|
||||||
|
fixable: "code",
|
||||||
},
|
},
|
||||||
defaultOptions: []
|
defaultOptions: [],
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = noHardcodedColorsRule;
|
module.exports = noHardcodedColorsRule;
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
import { RuleTester } from "@typescript-eslint/rule-tester";
|
import { RuleTester } from "@typescript-eslint/rule-tester";
|
||||||
import noHardcodedColorsRule from "../rules/no-hardcoded-colors";
|
import noHardcodedColorsRule from "../rules/no-hardcoded-colors";
|
||||||
|
|
||||||
|
|
||||||
const ruleTester = new RuleTester({
|
const ruleTester = new RuleTester({
|
||||||
parser: "@typescript-eslint/parser",
|
parser: "@typescript-eslint/parser",
|
||||||
parserOptions: {
|
parserOptions: {
|
||||||
@ -16,41 +15,28 @@ const ruleTester = new RuleTester({
|
|||||||
ruleTester.run("no-hardcoded-colors", noHardcodedColorsRule, {
|
ruleTester.run("no-hardcoded-colors", noHardcodedColorsRule, {
|
||||||
valid: [
|
valid: [
|
||||||
{
|
{
|
||||||
code: 'const color = theme.primaryColor;',
|
code: "const color = theme.background.secondary;",
|
||||||
filename: 'example.ts',
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
code: 'const color = "#FFFFFF";',
|
code: 'const color = "#000000";',
|
||||||
filename: 'example.ts',
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
invalid: [
|
invalid: [
|
||||||
{
|
{
|
||||||
code: 'const color = "#FF0000";',
|
code: 'const color = "rgb(154,205,50)";',
|
||||||
filename: 'example.ts',
|
|
||||||
errors: [
|
errors: [
|
||||||
{
|
{
|
||||||
messageId: 'avoidHardcodedColors',
|
messageId: "hardcodedColor",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
code: 'const color = "rgba(255, 0, 0, 0.5)";',
|
code: 'const color = "#ADFF2F";',
|
||||||
filename: 'example.ts',
|
|
||||||
errors: [
|
errors: [
|
||||||
{
|
{
|
||||||
messageId: 'avoidHardcodedColors',
|
messageId: "hardcodedColor",
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: 'const color = "#123456";',
|
|
||||||
filename: 'themes.ts',
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
messageId: 'avoidHardcodedColors',
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
@ -16,18 +16,17 @@ ruleTester.run("sort-css-properties-alphabetically", sortCssPropertiesAlphabetic
|
|||||||
valid: [
|
valid: [
|
||||||
{
|
{
|
||||||
code: 'const style = css`color: red;`;',
|
code: 'const style = css`color: red;`;',
|
||||||
filename: 'example.ts',
|
filename: 'react.tsx',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
code: 'const style = styled.div`background-color: $bgColor;`;',
|
code: 'const style = styled.div`background-color: $bgColor;`;',
|
||||||
filename: 'example.ts',
|
filename: 'react.tsx',
|
||||||
},
|
},
|
||||||
// Add more valid cases as needed
|
|
||||||
],
|
],
|
||||||
invalid: [
|
invalid: [
|
||||||
{
|
{
|
||||||
code: 'const style = css`color: #FF0000;`;',
|
code: 'const style = css`color: #FF0000;`;',
|
||||||
filename: 'example.ts',
|
filename: 'react.tsx',
|
||||||
errors: [
|
errors: [
|
||||||
{
|
{
|
||||||
messageId: "sort-css-properties-alphabetically",
|
messageId: "sort-css-properties-alphabetically",
|
||||||
@ -42,7 +41,7 @@ ruleTester.run("sort-css-properties-alphabetically", sortCssPropertiesAlphabetic
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
code: 'const style = styled.div`background-color: $bgColor; color: #FFFFFF;`;',
|
code: 'const style = styled.div`background-color: $bgColor; color: #FFFFFF;`;',
|
||||||
filename: 'example.ts',
|
filename: 'react.tsx',
|
||||||
errors: [
|
errors: [
|
||||||
{
|
{
|
||||||
messageId: "sort-css-properties-alphabetically",
|
messageId: "sort-css-properties-alphabetically",
|
||||||
@ -55,6 +54,5 @@ ruleTester.run("sort-css-properties-alphabetically", sortCssPropertiesAlphabetic
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
// Add more invalid cases as needed
|
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|||||||
@ -16,18 +16,17 @@ ruleTester.run("styled-components-prefixed-with-styled", styledComponentsPrefixe
|
|||||||
valid: [
|
valid: [
|
||||||
{
|
{
|
||||||
code: 'const StyledButton = styled.button``;',
|
code: 'const StyledButton = styled.button``;',
|
||||||
filename: 'example.ts',
|
filename: 'react.tsx',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
code: 'const StyledComponent = styled.div``;',
|
code: 'const StyledComponent = styled.div``;',
|
||||||
filename: 'example.ts',
|
filename: 'react.tsx',
|
||||||
},
|
},
|
||||||
|
|
||||||
],
|
],
|
||||||
invalid: [
|
invalid: [
|
||||||
{
|
{
|
||||||
code: 'const Button = styled.button``;',
|
code: 'const Button = styled.button``;',
|
||||||
filename: 'example.ts',
|
filename: 'react.tsx',
|
||||||
errors: [
|
errors: [
|
||||||
{
|
{
|
||||||
messageId: 'noStyledPrefix',
|
messageId: 'noStyledPrefix',
|
||||||
@ -36,40 +35,12 @@ ruleTester.run("styled-components-prefixed-with-styled", styledComponentsPrefixe
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
code: 'const Component = styled.div``;',
|
code: 'const Component = styled.div``;',
|
||||||
filename: 'example.ts',
|
filename: 'react.tsx',
|
||||||
errors: [
|
errors: [
|
||||||
{
|
{
|
||||||
messageId: 'noStyledPrefix',
|
messageId: 'noStyledPrefix',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
|
||||||
code: 'const styled = {}; const Button = styled.button``;',
|
|
||||||
filename: 'example.ts',
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
messageId: 'noStyledPrefix',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: 'const styled = {}; const Component = styled.div``;',
|
|
||||||
filename: 'example.ts',
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
messageId: 'noStyledPrefix',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: 'const StyledButton = styled.button``;',
|
|
||||||
filename: 'themes.ts',
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
messageId: 'noStyledPrefix',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
|
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user