Without the `for scope in data.scopes:` loop, scope is not assigned anything.
From the context a loop over `data.scopes` could be intended. But other things like indentation would be possibly correct too. Not sure how this code should be.
We try this fix.
https://trac.cppcheck.net/ticket/8946
Add tests to travis script for verifying rule text loading.
Add dummy rule text files.
misra.py: Try to find a suitable codec for rule texts file.
* MISRA: Allow printing of the suppressed rules to the console
--show-suppressed-rules will print rules in the suppression rule list to
the console sorted by rule number.
* MISRA: Correct rule suppression for entire file scope
The entire file scope suppression check was checking for the rule item
list to be None instead of looking for None as an entry into the list.
Correct this check and modify the documentation to explicitly state that
an entry of None in the rule item list will set the scope for that
suppression to be the entire file.
* MISRA: Tests for checking per-file rule suppressions
To run:
../../cppcheck --suppressions-list=suppressions.txt --dump misra-suppressions*-test.c
python ../misra.py misra-suppressions*-test.c.dump
There should be no violations reported
* MISRA: Allow ignoring a prefix from file paths when suppression matching
For environments that run cppcheck from the build system cppcheck may be
passed a filename that is a complete path.
Often this path will include a portion that is specific to the developer
or to the environment where the project is located.
The per-file suppression rules do filename matching based on the
filename passed to cppcheck. To match any path information also has to
be included into the suppressions file provided to cppcheck via the
--suppressions-list= option.
This limits the usefulness of the per-file based suppressions because
it requires the suppression to be customized on a per instance basis.
Add a option "--file-prefix" that allows a prefix to be excluded from
the file path when doing the suppression filename matching.
Example.
Given the following structure:
/test/path1/misra-suppressions1-test.c
/test/path1/misra-suppressions2-test.c
specifying --file-prefix /test/path1 will allow the use of
misra-suppressions1-test.c and misra-suppressions2-test.c as filenames
in the suppressions file without leading patch information but still
match the suppression rule.
* MISRA: Tests for --file-prefix option
To run:
../../cppcheck --suppressions-list=suppressions.txt \
--dump misra-suppressions*-test.c \
path1/misra-suppressions*-test.c
python ../misra.py misra-suppressions*-test.c.dump \
path1/misra-suppressions*-test.c
There should be no violations reported
Functions with variadic arguments trip an exception in the MISRA checker
because some of the token is None and does not have some of the members
the code is expecting.
Prevent this by checking to see if the token is None and skipping the
code that tries to use that value.
* MISRA: Refactor many top level functions into a class
All the checker operations were implemented as individual functions. In
order to share data globals were used.
By refactoring all these into class methods data can be shared between
them without resorting to globals.
This change is scope only. No functional change for any of the methods.
Data is still shared via globals.
* MISRA: Refactor non-option globals into MisraChecker class
- Move all non-option global variables into the MisraChecker class
- Allows data to be shared among the class methods without needing
globals.
- Move global VERIFY_EXPECTED to class variable verify_expected
- Move global VERIFY_ACTUAL to class variable verify_actual
- Move global VIOLATIONS to class variable violations
- Move global suppressRules to class variable suppressedRules
- Move global suppressions to class variable dumpfileSuppressions
This refactoring is in anticipation of parsing and using the
suppressions added into the dump file by cppcheck.
Only variable naming and scope changed. No functional change for any of the
methods.
* MISRA: Restore original summary behavior
Version 1.84 introduced a regression in the behavior of the rule summary
output due to changes in the way multiple input files were handled.
The intended behavior of the summary was to output the total number of
violations after all files have been processed.
Commit aa831ce972 restored the input file
handling behavior but left summary behavior such that a summary output
was produced for each file that caused a violation instead of the total
number of violations after all files were processed.
Move the -verify logic up into the main loop so that the exit calls are
in the top level and restore the original behavior of the summary
output.
* MISRA: Support per file rule suppressions
Parse the suppressions list from cppcheck and extract MISRA rule strings from
the suppressions class by matching for errorId strings that begin with
'MISRA' or 'misra'. Extract the MISRA rule from those strings by
looking for a '_' or a '.' to separate rule numbers.
Store the rule number, filename, line number, and symbol name from the
suppression entry into a structure that allows for dictionary lookups
by the rule number and then the filename. All the line number
and symbol entries for that filename are are stored in list of tuples of
(line number, symbol name). A rule entry that has a value of None for
the filename is treated as a global suppression for all files. A
filename entry that has None for the rule items list is treated as a
suppression for the entire file. If the rule item list exist then it is
searched for matching line numbers.
Although symbol names are parsed and added int the list of rule items
they are not used for rule matching. Symbol names can include regular
expressions. Adding support for symbol names and regular expressions is
left as a future feature.
The existing global suppression method provided by the --suppress-rules
option is supported. Those rules are added into the suppressions
structure as if they were provided by the suppressions list as global
suppressions. ie A rule with a None for the filename value.
* MISRA addon: Support multiple files with argparse
* MISRA addon fix exit code
Fix to run all dump files then exit with error code if any error in any file found.
* added CLion project folder to .gitignore
* adjusted project name in CMakeLists.txt
* avoid warning when compiling "Debug" with Visual Studio via CMake
There was a GCC-style compiler flag in the common flags in compileroptions.cmake which caused the following warning:
cl : Command line warning D9002 : ignoring unknown option '-O0'
* compileroptions.cmake: restored original formatting
* daca2.py: added missing import
* misra.py: removed unnecessary escaping from regular expression
* added CLion project folder to .gitignore
* adjusted project name in CMakeLists.txt
* avoid warning when compiling "Debug" with Visual Studio via CMake
There was a GCC-style compiler flag in the common flags in compileroptions.cmake which caused the following warning:
cl : Command line warning D9002 : ignoring unknown option '-O0'
* compileroptions.cmake: restored original formatting
* some small *.py script cleanups
WARNING: breaking change - now default misra.py report style will be the
same as cppcheck itself, but previosly misra.py default template was a
little different
* Added ignore list
- Added ignore list
- Use argparse to parse arguments
- Source formatting
* misra.py changed argument name
- Changed ` --ignore-rules` to ` --suppress-rules`
* Resolved VERIFY option in misra.py
Resolved broken broken logic in commit to add argparse.
* edit suppression list
Modified names
Hide some arguments
* command line help formatting
* Revert removal of --no-summary argument
* missing text rules no longer reported
* VERIFY scope modified to global
Output will still be given for style violations.
This allows the build process output to be smaller and cleaner,
making it easier to spot and address problems.
- Show a summary of the of the number of violations. This can be
disabled with the --no-summary option.
- Return an error code if -verify flag not used and violation exists.
Use python's __file__ variable to figure out where the checker script is
located.
This allows a customized per project scripts to be used instead of the
one provided in the cppcheck release.