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

[PUI] Switch linting to biome #8317

Merged
merged 45 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
45 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
9c49049
Merge branch 'master' of https://github.com/inventree/InvenTree into …
matmair Nov 10, 2024
b0d52ed
Merge branch 'master' of https://github.com/inventree/InvenTree into …
matmair Nov 10, 2024
77538c0
auto-fix problems
matmair Nov 10, 2024
e5c7b15
add autfix for unused imports
matmair Nov 10, 2024
f328401
fix SAST error
matmair Nov 10, 2024
baa3cee
fix useSelfClosingElements
matmair Nov 10, 2024
ce16288
fix useTemplate
matmair Nov 10, 2024
94d6815
Merge branch 'master' of https://github.com/inventree/InvenTree into …
matmair Nov 10, 2024
971eeee
add codespell exception
matmair Nov 10, 2024
92e596e
Update pui_printing.spec.ts
matmair Nov 11, 2024
6ea9287
Update pui_printing.spec.ts
matmair Nov 11, 2024
c47158e
Merge branch 'master' of https://github.com/inventree/InvenTree into …
matmair Nov 11, 2024
8afed29
add vscode defaults
matmair Nov 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
26 changes: 6 additions & 20 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,26 +69,12 @@ 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.12.0"
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.21.0
hooks:
Expand Down
43 changes: 43 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"$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",
"noUnusedImports":"error"
}, "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
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 { useServerApiState } from '../../states/ApiState';
import { useLocalState } from '../../states/LocalState';
import { useUserState } from '../../states/UserState';
Expand Down Expand Up @@ -78,14 +78,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
14 changes: 7 additions & 7 deletions src/frontend/src/components/buttons/PrintingActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ 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 { useUserSettingsState } from '../../states/SettingsState';
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 @@ -57,20 +57,20 @@ 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
};
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 Barcode Scanner`}
>
<IconQrcode />
Expand Down
10 changes: 5 additions & 5 deletions src/frontend/src/components/buttons/SplitButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { IconChevronDown } from '@tabler/icons-react';
import { useEffect, useMemo, useState } from 'react';

import { identifierString } from '../../functions/conversion';
import { TablerIconType } from '../../functions/icons';
import type { TablerIconType } from '../../functions/icons';
import * as classes from './SplitButton.css';

interface SplitButtonOption {
Expand Down Expand Up @@ -58,7 +58,7 @@ export function SplitButton({
const theme = useMantineTheme();

return (
<Group wrap="nowrap" style={{ gap: 0 }}>
<Group wrap='nowrap' style={{ gap: 0 }}>
<Button
onClick={currentOption?.onClick}
disabled={loading ? false : currentOption?.disabled}
Expand All @@ -70,12 +70,12 @@ export function SplitButton({
</Button>
<Menu
transitionProps={{ transition: 'pop' }}
position="bottom-end"
position='bottom-end'
withinPortal
>
<Menu.Target>
<ActionIcon
variant="filled"
variant='filled'
color={theme.primaryColor}
size={36}
className={classes.icon}
Expand All @@ -99,7 +99,7 @@ export function SplitButton({
disabled={option.disabled}
leftSection={<option.icon />}
>
<Tooltip label={option.tooltip} position="right">
<Tooltip label={option.tooltip} position='right'>
<Text>{option.name}</Text>
</Tooltip>
</Menu.Item>
Expand Down
Loading
Loading