Feature: Add naming convention warnings (--naming-check flag)#1571
Feature: Add naming convention warnings (--naming-check flag)#1571TinyuengKwan wants to merge 4 commits intorems-project:sail2from
Conversation
|
Nice work - I did start looking at this but from the |
Add optional warnings for identifiers that don't follow naming conventions: - Types / Structs / Enums: PascalCase - Functions: snake_case - Variables / Let bindings: snake_case - Constants: SCREAMING_SNAKE_CASE This feature is opt-in and disabled by default. Updates included in this commit: - Corrected naming style terminology (switched TitleCase to PascalCase). - Refactored `naming_check.ml` execution logic to align with `lint.ml`. - Updated test cases and documentation. Closes rems-project#1567:
788d307 to
91dde29
Compare
Added checks for variants within enums(with Train_Case).
| report_naming_issue l id config.type_style Category_type; | ||
| List.iter | ||
| (fun (Tu_aux (Tu_ty_id (_, constructor_id), def_annot)) -> | ||
| report_naming_issue def_annot.loc constructor_id config.type_style Category_type |
There was a problem hiding this comment.
I think these should be checked as variant style, as with the members of enums.
|
|
||
| (** Warning/error report *) | ||
| let report_naming_issue l id expected_style category = | ||
| let name = string_of_id id in |
There was a problem hiding this comment.
We should treat operators differently to other identifiers here.
|
Thanks for working on this. I tried it out on the RISC-V model to get an idea of how well it's currently working, and there are some things we need to think about:
|
Test Results 16 files 36 suites 0s ⏱️ Results for commit 3754b24. |
|
Perhaps it would be useful to add a smallish test case with all of the different usage styles @bacam discovered (e.g. |
Summary
This PR introduces optional naming convention checks to the Sail compiler. It adds a new pass that verifies if identifiers follow standard Sail naming conventions, helping to maintain code consistency.
Changes
--naming-check: Enables the naming checks. Violations are reported as warnings by default.--naming-check-strict: Enables checks and treats violations as errors.TitleCasesnake_caseSCREAMING_SNAKE_CASEdoc/asciidoc/usage.adocto include usage instructions for the new flags and correct the strict mode flag name.Relative Issue
Closes #1567
Implementation Details
The checks are implemented as an AST traversal in
src/lib/naming_check.ml. The traversal ensures that:FD_function) are checked.SD_funcl) are checked.DEF_impl) are checked.