Skip to content

Commit 6eb8657

Browse files
committed
feat(linter-core): implement global line tracking
- update the design docs
1 parent e5938f8 commit 6eb8657

14 files changed

Lines changed: 647 additions & 106 deletions

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
11
/target
2+
docs/implementation.typ
3+
docs/methodology.typ
4+
docs/pipeline_diagram.svg
5+
thesis_content.md

README.md

Lines changed: 107 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
- [Documentation](#documentation)
1313
- [Installation](#installation)
1414
- [Usage](#usage)
15+
- [Configuration](#configuration)
1516
- [Development environment](#development-environment)
1617
- [Using GitHub Codespaces](#using-github-codespaces)
1718
- [Using VS Code ](#using-vs-code-if-you-have-it-installed-locally)
@@ -30,6 +31,8 @@
3031
* [BNF Grammar for Ballerina Subset](docs/BNF.md)
3132
* [Software Requirement Specification (SRS)](https://github.com/RuztyCrabs/Blazelint/releases/latest/download/BlazeLint-SRS.pdf)
3233
* [Pipeline overview](docs/pipeline_overview.md)
34+
* [Quick Reference](docs/QUICK_REFERENCE.md)
35+
* [Implementation Notes](docs/IMPLEMENTATION_NOTES.md)
3336

3437
## Installation
3538

@@ -45,6 +48,8 @@ _Windows and MacOS binaries will be added in a later release._
4548

4649
## Usage
4750

51+
### Basic Usage
52+
4853
Analyze a Ballerina source file by passing its path to `blazelint`:
4954

5055
```bash
@@ -56,21 +61,88 @@ blazelint path/to/file.bal
5661
5762
The tool prints the input program, a token stream, the parsed AST, and exits or emits diagnostics if there is any and exits with a non-zero status.
5863

64+
### Development Usage
65+
5966
Running from a checked-out repository is also supported:
6067

6168
```bash
6269
cargo run -- path/to/file.bal
6370
```
6471

6572
> [!NOTE]
66-
> `cargo run` builds and executes an unoptimized build (for debug requirments). Always use `cargo build --release` for any benchmark or observations on performance.
73+
> `cargo run` builds and executes an unoptimized build (for debug requirements). Always use `cargo build --release` for any benchmark or observations on performance.
6774
68-
For a quick smoke test, you can reuse the sample program in `tests/test.bal`:
75+
For a quick smoke test, you can reuse the sample program in `tests/test-bal-files/`:
6976

7077
```bash
71-
blazelint tests/test.bal
78+
blazelint tests/test-bal-files/simple_errors.bal
79+
```
80+
81+
## Configuration
82+
83+
### Configuration File
84+
85+
Blazelint looks for a `.blazerc` configuration file in the current directory or any parent directory. The configuration uses TOML format:
86+
87+
```toml
88+
# .blazerc - Blazelint Configuration File
89+
90+
[rules]
91+
# Naming convention rules
92+
camel-case = "error" # Enforces camelCase for variables/functions
93+
constant-case = "warn" # Enforces SCREAMING_SNAKE_CASE for constants
94+
95+
# Code style rules
96+
line-length = "warn" # Limits line length
97+
max-function-length = "error" # Limits function body length
98+
missing-return = "error" # Ensures functions have return statements
99+
unused-variables = "warn" # Detects unused variable declarations
100+
101+
# Disable specific rules
102+
some-rule = "off"
103+
104+
[settings]
105+
max-line-length = 120 # Maximum characters per line
106+
max-function-length = 50 # Maximum lines in function body
72107
```
73108

109+
#### Rule Configuration Values
110+
111+
Each rule can be configured with one of these severity levels:
112+
113+
- `"error"` - Causes build failure (non-zero exit code)
114+
- `"warn"` - Shows warnings but allows build to succeed
115+
- `"info"` - Shows informational messages
116+
- `"off"` - Disables the rule completely
117+
118+
#### Available Rules
119+
120+
| Rule | Description | Default Severity | Settings |
121+
|------|-------------|------------------|----------|
122+
| `camel-case` | Enforces camelCase naming for variables and functions | `error` | None |
123+
| `constant-case` | Enforces SCREAMING_SNAKE_CASE for constants | `warn` | None |
124+
| `line-length` | Limits line length | `warn` | `max-line-length` |
125+
| `max-function-length` | Limits function body length | `warn` | `max-function-length` |
126+
| `missing-return` | Ensures functions have return statements | `error` | None |
127+
| `unused-variables` | Detects unused variable declarations | `warn` | None |
128+
129+
### Configuration Discovery
130+
131+
Blazelint searches for `.blazerc` files in this order:
132+
133+
1. **Current directory**: `./.blazerc`
134+
2. **Parent directories**: Walks up the directory tree looking for `.blazerc`
135+
3. **Default configuration**: Uses built-in defaults if no file found
136+
137+
### Rule Engine
138+
139+
The rule engine features:
140+
141+
- **Dynamic Rule Loading**: Only enabled rules are executed
142+
- **Configurable Severity**: Each rule respects configured severity levels
143+
- **Caching**: Configuration is cached for performance
144+
- **Extensible Design**: New rules can be added easily
145+
74146
## Development environment
75147

76148
A pre-configured [Dev Container](https://containers.dev/) is available that can be used to investigate, develop or debug the program without installing anything on the host machine.
@@ -98,6 +170,15 @@ The container comes with:
98170
- Ballerina runtime
99171
- Extensions for Language Servers, syntax highlighting and debugging support
100172
- Common utilities (zsh, GitHub CLI, git, etc.)
173+
174+
### Development Dependencies
175+
176+
The project uses the following key dependencies:
177+
178+
- **Core**: Standard library only for main linting logic
179+
- **Configuration**: `serde`, `toml` for config file parsing
180+
- **Utilities**: `once_cell`, `thiserror` for error handling and caching
181+
- **Testing**: `assert_cmd`, `tempfile` for integration tests
101182

102183
## Building
103184

@@ -133,7 +214,8 @@ The container comes with:
133214
- Ballerina toolchain and IDE extension (optional - for testing or writing ballerina codes)
134215

135216
### Steps
136-
- You can adjust the `tests/test.bal` file if you need to debug a specific diagnostic.
217+
- You can adjust the `tests/test-bal-files/` files if you need to debug a specific diagnostic.
218+
- Create a `.blazerc` config file to test configuration changes.
137219
- Set breakpoints as needed.
138220
- Click on **Run and Debug** from the main method or use `ctrl+shift+D` to jump to debug menu.
139221

@@ -144,6 +226,7 @@ The container comes with:
144226

145227
- Changes should be developed and push to following branches based on the area of the feature.
146228
- feature/linter-core: Changes to the linter engine (lexer, parser, semantic analyzer and BNF document).
229+
- feature/rule-engine: Changes to rule engine, configuration system, and linter rules.
147230
- ci/cd: Changes related to continous integration and deployments.
148231
- docs: Changes related to documentation.
149232

@@ -153,6 +236,26 @@ The container comes with:
153236
bash scripts/check.sh
154237
```
155238

239+
### Adding New Rules
240+
241+
When adding a new linter rule:
242+
243+
1. **Create the rule**: Implement the `LintRule` trait in `src/linter/rules/`
244+
2. **Register the rule**: Add to the rule registry in `src/lib.rs`
245+
3. **Add default configuration**: Update `Config::default()` in `src/config.rs`
246+
4. **Add tests**: Include unit tests and integration tests
247+
5. **Update docs**: Add rule to the Available Rules table above
248+
249+
### Configuration Changes
250+
251+
When modifying configuration:
252+
253+
1. **Update schema**: Modify configuration structs in `src/config.rs`
254+
2. **Update defaults**: Ensure backward compatibility in `Config::default()`
255+
3. **Update validation**: Add appropriate validation logic in `validate_config()`
256+
4. **Update tests**: Test configuration loading and validation
257+
5. **Update documentation**: Update configuration examples and rule tables
258+
156259
## TODO
157260
158261
Roadmap of the project can be viewed from [here](TODO.md).

0 commit comments

Comments
 (0)