Dlang-UPB / D-scanner

Fork of the official D-scanner that uses dmd-as-a-lib
Boost Software License 1.0
6 stars 2 forks source link

Replace libdparse with DMD in AlwaysCurlyCheck #109

Closed Vladiwostok closed 7 months ago

Vladiwostok commented 7 months ago

This check ensures some statements (if, for, foreach, while, do, try-catch) are always written with braces. My solution is to visit Compound statements and mark their parent as having braces, since compound statements in DMD are statements having more than 1 child statement (forcing a brace block). AST node changes include:

For visiting the common statements I have created a template. For TryCatchStatement and TryFinallyStatement I have created separated visit functions because:

I've also extended the unit tests by adding test cases for passing scenarios and a test case for a try-catch-finally statement.

RazvanN7 commented 7 months ago

I have a hard time understanding the logic here. Could you maybe explain a bit how you implemented this given that dmd does not store whether braces have been used or not?

RazvanN7 commented 7 months ago

Please, when you do PR try to explain a bit what the check does and how you implemented it. This makes it easier for me to review it and merge it.

RazvanN7 commented 7 months ago

mind the conflicts