* Add docs about ignoring format/presubmit checks. * Add java and swift info. * Sort python info. * Add link to swift-format doc on ignoring source.
3.0 KiB
Ignoring Files from Format and Presubmit Checks
This document describes all the ways to ignore files from format and presubmit checks in the Brave codebase. The main use cases are ignoring files that are vendored from external sources or generated by tools.
Quick Reference Table
| File Type / Check | Configuration File |
|---|---|
| C/C++ | add .clang-format in target directory |
| Java | does not support configuration |
| JS/TS/CSS/etc. | //brave/.prettierignore |
| Python | //brave/.yapfignore |
| Rust | //.rustfmt.toml (via patching) |
| Swift | add // swift-format-ignore-file comment |
| Presubmit Checks | //brave/chromium_presubmit_config.json5 |
Detailed Instructions
C/C++ Files (clang-format)
To ignore C/C++ files from clang-format checks, you need to add a
.clang-format file in the target directory with the following configuration:
DisableFormat: true
SortIncludes: false
This will disable both formatting and include sorting for files in that directory and its subdirectories.
Java Files
Chromium uses google-java-format for Java code formatting. Unlike other
formatters, google-java-format does not support ignore files or
directory-level configuration.
JavaScript/TypeScript/CSS/HTML Files
To ignore JavaScript, TypeScript, CSS, HTML, and other files handled by
Prettier, add them to //brave/.prettierignore.
The .prettierignore file uses gitignore-style patterns to exclude files from
Prettier formatting.
Python Files
To ignore Python files from formatting checks, add them to
//brave/.yapfignore.
The .yapfignore file uses pattern matching (fnmatch) to exclude files from
yapf formatting. Add one pattern per line.
Rust Files
To ignore directories from rustfmt formatting checks, you need to modify
//.rustfmt.toml via patching.
The .rustfmt.toml file contains an ignore array that lists directories to
exclude from rustfmt formatting. Add directory patterns to this array to ignore
them.
Swift Files
To ignore Swift files from swift-format checks, add a comment at the top of the file:
// swift-format-ignore-file
To ignore specific lines within a Swift file, add a comment before the line:
// swift-format-ignore
let example = ...
The swift-format configuration is located at //brave/ios/.swift-format and
controls formatting rules, but file-level ignores must be done using inline
comments.
See for more details: https://github.com/swiftlang/swift-format/blob/main/Documentation/IgnoringSource.md
Presubmit Checks
To ignore files from presubmit checks, you need to adjust the
default_files_to_skip configuration in
//brave/chromium_presubmit_config.json5.
This configuration controls which files are skipped during presubmit checks. This does not affect the formatting checks.