~novakane/agertu

agertu/CONTRIBUTING.md -rw-r--r-- 4.1 KiB
9ea83d8fHugo Machet build: Bump to version 2.0.0-dev 2 months ago

#CONTRIBUTING

#Commit messages

Commit messages should start with a prefix indicating which part of the project is affected by your change, if this a general code patch you may not add it, followed by a one sentence summary, first word is capitalized. First line is 50 columns long max.

If this is a breaking change, start the commit message with !.

Example:

seat: Add pointer events

Update to zig 1.0.0

!commands: Rename whatever command

You can add everything you feel need to be mentioned in the body of the commit message, wrap lines at 72 columns.

A great guide to follow here.

#Patches

For patches send a [plain text] mail to my public inbox ~novakane/public-inbox@lists.sr.ht with project prefix set to agertu:

You can configure your Git repo like so:

git config sendemail.to "~novakane/public-inbox@lists.sr.ht"
git config format.subjectPrefix "PATCH agertu"

Questions or discussions works the same way, precise the project name in the subject, you just don't need to add PATCH before the project name.

Some useful resources if you're not used to send patches by email:

git.sr.ht also provides a web UI if you prefer.

#Coding style

Follow zig style guide no other option for zig which is kinda great.

Some things are not enforced by zig fmt, I do have an opinion on some of these things though:

  • Use snake_case for function name, I know this is a pretty big difference from the official style guide but it makes code some much more readable.

  • Wrap lines at 100 columns unless it helps readability.

  • Wrap comments at 80 columns.

  • Filename: use Foo.zig if you only export one struct, if there is more than one struct to export use foo.zig:

    // Foo.zig
    const Foo = @This();
    
    field,
    field2,
    
    pub fn init() void {}
    
    fn function_foo() !void {}
    
    // foo.zig
    pub const Stuct1 = struct {
        field,
        field2,
    
        pub fn init() void {}
    };
    
    pub const Struct2 = struct {
        pub fn init() void {}
    
        fn function_foo() !void {}
    };
    
  • For import at the top of the file, I do it like this:

    • std libs.
    • Dependencies (alphabetical order).
    • Other files from the project (alphabetical order). At the end of this section, add const <Struct> = @This() if needed.
    const std = @import("std");
    const fmt = std.fmt;
    const mem = std.mem;
    const os = std.os;
    
    const fcft = @import("fcft");
    const pixman = @import("pixman");
    const wayland = @import("wayland");
    const wl = wayland.client.wl;
    
    const Buffer = @import("shm.zig").Buffer;
    const BufferStack = @import("shm.zig").BufferStack;
    const ctx = &@import("Client.zig").ctx;
    const renderer = @import("renderer.zig");
    const Surface = @import("Surface.zig");
    const Output = @This();
    
  • For small if condition, use:

    if (false) return;
    
    // or
    
    if (false) {
        return;
    }
    
    // Do not use this:
    
    if (false)
        return;
    
  • Format using zig fmt before every commit, some tips to use it:

    pub fn example_function(
        args1: type,
        args2: type,
        args3: type,
        args4: type, // <- Use a comma here so zig fmt respect it
    ) void {}
    
    if (cond1 == 1 and               // <- Line break after and/or
        cond2 == 2 and
        cond3 == 3 and cond4 == 4 or // <- Works like this too
        cond5 == 5) {}