Linters and formatters for ensuring WPILib's source code conforms to its style guide
Project description
wpiformat
Provides linters and formatters for ensuring WPILib's C++, Java, and Python code conform to its style guide. WPILib uses a variant of the Google style guides.
Dependencies
- Python 3.9 or newer
Installation
On Windows, execute:
py -m pip install wpiformat
On Linux/OSX, execute:
pip install wpiformat
Project Setup
To use these tools with a new project, copy .styleguide
, and .styleguide-license
from the examples folder into the project and create a new .clang-format
file based on the desired C/C++ style.
Note: Since wpiformat already handles include ordering, it is recommended to use SortIncludes: false
in .clang-format
.
.styleguide
wpiformat checks the current directory for the .styleguide
file. If one doesn't exist, all parent directories are tried as well. This file contains groups of filename regular expressions.
groupName {
regex_here
}
The regexes are matched using re.search(), so they don't have to match the whole filename.
Empty config groups can be omitted. Directory separators must be "/", not "\". During processing, they will be replaced internally with an os.sep that is automatically escaped for regexes.
See the .styleguide
file in the docs/examples directory for all possible groups.
Specifying C/C++ files to format
The cHeaderFileInclude
group specifies C headers to format, the cppHeaderFileInclude
group specifies C++ headers to format, and the cppSrcFileInclude
group specifies C++ source files to format. It's common to match just the file extension like so: \.hpp$
.
Ignoring files
There are two groups of regexes which prevent tasks (i.e., formatters and linters) from running on matching files:
generatedFileExclude
(generated files)modifiableFileExclude
(modifiable files)
Generated files should not be modified by the user; if they are, wpiformat will emit warnings. No warnings are emitted for modifications to modifiable files.
All files ignored by patterns in a repository's .gitignore
file are considered modifiable files. Exclusion groups take precedence over inclusion groups.
License update exclusion
Filenames matching regexes in the group licenseUpdateExclude
will be skipped by the license header update task.
Include guards
Valid include guard patterns have the following properties:
- Use capital letters
- Start with the repository name
- Include the path to the file and the filename itself
- Have directory separators and hyphens replaced with underscores
- Have a trailing underscore
The path to the file starts from the repository root by default. Other paths, such as include directories, can be specified in the includeGuardRoots
group. If a path matches, that string will be truncated from the include guard pattern.
For example, given a file at allwpilib/src/main/native/include/wpiutil/support/ConcurrentQueue.h
and an include path of src/main/native/include/
, the resulting include guard would be ALLWPILIB_WPIUTIL_SUPPORT_CONCURRENTQUEUE_H_
.
The repoRootNameOverride
group allows one to override the repository name used in include guards. This is useful for giving subprojects within one repository different repository roots in their include guards. Only specify one name in this group because subsequent names will be ignored.
Include sorting
The following groups correspond to the header groups in the style guide. If a header name matches a regex in one of the groups, it overrides the default ordering and is placed in the corresponding group. The groups of regexes are checked in order of include group precedence (the order shown below).
includeRelated
(headers related to a .cpp file, likeFile.h
included byFile.cpp
)includeCSys
(C system headers)includeCppSys
(C++ system headers)includeOtherLibs
(headers from thirdparty libraries or other monorepo subprojects)includeProject
(headers from the current subproject)
includeCSys
produces false positives on headers from "other libraries". Regexes for them should be added to includeOtherLibs
. Libraries with many headers generally group them within a folder, so a regex for just the folder will suffice.
Appending a // NOLINT
comment to a header include to prevent wpiformat's header include sorter from modifying it and to maintain its relative ordering with other header includes. This will, in effect, treat it as a barrier across which no header includes will be moved. Header includes on each side of the barrier will still be sorted as normal.
.styleguide-license
This file contains the license header template. It should contain Copyright (c)
followed by the company name and the string {year}
. See the .styleguide-license
file in the docs/examples directory.
wpiformat checks the currently processed file's directory for a .styleguide
file first and traverses up the directory tree if one isn't found. This allows templates which are closer to the processed file to override a project's main template.
License header semantics
The license header is always at the beginning of the file and ends after two newlines. If there isn't one, or it doesn't contain the required copyright contents, wpiformat inserts a new one containing the current year.
.styleguide-license
special variables
{year}
is replaced with a year range from the earliest copyright year in the file to the current year. If the earliest year is the current year, only that year will be written.
{padding}
is optional and represents an expanding space which pads the line to 80 columns. Multiple instances of {padding}
on the same line share the padding equally.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file wpiformat-2025.31.tar.gz
.
File metadata
- Download URL: wpiformat-2025.31.tar.gz
- Upload date:
- Size: 117.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | df2abd270eab323ea78534c2a4ace62791ca6855ccbc768bf53fac28176c96dc |
|
MD5 | 69343d16ba16e081d4afabcdbf77a464 |
|
BLAKE2b-256 | 41c232679ba38a108e4449570fdf170cef6a8b0cd66f1b0600f98c44b553140d |
Provenance
The following attestation bundles were made for wpiformat-2025.31.tar.gz
:
Publisher:
ci.yml
on wpilibsuite/styleguide
-
Statement:
- Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
wpiformat-2025.31.tar.gz
- Subject digest:
df2abd270eab323ea78534c2a4ace62791ca6855ccbc768bf53fac28176c96dc
- Sigstore transparency entry: 171935055
- Sigstore integration time:
- Permalink:
wpilibsuite/styleguide@7923fef7faf91e4369078c6f0ea8ab9099c15000
- Branch / Tag:
refs/heads/main
- Owner: https://github.com/wpilibsuite
- Access:
public
- Token Issuer:
https://token.actions.githubusercontent.com
- Runner Environment:
github-hosted
- Publication workflow:
ci.yml@7923fef7faf91e4369078c6f0ea8ab9099c15000
- Trigger Event:
push
- Statement type:
File details
Details for the file wpiformat-2025.31-py3-none-any.whl
.
File metadata
- Download URL: wpiformat-2025.31-py3-none-any.whl
- Upload date:
- Size: 112.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e9252ad94cce3bff0ad235060ecd67bdf8c87a83dcb49f2cb8b00864bc9addea |
|
MD5 | 79311f196d82a9fc2f06256dba652b51 |
|
BLAKE2b-256 | bc97843d7d3d06c8868a2f5966b9c7879a085fb50d6e126fff79a407e516676c |
Provenance
The following attestation bundles were made for wpiformat-2025.31-py3-none-any.whl
:
Publisher:
ci.yml
on wpilibsuite/styleguide
-
Statement:
- Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
wpiformat-2025.31-py3-none-any.whl
- Subject digest:
e9252ad94cce3bff0ad235060ecd67bdf8c87a83dcb49f2cb8b00864bc9addea
- Sigstore transparency entry: 171935057
- Sigstore integration time:
- Permalink:
wpilibsuite/styleguide@7923fef7faf91e4369078c6f0ea8ab9099c15000
- Branch / Tag:
refs/heads/main
- Owner: https://github.com/wpilibsuite
- Access:
public
- Token Issuer:
https://token.actions.githubusercontent.com
- Runner Environment:
github-hosted
- Publication workflow:
ci.yml@7923fef7faf91e4369078c6f0ea8ab9099c15000
- Trigger Event:
push
- Statement type: