Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IndentationCheck - preprocessor directives #1100

Open
dominickdm opened this issue Dec 6, 2023 · 1 comment
Open

IndentationCheck - preprocessor directives #1100

dominickdm opened this issue Dec 6, 2023 · 1 comment

Comments

@dominickdm
Copy link

Hello,

Today, we are struggling with the IndentationCheck rule in legacy code using preprocessor directives. For readability, we put statements that only apply for TTY (or not) with 1 extra tab. But this violates the IndentationCheck rule.

Example below:
image

Do you see a possibility to enhance this? I guess the file is preprocessed for SonarLint analysis? Maybe if the rule could be configured to check the non-preprocessed code and ignore preprocessed blocks?

@gquerret
Copy link
Contributor

gquerret commented Dec 6, 2023

There's also #1060 where preprocessor is involved. Dealing correctly with that is quite difficult for multiple reasons:

  • The preprocessor silently discards tokens from the stream if the &IF condition evaluates to false (the parser just doesn't see those tokens)
  • No extra info is (currently) added to the tokens that have been preprocessed, so the parser and then the rules doesn't have any knowledge of the preprocessor

Just thinking out loud, but it may be possible to keep the number of nested levels of &if into the tokens, and use this information when executing the rule. If two statements are in the same block but in a different preprocessor block, then the issue could be skipped. This behavior would be controlled by an attribute in the quality profile. The algorithm would have to be changed on how to compute the "base" position, but it's probably doable.

@gquerret gquerret transferred this issue from Riverside-Software/sonar-openedge Dec 22, 2023
@gquerret gquerret transferred this issue from Riverside-Software/pct Dec 22, 2023
@linear linear bot closed this as not planned Won't fix, can't repro, duplicate, stale Dec 22, 2023
@gquerret gquerret reopened this Dec 22, 2023
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

No branches or pull requests

2 participants