Skip to content

implement variable_naming#664

Open
hashtafak wants to merge 2 commits intoKampfkarren:mainfrom
escapepz:feature/variable-naming-lint
Open

implement variable_naming#664
hashtafak wants to merge 2 commits intoKampfkarren:mainfrom
escapepz:feature/variable-naming-lint

Conversation

@hashtafak
Copy link

@hashtafak hashtafak commented Feb 25, 2026

PR: Implement Variable Naming Lint

Description

Adds variable_naming lint that validates variable, function, constant, and type names against configurable regex patterns.

Changes

  • Implemented VariableNamingLint in selene-lib/src/lints/variable_naming.rs
  • Default patterns:
    • variables=snake_case
    • functions=camelCase
    • constants=SCREAMING_SNAKE_CASE
    • types=PascalCase
  • Configuration flags: check_locals, check_globals, check_parameters, check_functions, check_types, ignore_pattern
  • AST visitor for precise error locations on functions and types
  • ScopeManager integration for variable validation
  • Registered in selene-lib/src/lints.rs

Tests

  • All tests in selene-lib/tests/lints/variable_naming/ pass
  • Unit tests cover functions, types, valid/invalid variables
  • Edge cases (underscore prefix, heuristic type detection)

Configuration

# selene.toml
std = "lua51"

[lints]
variable_naming = "warn"
undefined_variable = "allow"

[config]
# Regular expressions for naming conventions
function_names = "^_?[a-z][a-zA-Z0-9]*$" # camelCase: starts with lowercase, optional underscore
variable_names = "^[a-z][a-z0-9_]*$"     # snake_case: lowercase with underscores
constant_names = "^[A-Z][A-Z0-9_]*$"     # UPPER_CASE: all caps with underscores
type_names = "^[A-Z][a-zA-Z0-9]+$"       # PascalCase: starts with uppercase

ignore_pattern = "^__?ignored"

check_locals = true
check_globals = true
check_parameters = true
check_functions = true
check_types = true

Checklist

  • Builds successfully (cargo build)
  • All tests pass (cargo test)
  • No clippy warnings
  • Backward compatible
  • Documentation added

@hashtafak hashtafak marked this pull request as draft February 25, 2026 08:35
@hashtafak hashtafak marked this pull request as ready for review February 25, 2026 09:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant