2.3 KiB
2.3 KiB
Crafter.LintRules
The Catcrafts house-style lint rules for crafter-build projects, packaged as one C++ module.
Use
In a project.cpp:
import std;
import Crafter.Build;
#pragma crafter dependency "https://forgejo.catcrafts.net/Catcrafts/Crafter.LintRules.git"
import Crafter.LintRules;
using namespace Crafter;
extern "C" Configuration CrafterBuildProject(std::span<const std::string_view> args) {
Configuration cfg;
// ...
LintRules::AddRules(cfg);
return cfg;
}
Then crafter-build lint reports, crafter-build format rewrites, and crafter-build format --check gates CI. Pin a revision for reproducible builds:
#pragma crafter dependency "https://forgejo.catcrafts.net/Catcrafts/Crafter.LintRules.git" commit "<sha>"
Suppress a finding with // lint-disable-next-line <rule> or a whole file with // lint-disable-file <rule>.
Rules
| Rule | Kind | What it wants |
|---|---|---|
spdx-header |
report | // SPDX-License-Identifier: on line 1, // SPDX-FileCopyrightText: on line 2, blank line 3 |
no-tabs |
report | spaces |
naming |
report, AST | PascalCase types and functions; camelCase variables, including statics and constants |
enum-class |
report | enum class, never a plain enum |
no-iostream-print |
report | std::println instead of std::cout/std::cerr streaming |
no-char-pointer |
report, AST | std::string / std::string_view over char* outside C interop |
const-local |
report, AST | const on a scalar local that is never written |
constexpr-constant |
report, AST | constexpr on a constant with a constant initialiser |
format-concat |
transform | std::format instead of + with string literals |
fixed-width-types |
transform, AST | std::int32_t and friends instead of int, long, … |
single-declaration |
transform, AST | one declaration per statement |
brace-style |
transform | K&R braces |
if-single-line |
transform | if (x) return; on one line when it fits |
wrap-join |
transform | join wrapped statements that fit on one line |
paren-spacing |
transform | if ( and for (, no space before a call's ( |
trim-trailing-ws |
transform | no trailing whitespace |
final-newline |
transform | files end with a newline |