Skip to content

Commit

Permalink
ci: add CI to lint the codebase. (#78)
Browse files Browse the repository at this point in the history
I've found some inconsistencies in the code. So, perhaps this PR will
solve the issue.

This PR adds:
- [typos by crate-ci](https://github.com/crate-ci/typos), to fix and
check for typos.
- [dprint by dprint](https://github.com/dprint/dprint), to properly
format markdown, YAML, and Dockerfile files.

The mentioned tools are also included inside the `justfile`. So, one is
able to check locally just using `just fmt` or `just fmt-check`.
  • Loading branch information
azzamsa committed Jul 3, 2024
1 parent 3524c3f commit 5c68e96
Show file tree
Hide file tree
Showing 27 changed files with 374 additions and 237 deletions.
11 changes: 11 additions & 0 deletions .dprint.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"markdown": {},
"toml": {},
"dockerfile": {},
"excludes": [],
"plugins": [
"https://plugins.dprint.dev/markdown-0.17.1.wasm",
"https://plugins.dprint.dev/toml-0.6.2.wasm",
"https://plugins.dprint.dev/dockerfile-0.3.2.wasm"
]
}
2 changes: 1 addition & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ module.exports = {
}
],
rules: {
"@typescript-eslint/no-floating-promises": "error",
'@typescript-eslint/no-floating-promises': 'error'
}
};
40 changes: 40 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Lint

on: [push, pull_request]

jobs:
code_quality:
name: Code quality
runs-on: ubuntu-latest
steps:
- name: Checkout source code
uses: actions/checkout@v4

- uses: taiki-e/install-action@just
- uses: taiki-e/install-action@dprint
- uses: taiki-e/install-action@v2
with:
tool: typos-cli

- uses: pnpm/action-setup@v4
with:
version: 9

- name: Install dependencies
run: |
pnpm install
- name: Show version information
shell: bash
run: |
just --version
dprint --version
typos --version
pnpm --version
- name: Lint codebase
shell: bash
run: |
just lint
just fmt-check
7 changes: 7 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,10 @@
pnpm-lock.yaml
package-lock.json
yarn.lock

# Managed by dprint
*.yml
*.yaml
*.md

static/
2 changes: 2 additions & 0 deletions .typos.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[default.extend-words]
ratatui = "ratatui"
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:20 as build
FROM node:20 AS build
RUN npm i -g pnpm
COPY . /project
WORKDIR /project
Expand All @@ -8,6 +8,6 @@ FROM node:20
COPY --from=build /project/build /project
RUN useradd weird
RUN echo '{"type": "module"}' > /project/package.json
RUN chown -R weird:weird /project
RUN chown -R weird:weird /project
USER weird
CMD ["node", "/project"]
4 changes: 2 additions & 2 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Weird source code is Copyright (c) 2024 Weird team ([Erlend Sogge Heggen](https://github.com/erlend-sh/), [Kapono Haws](https://github.com/zicklag/) & [Joe](https://github.com/hnb-ku)) \
Weird source code is Copyright (c) 2024 Weird team ([Erlend Sogge Heggen](https://github.com/erlend-sh/), [Kapono Haws](https://github.com/zicklag/) & [Joe](https://github.com/hnb-ku))\
and licensed as [PolyForm NonCommercial v1.0](https://polyformproject.org/licenses/noncommercial/1.0.0/).

..except for the general utilities of `/example`, `/example2` and `/example3`, which are licensed under [Blue Oak Model License v1.0](https://blueoakcouncil.org/license/1.0.0).
..except for the general utilities of `/example`, `/example2` and `/example3`, which are licensed under [Blue Oak Model License v1.0](https://blueoakcouncil.org/license/1.0.0).
12 changes: 6 additions & 6 deletions backend/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
[package]
name = "backend"
version = "0.1.0"
edition = "2021"
default-run = "backend"
edition = "2021"

[dependencies]
weird = { path = "./weird" }
anyhow = "1.0.86"
async-graphql = "7.0.5"
async-graphql-axum = "7.0.5"
async-trait = "0.1.80"
axum = { version = "0.7.5", features = ["multipart"] }
axum-extra = { version = "0.9.3", features = ["cookie"] }
bytes = "1.6.0"
clap = { version = "4.5.4", features = ["derive", "env"] }
futures = { version = "0.3", default-features = false }
headers = "0.4.0"
Expand All @@ -20,12 +22,10 @@ rand = "0.8.5"
reqwest = { version = "0.12.4", features = ["json"], default-features = false }
serde = { version = "1.0.202", features = ["derive"] }
serde_json = "1.0.117"
serde_yaml = "0.9.34"
tokio = { version = "1.37.0", default-features = false, features = ["macros"] }
tower = { version = "0.4.13", features = ["filter"] }
tower-http = { version = "0.5.2", features = ["trace"] }
tracing = "0.1.40"
tracing-subscriber = { version = "0.3.18", features = ["fmt", "env-filter"] }
async-graphql = "7.0.5"
async-graphql-axum = "7.0.5"
serde_yaml = "0.9.34"
bytes = "1.6.0"
weird = { path = "./weird" }
2 changes: 1 addition & 1 deletion backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM messense/rust-musl-cross:x86_64-musl as build
FROM messense/rust-musl-cross:x86_64-musl AS build
COPY . /home/rust/src
RUN --mount=type=cache,target=/home/rust/src/target \
--mount=type=cache,target=/root/.cargo/registry \
Expand Down
2 changes: 1 addition & 1 deletion backend/gdata/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ futures = { version = "0.3.30", default-features = false }
iroh = { version = "0.18.0", default-features = false }
quic-rpc = "0.10.1"
quick_cache = "0.5.1"
serde = { version = "1.0", features = ["derive"], optional = true }
smallstr = "0.3.0"
smallvec = "1.13.2"
ulid = "1.1.2"
serde = { version = "1.0", features = ["derive"], optional = true }

[dev-dependencies]
tokio = "1.38.0"
14 changes: 7 additions & 7 deletions backend/gdata/gdata_explorer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ version = "0.1.0"
edition = "2021"

[dependencies]
anyhow = "1.0.86"
base64 = "0.22.1"
bytes = "1.6.0"
clap = { version = "4.5.6", features = ["derive", "env"] }
crossterm = { version = "0.27.0", features = ["event-stream"] }
ratatui = "0.26.3"
futures = "0.3.30"
futures-timer = "3.0.3"
gdata = { path = "../" }
clap = { version = "4.5.6", features = ["derive", "env"] }
iroh = { version = "0.18.0", default-features = false, features = ["fs-store"] }
anyhow = "1.0.86"
once_cell = "1.19.0"
ratatui = "0.26.3"
tokio = { version = "1.38.0" }
futures-timer = "3.0.3"
futures = "0.3.30"
bytes = "1.6.0"
base64 = "0.22.1"
2 changes: 1 addition & 1 deletion backend/weird/src/profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ impl<S> Weird<S> {
// TODO: Wait Until Remote Instance Has Been Synced
//
// Currently there will be an error looking up a user the first time we connect to a
// remote instance beause we haven't waited until the instance is synced before trying
// remote instance because we haven't waited until the instance is synced before trying
// to access the profile data.
self.node.docs().import(ticket).await?;
Ok(ns)
Expand Down
1 change: 0 additions & 1 deletion deploy/rauthy/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ FROM scratch
COPY --from=rauthy /app/rauthy /
COPY --from=rauthy /app/rauthy.cfg /
CMD "/idontexist"

43 changes: 43 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env -S just --justfile

set dotenv-load := true

alias d := dev
alias f := fmt
alias l := lint
alias c := comply
alias k := check

# List available commands.
_default:
just --list --unsorted

# Setup the repository.
setup:
docker compose up -d
pnpm i

# Tasks to make the code-base comply with the rules. Mostly used in git hooks.
comply: fmt lint

# Check if the repository comply with the rules and ready to be pushed.
check: fmt-check lint

# Develop the app.
dev:
pnpm run dev

# Format the codebase.
fmt:
pnpm run format
dprint fmt

# Check is the codebase properly formatted.
fmt-check:
dprint check

# Lint the codebase.
lint:
pnpm run lint
# Run `typos --write-changes` to fix the mistakes
typos
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"preview": "vite preview",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
"lint": "prettier --check . && eslint .",
"format": "prettier --write ."
"lint": "prettier --check . --log-level warn",
"format": "prettier --write . --log-level warn"
},
"devDependencies": {
"@skeletonlabs/skeleton": "^2.10.0",
Expand Down
1 change: 0 additions & 1 deletion src/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@
@tailwind components;
@tailwind utilities;
@tailwind variants;

8 changes: 4 additions & 4 deletions src/lib/spow/spow-wasm.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* tslint:disable */
/* eslint-disable */
/**
* Calculates the Proof of Work for the given challenge
* @param {string} challenge
* @returns {Promise<string | undefined>}
*/
* Calculates the Proof of Work for the given challenge
* @param {string} challenge
* @returns {Promise<string | undefined>}
*/
export function pow_work_wasm(challenge: string): Promise<string | undefined>;
6 changes: 3 additions & 3 deletions src/lib/spow/spow-wasm.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as wasm from "./spow-wasm_bg.wasm";
import { __wbg_set_wasm } from "./spow-wasm_bg.js";
import * as wasm from './spow-wasm_bg.wasm';
import { __wbg_set_wasm } from './spow-wasm_bg.js';
__wbg_set_wasm(wasm);
export * from "./spow-wasm_bg.js";
export * from './spow-wasm_bg.js';
Loading

0 comments on commit 5c68e96

Please sign in to comment.