lint
A code style checker for Jda source code. Validates naming conventions (snake_case for functions/variables, UPPER_SNAKE for constants, PascalCase for structs), checks line length, and detects trailing whitespace.
Usage
import lint
fn main() {
lint_init()
// Check naming conventions
lint_check_fn("my_function") // OK — snake_case
lint_check_fn("myFunction") // warning — not snake_case
lint_check_const("MAX_SIZE") // OK — UPPER_SNAKE
lint_check_struct("MyStruct") // OK — PascalCase
// Check line style
lint_check_line_len("short line", 80) // OK
lint_has_trailing_ws("hello ") // returns 1
lint_summary()
// Output: [LINT] 1 warning(s)
ret 0
}Function Reference
| Function | Signature | Description |
|---|---|---|
lint_init | () | Initialise linter state |
lint_reset | () | Reset warning count to zero |
lint_is_snake | (name: &i8) -> i64 | Check if name is snake_case |
lint_is_upper | (name: &i8) -> i64 | Check if name is UPPER_SNAKE |
lint_is_pascal | (name: &i8) -> i64 | Check if name is PascalCase |
lint_check_fn | (name: &i8) -> i64 | Validate function name (snake_case) |
lint_check_const | (name: &i8) -> i64 | Validate constant name (UPPER_SNAKE) |
lint_check_struct | (name: &i8) -> i64 | Validate struct name (PascalCase) |
lint_check_var | (name: &i8) -> i64 | Validate variable name (snake_case) |
lint_warn | (name: &i8, msg: &i8) | Print a lint warning |
lint_add_warning | (msg: &i8) | Add a custom warning |
lint_warning_count | () -> i64 | Return total warning count |
lint_check_line_len | (line: &i8, maxlen: i64) -> i64 | Check if line exceeds max length |
lint_has_trailing_ws | (line: &i8) -> i64 | Check for trailing whitespace |
lint_summary | () | Print warning summary |
Detailed API
lint_init
fn lint_init()Initialise the linter. Resets internal warning count to zero. Call once before using other lint functions.
lint_is_snake
fn lint_is_snake(name: &i8) -> i64Returns 1 if name is valid snake_case: lowercase letters, digits, and underscores only. Must start with a lowercase letter. Returns 0 otherwise.
lint_is_snake("my_func") // 1
lint_is_snake("myFunc") // 0 (uppercase)
lint_is_snake("_private") // 0 (starts with underscore)
lint_is_snake("x2") // 1lint_is_upper
fn lint_is_upper(name: &i8) -> i64Returns 1 if name is valid UPPER_SNAKE_CASE: uppercase letters, digits, and underscores. Must start with an uppercase letter.
lint_is_upper("MAX_SIZE") // 1
lint_is_upper("Max_Size") // 0
lint_is_upper("MAX") // 1lint_is_pascal
fn lint_is_pascal(name: &i8) -> i64Returns 1 if name is valid PascalCase: starts with an uppercase letter, followed by letters and digits. No underscores.
lint_is_pascal("MyStruct") // 1
lint_is_pascal("myStruct") // 0 (lowercase start)
lint_is_pascal("My_Struct") // 0 (underscore)lint_check_fn
fn lint_check_fn(name: &i8) -> i64Validate a function name. Returns 1 if it passes (snake_case). If it fails, emits a [LINT] warning and increments the warning count.
lint_check_fn("parse_json") // 1, no warning
lint_check_fn("ParseJSON") // 0, prints: [LINT] ParseJSON: function should be snake_caselint_check_const
fn lint_check_const(name: &i8) -> i64Validate a constant name. Returns 1 if it passes (UPPER_SNAKE). Emits a warning on failure.
lint_check_struct
fn lint_check_struct(name: &i8) -> i64Validate a struct name. Returns 1 if it passes (PascalCase). Emits a warning on failure.
lint_check_var
fn lint_check_var(name: &i8) -> i64Validate a variable name. Returns 1 if it passes (snake_case). Emits a warning on failure.
lint_warn
fn lint_warn(name: &i8, msg: &i8)Print a formatted lint warning: [LINT] <name>: <msg> and increment the warning count.
lint_warn("my_var", "unused variable")
// Output: [LINT] my_var: unused variablelint_check_line_len
fn lint_check_line_len(line: &i8, maxlen: i64) -> i64Returns 1 if line exceeds maxlen characters, 0 otherwise. Does not emit a warning automatically — combine with lint_warn if desired.
if lint_check_line_len(line, 100) == 1 {
lint_warn("line", "exceeds 100 characters")
}lint_has_trailing_ws
fn lint_has_trailing_ws(line: &i8) -> i64Returns 1 if line ends with a space or tab, 0 otherwise.
lint_has_trailing_ws("hello ") // 1
lint_has_trailing_ws("hello") // 0lint_summary
fn lint_summary()Print a summary of all warnings: [LINT] <count> warning(s). If count is 0, prints [LINT] No warnings.
lint_init()
lint_check_fn("badName")
lint_check_fn("good_name")
lint_summary()
// Output: [LINT] 1 warning(s)