Skip to content

Commit 50e287c

Browse files
authored
docs: Clarify include/exclude documentation (#4072)
1 parent e4ae213 commit 50e287c

File tree

2 files changed

+28
-27
lines changed

2 files changed

+28
-27
lines changed

docs/usage_and_configuration/the_basics.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -241,24 +241,17 @@ Because of our [stability policy](../the_black_code_style/index.md), this will g
241241
stable formatting, but still allow you to take advantage of improvements that do not
242242
affect formatting.
243243

244-
#### `--include`
245-
246-
A regular expression that matches files and directories that should be included on
247-
recursive searches. An empty value means all files are included regardless of the name.
248-
Use forward slashes for directories on all platforms (Windows, too). Exclusions are
249-
calculated first, inclusions later.
250-
251244
#### `--exclude`
252245

253246
A regular expression that matches files and directories that should be excluded on
254247
recursive searches. An empty value means no paths are excluded. Use forward slashes for
255-
directories on all platforms (Windows, too). Exclusions are calculated first, inclusions
256-
later.
248+
directories on all platforms (Windows, too). By default, Black also ignores all paths
249+
listed in `.gitignore`. Changing this value will override all default exclusions.
257250

258251
#### `--extend-exclude`
259252

260-
Like `--exclude`, but adds additional files and directories on top of the excluded ones.
261-
Useful if you simply want to add to the default.
253+
Like `--exclude`, but adds additional files and directories on top of the default values
254+
instead of overriding them.
262255

263256
#### `--force-exclude`
264257

@@ -271,6 +264,13 @@ programmatically on changed files, such as in a pre-commit hook or editor plugin
271264
The name of the file when passing it through stdin. Useful to make sure Black will
272265
respect the `--force-exclude` option on some editors that rely on using stdin.
273266

267+
#### `--include`
268+
269+
A regular expression that matches files and directories that should be included on
270+
recursive searches. An empty value means all files are included regardless of the name.
271+
Use forward slashes for directories on all platforms (Windows, too). Overrides all
272+
exclusions, including from `.gitignore` and command line options.
273+
274274
#### `-W`, `--workers`
275275

276276
When _Black_ formats multiple files, it may use a process pool to speed up formatting.

src/black/__init__.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -344,19 +344,6 @@ def validate_regex(
344344
" either a major version number or an exact version."
345345
),
346346
)
347-
@click.option(
348-
"--include",
349-
type=str,
350-
default=DEFAULT_INCLUDES,
351-
callback=validate_regex,
352-
help=(
353-
"A regular expression that matches files and directories that should be"
354-
" included on recursive searches. An empty value means all files are included"
355-
" regardless of the name. Use forward slashes for directories on all platforms"
356-
" (Windows, too). Exclusions are calculated first, inclusions later."
357-
),
358-
show_default=True,
359-
)
360347
@click.option(
361348
"--exclude",
362349
type=str,
@@ -365,8 +352,8 @@ def validate_regex(
365352
"A regular expression that matches files and directories that should be"
366353
" excluded on recursive searches. An empty value means no paths are excluded."
367354
" Use forward slashes for directories on all platforms (Windows, too)."
368-
" Exclusions are calculated first, inclusions later. [default:"
369-
f" {DEFAULT_EXCLUDES}]"
355+
" By default, Black also ignores all paths listed in .gitignore. Changing this"
356+
f" value will override all default exclusions. [default: {DEFAULT_EXCLUDES}]"
370357
),
371358
show_default=False,
372359
)
@@ -376,7 +363,7 @@ def validate_regex(
376363
callback=validate_regex,
377364
help=(
378365
"Like --exclude, but adds additional files and directories on top of the"
379-
" excluded ones. (Useful if you simply want to add to the default)"
366+
" default values instead of overriding them."
380367
),
381368
)
382369
@click.option(
@@ -398,6 +385,20 @@ def validate_regex(
398385
"editors that rely on using stdin."
399386
),
400387
)
388+
@click.option(
389+
"--include",
390+
type=str,
391+
default=DEFAULT_INCLUDES,
392+
callback=validate_regex,
393+
help=(
394+
"A regular expression that matches files and directories that should be"
395+
" included on recursive searches. An empty value means all files are included"
396+
" regardless of the name. Use forward slashes for directories on all platforms"
397+
" (Windows, too). Overrides all exclusions, including from .gitignore and"
398+
" command line options."
399+
),
400+
show_default=True,
401+
)
401402
@click.option(
402403
"-W",
403404
"--workers",

0 commit comments

Comments
 (0)