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

Feat/biome #242

Merged
merged 4 commits into from
Jun 6, 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
55 changes: 11 additions & 44 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,58 +37,25 @@ repos:
- id: conventional-pre-commit
stages: [commit-msg]

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: "v0.0.289"
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.4.7"
hooks:
- id: ruff
name: Code linting
name: Python lint
files: ^api/.*\.py$
args:
- --fix
args: ["--fix"]

- repo: https://github.com/ambv/black
rev: 23.9.1
hooks:
- id: black
name: Code formatting
language_version: python3.10
args: [--config=api/pyproject.toml]
files: ^api/src/.*\.py$

- repo: https://github.com/econchick/interrogate
rev: 1.5.0
hooks:
- id: interrogate
language_version: python3.10
types: [python]
args: [--config=api/pyproject.toml]
- id: ruff-format
name: Python format
files: ^api/.*\.py$

- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.0.3
- repo: https://github.com/biomejs/pre-commit
rev: v0.2.0
hooks:
- id: prettier
files: ^web/src/.*\.(ts|tsx|js|css|html|json)$
args:
["--config=web/.prettierrc.js", "--ignore-path=web/.prettierignore"]
- id: biome-check
additional_dependencies: [ "@biomejs/[email protected]" ]
args: ["--config-path", "web"]

- repo: https://github.com/pre-commit/mirrors-eslint
rev: "v8.49.0"
hooks:
- id: eslint
additional_dependencies:
- eslint
- typescript
- "@typescript-eslint/parser"
- "@typescript-eslint/eslint-plugin"
- eslint-config-prettier # turns off all rules that might conflict with prettier
- eslint-plugin-jsx-a11y # checks accessibility rules on jsx elements
- eslint-plugin-prettier # runs prettier as an eslint rule
- eslint-plugin-react # react specific linting rules
- eslint-plugin-react-hooks # enforces the rules of hooks
files: ^web/src/.*\.[jt]sx?$ # *.js, *.jsx, *.ts and *.tsx
types: [file]
args: ["--config=web/.eslintrc.json", "--ignore-path=web/.eslintignore"]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.5.1
Expand Down
20 changes: 2 additions & 18 deletions api/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,6 @@ pre-commit = ">=3"
pytest = "^7.2.2"
mongomock = "^4.1.2"

[tool.black]
line-length = 119
target-version = ['py310']
include = '\.pyi?$'
exclude = '''
/(
\.eggs
| \.git
| \.hg
| \.mypy_cache
| \.tox
| \.venv
)/
'''

[tool.interrogate]
ignore-init-method = true
ignore-init-module = true
Expand Down Expand Up @@ -82,6 +67,7 @@ src = ["src"]
target-version = "py311"
line-length = 119

[tool.ruff.lint]
select = [
"E", # pycodestyle errors
"W", # pycodestyle warnings
Expand All @@ -92,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

Expand Down
4 changes: 2 additions & 2 deletions api/src/common/exception_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ def add_exception_handlers(app: FastAPI) -> None:
app.add_exception_handler(MissingPrivilegeException, generic_exception_handler)

# Override built-in default handler
app.add_exception_handler(RequestValidationError, validation_exception_handler)
app.add_exception_handler(HTTPStatusError, http_exception_handler)
app.add_exception_handler(RequestValidationError, validation_exception_handler) # type: ignore
app.add_exception_handler(HTTPStatusError, http_exception_handler) # type: ignore

# Fallback exception handler for all unexpected exceptions
app.add_exception_handler(Exception, fall_back_exception_handler)
Expand Down
6 changes: 0 additions & 6 deletions web/.eslintignore

This file was deleted.

39 changes: 0 additions & 39 deletions web/.eslintrc.json

This file was deleted.

6 changes: 0 additions & 6 deletions web/.prettierignore

This file was deleted.

7 changes: 0 additions & 7 deletions web/.prettierrc.js

This file was deleted.

541 changes: 0 additions & 541 deletions web/.yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs

This file was deleted.

9 changes: 0 additions & 9 deletions web/.yarn/plugins/@yarnpkg/plugin-typescript.cjs

This file was deleted.

873 changes: 0 additions & 873 deletions web/.yarn/releases/yarn-3.4.1.cjs

This file was deleted.

19 changes: 0 additions & 19 deletions web/.yarnrc.yml

This file was deleted.

3 changes: 1 addition & 2 deletions web/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ RUN touch /var/run/nginx.pid && \
# Run master process as non-root user
USER 1000

# Fails to build styled-common with node 18
FROM node:16 as base
FROM node:22 as base
ARG AUTH_ENABLED=0
ARG REDIRECT_URI=http://localhost/
# Azure AD requires a scope.
Expand Down
33 changes: 33 additions & 0 deletions web/biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"$schema": "https://biomejs.dev/schemas/1.8.0/schema.json",
"files": {
"ignore": ["documentation/*", "api/*", "web/src/api/generated"]
},
"javascript": {
"formatter": {
"indentStyle": "space",
"indentWidth": 2,
"quoteStyle": "single",
"trailingCommas": "es5",
"lineWidth": 119,
"semicolons": "asNeeded"
}
},
"json": {
"formatter": {
"indentStyle": "space",
"indentWidth": 2
}
},
"linter": {
"rules": {
"a11y": {
"useButtonType": "off"
},
"correctness": {
"useExhaustiveDependencies": "off",
"noVoidTypeReturn": "off"
}
}
}
}
7 changes: 1 addition & 6 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,13 @@
"lint": "yarn eslint --fix --ext .ts,.tsx ."
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"production": [">0.2%", "not dead", "not op_mini all"],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"packageManager": "[email protected]",
"dependencies": {
"@equinor/eds-core-react": "^0.29.1",
"@equinor/eds-icons": "^0.18.0",
Expand Down
10 changes: 5 additions & 5 deletions web/src/App.tsx
Original file line number Diff line number Diff line change
@@ -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'

Expand Down
7 changes: 2 additions & 5 deletions web/src/auth.ts
Original file line number Diff line number Diff line change
@@ -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 || '',
Expand All @@ -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 || '')),
}
14 changes: 2 additions & 12 deletions web/src/common/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,10 @@ const Header = () => {
<TopBar.Actions style={{ gap: 8 }}>
<Typography>{`Logged in as ${username}`}</Typography>
<IconButton title={'Log out'} icon={log_out} onClick={logOut} />
<IconButton
title={'Application info'}
icon={info_circle}
onClick={togglePopover}
ref={aboutRef}
/>
<IconButton title={'Application info'} icon={info_circle} onClick={togglePopover} ref={aboutRef} />
</TopBar.Actions>
</TopBar>
<Popover
title={'About'}
isOpen={isPopoverOpen}
toggle={togglePopover}
anchor={aboutRef.current}
>
<Popover title={'About'} isOpen={isPopoverOpen} toggle={togglePopover} anchor={aboutRef.current}>
<VersionText />
<p>Person of contact: Eirik Ola Aksnes ([email protected])</p>
</Popover>
Expand Down
30 changes: 14 additions & 16 deletions web/src/common/components/IconButton.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
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
icon: IconData
onClick: () => Promise<void> | void
}

const IconButton = forwardRef<HTMLButtonElement, IconButtonProps>(
function IconButton(
{ title, icon, onClick }: IconButtonProps,
ref: Ref<HTMLButtonElement>
) {
return (
<Tooltip title={title}>
<Button variant="ghost_icon" onClick={onClick} ref={ref}>
<Icon data={icon} size={24} title={title} />
</Button>
</Tooltip>
)
}
)
const IconButton = forwardRef<HTMLButtonElement, IconButtonProps>(function IconButton(
{ title, icon, onClick }: IconButtonProps,
ref: Ref<HTMLButtonElement>
) {
return (
<Tooltip title={title}>
<Button variant="ghost_icon" onClick={onClick} ref={ref}>
<Icon data={icon} size={24} title={title} />
</Button>
</Tooltip>
)
})

export default IconButton
Loading
Loading