diff options
author | Jordan Demeulenaere <jdemeulenaere@google.com> | 2022-08-29 17:31:50 +0200 |
---|---|---|
committer | Jordan Demeulenaere <jdemeulenaere@google.com> | 2022-08-29 17:40:50 +0200 |
commit | 75418db586a698ad4ae11ada2acee6a9d881fcec (patch) | |
tree | 5a4e727181cfa721639d3246d9300ce71818b6c7 /ktfmt.py | |
parent | 9839dc339f059bdeb33e1fb2ef2ea31350b12895 (diff) | |
download | ktfmt-75418db586a698ad4ae11ada2acee6a9d881fcec.tar.gz |
Add support for file exclusion in ktfmt.py
This CL adds support for file exclusion in ktfmt.py. This will allow to
include all files in a directory but exclude those that are not
currently formatted properly.
This CL also adds the generate_includes_file.py to generate such a file
from a list of directories.
Bug: 235461679
Test: Manual
Change-Id: I17e17de40d4c558c617e06a55d27eaeb2743f368
Diffstat (limited to 'ktfmt.py')
-rwxr-xr-x | ktfmt.py | 11 |
1 files changed, 7 insertions, 4 deletions
@@ -36,7 +36,7 @@ def main(): '--includes_file', '-i', default='', - help='The file containing the Kotlin files and directories that should be formatted/checked.' + help='The file containing the Kotlin files and directories that should be included/excluded, generated using generate_includes_file.py.' ) parser.add_argument( 'files', @@ -68,17 +68,20 @@ def main(): f = open(includes_file, 'r') lines = f.read().splitlines() + included = [line[1:] for line in lines if line.startswith('+')] included_files = set() included_dirs = [] - for line in lines: + for line in included: if is_kotlin_file(line): included_files.add(line) else: included_dirs += [line] + excluded_files = [line[1:] for line in lines if line.startswith('-')] + kt_files = [ - kt_file for kt_file in kt_files - if kt_file in included_files or is_included(kt_file, included_dirs) + kt_file for kt_file in kt_files if kt_file not in excluded_files and + (kt_file in included_files or is_included(kt_file, included_dirs)) ] # No need to start ktfmt if there are no files to check/format. |