From e38e7438ccb77d11d59c54d4aa226f353f73cae3 Mon Sep 17 00:00:00 2001 From: freshavocado7 Date: Wed, 18 Sep 2024 14:27:21 +0200 Subject: [PATCH] refactor: Make tailwind classes prettier --- .pre-commit-config.yaml | 7 +- frontend/.eslintrc.cjs | 3 +- frontend/.prettierrc.js | 9 ++- frontend/.storybook/main.js | 20 ++--- frontend/.storybook/preview.js | 12 +-- frontend/package-lock.json | 48 ++++++++++++ frontend/package.json | 2 + frontend/postcss.config.js | 6 +- frontend/public/static/env.js | 4 +- frontend/src/APIConfig.js | 4 +- frontend/src/components/Badge.jsx | 28 ++++--- frontend/src/components/Breadcrumbs.jsx | 17 ++--- frontend/src/components/Button.jsx | 11 +-- frontend/src/components/Card.jsx | 8 +- frontend/src/components/DiffExplorer.jsx | 8 +- frontend/src/components/DiffView.jsx | 16 ++-- frontend/src/components/Header.jsx | 8 +- frontend/src/components/HomeIcon.jsx | 4 +- frontend/src/components/InstanceView.jsx | 28 +++---- frontend/src/components/Lightbox.jsx | 12 +-- frontend/src/components/LightboxButton.jsx | 6 +- frontend/src/components/ModelDiff.jsx | 32 +++++--- frontend/src/components/SVGDisplay.jsx | 13 ++-- frontend/src/components/SettingsMenu.jsx | 13 +--- frontend/src/components/SoftwareVersion.jsx | 4 +- frontend/src/components/Spinner.jsx | 6 +- frontend/src/components/TemplateCard.jsx | 19 ++--- frontend/src/components/TemplateDetails.jsx | 74 ++++++++----------- frontend/src/components/ThemeSwitcher.jsx | 12 +-- frontend/src/components/ViewsList.jsx | 22 ++---- .../src/components/WiredTemplatesList.jsx | 15 ++-- frontend/src/main.jsx | 12 +-- frontend/src/views/HomeView.jsx | 14 +++- frontend/src/views/ModelComparisonView.jsx | 55 ++++++-------- frontend/src/views/TemplateView.jsx | 68 ++++++++--------- frontend/vite.config.js | 8 +- 36 files changed, 320 insertions(+), 308 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e892cd5..71e4354 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -127,10 +127,12 @@ repos: name: prettier entry: prettier --write language: node - types_or: [ts, css, html, markdown] + types_or: [javascript, jsx, ts, css, html, markdown] additional_dependencies: - 'prettier@^3.3.3' - 'prettier-plugin-tailwindcss@^0.6.6' + - 'prettier-plugin-classnames@^0.7.2' + - 'prettier-plugin-merge@^0.7.1' - 'tailwind-scrollbar@^3.1.0' - repo: https://github.com/pre-commit/mirrors-eslint rev: v9.10.0 @@ -147,3 +149,6 @@ repos: - 'eslint-plugin-react@^7.34.1' - 'eslint-plugin-react-hooks@^4.6.2' - 'eslint-plugin-react-refresh@^0.4.5' + args: ['--fix'] + types: [] + files: '^frontend/.*\.(js|jsx)$' diff --git a/frontend/.eslintrc.cjs b/frontend/.eslintrc.cjs index 71ff1a6..b7db9aa 100644 --- a/frontend/.eslintrc.cjs +++ b/frontend/.eslintrc.cjs @@ -22,6 +22,7 @@ module.exports = { 'warn', { allowConstantExport: true } ], - 'max-len': ['error', { code: 79 }] + 'max-len': ['error', { code: 100 }], + 'react/no-unescaped-entities': 'off' } }; diff --git a/frontend/.prettierrc.js b/frontend/.prettierrc.js index d17e3d4..9585637 100644 --- a/frontend/.prettierrc.js +++ b/frontend/.prettierrc.js @@ -4,11 +4,16 @@ */ module.exports = { - plugins: [require.resolve('prettier-plugin-tailwindcss')], + plugins: [ + require.resolve('prettier-plugin-tailwindcss'), + require.resolve('prettier-plugin-classnames'), + require.resolve('prettier-plugin-merge') + ], semi: true, tabWidth: 2, printWidth: 79, singleQuote: true, trailingComma: 'none', - bracketSameLine: true + bracketSameLine: true, + endingPosition: 'absolute-with-indent' }; diff --git a/frontend/.storybook/main.js b/frontend/.storybook/main.js index b11f63a..14e108f 100644 --- a/frontend/.storybook/main.js +++ b/frontend/.storybook/main.js @@ -3,14 +3,14 @@ /** @type { import('@storybook/react-vite').StorybookConfig } */ const config = { - stories: ["../src/**/*.mdx", "../src/**/*.stories.@(js|jsx|mjs|ts|tsx)"], + stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'], addons: [ - "@storybook/addon-links", - "@storybook/addon-essentials", - "@storybook/addon-onboarding", - "@storybook/addon-interactions", + '@storybook/addon-links', + '@storybook/addon-essentials', + '@storybook/addon-onboarding', + '@storybook/addon-interactions', { - name: "@storybook/addon-postcss", + name: '@storybook/addon-postcss', options: { postcssLoaderOptions: { implementation: require('postcss') @@ -19,11 +19,11 @@ const config = { } ], framework: { - name: "@storybook/react-vite", - options: {}, + name: '@storybook/react-vite', + options: {} }, docs: { - autodocs: "tag", - }, + autodocs: 'tag' + } }; export default config; diff --git a/frontend/.storybook/preview.js b/frontend/.storybook/preview.js index b27ad0f..8c248a6 100644 --- a/frontend/.storybook/preview.js +++ b/frontend/.storybook/preview.js @@ -1,19 +1,19 @@ // Copyright DB InfraGO AG and contributors // SPDX-License-Identifier: Apache-2.0 -import '../src/index.css' +import '../src/index.css'; /** @type { import('@storybook/react').Preview } */ const preview = { parameters: { - actions: { argTypesRegex: "^on[A-Z].*" }, + actions: { argTypesRegex: '^on[A-Z].*' }, controls: { matchers: { color: /(background|color)$/i, - date: /Date$/i, - }, - }, - }, + date: /Date$/i + } + } + } }; export default preview; diff --git a/frontend/package-lock.json b/frontend/package-lock.json index f3f0d70..10c3bdb 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -42,6 +42,8 @@ "globals": "^15.9.0", "postcss": "^8.4.45", "prettier": "^3.3.3", + "prettier-plugin-classnames": "^0.7.2", + "prettier-plugin-merge": "^0.7.1", "prettier-plugin-tailwindcss": "^0.6.6", "prop-types": "^15.8.1", "react-router-dom": "^6.26.2", @@ -6039,6 +6041,15 @@ "resolved": "https://registry.npmjs.org/didyoumean/-/didyoumean-1.2.2.tgz", "integrity": "sha512-gxtyfqMg7GKyhQmb056K7M3xszy/myH8w+B4RT+QXBQsvAOdc3XymqDDPHx1BgPgsdAA5SIifona89YtRATDzw==" }, + "node_modules/diff": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/diff/-/diff-5.1.0.tgz", + "integrity": "sha512-D+mk+qE8VC/PAUrlAU34N+VfXev0ghe5ywmpqrawphmVZc1bEfn56uo9qpyGp1p4xpzOHkSW4ztBd6L7Xx4ACw==", + "dev": true, + "engines": { + "node": ">=0.3.1" + } + }, "node_modules/diff-sequences": { "version": "29.6.3", "resolved": "https://registry.npmjs.org/diff-sequences/-/diff-sequences-29.6.3.tgz", @@ -10299,6 +10310,43 @@ "node": ">=6.0.0" } }, + "node_modules/prettier-plugin-classnames": { + "version": "0.7.2", + "resolved": "https://registry.npmjs.org/prettier-plugin-classnames/-/prettier-plugin-classnames-0.7.2.tgz", + "integrity": "sha512-rocYqVSWV/YSJE+TA7b1IgYY9/I4bx0lxJjE5Iwv/kavNNEYhKh7Gl1+MQARQYgPisGMd5DU8Uj6ZEVX0KmTTA==", + "dev": true, + "engines": { + "node": ">=14" + }, + "peerDependencies": { + "prettier": "^2 || ^3", + "prettier-plugin-astro": "*", + "prettier-plugin-svelte": "*" + }, + "peerDependenciesMeta": { + "prettier-plugin-astro": { + "optional": true + }, + "prettier-plugin-svelte": { + "optional": true + } + } + }, + "node_modules/prettier-plugin-merge": { + "version": "0.7.1", + "resolved": "https://registry.npmjs.org/prettier-plugin-merge/-/prettier-plugin-merge-0.7.1.tgz", + "integrity": "sha512-R3dSlv3kAlScjd/liWjTkGHcUrE4MBhPKKBxVOvHK7+FY2P5SEmLarZiD11VUEuaMRK0L7zqIurX6JcRYS9Y5Q==", + "dev": true, + "dependencies": { + "diff": "5.1.0" + }, + "engines": { + "node": ">=14" + }, + "peerDependencies": { + "prettier": "^2 || ^3" + } + }, "node_modules/prettier-plugin-tailwindcss": { "version": "0.6.6", "resolved": "https://registry.npmjs.org/prettier-plugin-tailwindcss/-/prettier-plugin-tailwindcss-0.6.6.tgz", diff --git a/frontend/package.json b/frontend/package.json index 1609fed..091dd43 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -47,6 +47,8 @@ "globals": "^15.9.0", "postcss": "^8.4.45", "prettier": "^3.3.3", + "prettier-plugin-classnames": "^0.7.2", + "prettier-plugin-merge": "^0.7.1", "prettier-plugin-tailwindcss": "^0.6.6", "prop-types": "^15.8.1", "react-router-dom": "^6.26.2", diff --git a/frontend/postcss.config.js b/frontend/postcss.config.js index f139503..61dd434 100644 --- a/frontend/postcss.config.js +++ b/frontend/postcss.config.js @@ -6,6 +6,6 @@ module.exports = { plugins: { tailwindcss: {}, - autoprefixer: {}, - }, -} + autoprefixer: {} + } +}; diff --git a/frontend/public/static/env.js b/frontend/public/static/env.js index 83ba5c4..1f83af3 100644 --- a/frontend/public/static/env.js +++ b/frontend/public/static/env.js @@ -4,6 +4,6 @@ */ window.env = { - ROUTE_PREFIX: "__ROUTE_PREFIX__", - API_BASE_URL: "__ROUTE_PREFIX__/api", + ROUTE_PREFIX: '__ROUTE_PREFIX__', + API_BASE_URL: '__ROUTE_PREFIX__/api' }; diff --git a/frontend/src/APIConfig.js b/frontend/src/APIConfig.js index b0b75f1..422211d 100644 --- a/frontend/src/APIConfig.js +++ b/frontend/src/APIConfig.js @@ -5,8 +5,8 @@ var API_BASE_URL = window.env.API_BASE_URL; var ROUTE_PREFIX = window.env.ROUTE_PREFIX; -if (!process.env.NODE_ENV || process.env.NODE_ENV === "development") { - ROUTE_PREFIX = ""; +if (!process.env.NODE_ENV || process.env.NODE_ENV === 'development') { + ROUTE_PREFIX = ''; API_BASE_URL = `http://localhost:8000${ROUTE_PREFIX}/api`; } export { API_BASE_URL, ROUTE_PREFIX }; diff --git a/frontend/src/components/Badge.jsx b/frontend/src/components/Badge.jsx index a24b443..dd6b12c 100644 --- a/frontend/src/components/Badge.jsx +++ b/frontend/src/components/Badge.jsx @@ -1,18 +1,22 @@ - // Copyright DB InfraGO AG and contributors // SPDX-License-Identifier: Apache-2.0 const color_classes = { - "default": "bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-300", - "danger": "bg-red-100 text-red-800 dark:bg-red-900 dark:text-red-300", - "success": "bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-300", - "warning": "bg-yellow-100 text-yellow-800 dark:bg-yellow-900 dark:text-yellow-300" -} + default: 'bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-300', + danger: 'bg-red-100 text-red-800 dark:bg-red-900 dark:text-red-300', + success: 'bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-300', + warning: + 'bg-yellow-100 text-yellow-800 dark:bg-yellow-900 dark:text-yellow-300' +}; /* -* provides a badge that may have different colors -*/ -export const Badge = ({ children, color="default" }) => ( -
- {children} -
+ * provides a badge that may have different colors + */ +export const Badge = ({ children, color = 'default' }) => ( +
+ {children} +
); diff --git a/frontend/src/components/Breadcrumbs.jsx b/frontend/src/components/Breadcrumbs.jsx index dafe0f8..d2805a6 100644 --- a/frontend/src/components/Breadcrumbs.jsx +++ b/frontend/src/components/Breadcrumbs.jsx @@ -67,9 +67,7 @@ export const Breadcrumbs = () => { return (