Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend prettier setup #40

Merged
merged 1 commit into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)$'
8 changes: 6 additions & 2 deletions frontend/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ module.exports = {
],
ignorePatterns: ['dist', '.eslintrc.cjs'],
parserOptions: { ecmaVersion: 'latest', sourceType: 'module' },
settings: { react: { version: '18.2' } },
settings: {
react: {
version: '18.2'
}
},
plugins: ['react-refresh'],
rules: {
'react/jsx-no-target-blank': 'off',
Expand All @@ -22,6 +26,6 @@ module.exports = {
'warn',
{ allowConstantExport: true }
],
'max-len': ['error', { code: 79 }]
'max-len': ['error', { code: 100, ignoreUrls: true, ignoreStrings: true }]
}
};
11 changes: 9 additions & 2 deletions frontend/.prettierrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@
*/

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,
endOfLine: 'lf',
useTabs: false,
endingPosition: 'absolute-with-indent'
};
20 changes: 10 additions & 10 deletions frontend/.storybook/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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;
12 changes: 6 additions & 6 deletions frontend/.storybook/preview.js
Original file line number Diff line number Diff line change
@@ -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;
48 changes: 48 additions & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"storybook": "storybook dev -p 6006",
"build-storybook": "storybook build",
"lint:fix": "eslint . --fix",
"format": "prettier --write ./**/*.{js,jsx,ts,tsx,css,md,json} --config ./.prettierrc.json"
"format": "prettier --write ./**/*.{js,jsx,ts,tsx,css,md,json} --config ./.prettierrc.js"
},
"dependencies": {
"@icons-pack/react-simple-icons": "^10.0.0",
Expand Down Expand Up @@ -40,14 +40,15 @@
"dompurify": "^3.1.6",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-react": "^7.35.2",
"eslint-plugin-react-hooks": "^4.6.2",
"eslint-plugin-react-refresh": "^0.4.11",
"eslint-plugin-storybook": "^0.8.0",
"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",
Expand Down
6 changes: 3 additions & 3 deletions frontend/postcss.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
}
autoprefixer: {}
}
};
4 changes: 2 additions & 2 deletions frontend/public/static/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
};
4 changes: 2 additions & 2 deletions frontend/src/APIConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
4 changes: 3 additions & 1 deletion frontend/src/components/AppInfo.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ export const AppInfo = () => {
className="flex items-center space-x-2 hover:underline"
target="_blank">
<span>Contribute on GitHub</span>
<div className="flex h-6 w-6 items-center justify-center rounded-full bg-custom-light">
<div
className="flex h-6 w-6 items-center justify-center rounded-full
bg-custom-light">
<SiGithub className="h-5 w-5 text-black" />
</div>
</a>
Expand Down
28 changes: 16 additions & 12 deletions frontend/src/components/Badge.jsx
Original file line number Diff line number Diff line change
@@ -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" }) => (
<div className={"text-xs inline-block font-medium me-2 px-2.5 py-1 rounded-full " + color_classes[color] }>
{children}
</div>
* provides a badge that may have different colors
*/
export const Badge = ({ children, color = 'default' }) => (
<div
className={
'me-2 inline-block rounded-full px-2.5 py-1 text-xs font-medium ' +
color_classes[color]
}>
{children}
</div>
);
17 changes: 6 additions & 11 deletions frontend/src/components/Breadcrumbs.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ export const Breadcrumbs = () => {
return (
<nav
aria-label="breadcrumb"
className={
'flex items-center font-medium text-black dark:text-gray-200'
}>
className="flex items-center font-medium text-black dark:text-gray-200">
<ol className="flex items-center">
<li className="hidden items-center truncate lg:block">
<Link to={'/'}>{breadcrumbLabels['/']}</Link>
Expand All @@ -86,19 +84,16 @@ export const Breadcrumbs = () => {
{!last && (
<Link
to={to}
className={
'hidden max-w-64 truncate whitespace-nowrap md:block'
}>
className="hidden max-w-64 truncate whitespace-nowrap
md:block">
{label}
</Link>
)}
{last && (
<span
className={
'hidden w-full truncate whitespace-nowrap ' +
'text-custom-blue custom-phone-width:block ' +
'custom-phone-width:max-w-60 md:max-w-full'
}
className="hidden w-full truncate whitespace-nowrap
text-custom-blue custom-phone-width:block
custom-phone-width:max-w-60 md:max-w-full"
title={label}>
{label}
</span>
Expand Down
11 changes: 4 additions & 7 deletions frontend/src/components/Button.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@ export const Button = ({ children, ...props }) => {
<a
href="#"
{...props}
className={
'print:hidden rounded-md mx-1 bg-custom-blue px-2.5 py-1.5 ' +
'text-sm font-semibold text-white shadow-sm dark:shadow-dark ' +
'hover:bg-custom-blue-hover hover:text-gray-50 ' +
'focus-visible:outline focus-visible:outline-2 ' +
'focus-visible:outline-offset-2'
}>
className="mx-1 rounded-md bg-custom-blue px-2.5 py-1.5 text-sm
font-semibold text-white shadow-sm hover:bg-custom-blue-hover
hover:text-gray-50 focus-visible:outline focus-visible:outline-2
focus-visible:outline-offset-2 dark:shadow-dark print:hidden">
{children}
</a>
);
Expand Down
8 changes: 3 additions & 5 deletions frontend/src/components/Card.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
export const Card = ({ children, onClick }) => (
<div
onClick={onClick}
className={
'm-2 max-w-sm cursor-pointer rounded-lg border border-gray-200 ' +
'bg-white shadow-md hover:bg-gray-100 dark:border-gray-700' +
'dark:bg-gray-800 dark:shadow-dark dark:hover:bg-gray-700 '
}>
className="m-2 max-w-sm cursor-pointer rounded-lg border border-gray-200
bg-white shadow-md hover:bg-gray-100 dark:border-gray-700
dark:bg-gray-800 dark:shadow-dark dark:hover:bg-gray-700">
{children}
</div>
);
8 changes: 5 additions & 3 deletions frontend/src/components/DiffExplorer.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright DB InfraGO AG and contributors
// SPDX-License-Identifier: Apache-2.0

import React, { useState } from 'react';
import { useState } from 'react';
import {
CirclePlus,
CircleX,
Expand Down Expand Up @@ -123,13 +123,15 @@ export const DiffExplorer = ({
)}
<span
onClick={() => handleLeafClick(node)}
className={`flex-1 cursor-pointer truncate ${node.change === 'deleted' ? 'pointer-events-none' : ''}`}
className={`flex-1 cursor-pointer truncate
${node.change === 'deleted' ? 'pointer-events-none' : ''}`}
title={node.display_name}>
{node.display_name}
</span>
</div>
<span
className={`flex h-6 w-6 items-center justify-center rounded-full ${getNodeClass(node.change, node.attributes)}`}>
className={`flex h-6 w-6 items-center justify-center rounded-full
${getNodeClass(node.change, node.attributes)}`}>
{getIcon(node.change, node.attributes)}
</span>
</div>
Expand Down
Loading
Loading