Add a mixin for setting file_patterns based off tool settings.
Review Request #11546 — Created March 22, 2021 and submitted — Latest diff uploaded
A common pattern in Review Bot tools is to allow users to set a list of
supported file extensions. The tools that support this all do it a bit
differently, in terms of what they expect or allow, and how they set it.
This change introduces a new mixin,
which standardizes how this works. It offers three new class attributes
for a tool:
file_extensions_setting- The name of a configurable tool setting
where custom file extensions are set.
file_patterns_setting- The name of a configurable tool setting
where custom glob file patterns are set.
include_default_file_patterns- Whether any class-level defaults for
file_patternsshould always be included in the final result.
This simplifies tools, leading to fewer differences in behavior, and
encourages more customization.
The new implementation handles escaping of file extensions in order to
avoid issues with patterns, as well as handling inconsistencies in
lists of extensions and patterns (extra commas, whitespace, or duplicates).
Unit tests pass on Python 2.7 and 3.x.