Skip to main content

Linters and formatters for ensuring WPILib's source code conforms to its style guide

Project description

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

To obtain newer versions of clang-format on older Debian and Ubuntu releases, either upgrade to one that does or add the appropriate deb ... main line from apt.llvm.org to /etc/apt/sources.list. Then install clang-format-# where # is the version number.

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. See the .styleguide file in the docs/examples directory for all possible groups.

This file contains groups of file name regular expressions. There are two groups of regexes which prevent tasks (i.e., formatters and linters) from running on matching files:

  • generated files
  • modifiable files

Generated files should not be modified; 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.

File names matching regexes in the group licenseUpdateExclude will be skipped by the license header update task.

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.

Valid include guard patterns use capital letters, start with the repository name, include the path to the file and the file name itself, have directory separators and hyphens replaced with underscores, and 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 group includeGuardRoots. 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 group repoRootNameOverride 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.

The groups includeRelated, includeCSys, includeCppSys, includeOtherLibs, and includeProject 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 regex for C system headers 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.

NOLINT can be appended in a 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.

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.

{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

This version
History Node

2018.110

History Node

2018.109

History Node

2018.108

History Node

2018.107

History Node

2018.106

History Node

2018.104

History Node

2018.103

History Node

2018.102

History Node

2018.101

History Node

2018.100

History Node

2018.99

History Node

2018.98

History Node

2018.96

History Node

2018.95

History Node

2018.94

History Node

2018.91

History Node

2018.88

History Node

2018.87

History Node

2018.85

History Node

2018.82

History Node

2018.80

History Node

2018.78

History Node

2018.77

History Node

2018.75

History Node

2018.74

History Node

2018.73

History Node

2018.72

History Node

2018.70

History Node

2017.120

History Node

2017.119

History Node

2017.118

History Node

2017.117

History Node

2017.115

History Node

2017.114

History Node

2017.112

History Node

2017.111

History Node

2017.107

History Node

2017.103

History Node

2017.101

History Node

2017.99

History Node

2017.98

History Node

2017.95

History Node

2017.90

History Node

2017.84

History Node

2017.82

History Node

2017.81

History Node

2017.80

History Node

2017.79

History Node

2017.78

History Node

2017.77

History Node

2017.74

History Node

2017.69

History Node

2017.68

History Node

2017.65

History Node

2017.59

History Node

2017.55

History Node

2017.53

History Node

2016.50

History Node

2016.47

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
wpiformat-2018.110-py3-none-any.whl (86.5 kB) Copy SHA256 hash SHA256 Wheel py3 Jul 7, 2018
wpiformat-2018.110.tar.gz (73.8 kB) Copy SHA256 hash SHA256 Source None Jul 7, 2018

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page