From 2adabb3ba2e00f0a0be70e594fa81e29cb9b6387 Mon Sep 17 00:00:00 2001 From: Charles Bochet Date: Sun, 17 Sep 2023 08:59:42 -0700 Subject: [PATCH] Fix tests --- .../src/rules/no-hardcoded-colors.ts | 22 +++++------ .../src/tests/no-hardcoded-colors.spec.ts | 28 ++++---------- ...sort-css-properties-alphabetically.spec.ts | 10 ++--- ...ed-components-prefixed-with-styled.spec.ts | 37 ++----------------- 4 files changed, 26 insertions(+), 71 deletions(-) diff --git a/packages/eslint-plugin-twenty-ts/src/rules/no-hardcoded-colors.ts b/packages/eslint-plugin-twenty-ts/src/rules/no-hardcoded-colors.ts index 1a1366d00..9c542d9e5 100644 --- a/packages/eslint-plugin-twenty-ts/src/rules/no-hardcoded-colors.ts +++ b/packages/eslint-plugin-twenty-ts/src/rules/no-hardcoded-colors.ts @@ -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; diff --git a/packages/eslint-plugin-twenty-ts/src/tests/no-hardcoded-colors.spec.ts b/packages/eslint-plugin-twenty-ts/src/tests/no-hardcoded-colors.spec.ts index 10013637e..51e17ce63 100644 --- a/packages/eslint-plugin-twenty-ts/src/tests/no-hardcoded-colors.spec.ts +++ b/packages/eslint-plugin-twenty-ts/src/tests/no-hardcoded-colors.spec.ts @@ -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", }, ], }, ], -}); +}); \ No newline at end of file diff --git a/packages/eslint-plugin-twenty-ts/src/tests/sort-css-properties-alphabetically.spec.ts b/packages/eslint-plugin-twenty-ts/src/tests/sort-css-properties-alphabetically.spec.ts index 3d5f43534..df43067e2 100644 --- a/packages/eslint-plugin-twenty-ts/src/tests/sort-css-properties-alphabetically.spec.ts +++ b/packages/eslint-plugin-twenty-ts/src/tests/sort-css-properties-alphabetically.spec.ts @@ -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 ], }); diff --git a/packages/eslint-plugin-twenty-ts/src/tests/styled-components-prefixed-with-styled.spec.ts b/packages/eslint-plugin-twenty-ts/src/tests/styled-components-prefixed-with-styled.spec.ts index 3f1fedd77..19da8e8da 100644 --- a/packages/eslint-plugin-twenty-ts/src/tests/styled-components-prefixed-with-styled.spec.ts +++ b/packages/eslint-plugin-twenty-ts/src/tests/styled-components-prefixed-with-styled.spec.ts @@ -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', - }, - ], - }, - ], });