Add ECS linter and formatter - #8
Merged
Merged
Conversation
- Introduced a new linter package (ecs_lint) that includes various linting rules for naming conventions, empty blocks, unreachable code, and formatting issues. - Implemented helper functions for checking naming styles (snake_case, UPPER_SNAKE_CASE) and identifying comments or blank lines. - Enhanced the parser (ecs_parser) to support format-specific syntax and lexical rules. - Created a test file (test_lint.ecs) containing intentional style issues to verify the linter's functionality.
- Introduced `get_fmt_grammar` and `get_fmt_syntax` functions to handle format-specific grammar and syntax. - Updated `get_lexical` to accept a `strict` parameter, allowing for different lexical rules based on mode. - Modified grammar rules to differentiate between strict and non-strict parsing, particularly in handling comments and newlines. - Enhanced syntax definitions to use function pointers for end-of-line and end-of-statement handling based on the parsing mode. - Removed redundant code and improved overall structure for better maintainability and readability.
…ved readability and maintainability
…handling and code structure
… and unused expressions
…s and syntax handling
…o reflect latest releases
… and useless expressions
There was a problem hiding this comment.
Pull request overview
Adds first-party linting and formatting support to the ECS toolchain by extending the parser to support a strict/comment-preserving mode, introducing new ecs_lint / ecs_format packages, wiring them into the ecs bootstrap wrapper, and adding unit tests + fixtures to validate behavior.
Changes:
- Extend
ecs_parserwith strict/non-strict lexical + syntax modes to preserve comments/newlines for formatter use. - Add
ecs_lint(AST + source-based lint rules) andecs_format(AST-driven formatter using strict grammar). - Add wrapper flags (
-l,-F,-n) and unit tests/fixtures to exercise parser modes and lint rules.
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| unit_tests/test_parser_modes.ecs | Adds unit coverage for strict vs non-strict parser mode behavior. |
| unit_tests/test_lint_rules.ecs | Adds unit coverage asserting expected lint rule detections and severity counts. |
| tests/test_lint.ecs | Adds an intentionally “bad style” fixture file to trigger lint rules. |
| imports/ecs.csp | Introduces lambda_base marker type and updates function type validation for lambdas. |
| imports/ecs_parser.csp | Adds strict-aware lexical/syntax generation and updates default grammar wiring. |
| imports/ecs_lint.csp | New linter implementation (rules + AST walker + report printing). |
| imports/ecs_generator.csp | Updates lambda body handling and generated lambda struct base type; improves REPL error cleanup. |
| imports/ecs_format.csp | New formatter implementation using strict grammar and comment-aware line handling. |
| imports/ecs_bootstrap.csp | Adds ecs -l / ecs -F / ecs -n modes, adjusts cache behavior, and updates exit codes. |
| csbuild/ecs.json | Bumps ecs package version to reflect runtime type-system change. |
| csbuild/ecs_parser.json | Bumps ecs_parser package version to reflect strict mode API. |
| csbuild/ecs_lint.json | Adds build package definition for the new linter. |
| csbuild/ecs_generator.json | Bumps ecs_generator package version for lambda-related changes. |
| csbuild/ecs_format.json | Adds build package definition for the new formatter. |
| csbuild/ecs_bootstrap.json | Bumps wrapper version and adds dependencies on new lint/format packages. |
Comments suppressed due to low confidence (1)
imports/ecs_lint.csp:400
- The position for trailing consecutive blank lines at EOF uses 0-based line indexes (
ctx.code_buff.size - blank_count). This will point to the wrong line in reports; it should be 1-based like other parsergen positions.
if blank_count > 2
ctx.add_issue({1, ctx.code_buff.size - blank_count}, "Too many consecutive blank lines (" + to_string(blank_count) + ").", SEVERITY_INFO, "consecutive_blank_lines")
end
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…e exit codes based on linting results
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.