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

WIP: Switch PUI linting to biome #8317

Draft
wants to merge 32 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
92f494a
bump pre-commit
matmair Oct 18, 2024
10cacb5
add biome
matmair Oct 18, 2024
fd57a4d
autofixes
matmair Oct 18, 2024
5e0ee93
use number functions
matmair Oct 18, 2024
6fc1cd1
fix string usage
matmair Oct 18, 2024
f389048
use specific variable definition
matmair Oct 18, 2024
d9bb053
fix missing translations
matmair Oct 18, 2024
77a5919
reduce alerts
matmair Oct 18, 2024
59610a3
add missing keys
matmair Oct 18, 2024
0837050
fix index creation
matmair Oct 18, 2024
dead447
fix more strings
matmair Oct 18, 2024
0c72f75
fix types
matmair Oct 18, 2024
c6931e5
fix function
matmair Oct 18, 2024
47ed1a7
add missing keys
matmair Oct 18, 2024
a24f993
fiy array access
matmair Oct 18, 2024
318cae5
fix string functions
matmair Oct 18, 2024
ca22351
do not redefine var
matmair Oct 19, 2024
ae2d73d
extend exlcusions
matmair Oct 19, 2024
de6545e
reduce unnecessary operators
matmair Oct 19, 2024
b9f3ee8
simplify request
matmair Oct 19, 2024
e7ee1b7
use number functions
matmair Oct 19, 2024
a06efb1
fix missing translation
matmair Oct 19, 2024
c157360
add missing type
matmair Oct 19, 2024
59fec93
fix filter
matmair Oct 19, 2024
3645ff2
use newer func
matmair Oct 19, 2024
216c31f
remove unused fragment
matmair Oct 19, 2024
4238b33
Merge branch 'master' of https://github.com/inventree/InvenTree into …
matmair Oct 19, 2024
70fee99
fix confusing assigment
matmair Oct 19, 2024
5ca4e62
pass children as elements
matmair Oct 19, 2024
88ef383
add missing translation
matmair Oct 19, 2024
7ef36c1
fix imports
matmair Oct 19, 2024
4af3473
fix import
matmair Oct 19, 2024
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
32 changes: 9 additions & 23 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ repos:
- id: check-yaml
- id: mixed-line-ending
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.8
rev: v0.7.0
hooks:
- id: ruff-format
args: [--preview]
Expand All @@ -28,7 +28,7 @@ repos:
--preview
]
- repo: https://github.com/astral-sh/uv-pre-commit
rev: 0.4.17
rev: 0.4.24
hooks:
- id: pip-compile
name: pip-compile requirements-dev.in
Expand Down Expand Up @@ -69,28 +69,14 @@ repos:
pyproject.toml |
src/frontend/vite.config.ts |
)$
- repo: https://github.com/pre-commit/mirrors-prettier
rev: "v4.0.0-alpha.8"
hooks:
- id: prettier
files: ^src/frontend/.*\.(js|jsx|ts|tsx)$
additional_dependencies:
- "prettier@^2.4.1"
- "@trivago/prettier-plugin-sort-imports"
- repo: https://github.com/pre-commit/mirrors-eslint
rev: "v9.11.1"
hooks:
- id: eslint
additional_dependencies:
- eslint@^8.41.0
- eslint-config-google@^0.14.0
- [email protected]
- [email protected]
- "@typescript-eslint/eslint-plugin@latest"
- "@typescript-eslint/parser"
files: ^src/frontend/.*\.(js|jsx|ts|tsx)$
- repo: https://github.com/biomejs/pre-commit
rev: "v0.5.0"
hooks:
- id: biome-check
additional_dependencies: ["@biomejs/[email protected]"]
files: ^src/frontend/.*\.(js|ts|tsx)$
- repo: https://github.com/gitleaks/gitleaks
rev: v8.19.3
rev: v8.21.0
hooks:
- id: gitleaks
#- repo: https://github.com/jumanjihouse/pre-commit-hooks
Expand Down
42 changes: 42 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
"javascript": {
"formatter": {
"quoteStyle": "single",
"jsxQuoteStyle": "single",
"trailingCommas": "none",
"indentStyle": "space"
}
},
"linter": {
"rules": {
"suspicious" : {
"noExplicitAny": "off",
"noDoubleEquals": "off",
"noArrayIndexKey": "off",
"useDefaultSwitchClauseLast": "off"
},

"style": {
"useSelfClosingElements": "off",
"noUselessElse": "off",
"useTemplate": "off",
"noNonNullAssertion": "off",
"noParameterAssign": "off"
}, "correctness":{
"useExhaustiveDependencies": "off",
"useJsxKeyInIterable": "off",
"noUnsafeOptionalChaining": "off",
"noSwitchDeclarations": "off"
}, "complexity": {
"noBannedTypes": "off",
"noExtraBooleanCast": "off",
"noForEach": "off",
"noUselessSwitchCase": "off",
"useLiteralKeys":"off"
}, "performance": {
"noDelete":"off"
}
}
}
}
9 changes: 0 additions & 9 deletions src/frontend/.prettierrc

This file was deleted.

7 changes: 0 additions & 7 deletions src/frontend/eslint.config.cjs

This file was deleted.

2 changes: 1 addition & 1 deletion src/frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function setApiDefaults() {
api.defaults.xsrfHeaderName = 'X-CSRFToken';

if (token) {
api.defaults.headers['Authorization'] = `Token ${token}`;
api.defaults.headers.Authorization = `Token ${token}`;
} else {
delete api.defaults.headers['Authorization'];
}
Expand Down
6 changes: 3 additions & 3 deletions src/frontend/src/components/Boundary.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { t } from '@lingui/macro';
import { Alert } from '@mantine/core';
import { ErrorBoundary, FallbackRender } from '@sentry/react';
import { ErrorBoundary, type FallbackRender } from '@sentry/react';
import { IconExclamationCircle } from '@tabler/icons-react';
import { ReactNode, useCallback } from 'react';
import { type ReactNode, useCallback } from 'react';

function DefaultFallback({ title }: Readonly<{ title: string }>): ReactNode {
return (
<Alert
color="red"
color='red'
icon={<IconExclamationCircle />}
title={t`Error rendering component` + `: ${title}`}
>
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/components/DashboardItemProxy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useQuery } from '@tanstack/react-query';
import { useEffect, useState } from 'react';

import { api } from '../App';
import { ApiEndpoints } from '../enums/ApiEndpoints';
import type { ApiEndpoints } from '../enums/ApiEndpoints';
import { apiUrl } from '../states/ApiState';
import { StatisticItem } from './items/DashboardItem';
import { ErrorItem } from './items/ErrorItem';
Expand Down
11 changes: 8 additions & 3 deletions src/frontend/src/components/buttons/ActionButton.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { ActionIcon, FloatingPosition, Group, Tooltip } from '@mantine/core';
import { ReactNode } from 'react';
import {
ActionIcon,
type FloatingPosition,
Group,
Tooltip
} from '@mantine/core';
import type { ReactNode } from 'react';

import { identifierString } from '../../functions/conversion';

Expand Down Expand Up @@ -46,7 +51,7 @@ export function ActionButton(props: ActionButtonProps) {
}}
variant={props.variant ?? 'transparent'}
>
<Group gap="xs" wrap="nowrap">
<Group gap='xs' wrap='nowrap'>
{props.icon}
</Group>
</ActionIcon>
Expand Down
4 changes: 2 additions & 2 deletions src/frontend/src/components/buttons/AddItemButton.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { IconPlus } from '@tabler/icons-react';

import { ActionButton, ActionButtonProps } from './ActionButton';
import { ActionButton, type ActionButtonProps } from './ActionButton';

/**
* A generic icon button which is used to add or create a new item
*/
export function AddItemButton(props: Readonly<ActionButtonProps>) {
return <ActionButton {...props} color="green" icon={<IconPlus />} />;
return <ActionButton {...props} color='green' icon={<IconPlus />} />;
}
12 changes: 6 additions & 6 deletions src/frontend/src/components/buttons/AdminButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { t } from '@lingui/macro';
import { IconUserStar } from '@tabler/icons-react';
import { useCallback, useMemo } from 'react';

import { ModelType } from '../../enums/ModelType';
import type { ModelType } from '../../enums/ModelType';
import { useLocalState } from '../../states/LocalState';
import { useUserState } from '../../states/UserState';
import { ModelInformationDict } from '../render/ModelType';
Expand Down Expand Up @@ -73,14 +73,14 @@ export default function AdminButton(props: Readonly<AdminButtonProps>) {
return (
<ActionButton
icon={<IconUserStar />}
color="blue"
size="lg"
radius="sm"
variant="filled"
color='blue'
size='lg'
radius='sm'
variant='filled'
tooltip={t`Open in admin interface`}
hidden={!enabled}
onClick={openAdmin}
tooltipAlignment="bottom"
tooltipAlignment='bottom'
/>
);
}
6 changes: 3 additions & 3 deletions src/frontend/src/components/buttons/ButtonMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ export function ButtonMenu({
tooltip?: string;
}>) {
return (
<Menu shadow="xs">
<Menu shadow='xs'>
<Menu.Target>
<ActionIcon variant="default">
<ActionIcon variant='default'>
<Tooltip label={tooltip}>{icon}</Tooltip>
</ActionIcon>
</Menu.Target>
<Menu.Dropdown>
{label && <Menu.Label>{label}</Menu.Label>}
{actions.map((action, i) => (
<Menu.Item key={i}>{action}</Menu.Item>
<Menu.Item key={`${i}-${action}`}>{action}</Menu.Item>
))}
</Menu.Dropdown>
</Menu>
Expand Down
8 changes: 4 additions & 4 deletions src/frontend/src/components/buttons/CopyButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
ActionIcon,
Button,
CopyButton as MantineCopyButton,
MantineSize,
type MantineSize,
Text,
Tooltip
} from '@mantine/core';
Expand All @@ -30,13 +30,13 @@ export function CopyButton({
<ButtonComponent
color={copied ? 'teal' : 'gray'}
onClick={copy}
variant="transparent"
variant='transparent'
size={size ?? 'sm'}
>
{copied ? (
<InvenTreeIcon icon="check" />
<InvenTreeIcon icon='check' />
) : (
<InvenTreeIcon icon="copy" />
<InvenTreeIcon icon='copy' />
)}
{content}
{label && (
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/components/buttons/EditButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function EditButton({
<ActionIcon
onClick={() => setEditing()}
disabled={disabled}
variant="default"
variant='default'
>
{editing ? saveIcon : <IconEdit />}
</ActionIcon>
Expand Down
8 changes: 4 additions & 4 deletions src/frontend/src/components/buttons/PrimaryActionButton.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Button, Tooltip } from '@mantine/core';

import { InvenTreeIcon, InvenTreeIconType } from '../../functions/icons';
import { InvenTreeIcon, type InvenTreeIconType } from '../../functions/icons';

/**
* A "primary action" button for display on a page detail, (for example)
Expand All @@ -25,12 +25,12 @@ export default function PrimaryActionButton({
}

return (
<Tooltip label={tooltip ?? title} position="bottom" hidden={!tooltip}>
<Tooltip label={tooltip ?? title} position='bottom' hidden={!tooltip}>
<Button
leftSection={icon && <InvenTreeIcon icon={icon} />}
color={color}
radius="sm"
p="xs"
radius='sm'
p='xs'
onClick={onClick}
>
{title}
Expand Down
18 changes: 9 additions & 9 deletions src/frontend/src/components/buttons/PrintingActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import { useMemo, useState } from 'react';

import { api } from '../../App';
import { ApiEndpoints } from '../../enums/ApiEndpoints';
import { ModelType } from '../../enums/ModelType';
import type { ModelType } from '../../enums/ModelType';
import { extractAvailableFields } from '../../functions/forms';
import { useCreateApiFormModal } from '../../hooks/UseForm';
import { apiUrl } from '../../states/ApiState';
import { useLocalState } from '../../states/LocalState';
import { ApiFormFieldSet } from '../forms/fields/ApiFormField';
import type { ApiFormFieldSet } from '../forms/fields/ApiFormField';
import { ActionDropdown } from '../items/ActionDropdown';

export function PrintingActions({
Expand Down Expand Up @@ -54,26 +54,26 @@ export function PrintingActions({
});

const labelFields: ApiFormFieldSet = useMemo(() => {
let fields: ApiFormFieldSet = printingFields.data || {};
const fields: ApiFormFieldSet = printingFields.data || {};

// Override field values
fields['template'] = {
...fields['template'],
fields.template = {
...fields.template,
filters: {
enabled: true,
model_type: modelType,
items: items.join(',')
}
};

fields['items'] = {
...fields['items'],
fields.items = {
...fields.items,
value: items,
hidden: true
};

fields['plugin'] = {
...fields['plugin'],
fields.plugin = {
...fields.plugin,
filters: {
active: true,
mixin: 'labels'
Expand Down
6 changes: 3 additions & 3 deletions src/frontend/src/components/buttons/RemoveRowButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ export default function RemoveRowButton({
return (
<ActionButton
onClick={onClick}
icon={<InvenTreeIcon icon="square_x" />}
icon={<InvenTreeIcon icon='square_x' />}
tooltip={tooltip}
tooltipAlignment="top"
color="red"
tooltipAlignment='top'
color='red'
/>
);
}
6 changes: 3 additions & 3 deletions src/frontend/src/components/buttons/SSOButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
import { api } from '../../App';
import { ApiEndpoints } from '../../enums/ApiEndpoints';
import { apiUrl } from '../../states/ApiState';
import { Provider } from '../../states/states';
import type { Provider } from '../../states/states';

const brandIcons: { [key: string]: JSX.Element } = {
google: <IconBrandGoogle />,
Expand Down Expand Up @@ -51,8 +51,8 @@ export function SsoButton({ provider }: Readonly<{ provider: Provider }>) {
return (
<Button
leftSection={getBrandIcon(provider)}
radius="xl"
component="a"
radius='xl'
component='a'
onClick={login}
>
{provider.display_name}{' '}
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/components/buttons/ScanButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function ScanButton() {
innerProps: {}
})
}
variant="transparent"
variant='transparent'
title={t`Open QR code scanner`}
>
<IconQrcode />
Expand Down
Loading
Loading