Skip to content

Commit

Permalink
Upgrade to biome
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiask committed Apr 3, 2024
1 parent bf9a285 commit c3317ea
Show file tree
Hide file tree
Showing 28 changed files with 105 additions and 160 deletions.
12 changes: 0 additions & 12 deletions .eslintrc.js

This file was deleted.

36 changes: 9 additions & 27 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
exclude: ".yarn/|yarn.lock"
exclude: ".yarn/|yarn.lock|workbench/static/workbench/lib"
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
Expand Down Expand Up @@ -28,41 +28,18 @@ repos:
rev: 1.16.0
hooks:
- id: django-upgrade
args: [--target-version, "4.2"]
args: [--target-version, "5.0"]
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.3.0"
rev: "v0.3.5"
hooks:
- id: ruff
- id: ruff-format
- repo: https://github.com/pre-commit/mirrors-eslint
rev: v8.56.0
hooks:
- id: eslint
args: [--fix]
types_or: [css, scss, javascript]
verbose: true
additional_dependencies:
- eslint
- eslint-config-prettier
- eslint-config-preact
- eslint-plugin-compat
- eslint-plugin-jest
- eslint-plugin-react
- eslint-plugin-react-hooks
- "@babel/core"
- "@babel/eslint-parser"
- "@babel/preset-env"
- "@babel/preset-react"
- "@babel/plugin-syntax-class-properties"
- "@babel/plugin-syntax-decorators"
- "@babel/plugin-syntax-jsx"
- jest
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.1.0
hooks:
- id: prettier
args: [--list-different, --no-semi]
types_or: [css, scss, javascript]
types_or: [scss]
exclude: "^conf/|.*\\.html$|.*\\.json$"
- repo: https://github.com/tox-dev/pyproject-fmt
rev: 1.7.0
Expand All @@ -72,3 +49,8 @@ repos:
rev: v0.16
hooks:
- id: validate-pyproject
- repo: https://github.com/biomejs/pre-commit
rev: "v0.1.0"
hooks:
- id: biome-check
additional_dependencies: ["@biomejs/[email protected]"]
16 changes: 13 additions & 3 deletions absences/absences.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,19 @@ const getRowName = (id) => `person-${id}`

// prettier-ignore
const MONTHS = [
"January", "February", "March", "April", "May", "June", "July", "August",
"September", "October", "November", "December"
].map(m => gettext(m))
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December",
].map((m) => gettext(m))

export const Absences = ({ absencesByPerson, dateList, reasonList }) => {
const scaleValues = useMemo(
Expand Down
4 changes: 2 additions & 2 deletions absences/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import React from "react"
import { Absences } from "./absences"

function getDateList(start, end) {
let list = []
const list = []
let currentDate = start

while (currentDate <= end) {
Expand All @@ -22,7 +22,7 @@ function getDateList(start, end) {
}

document.addEventListener("DOMContentLoaded", () => {
let { absencesByPerson, reasonList, timeBoundaries } = JSON.parse(
const { absencesByPerson, reasonList, timeBoundaries } = JSON.parse(
document.getElementById("absences-data").textContent,
)

Expand Down
4 changes: 2 additions & 2 deletions absences/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ export function getWeekNumber(d) {
// Make Sunday's day number 7
d.setUTCDate(d.getUTCDate() + 4 - (d.getUTCDay() || 7))
// Get first day of year
let yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1))
const yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1))
// Calculate full weeks to nearest Thursday
let weekNo = Math.ceil(((d - yearStart) / 86400000 + 1) / 7)
const weekNo = Math.ceil(((d - yearStart) / 86400000 + 1) / 7)
// Return array of year and week number
return [d.getUTCFullYear(), weekNo]
}
23 changes: 23 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"$schema": "https://biomejs.dev/schemas/1.6.3/schema.json",
"organizeImports": {
"enabled": false
},
"formatter": {
"enabled": true,
"indentStyle": "space",
"indentWidth": 2,
"ignore": ["*/map/styles_*.json"]
},
"javascript": {
"formatter": {
"semicolons": "asNeeded"
}
},
"linter": {
"enabled": true,
"rules": {
"recommended": true
}
}
}
4 changes: 1 addition & 3 deletions fabfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ def _do_deploy(conn, folder, rsync):
with conn.cd(folder):
fl.run(
conn,
"DOTENV=.env/{} venv/bin/python manage.py collectstatic --noinput".format(
fl.config.installations[0]
),
f"DOTENV=.env/{fl.config.installations[0]} venv/bin/python manage.py collectstatic --noinput",
)


Expand Down
3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
"scripts": {
"build-bootstrap": "webpack -p --config webpack.config.bootstrap.js"
},
"eslintIgnore": [
"workbench/static/workbench/lib"
],
"dependencies": {
"bootstrap": "^4.6.0",
"fh-webpack-config": "^2.0.1",
Expand Down
22 changes: 11 additions & 11 deletions planning/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const clamp = (min, value, max) => Math.max(Math.min(value, max), min)
const opacityClamp = (value) => clamp(0.3, value, 1)
const gettext = window.gettext || ((t) => t)
const pgettext = window.pgettext || ((ctx, t) => t)
const fixed = (s, decimalPlaces) => parseFloat(s).toFixed(decimalPlaces)
const fixed = (s, decimalPlaces) => Number.parseFloat(s).toFixed(decimalPlaces)

document.addEventListener("DOMContentLoaded", () => {
const data = JSON.parse(document.querySelector("#planning-data").textContent)
Expand All @@ -41,7 +41,7 @@ function months(weeks) {
const months = []
let month = null
for (let index = 0; index < weeks.length; ++index) {
let week = weeks[index]
const week = weeks[index]
if (week.month !== month) {
month = week.month
months.push({ index, month })
Expand Down Expand Up @@ -69,8 +69,8 @@ function Planning({ data }) {
const [collapse, setCollapse] = useState(getCollapse())
const toggleCollapse = (id) => {
const storage = window.localStorage.getItem("planningCollapse")
let storageData = storage ? JSON.parse(storage) : []
let index = storageData.indexOf(id)
const storageData = storage ? JSON.parse(storage) : []
const index = storageData.indexOf(id)
if (index >= 0) storageData.splice(index, 1)
else storageData.push(id)
window.localStorage.setItem("planningCollapse", JSON.stringify(storageData))
Expand Down Expand Up @@ -201,7 +201,7 @@ function TotalByWeek({ by_week, title }) {
column={FIRST_DATA_COLUMN + idx}
className="planning--range planning--small is-total"
style={{
opacity: opacityClamp(0.3 + parseFloat(hours) / 20),
opacity: opacityClamp(0.3 + Number.parseFloat(hours) / 20),
}}
>
{fixed(hours, 0)}
Expand Down Expand Up @@ -374,7 +374,7 @@ function Project({
)}
{external_view ||
by_week.map((hours, idx) => {
hours = parseFloat(hours)
hours = Number.parseFloat(hours)
if (!hours) return null

return (
Expand Down Expand Up @@ -410,7 +410,7 @@ function Project({
function WorkedHours({ project }) {
const ctx = useContext(RowContext)
const row = ctx.next()
const sum = project.worked_hours.reduce((a, b) => a + parseFloat(b), 0)
const sum = project.worked_hours.reduce((a, b) => a + Number.parseFloat(b), 0)

return (
<>
Expand All @@ -422,7 +422,7 @@ function WorkedHours({ project }) {
</Cell>

{project.worked_hours.map((hours, idx) => {
hours = parseFloat(hours)
hours = Number.parseFloat(hours)
if (!hours) return null

return (
Expand Down Expand Up @@ -906,7 +906,7 @@ function UserAbsences({ user }) {
{user[1].map((absences, idx) => {
if (!absences.length) return null

const hours = absences.reduce((a, b) => a + parseFloat(b[0]), 0)
const hours = absences.reduce((a, b) => a + Number.parseFloat(b[0]), 0)

return (
<Cell
Expand All @@ -925,13 +925,13 @@ function UserAbsences({ user }) {
}

function findContiguousWeekRanges(hours_per_week) {
hours_per_week = hours_per_week.map((hours) => parseFloat(hours))
hours_per_week = hours_per_week.map((hours) => Number.parseFloat(hours))

let rangeStart = -1
// const ranges = [{start: 0, length: hours_per_week.length - 1}]
// return ranges

let ranges = []
const ranges = []

for (let i = 0; i < hours_per_week.length; ++i) {
if (hours_per_week[i]) {
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ extend-select = [
# flake8-logging
"LOG",
# ruff
"RUF005", "RUF006", "RUF007", "RUF008", "RUF009", "RUF010", "RUF011",
"RUF005", "RUF006", "RUF007", "RUF008", "RUF009", "RUF010",
"RUF015", "RUF016", "RUF017", "RUF100", "RUF200",
]
extend-ignore = [
Expand Down
2 changes: 1 addition & 1 deletion timer/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export async function sendLogbook(dispatch, { activity, current }) {
}

export function overwriteSeconds(dispatch, { activity, current }) {
const seconds = parseInt(
const seconds = Number.parseInt(
prompt(gettext("Overwrite seconds"), Math.ceil(activity.seconds)),
10,
)
Expand Down
6 changes: 3 additions & 3 deletions timer/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const serialize = (data) => {

const deserialize = (blob) => {
const deserializeRaw = () => {
let parsed = JSON.parse(blob)
const parsed = JSON.parse(blob)
if (!parsed || !parsed._v) return {}
const { _v, ...data } = parsed
if (_v == VERSION) {
Expand Down Expand Up @@ -60,7 +60,7 @@ export function configureStore() {
} catch (e) {
/* intentionally empty */
}
let store = createStore(
const store = createStore(
reducer,
initialState,
compose(
Expand All @@ -79,7 +79,7 @@ export function configureStore() {

if (module.hot) {
module.hot.accept(() => {
let reducer = require("./reducers").default
const reducer = require("./reducers").default
store.replaceReducer(reducer)
})
}
Expand Down
7 changes: 1 addition & 6 deletions workbench/audit/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,7 @@ class Meta:
verbose_name_plural = _("logged actions")

def __str__(self):
return "{} {} by {} at {}".format(
self.get_action_display(),
self.table_name,
self.user_name,
self.created_at,
)
return f"{self.get_action_display()} {self.table_name} by {self.user_name} at {self.created_at}"

@cached_property
def user_id(self):
Expand Down
10 changes: 2 additions & 8 deletions workbench/awt/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,7 @@ class Meta:
def __str__(self):
if self.date_until.year > 3000:
return _("since %s") % local_date_format(self.date_from)
return "{} - {}".format(
local_date_format(self.date_from),
local_date_format(self.date_until),
)
return f"{local_date_format(self.date_from)} - {local_date_format(self.date_until)}"

def save(self, *args, **kwargs):
super().save(*args, **kwargs)
Expand Down Expand Up @@ -234,10 +231,7 @@ def pretty_status(self):

@property
def pretty_period(self):
return "{} - {}".format(
local_date_format(self.starts_on),
local_date_format(self.ends_on or self.starts_on),
)
return f"{local_date_format(self.starts_on)} - {local_date_format(self.ends_on or self.starts_on)}"


class VacationDaysOverride(models.Model):
Expand Down
4 changes: 1 addition & 3 deletions workbench/deals/test_deals.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,7 @@ def test_values_and_attributes(self):
response = self.client.get(deal.urls["update"])
self.assertContains(
response,
'<input class="form-check-input" type="radio" name="attribute_{g}" value="{a}" class="my-2" required id="id_attribute_{g}_0" checked>'.format(
g=attribute1_1.group_id, a=attribute1_1.id
),
f'<input class="form-check-input" type="radio" name="attribute_{attribute1_1.group_id}" value="{attribute1_1.id}" class="my-2" required id="id_attribute_{attribute1_1.group_id}_0" checked>',
html=True,
)

Expand Down
6 changes: 1 addition & 5 deletions workbench/expenses/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,7 @@ class Meta:
verbose_name_plural = _("expense reports")

def __str__(self):
return "{}, {}, {}".format(
self.owned_by.get_full_name(),
local_date_format(self.created_at.date()),
currency(self.total),
)
return f"{self.owned_by.get_full_name()}, {local_date_format(self.created_at.date())}, {currency(self.total)}"

def save(self, *args, **kwargs):
if self.pk:
Expand Down
7 changes: 1 addition & 6 deletions workbench/expenses/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,7 @@ def get(self, request, *args, **kwargs):
(
"%d." % (next(counter),),
MarkupParagraph(
"{}<br />{}: {}<br />{}<br />&nbsp;".format(
local_date_format(cost.rendered_on),
cost.service.project,
cost.service,
cost.description,
),
f"{local_date_format(cost.rendered_on)}<br />{cost.service.project}: {cost.service}<br />{cost.description}<br />&nbsp;",
pdf.style.normal,
),
currency(cost.third_party_costs)
Expand Down
6 changes: 1 addition & 5 deletions workbench/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,7 @@ def get_template_names(self):
if self.template_name is not None:
return [self.template_name]
return [
"{}/{}{}.html".format(
self.model._meta.app_label,
self.model._meta.object_name.lower(),
self.template_name_suffix,
),
f"{self.model._meta.app_label}/{self.model._meta.object_name.lower()}{self.template_name_suffix}.html",
"generic/object%s.html" % self.template_name_suffix,
]

Expand Down
Loading

0 comments on commit c3317ea

Please sign in to comment.