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