summaryrefslogtreecommitdiff
path: root/utils/checkstyle.py
AgeCommit message (Collapse)Author
2024-05-31utils: checkstyle.py: Show location of coding style issue within lineLaurent Pinchart
The issue checkers display the line number and line content of each offending line, but don't show the location of the issue within a line. Improve checkstyle by adding a marker that points to the exact location. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2024-05-31utils: checkstyle.py: Add a check for hex valuesLaurent Pinchart
libcamera uses lowercase hex values. Add a corresponding checker. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Tested-by: Milan Zamazal <mzamazal@redhat.com>
2024-05-31utils: checkstyle.py: Extend IncludeChecker to cover math.hLaurent Pinchart
math.h is an exception to the C compatibility header rule, as we prefer using cmath. Extend the IncludeCheck to warn about it. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2024-05-31utils: checkstyle.py: Refactor IncludeCheckerLaurent Pinchart
The IncludeCheck warns when code uses C++ standard library headers where corresponding C compatibility headers are preferred. We have an exception to that rule for math.h, where cmath is prefered. In order to prepare for extending checkstyle.py to enforce that rule, refactor the way the IncludeChecker identifies headers. No functional change is intended. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2024-05-08libcamera: Drop file name from header comment blocksLaurent Pinchart
Source files in libcamera start by a comment block header, which includes the file name and a one-line description of the file contents. While the latter is useful to get a quick overview of the file contents at a glance, the former is mostly a source of inconvenience. The name in the comments can easily get out of sync with the file name when files are renamed, and copy & paste during development have often lead to incorrect names being used to start with. Readers of the source code are expected to know which file they're looking it. Drop the file name from the header comment block. The change was generated with the following script: ---------------------------------------- dirs="include/libcamera src test utils" declare -rA patterns=( ['c']=' \* ' ['cpp']=' \* ' ['h']=' \* ' ['py']='# ' ['sh']='# ' ) for ext in ${!patterns[@]} ; do files=$(for dir in $dirs ; do find $dir -name "*.${ext}" ; done) pattern=${patterns[${ext}]} for file in $files ; do name=$(basename ${file}) sed -i "s/^\(${pattern}\)${name} - /\1/" "$file" done done ---------------------------------------- This misses several files that are out of sync with the comment block header. Those will be addressed separately and manually. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Daniel Scally <dan.scally@ideasonboard.com>
2024-04-19utils: checkstyle.py: Drop period at end of Doxygen one linersLaurent Pinchart
The libcamera documentation style calls for no period at the end of the Doxygen one-liner commands (\brief, \param and \return). Extend the DoxygenFormatter class to drop the period. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2024-04-19utils: checkstyle.py: Use r'' strings for regular expressionsLaurent Pinchart
It's a good practice to use r'' strings for regular expressions in Python, to avoid unexpected interaction with string escape sequences. Use them globally. This allows simplifying escaping in one of the regular expression strings. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2024-03-15checkstyle: Work around bug in difflibStefan Klug
If a file misses the newline at the end it gets detected by checkstyle, but the resulting patch is incorrect and does not apply. It took me a while to understand that it wasn't me using checkstyle incorrectly, but that the patch was faulty. The bug itself is in difflib and dates back to 2008. To reproduce: - Remove trailing newline from a file - git add the file - run ./utils/checkstyle.py -s | patch -p0 Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2024-03-11utils: checkstyle.py: Fix known_trailers sort orderHans de Goede
An unruly libcamera maintainer merged the wrong patch adding the Co-developed-by: tag to the known_trailers. Fix the sort order alphabetically to match the version which should have been merged. Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Signed-off-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2024-03-11utils: checkstyle.py: Add Co-developed-by to known_trailersHans de Goede
Add Co-developed-by to known_trailers to silence false positive "Invalid commit trailer key 'Co-developed-by'" warnings. Signed-off-by: Hans de Goede <hdegoede@redhat.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2024-02-27utils: checkstyle.py: Update LogCategoryChecker regexpMilan Zamazal
The regexp uses obsolete form, update it to mute the warning emitted by Python 3.12: SyntaxWarning: invalid escape sequence '\(' Signed-off-by: Milan Zamazal <mzamazal@redhat.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2024-02-27utils: checkstyle.py: Don't presume python3 locationMilan Zamazal
python3 binary may be present in a location other than /usr/bin/. Signed-off-by: Milan Zamazal <mzamazal@redhat.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2023-07-28utils: checkstyle.py: Extract title and trailers with one commandLaurent Pinchart
The Amendment class calls `git show` twice, once to extract the commit title, and a second time to extract the trailers. This can be combined in a single command, which is more efficient. Do so. While at it, centralize initialization of self._trailers in the Commit.__init__() function. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2023-07-18utils: checkstyle.py: Check trailers for Amendment commitsKieran Bingham
The commit trailers are checked as part of processing the commit message with the newly introduced TrailersChecker. This relies on the trailers property being correctly exposed by the Commit object, and is implemented for the base Commit but not processed for Amendment commits. Refactor the trailer property handling to a helper function in the base Commit class and make use of it with a newly added call to obtain the existing Trailers from the most recent commit when using Amendment. Reviewed-by: Umang Jain <umang.jain@ideasonboard.com> Tested-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2023-07-18utils: checkstyle.py: Derive Amendment from CommitKieran Bingham
The Amendment commit class is derived from the StagedChanges class (which in turn derives from the Commit base class), however there is no code sharing between Amendment and StagedChanges other than the call to initalise through the base Commit class. Refactor the inheritance to make an Amendment derive directly from Commit. Reviewed-by: Umang Jain <umang.jain@ideasonboard.com> Tested-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2023-07-18utils: checkstyle.py: Initialise staged trailersKieran Bingham
There are no possible Trailers for staged changes as the commit message has not yet been written. Initialise the empty trailers when the commit object is initialised. Reviewed-by: Umang Jain <umang.jain@ideasonboard.com> Tested-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2023-07-18utils: checkstyle.py: Treat Malformed trailers as a CommitIssueKieran Bingham
If a Malformed trailer is identified the checkstyle script triggers a RuntimeError and stops processing the rest of the commit. A malformed trailer can be regarded as an issue in the commit and reported as such using the same method as other faults identified by the tool. Convert the RuntimeError into a CommitIssue and continue processing other trailers. Reviewed-by: Umang Jain <umang.jain@ideasonboard.com> Tested-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2023-07-05utils: checkstyle: Add trailers checkerLaurent Pinchart
The libcamera git history contains numerous examples of incorrect commit message trailers due to invalid trailer types (e.g. Change-Id), typos and other small issues. Those went unnoticed through reviews, which shows that an automated checker is required. Add a trailers checker to checkstyle.py to catch invalid or malformed trailers, with a set of supported trailers that match libcamera's commit message practices. New trailer keys can easily be added later as new needs arise. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2023-07-05utils: checkstyle: Don't include commit ID in commit titleLaurent Pinchart
The commit title and commit ID are two different pieces of information. Don't include the latter in the former, to simplify code that only needs the commit title. Constructing a string from the ID and title is easier than splitting the combined string back into its elements. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2023-07-05utils: checkstyle: Support running checkers selectivelyLaurent Pinchart
During development of the checkstyle.py script, it can be useful to run only a subset of the checker. Add the ability to do so with a '--checkers' command line argument. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Mattijs Korpershoek <mkorpershoek@baylibre.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2023-07-05utils: checkstyle: Add __repr__ method to CommitFile classLaurent Pinchart
Add a custom representation to the CommitFile class in order to facilitate debugging. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2023-03-01utils: checkstyle.py: Don't run commit title checker on staged commitsPaul Elder
When creating a new commit, there is no title, so the title checker complains that the title isn't compliant and the commit cannot be created if checkstyle is run as a pre-commit hook. Fix this by skipping the title checker when run on staged changes. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2023-01-10utils: checkstyle.py: Add commit title checkerLaurent Pinchart
Add a commit checker to ensure that commit titles start with a prefix. The commit issue message lists prefix candidates retrieved from the git log. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
2022-12-15utils: checkstyle.py: Check new header file on new and renamed meson.build filesXavier Roumegue
Declaration of new header file to the build system are only checked against modified meson.build file. Therefore, this raises a false positive warning in case the meson.build is added or renamed. Add the new and renamed meson.build files to the list of files to check header file inclusion. Signed-off-by: Xavier Roumegue <xavier.roumegue@oss.nxp.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-06-03utils: checkstyle.py: Fix color bleedTomi Valkeinen
If issue.line is None, the the terminal color is never reset back to normal. This causes the yellow color to bleed. Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-06-01utils: checkstyle: Ensure "..." include style for internal headersLaurent Pinchart
libcamera uses the "..." include style for internal headers. Enforce it. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Umang Jain <umang.jain@ideasonboard.com> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
2022-06-01utils: checkstyle: Run the CLangFormatter lastLaurent Pinchart
The IncludeOrderFormatter will be extended with more formatting rules that should be applied before clang-format gets run, as it will influence its output. Add a priority mechanism for formatters, and give a negative priority to the CLangFormatter to make it run last. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Umang Jain <umang.jain@ideasonboard.com> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
2021-08-27utils: checkstyle.py: Use single-quoted strings when possibleLaurent Pinchart
checkstyle.py uses single-quoted strings in most locations already. There are a few locations where this wouldn't be convenient (when the string itself contains a single quote, which would then require escaping), but there are also a few other locations where double quotes are used when single quotes would work fine. Change those to standardize on single-quoted strings. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2021-02-16utils: checkstyle.py: Handle renamed files in header add checkerLaurent Pinchart
The header add checker only handles added header, which makes it miss issues when a header is renamed. Fix it. Fixes: 8fffab46b80f ("utils: checkstyle.py: Add header add checker") Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2021-02-16utils: checkstyle.py: Restore checks of renamed filesLaurent Pinchart
Commit fc91951250ca ("utils: checkstyle.py: Add ability to filter files by status in a commit") caused all renamed files to be ignored by the checker. Fix it. Fixes: fc91951250ca ("utils: checkstyle.py: Add ability to filter files by status in a commit") Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2021-01-21utils: checkstyle.py: Fix "protected" members in Commit classLaurent Pinchart
The Commit class and subclasses were reworked in commit 4f5d17f3a4f5 ("utils: checkstyle.py: Make title and files properties of commit class") with the introduction of members of the base class that were meant to be protected (not used externally, but accessible by subclasses). They have been named with a '__' prefix for this purpose, which was a bad choice as Python effectively replaces a leading '__' with a literal '__classname__' prefix to make them private (https://docs.python.org/3/tutorial/classes.html#private-variables). The members accessed in the derived classes are thus different from the ones in the base class. Fix this by replacing the double underscore prefix with a single underscore, which is a "weak internal use indicator" (as specified in https://www.python.org/dev/peps/pep-0008/), closer to the protected access specifier of C++. Reported-by: Umang Jain <email@uajain.com> Reported-by: Naushir Patuck <naush@raspberrypi.com> Fixes: 4f5d17f3a4f5 ("utils: checkstyle.py: Make title and files properties of commit class") Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Tested-by: Naushir Patuck <naush@raspberrypi.com> Reviewed-by: Naushir Patuck <naush@raspberrypi.com>
2020-12-29utils: checkstyle.py: Drop astyle supportLaurent Pinchart
Formatting code using astyle doesn't lead to results as good as with clang-format, and doesn't receive much test coverage as most developers use clang-format. The code is thus bitrotting. Drop it. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
2020-12-29utils: checkstyle.py: Add header add checkerLaurent Pinchart
Add a commit checker that ensures that all header files added to the libcamera includes (public or internal) are accompanied by a corresponding update of the meson.build file in the same directory. Here's the output of the new checker when run against a commit that forgot to update meson.build. $ ./utils/checkstyle.py b3383da79f1d --------------------------------------------------------------------------------- b3383da79f1d513b0d76db220a7104e1c1035e30 libcamera: buffer: Create a MappedBuffer --------------------------------------------------------------------------------- Header include/libcamera/internal/buffer.h added without corresponding update to include/libcamera/internal/meson.build --- 1 potential issue detected, please review In theory we could extend the checker to cover .cpp files too, but the issue will be quite noticeable as meson won't build the file if meson.build isn't updated. Header files are more tricky as problems would only occur at when installing the headers (for public headers), or would result in race conditions in the build. Both of those issues are harder to catch. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2020-12-29utils: checkstyle.py: Add commit checkersLaurent Pinchart
Add a new category of checkers that operate on a whole commit. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2020-12-29utils: checkstyle.py: Move diff parsing to Commit classLaurent Pinchart
To avoid duplicating diff parsing in commit checkers, move it to the Commit class. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2020-12-29utils: checkstyle.py: Add ability to filter files by status in a commitLaurent Pinchart
A commit can perform different operations on a file. Record the file status (added, modified, renamed, deleted, ...) and add the ability to filter files by status when listing the files touched by a commit. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2020-12-29utils: checkstyle.py: Make title and files properties of commit classLaurent Pinchart
Make the API of the Commit class more explicit by exposing the title and files as properties instead of through a get_info() method. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
2020-12-29utils: checkstyle.py: Move commit handling to a separate sectionLaurent Pinchart
To prepare for checkers that operate directly on commits, move the related classes to a separate section. No functional change is included. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
2020-12-29utils: checkstyle.py: Factor out automatic class registryLaurent Pinchart
The style checkers and formatters duplicate automatic class registry code. Factor it out to a common ClassRegistry helper class. The list of subclasses is moved to a class member variable of the auto-registered base class type. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2020-12-29utils: checkstyle.py: Drop arguments to super() when possibleLaurent Pinchart
The super() call is a shortcut syntax for super(__class__, <first arg>). Drop the arguments when they match the default. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
2020-11-08utils: checkstyle.py: Add d-pointer formatterLaurent Pinchart
Add a formatter to ensure consistent naming of 'd' and 'o' variables related to the d-pointer design pattern, as implemented by the Extensible class. The formatter also ensures that the pointer is always const. const-correctness issues related to the data pointed to will be caught by the compiler, and thus don't need to be checked here. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2020-09-21Documentation: Adjust guidelines regarding math.h headerLaurent Pinchart
While libcamera prefers usage of the C standard library headers (xxx.h) over the C++ version (cxxx), we make an exception for cmath as the overloaded versions of the math functions are convenient. Document this, and adjust checkstyle.py accordingly. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2020-03-23utils: checkstyle: Add formatter to sort #include statementsLaurent Pinchart
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2020-03-16utils: checkstyle: Add a ShellCheckerKieran Bingham
Hook the utility 'shellcheck' into our checkstyle helper to automatically verify shell script additions. Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-01-18checkstyle: Add support for checking style on amendmentsNicolas Dufresne
This introduces a new argument "--amend" and a new special type of commit "Amendment". It will check the style of changes that are in the index combined with the changes of the last commit. So this is the changes that would be applied by "git commit --amend" hence the name of the argument. This is needed to implement pre-commit hook. Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-01-18checkstyle: Add support for checking style on staged changesNicolas Dufresne
This introduces a new command line "--staged" and a new special type of commit "StagedChanges". It will check the style of changes that are in the index, so the changes that would be committed by "git commit". "--staged" was chosen to match with "git diff --staged" command line. Other valid name could have been "--index" or "--cached". This was my personal preference, aliases can be added later. Note that we must not confuse this with working tree changes, as these changes are not picked by "git commit". This feature is needed to implement pre-commit hook. Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-01-18checkstyle: Introduce a Commit classNicolas Dufresne
This introduces a Commit class used in the final revlist list. All the git commands are moved into that class. This class will be used to introduce new types of commit (StagedChanges and Amendment) needed to implement pre-commit hook support. Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-01-18checkstyle: Exit with 1 status if issues are foundNicolas Dufresne
Makes the tool return 1 if there is any potential issues. This is needed when using this tool for pre-commit hook in order to abort the commit process. Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-01-18checkstyle: Move from pep8 to pycodestyleNicolas Dufresne
The tool has been renamed in 2016 to make it more obvious what it is doing. There is no other changes needed on our side. See https://github.com/PyCQA/pycodestyle/issues/466 Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-01-07utils: checkstyle.py: Support single line hunksKieran Bingham
The checkstyle script expects hunks to be declared with a start line and line count, however the unified diff format [0] declares that a single line hunk will only have the start line: > If a hunk contains just one line, only its start line number appears. > Otherwise its line numbers look like ‘start,count’. An empty hunk is > considered to start at the line that follows the hunk. [0] https://www.gnu.org/software/diffutils/manual/html_node/Detailed-Unified.html#Detailed-Unified Attempting to parse a single line hunk results in the following error: File "./utils/checkstyle.py", line 110, in __init__ raise RuntimeError("Malformed diff hunk header '%s'" % line) RuntimeError: Malformed diff hunk header '@@ -1 +1,2 @@ The DiffHunk class only makes use of the start line, and does not utilise the line count, thus update the regex to make the unused groups optional. Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>