Norminette Checker
Automatically verify C code compliance with 42 School's Norminette standards.
Key Norminette Rules
File Structure
- •Header: Standard 42 header required in all files
- •Header Guards:
#ifndef,#define,#endifin .h files - •Max Line Length: 80 characters (including newline)
- •Max Function Length: 25 lines
- •Functions per File: Maximum 5 functions
Formatting Rules
- •Indentation: Tabs only (no spaces)
- •Control Structure Braces:
c
if (condition) { // code on new line } - •Function Braces:
c
int function(void) { // opening brace on new line } - •Spaces:
- •After keywords:
if (,while (,return - •Around operators:
a + b,i = 0 - •No space before semicolon
- •After keywords:
Naming Conventions
- •Functions:
ft_strlen,init_data(lowercase + underscore) - •Variables:
last_meal_time,count(lowercase + underscore) - •Macros:
MAX_PHILOS,BUFFER_SIZE(UPPERCASE) - •Structs:
struct s_philo(prefixs_) - •Typedefs:
t_philo,t_data(prefixt_)
Common Violations
- •Line too long: Split at operators or function parameters
- •Function too long: Extract logic into helper functions
- •Too many functions: Split file into logical modules
- •Mixed spaces/tabs: Use tabs only for indentation
- •Missing newline at EOF: Add empty line at file end
- •Multiple newlines: Remove extra blank lines
- •Space before semicolon: Remove space
- •Forbidden functions: Use only allowed functions per subject
Process
- •Check files: Run
norminette *.c *.hornorminette -R CheckForbiddenSourceHeader - •Read errors: Identify specific violations and line numbers
- •Fix violations: Apply corrections following rules above
- •Verify: Re-run norminette to confirm fixes
- •Common fixes:
- •Line length → break at logical points
- •Function length → extract subfunctions
- •Formatting → adjust braces/spaces
- •Naming → rename to convention
Standard 42 Header Template
c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* filename.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: login <login@student.42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: YYYY/MM/DD HH:MM:SS by login #+# #+# */ /* Updated: YYYY/MM/DD HH:MM:SS by login ### ########.fr */ /* */ /* ************************************************************************** */
Quick Fixes
Line Too Long
c
// Before (83 chars)
printf("Philosopher %d has taken a fork and is now eating spaghetti\n", id);
// After (split string)
printf("Philosopher %d has taken a fork and is now eating "
"spaghetti\n", id);
Function Too Long
Extract repeated logic:
c
// Before: 30-line function
int process_data(t_data *data)
{
// validation (5 lines)
// processing (20 lines)
// cleanup (5 lines)
}
// After: split into helpers
int validate_data(t_data *data);
int process_logic(t_data *data);
int cleanup_data(t_data *data);
Check Command
bash
# Check all files norminette # Check specific files norminette src/*.c include/*.h # Ignore header check (for testing) norminette -R CheckDefine src/main.c