-
Notifications
You must be signed in to change notification settings - Fork 362
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
support gcc warnings without rule id #1708
Merged
guwirth
merged 3 commits into
SonarOpenCommunity:master
from
stalb:feature/gcc_warning_without_id
Apr 25, 2019
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,8 +32,12 @@ public class CxxCompilerGccSensor extends CxxCompilerSensor { | |
public static final String REPORT_REGEX_DEF = "gcc.regex"; | ||
public static final String REPORT_CHARSET_DEF = "gcc.charset"; | ||
public static final String DEFAULT_CHARSET_DEF = "UTF-8"; | ||
/** | ||
* Default id used for gcc warnings not associated with any activation switch. | ||
*/ | ||
public static final String DEFAULT_ID = "default"; | ||
public static final String DEFAULT_REGEX_DEF | ||
= "(?<file>.*):(?<line>[0-9]+):[0-9]+:\\x20warning:\\x20(?<message>.*)\\x20\\[(?<id>.*)\\]"; | ||
= "(?<file>.*):(?<line>[0-9]+):[0-9]+:\\x20warning:\\x20(?<message>.*?)(\\x20\\[(?<id>.*)\\])?\\s*$"; | ||
|
||
public CxxCompilerGccSensor(CxxLanguage language) { | ||
super(language, REPORT_PATH_KEY, CxxCompilerGccRuleRepository.getRepositoryKey(language)); | ||
|
@@ -70,6 +74,12 @@ protected CxxMetricsFactory.Key getMetricKey() { | |
|
||
@Override | ||
protected String alignId(String id) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add short description why we need this special case. |
||
/* Some gcc warnings are not associated to any activation switch and don't have a matching id. | ||
* In these cases a default id is used. | ||
*/ | ||
if (id == null || "".equals(id)) { | ||
id = DEFAULT_ID; | ||
} | ||
return id.replaceAll("=$", ""); | ||
} | ||
|
||
|
This file contains 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
This file contains 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
7 changes: 7 additions & 0 deletions
7
...es/org/sonar/cxx/sensors/reports-project/compiler-reports/build-warning-without-id.gcclog
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
main.c:7:1: warning: no semicolon at end of struct or union | ||
} my_struct; | ||
^ | ||
main.c: In function 'main': | ||
main.c:11:6: warning: unused variable 'i' [-Wunused-variable] | ||
int i; | ||
^ |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are all messages always in one line?
Maybe regex would be better (with id | without id)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my understanding all the warnings look either like:
main.c:11:6: warning: unused variable 'i' [-Wunused-variable]
where the id is the corresponding switch param (-Wunused-variable
) ormain.c:7:1: warning: no semicolon at end of struct or union
where the id part is missing.The regex match both of them.
By default warning messages are on one line, The user can force warning messages to be on several lines (if using for example
-fmessage-length
switch, but then current actual regex won't match either).A named group can only appears once. So it's not possible to duplicate the beginning of the regex and if I use something like:
(?<file>.*):(?<line>[0-9]+):[0-9]+:\\x20warning:\\x20(?<message>.*)(\\x20\\[(?<id>.*)\\])?
or(?<file>.*):(?<line>[0-9]+):[0-9]+:\\x20warning:\\x20(?<message>.*)((\\x20\\[(?<id>.*)\\])|(?!(\\x20\\[.*\\])))
(matching id or not matching id)The id is not recognized anymore.
I solved the problem using the greedy (?) and non-greedy (*?) operators and forcing to match the last part of the line.