From 27b2b15e18f11dd1c123843e380aed14ef5b6a97 Mon Sep 17 00:00:00 2001 From: Stig Ofstad Date: Wed, 5 Jun 2024 10:46:21 +0200 Subject: [PATCH] style: run biome --- .pre-commit-config.yaml | 7 +++-- api/pyproject.toml | 5 ++-- web/biome.json | 1 - web/src/App.tsx | 10 +++---- web/src/auth.ts | 7 ++--- web/src/common/components/Header.tsx | 14 ++------- web/src/common/components/IconButton.tsx | 30 +++++++++---------- web/src/common/components/VersionText.tsx | 17 +++-------- web/src/contexts/TodoContext.tsx | 13 ++++---- .../todos/todo-list/TodoItem.styled.tsx | 5 ++-- web/src/features/todos/todo-list/TodoItem.tsx | 15 +++------- web/src/features/todos/todo-list/TodoList.tsx | 16 ++++------ web/src/hooks/useTodoAPI.tsx | 7 +---- web/src/index.tsx | 4 +-- web/src/router.tsx | 2 +- 15 files changed, 54 insertions(+), 99 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d16b1659..f7fe4412 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -41,10 +41,13 @@ repos: rev: "v0.4.7" hooks: - id: ruff + name: Python lint + files: ^api/.*\.py$ + args: ["--fix"] + + - id: ruff-format name: Python format files: ^api/.*\.py$ - args: - - --fix - repo: https://github.com/biomejs/pre-commit rev: v0.2.0 diff --git a/api/pyproject.toml b/api/pyproject.toml index b9dc8c46..674abda8 100644 --- a/api/pyproject.toml +++ b/api/pyproject.toml @@ -67,6 +67,7 @@ src = ["src"] target-version = "py311" line-length = 119 +[tool.ruff.lint] select = [ "E", # pycodestyle errors "W", # pycodestyle warnings @@ -77,14 +78,12 @@ select = [ "B", # flake8-bugbear "UP", # automatically upgrade syntax for newer versions of the language ] - - ignore = [ "B904", # TODO: Within an except clause, raise exceptions with `raise ... from err` or `raise ... from None` to distinguish them from errors in exception handling "B008", # do not perform function calls in argument defaults. Ignored to allow dependencies in FastAPI ] -[tool.ruff.per-file-ignores] +[tool.ruff.lint.per-file-ignores] "__init__.py" = ["E402"] # Ignore `E402` (import violations) in all `__init__.py` files "src/tests/*" = ["S101"] # Allow the use of ´assert´ in tests diff --git a/web/biome.json b/web/biome.json index d33463cd..fadd6217 100644 --- a/web/biome.json +++ b/web/biome.json @@ -7,7 +7,6 @@ "formatter": { "indentStyle": "space", "indentWidth": 2, - "jsxQuoteStyle": "single", "quoteStyle": "single", "trailingCommas": "es5", "lineWidth": 119, diff --git a/web/src/App.tsx b/web/src/App.tsx index 3a6f4d92..d0c05f66 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -1,11 +1,11 @@ -import { router } from './router' -import { RouterProvider } from 'react-router-dom' -import Header from './common/components/Header' -import { AuthContext } from 'react-oauth2-code-pkce' -import { useContext } from 'react' import { Button, Progress, Typography } from '@equinor/eds-core-react' +import { useContext } from 'react' +import { AuthContext } from 'react-oauth2-code-pkce' +import { RouterProvider } from 'react-router-dom' import styled from 'styled-components' import { OpenAPI } from './api/generated' +import Header from './common/components/Header' +import { router } from './router' const hasAuthConfig = import.meta.env.VITE_AUTH === '1' diff --git a/web/src/auth.ts b/web/src/auth.ts index 0686a72e..a6f3c936 100644 --- a/web/src/auth.ts +++ b/web/src/auth.ts @@ -1,4 +1,4 @@ -import { TAuthConfig } from 'react-oauth2-code-pkce' +import type { TAuthConfig } from 'react-oauth2-code-pkce' export const authConfig: TAuthConfig = { clientId: import.meta.env.VITE_AUTH_CLIENT_ID || '', @@ -14,8 +14,5 @@ export const authConfig: TAuthConfig = { `${window.location.pathname}${window.location.search}${window.location.hash}` ), postLogin: () => - window.location.replace( - localStorage.getItem('preLoginPath') ?? - (import.meta.env.VITE_AUTH_REDIRECT_URI || '') - ), + window.location.replace(localStorage.getItem('preLoginPath') ?? (import.meta.env.VITE_AUTH_REDIRECT_URI || '')), } diff --git a/web/src/common/components/Header.tsx b/web/src/common/components/Header.tsx index ff7bac2a..76222c08 100644 --- a/web/src/common/components/Header.tsx +++ b/web/src/common/components/Header.tsx @@ -27,20 +27,10 @@ const Header = () => { {`Logged in as ${username}`} - + - +

Person of contact: Eirik Ola Aksnes (eaks@equinor.com)

diff --git a/web/src/common/components/IconButton.tsx b/web/src/common/components/IconButton.tsx index 1f4adc25..38c931d9 100644 --- a/web/src/common/components/IconButton.tsx +++ b/web/src/common/components/IconButton.tsx @@ -1,6 +1,6 @@ import { Button, Icon, Tooltip } from '@equinor/eds-core-react' -import { IconData } from '@equinor/eds-icons' -import { forwardRef, Ref } from 'react' +import type { IconData } from '@equinor/eds-icons' +import { type Ref, forwardRef } from 'react' interface IconButtonProps { title: string @@ -8,19 +8,17 @@ interface IconButtonProps { onClick: () => Promise | void } -const IconButton = forwardRef( - function IconButton( - { title, icon, onClick }: IconButtonProps, - ref: Ref - ) { - return ( - - - - ) - } -) +const IconButton = forwardRef(function IconButton( + { title, icon, onClick }: IconButtonProps, + ref: Ref +) { + return ( + + + + ) +}) export default IconButton diff --git a/web/src/common/components/VersionText.tsx b/web/src/common/components/VersionText.tsx index 3e14da88..2657cbaf 100644 --- a/web/src/common/components/VersionText.tsx +++ b/web/src/common/components/VersionText.tsx @@ -1,5 +1,5 @@ import { Typography } from '@equinor/eds-core-react' -import axios, { AxiosError, AxiosResponse } from 'axios' +import axios, { type AxiosError, type AxiosResponse } from 'axios' import { useEffect, useState } from 'react' type CommitInfo = { @@ -19,15 +19,9 @@ const useCommitInfo = () => { const fetchVersionFile = () => axios .get('version.txt') - .then((res: AxiosResponse) => - Object.fromEntries( - res.data.split('\n').map((line) => line.split(': ')) - ) - ) + .then((res: AxiosResponse) => Object.fromEntries(res.data.split('\n').map((line) => line.split(': ')))) .catch((error: AxiosError) => { - throw new Error( - `Could not read version file, ${error.response?.data ?? error}` - ) + throw new Error(`Could not read version file, ${error.response?.data ?? error}`) }) fetchVersionFile().then((commitInfo) => setCommitInfo(commitInfo)) }, []) @@ -42,10 +36,7 @@ export const VersionText = () => {

Version:{' '} <> - + {commitInfo.refs === '' ? commitInfo.hash : commitInfo.refs} {' '} {commitInfo.date} diff --git a/web/src/contexts/TodoContext.tsx b/web/src/contexts/TodoContext.tsx index 7e799de9..0b9e9af7 100644 --- a/web/src/contexts/TodoContext.tsx +++ b/web/src/contexts/TodoContext.tsx @@ -1,5 +1,6 @@ -import React, { createContext, useContext, useReducer } from 'react' -import { AddTodoResponse } from '../api/generated' +import type React from 'react' +import { createContext, useContext, useReducer } from 'react' +import type { AddTodoResponse } from '../api/generated' /** * Definitions of the types of actions an user can do, @@ -14,9 +15,7 @@ type Dispatch = (action: Action) => void type State = { todos: AddTodoResponse[] } type TodoProviderProps = { children: React.ReactNode } -const TodoContext = createContext< - { state: State; dispatch: Dispatch } | undefined ->(undefined) +const TodoContext = createContext<{ state: State; dispatch: Dispatch } | undefined>(undefined) function TodoProvider({ children }: TodoProviderProps) { const [state, dispatch] = useReducer(todoReducer, { todos: [] }) @@ -49,9 +48,7 @@ function todoReducer(state: State, action: Action) { return { ...state, todos: state.todos.map((todo) => - todo !== action.payload - ? todo - : { ...todo, is_completed: !todo.is_completed } + todo !== action.payload ? todo : { ...todo, is_completed: !todo.is_completed } ), } } diff --git a/web/src/features/todos/todo-list/TodoItem.styled.tsx b/web/src/features/todos/todo-list/TodoItem.styled.tsx index 2d64204d..89e1c187 100644 --- a/web/src/features/todos/todo-list/TodoItem.styled.tsx +++ b/web/src/features/todos/todo-list/TodoItem.styled.tsx @@ -1,7 +1,6 @@ -import styled from 'styled-components' import { Typography } from '@equinor/eds-core-react' +import styled from 'styled-components' export const StyledTodoItemTitle = styled(Typography)` - text-decoration: ${(props: { isStruckThrough?: boolean }) => - props.isStruckThrough ? 'line-through' : 'none'}; + text-decoration: ${(props: { isStruckThrough?: boolean }) => (props.isStruckThrough ? 'line-through' : 'none')}; ` diff --git a/web/src/features/todos/todo-list/TodoItem.tsx b/web/src/features/todos/todo-list/TodoItem.tsx index 8b4ae58a..386a1bef 100644 --- a/web/src/features/todos/todo-list/TodoItem.tsx +++ b/web/src/features/todos/todo-list/TodoItem.tsx @@ -1,6 +1,6 @@ import { Card, Typography } from '@equinor/eds-core-react' import { done, remove_outlined, undo } from '@equinor/eds-icons' -import { AddTodoResponse } from '../../../api/generated' +import type { AddTodoResponse } from '../../../api/generated' import IconButton from '../../../common/components/IconButton' import { useTodos } from '../../../contexts/TodoContext' import { useTodoAPI } from '../../../hooks/useTodoAPI' @@ -20,8 +20,7 @@ const TodoItem = ({ todo }: { todo: AddTodoResponse }) => { dispatch({ type: 'REMOVE_TODO', payload: todo }) } - const statusOf = (isCompleted: boolean | undefined) => - isCompleted ? 'Done' : 'Todo' + const statusOf = (isCompleted: boolean | undefined) => (isCompleted ? 'Done' : 'Todo') return ( @@ -30,20 +29,14 @@ const TodoItem = ({ todo }: { todo: AddTodoResponse }) => { {todo.title} - - {statusOf(todo.is_completed)} - + {statusOf(todo.is_completed)} toggle(todo)} /> - remove(todo)} - /> + remove(todo)} /> ) diff --git a/web/src/features/todos/todo-list/TodoList.tsx b/web/src/features/todos/todo-list/TodoList.tsx index 7ec71f2b..2c589529 100644 --- a/web/src/features/todos/todo-list/TodoList.tsx +++ b/web/src/features/todos/todo-list/TodoList.tsx @@ -1,6 +1,6 @@ import { Button, Input } from '@equinor/eds-core-react' -import { ChangeEvent, FormEventHandler, useEffect, useState } from 'react' -import { AddTodoResponse } from '../../../api/generated' +import { type ChangeEvent, type FormEventHandler, useEffect, useState } from 'react' +import type { AddTodoResponse } from '../../../api/generated' import { useTodos } from '../../../contexts/TodoContext' import { useTodoAPI } from '../../../hooks/useTodoAPI' import TodoItem from './TodoItem' @@ -14,9 +14,7 @@ const AddItem = () => { const add: FormEventHandler = (event) => { event.preventDefault() if (value) { - addTodo(value).then((todo) => - dispatch({ type: 'ADD_TODO', payload: todo }) - ) + addTodo(value).then((todo) => dispatch({ type: 'ADD_TODO', payload: todo })) } setValue('') } @@ -29,9 +27,7 @@ const AddItem = () => { value={value} className="input" placeholder="Add Task" - onChange={(e: ChangeEvent) => - setValue(e.target.value) - } + onChange={(e: ChangeEvent) => setValue(e.target.value)} />