From b1322e092afb4f145667fb5820eff9e72355f020 Mon Sep 17 00:00:00 2001 From: jiacai2050 Date: Fri, 24 Nov 2023 20:20:38 +0800 Subject: [PATCH] add lint --- .github/workflows/lint.yml | 30 ++++++++++++++++++++++++++++++ 01-zig-files-are-struct/build.zig | 15 +++------------ Makefile | 3 +++ README.md | 5 +++++ 4 files changed, 41 insertions(+), 12 deletions(-) create mode 100644 .github/workflows/lint.yml create mode 100644 Makefile diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..5fd4243 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,30 @@ +name: Lint + +on: + workflow_dispatch: + pull_request: + paths: + - "**.md" + - ".github/workflows/**" + push: + branches: + - main + paths: + - "**.md" + - ".github/workflows/**" + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - uses: actions/setup-node@v3 + with: + node-version: "14" + - name: Prettier check + run: | + # if you encounter error, rerun the command below and commit the changes + make lint + git diff --exit-code diff --git a/01-zig-files-are-struct/build.zig b/01-zig-files-are-struct/build.zig index 93fc513..703cb13 100644 --- a/01-zig-files-are-struct/build.zig +++ b/01-zig-files-are-struct/build.zig @@ -1,22 +1,13 @@ const std = @import("std"); pub fn build(b: *std.Build) void { - const target = b.standardTargetOptions(.{}); - const optimize = b.standardOptimizeOption(.{}); - const exe = b.addExecutable(.{ .name = "01-zig-files-are-struct", .root_source_file = .{ .path = "src/main.zig" }, - .target = target, - .optimize = optimize, + .target = .{}, + .optimize = .Debug, }); b.installArtifact(exe); - const run_cmd = b.addRunArtifact(exe); - run_cmd.step.dependOn(b.getInstallStep()); - if (b.args) |args| { - run_cmd.addArgs(args); - } - const run_step = b.step("run", "Run"); - run_step.dependOn(&run_cmd.step); + b.step("run", "Run").dependOn(&b.addRunArtifact(exe).step); } diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..38897e0 --- /dev/null +++ b/Makefile @@ -0,0 +1,3 @@ + +lint: + npx prettier@2.7.1 --write *md diff --git a/README.md b/README.md index 157cdae..1e49e59 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ This repository collects tips for writing clean, idiomatic Zig code. +Each tips is given an example named after it, which could be run with `zig build run`. + > This could be used as guide for developer with other programming languages background. ## 01. Zig files are structs @@ -9,6 +11,7 @@ This repository collects tips for writing clean, idiomatic Zig code. > Source: https://ziglang.org/documentation/master/#import Zig source files are implicitly structs, with a name equal to the file's basename with the extension truncated. `@import` returns the struct type corresponding to the file. + ```zig // foo.zig pub var a: usize = 1; @@ -26,7 +29,9 @@ pub fn main() !void { }); } ``` + This will output + ``` Type of Foo is type, foo is foo ```