Skip to content

Commit

Permalink
add lint
Browse files Browse the repository at this point in the history
  • Loading branch information
jiacai2050 committed Nov 24, 2023
1 parent 3d120cf commit b1322e0
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 12 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -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
15 changes: 3 additions & 12 deletions 01-zig-files-are-struct/build.zig
Original file line number Diff line number Diff line change
@@ -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);
}
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

lint:
npx [email protected] --write *md
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

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

> 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;
Expand All @@ -26,7 +29,9 @@ pub fn main() !void {
});
}
```

This will output

```
Type of Foo is type, foo is foo
```

0 comments on commit b1322e0

Please sign in to comment.