- Python 63%
- TeX 18.2%
- C 17.5%
- Shell 1.2%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
|
All checks were successful
CI / debian (push) Successful in 1m0s
CI / fedora (push) Successful in 1m2s
CI / leap (push) Successful in 55s
CI / opensuse (push) Successful in 1m7s
CI / python 3.10 (push) Successful in 1m3s
CI / python 3.13 (push) Successful in 50s
CI / ubuntu (push) Successful in 52s
- Rules that did nothing any more (CheckDeclaration, CheckEnumVarDecl, CheckInHeader, CheckStructNaming), unused methods, constants, counters and commented-out code, and 13 error codes nothing reported. - One shared name check (norminette/naming.py); File.lines splits the source once per file. - Fix a crash when the tabs before a function name reach the start of the file. - Golden files: one render function for the test and for `python -m tests.rules.regenerate`. - CI: one matrix, steps shared with container-ci.sh (--steps). - Issue and PR templates moved to .forgejo/ and written for this fork; the upstream CONTRIBUTING.md and the v3/v4 Norm translations are gone. - Translations for the three messages this fork added. - BUILDING, COVERAGE and CHANGELOG brought up to date. Same output as before on the test suite and on 4,494 generated files, except the crash case. |
||
| .forgejo | ||
| docs | ||
| norminette | ||
| staff_report | ||
| tests | ||
| .flake8 | ||
| .gitignore | ||
| action.yml | ||
| CHANGELOG.md | ||
| container-ci.sh | ||
| CREDITS.md | ||
| Dockerfile | ||
| install.sh | ||
| LICENSE | ||
| norm-v4.1.txt | ||
| pyproject.toml | ||
| README.md | ||
| run_test.sh | ||
| uv.lock | ||
norminette for the Norm v4.1
At 42, every C file you hand in has to follow the Norm: the school's
coding standard (25-line functions, tabs, s_/t_ prefixes, no for,
and so on). The norminette is the program that checks it.
This project is a norminette that checks the current version of the Norm, v4.1 — exactly what the document says, nothing more and nothing less.
$ norminette main.c
main.c: Error!
Error: NON_CONST_STATIC_GLOBAL (line: 13, col: 1): global variables must be declared as const or static
Error: TERNARY_FBIDDEN (line: 21, col: 9): Ternaries are forbidden
A file that follows the Norm prints main.c: OK!.
Why it exists
The official norminette (42school/norminette, 3.3.60) was written for the older Norm v3. Compared with the v4.1 document, it:
- misses rules the Norm has, such as globals that must be
constorstatic, snake_case file names, or the header guard every.hneeds; - reports things the Norm doesn't forbid, such as labels, enums in a
.cfile, or a missing space inside parentheses; - gets some valid code wrong, such as
unsigned i;read as an implicit type.
This project starts from the official code and fixes that, one rule of the document at a time. Where the two disagree, it follows the document.
Before you rely on it
Evaluations at 42 use the official norminette. Because this one follows the document instead, a file can pass here and fail there, or the other way around. Use this tool to learn and check the Norm as written, and run the official one before an evaluation.
Every known difference is listed, with a small example file for each, in the staff report. That report also collects the places where the Norm itself is unclear, as questions for the 42 staff, with what this tool does in the meantime.
What it checks
Every rule of the Norm that a program can check:
- naming:
s_,t_,u_,e_,g_prefixes, lowercase identifiers, file and folder names, no non-ASCII characters outside strings; - formatting: 25 lines per function, 80 columns, tabs, braces, spacing, empty lines, declarations at the top and aligned, one instruction per line;
- functions: at most 4 named parameters and 5 variables,
voidfor no parameters, named prototype parameters,return (value);; - types: struct, enum, union and typedef layout, no structure in a
.cfile; - headers and files: include guards named after the file, includes first,
no
.cincludes, the 42 header, at most 5 functions per.cfile; - macros: uppercase names, one line each, indented inside
#ifblocks, only at global scope; - forbidden constructs:
for,do...while,switch,case,goto, ternaries, variable-length arrays, implicit types; - comments: none inside function bodies.
The Norm marks some rules with (*) to say a person checks them: whether
names are meaningful, comments useful, headers up to date, includes needed.
This tool leaves those to the evaluator, as the Norm intends. The Makefile
rules aren't checked either; the Norm says so itself.
The full rule-by-rule table, with the error code for each rule, is in docs/COVERAGE.md.
Install
You need Python 3.10 or newer, and nothing else.
sh install.sh # install, or update
sh install.sh --uninstall # remove
It installs into your home folder (no root needed) and puts norminette
on your PATH. pip install ., uv tool install . and the Dockerfile
work too; see docs/BUILDING.md.
Use
norminette # every .c and .h file under this folder
norminette main.c src/ # some files or folders
norminette --format json # output for scripts
norminette --allow-globals # for projects that allow plain globals
norminette -v # version
The exit code is 0 when every file is OK, so it fits in scripts and CI.
For contributors
sh run_test.sh # the whole test suite
- docs/BUILDING.md: installing on each distro, tests, CI, translations, and updating to a newer official version
- docs/COVERAGE.md: each rule of the Norm and how it's checked
- CHANGELOG.md: what changed compared with the official norminette
- staff_report/: differences with the official tool, and questions for the staff
License and credits
MIT. The engine is the work of the 42 Association and the norminette contributors; see LICENSE and CREDITS.md, which also explains how AI tools were used in this project.