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

Replace eslint/prettier with biome #10

Merged
merged 36 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
07f890e
Remove eslint and prettier
sverhoeven Aug 1, 2024
b203b86
Move biome to now
sverhoeven Aug 1, 2024
17615d9
pnpm add --save-dev --save-exact --workspace-root @biomejs/biome
sverhoeven Aug 1, 2024
9f976b9
pnpm biome init
sverhoeven Aug 1, 2024
b49140e
Suggest biome vs code extension
sverhoeven Aug 1, 2024
9d035c8
Add format-and-lint script
sverhoeven Aug 1, 2024
a748097
Enable formatter
sverhoeven Aug 1, 2024
797932e
Add biome to CI
sverhoeven Aug 1, 2024
db93a82
Ignore solidstart build files
sverhoeven Aug 1, 2024
aa780d2
Enable vcs
sverhoeven Aug 1, 2024
76db05d
Move biome commands to own chapter
sverhoeven Aug 1, 2024
642f055
Format
sverhoeven Aug 1, 2024
cd523c1
Fix lint errors
sverhoeven Aug 1, 2024
27f024f
Sort imports
sverhoeven Aug 1, 2024
3c536f9
Fix lint errors with unsafe fixes
sverhoeven Aug 1, 2024
59425b1
Dont run workflow twice
sverhoeven Aug 1, 2024
1b52800
Use github reporter + only one running workflow
sverhoeven Aug 1, 2024
66b222b
Use space for indent
sverhoeven Aug 2, 2024
28a7d91
npx needs node
sverhoeven Aug 2, 2024
0c8f3a7
Added typecheck
sverhoeven Aug 2, 2024
38efb9a
Ignore most remaining biome errors
sverhoeven Aug 2, 2024
e63a720
Badges for github and quality ci workflow
sverhoeven Aug 2, 2024
05db998
Sort tailwind classes
sverhoeven Aug 2, 2024
df85da6
Merge remote-tracking branch 'origin/main' into biome
sverhoeven Aug 2, 2024
01171c0
Move typecheck to linter chapter
sverhoeven Aug 2, 2024
639e349
Auto-sort imports on save in vscode
Peter9192 Aug 2, 2024
d328c3b
Format settings
Peter9192 Aug 2, 2024
f870961
Merge remote-tracking branch 'origin/main' into biome
sverhoeven Aug 2, 2024
cafdd7f
Merge remote-tracking branch 'origin/main' into biome
sverhoeven Aug 2, 2024
a03154b
format-and-lint:fix
sverhoeven Aug 2, 2024
7d1a14e
fix typecheck
sverhoeven Aug 2, 2024
a61b3c2
Use biome from package.json
sverhoeven Aug 2, 2024
640dcde
Add lint errors to test ci reporting
sverhoeven Aug 2, 2024
98a8576
Enable github reporter again
sverhoeven Aug 2, 2024
3ea691e
Revert "Add lint errors to test ci reporting"
sverhoeven Aug 2, 2024
f69234d
Remove root tasks for biome
sverhoeven Aug 2, 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
5 changes: 0 additions & 5 deletions .eslintrc.js

This file was deleted.

20 changes: 20 additions & 0 deletions .github/workflows/publish-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Publish class package

on:
release:
types: [published]

jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write # The OIDC ID token is used for authentication with JSR.
steps:
- uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: "20"
- run: npx jsr publish --allow-slow-types
working-directory: packages/class
40 changes: 40 additions & 0 deletions .github/workflows/quality.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Code quality

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
quality:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Biome
uses: biomejs/setup-biome@v2
with:
version: latest
- name: Run Biome
run: biome ci --reporter github .
typecheck:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: "20"
cache: "pnpm"
cache-dependency-path: ./pnpm-lock.yaml
- name: Install dependencies
run: pnpm install
- name: Typecheck
run: pnpm typecheck
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ dist-ssr
.cache
server/dist
public/dist
apps/class-solid/.vinxi
apps/class-solid/.output
3 changes: 3 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"recommendations": ["biomejs.biome"]
}
6 changes: 2 additions & 4 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{
"eslint.workingDirectories": [
{
"mode": "auto"
"editor.codeActionsOnSave":{
"source.organizeImports.biome": "explicit"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took the liberty of adding an auto-sort imports on save. I think this is handy, but feel free to disagree :-)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW I noticed that biome respects grouped imports, i.e. there is no sorting off import statements separated by empty lines

Copy link
Member

@Peter9192 Peter9192 Aug 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also imports from the same module that are on different lines are not sorted or combined. But once you combine them on one line, they will be sorted alphabetically 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool thanks, the organize sort is not part of lint or format commands so its nice the editor can do it.

}
]
}
674 changes: 674 additions & 0 deletions COPYING

Large diffs are not rendered by default.

24 changes: 21 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# CLASS-web

[![github repo badge](https://img.shields.io/badge/github-repo-000.svg?logo=github&labelColor=gray&color=blue)]([https://github.com//classmodel/class-web](https://github.com//classmodel/class-web))
[![Code quality](https://github.com/classmodel/class-web/actions/workflows/quality.yml/badge.svg)](https://github.com/classmodel/class-web/actions/workflows/quality.yml)

This is an implementation of the **C**hemistry **L**and-surface **A**tmosphere **S**oil **S**lab (CLASS) model that runs entirely in the browser.

The CLASS web application is available at https://classmodel.github.io/class-web.
Expand All @@ -22,8 +25,6 @@ Currently the repo is home to the following:

- packages/
- class: reimplementation of CLASS in typescript
- config-eslint: shared configuration for eslint
- config-typescript: shared configuration for typescript
- apps/
- class-solid: web application with a graphical user interface for CLASS

Expand All @@ -38,6 +39,22 @@ pnpm install
pnpm dev
```

## Linter & formatter

We use [biome](https://biomejs.dev/) to lint and format the code.
The following commands are available

```shell
# To run linter and formatter use
pnpm format-and-lint
# To fix formatting and some lint errors run
pnpm format-and-lint:fix
# To run other biome comands use
pnpm exec biome --help
```

To check types, you can run the `pnpm typecheck` command as other commands ignore types.

## Tech stack

The CLASS package is written in typescript. It uses [zod](https://zod.dev/) for
Expand All @@ -59,9 +76,10 @@ by [Kobalte](https://kobalte.dev/docs/core/overview/introduction) and
application and tweaked further as seen fit. It can also do charts, using
[chart.js](https://www.chartjs.org/), though we might deviate from that later.

To format and lint the code, we use [biome](https://biomejs.dev/) as it combines eslint, prettier in one package.

**Further plans/ideas**

- Use [biome](https://biomejs.dev/) for linting/formatting
- Use [modular forms](https://modularforms.dev/) for form state management/validation
- Use [auto](https://intuit.github.io/auto/index) for managing versions/releases
- Use [d3.js](https://d3js.org/) for more low-level charting
Expand Down
8 changes: 6 additions & 2 deletions apps/class-solid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
"scripts": {
"dev": "vinxi dev",
"build": "vinxi build",
"start": "vinxi start"
"start": "vinxi start",
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@classmodel/class": "workspace:*",
"@kobalte/core": "^0.13.3",
"@repo/class": "workspace:*",
"@solid-primitives/refs": "^1.0.8",
"@solidjs/router": "^0.14.1",
"@solidjs/start": "^1.0.4",
Expand All @@ -27,5 +28,8 @@
},
"engines": {
"node": ">=18"
},
"devDependencies": {
"typescript": "^5.3.3"
}
}
2 changes: 1 addition & 1 deletion apps/class-solid/postcss.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ module.exports = {
tailwindcss: {},
autoprefixer: {},
},
}
};
24 changes: 11 additions & 13 deletions apps/class-solid/src/components/Analysis.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { createUniqueId, For, Match, Switch } from "solid-js";
import { setAnalyses, analyses, experiments } from "~/lib/store";
import { MdiDownload, MdiCog, MdiContentCopy, MdiDelete } from "./icons";
import { For, Match, Switch, createUniqueId } from "solid-js";
import { analyses, experiments, setAnalyses } from "~/lib/store";
import type { Experiment } from "./Experiment";
import { MdiCog, MdiContentCopy, MdiDelete, MdiDownload } from "./icons";
import { Button } from "./ui/button";
import {
Card,
CardHeader,
CardTitle,
CardContent,
CardFooter,
CardHeader,
CardTitle,
} from "./ui/card";
import { Button } from "./ui/button";
import { Experiment } from "./Experiment";
import { LineChart } from "./ui/charts";

export interface Analysis {
Expand Down Expand Up @@ -44,13 +44,14 @@ function deleteAnalysis(analysis: Analysis) {
*/
export function TimeSeriesPlot() {
const chartData = {
labels: experiments[0].output?.t,
labels:
experiments[0].output === undefined ? undefined : experiments[0].output.t,
datasets: experiments
.filter((e) => e.output)
.map((e) => {
return {
label: e.id,
data: e.output!.h,
data: e.output === undefined ? [null] : e.output.h,
fill: false,
};
}),
Expand All @@ -64,10 +65,7 @@ function FinalHeights() {
return (
<For each={experiments}>
{(experiment, i) => {
const h =
(experiment.output &&
experiment.output.h[experiment.output.h.length - 1]) ||
0;
const h = experiment.output?.h[experiment.output.h.length - 1] || 0;
return (
<div class="mb-2">
<p>
Expand Down
24 changes: 12 additions & 12 deletions apps/class-solid/src/components/Experiment.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
import { type ClassConfig, classConfig } from "@classmodel/class/config";
import { type ClassOutput, runClass } from "@classmodel/class/runner";
import { createSignal, createUniqueId } from "solid-js";
import { Button } from "~/components/ui/button";
import { MdiDownload, MdiCog, MdiContentCopy, MdiDelete } from "./icons";
import { experiments, setExperiments } from "~/lib/store";
import { ExperimentConfigForm } from "./ExperimentConfigForm";
import { MdiCog, MdiContentCopy, MdiDelete, MdiDownload } from "./icons";
import {
Card,
CardHeader,
CardTitle,
CardDescription,
CardContent,
CardDescription,
CardFooter,
CardHeader,
CardTitle,
} from "./ui/card";
import { ClassConfig, classConfig } from "@repo/class/config";
import { ClassOutput, runClass } from "@repo/class/runner";
import { createUniqueId, createSignal } from "solid-js";
import { ExperimentConfigForm } from "./ExperimentConfigForm";
import {
Dialog,
DialogTrigger,
DialogContent,
DialogHeader,
DialogTitle,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
DialogTrigger,
} from "./ui/dialog";
import { experiments, setExperiments } from "~/lib/store";

export interface Experiment {
name: string;
Expand Down
20 changes: 13 additions & 7 deletions apps/class-solid/src/components/ExperimentConfigForm.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
import {
type ClassConfig,
classConfig,
classDefaultConfigSchema,
} from "@classmodel/class/config";
import { For, Match, Switch } from "solid-js";
import {
TextField,
TextFieldInput,
TextFieldLabel,
} from "~/components/ui/text-field";
import { For, Switch, Match } from "solid-js";
import {
classConfig,
ClassConfig,
classDefaultConfigSchema,
} from "@repo/class/config";

const ClassConfigJsonSchema = classDefaultConfigSchema.definitions!.classConfig;
const ClassConfigJsonSchema = classDefaultConfigSchema.definitions?.classConfig;

/**
* Nest form rawData to shape of classConfig
* "initialState.h_0" => { initialState: { h_0: ... } }
*/

// biome-ignore lint/suspicious/noExplicitAny: json schema types are too complex
function inflate(rawData: { [key: string]: any }) {
// biome-ignore lint/suspicious/noExplicitAny: json schema types are too complex
const config: { [key: string]: any } = {};

for (const key in rawData) {
Expand Down Expand Up @@ -67,6 +70,7 @@ export function ExperimentConfigForm({
);
}

// biome-ignore lint/suspicious/noExplicitAny: json schema types are too complex
function ObjectField({ schema, name = "" }: { schema: any; name?: string }) {
// name can be empty, but only for root, which should be treated differently
const isRoot = name === "";
Expand Down Expand Up @@ -100,6 +104,7 @@ function ObjectField({ schema, name = "" }: { schema: any; name?: string }) {
);
}

// biome-ignore lint/suspicious/noExplicitAny: json schema types are too complex
function PropField({ name, schema }: { name: string; schema: any }) {
return (
<Switch fallback={<p>Unknown type</p>}>
Expand All @@ -116,6 +121,7 @@ function PropField({ name, schema }: { name: string; schema: any }) {
);
}

// biome-ignore lint/suspicious/noExplicitAny: json schema types are too complex
function MyTextField({ name, schema }: { name: string; schema: any }) {
return (
<TextField class="grid w-full max-w-sm items-center gap-1.5">
Expand Down
4 changes: 3 additions & 1 deletion apps/class-solid/src/components/Nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import { useLocation } from "@solidjs/router";
export default function Nav() {
const location = useLocation();
const active = (path: string) =>
path == location.pathname ? "border-sky-600" : "border-transparent hover:border-sky-600";
path === location.pathname
? "border-sky-600"
: "border-transparent hover:border-sky-600";
return (
<nav class="bg-sky-800">
<ul class="container flex items-center p-3 text-gray-200">
Expand Down
6 changes: 5 additions & 1 deletion apps/class-solid/src/components/icons.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { JSX } from "solid-js";
import type { JSX } from "solid-js";

export function MdiDownload(props: JSX.IntrinsicElements["svg"]) {
return (
// biome-ignore lint/a11y/noSvgWithoutTitle: generated code
<svg
xmlns="http://www.w3.org/2000/svg"
width="1em"
Expand All @@ -16,6 +17,7 @@ export function MdiDownload(props: JSX.IntrinsicElements["svg"]) {

export function MdiCog(props: JSX.IntrinsicElements["svg"]) {
return (
// biome-ignore lint/a11y/noSvgWithoutTitle: generated code
<svg
xmlns="http://www.w3.org/2000/svg"
width="1em"
Expand All @@ -33,6 +35,7 @@ export function MdiCog(props: JSX.IntrinsicElements["svg"]) {

export function MdiContentCopy(props: JSX.IntrinsicElements["svg"]) {
return (
// biome-ignore lint/a11y/noSvgWithoutTitle: generated code
<svg
xmlns="http://www.w3.org/2000/svg"
width="1em"
Expand All @@ -50,6 +53,7 @@ export function MdiContentCopy(props: JSX.IntrinsicElements["svg"]) {

export function MdiDelete(props: JSX.IntrinsicElements["svg"]) {
return (
// biome-ignore lint/a11y/noSvgWithoutTitle: generated code
<svg
xmlns="http://www.w3.org/2000/svg"
width="1em"
Expand Down
Loading
Loading