-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathoptions.rs
2218 lines (2164 loc) · 87 KB
/
options.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
use regex::Regex;
use ruff::line_width::{LineLength, TabSize};
use ruff::rules::flake8_pytest_style::settings::SettingsError;
use ruff::rules::flake8_pytest_style::types;
use ruff::rules::flake8_quotes::settings::Quote;
use ruff::rules::flake8_tidy_imports::settings::{ApiBan, Strictness};
use ruff::rules::isort::settings::RelativeImportsOrder;
use ruff::rules::isort::{ImportSection, ImportType};
use ruff::rules::pydocstyle::settings::Convention;
use ruff::rules::pylint::settings::ConstantType;
use ruff::rules::{
flake8_copyright, flake8_errmsg, flake8_gettext, flake8_implicit_str_concat,
flake8_import_conventions, flake8_pytest_style, flake8_quotes, flake8_self,
flake8_tidy_imports, flake8_type_checking, flake8_unused_arguments, isort, mccabe, pep8_naming,
pycodestyle, pydocstyle, pyflakes, pylint, pyupgrade,
};
use ruff::settings::types::{IdentifierPattern, PythonVersion, SerializationFormat, Version};
use ruff::{warn_user_once, RuleSelector};
use ruff_macros::{CombineOptions, ConfigurationOptions};
use rustc_hash::{FxHashMap, FxHashSet};
use serde::{Deserialize, Serialize};
use std::collections::BTreeSet;
use std::hash::BuildHasherDefault;
use strum::IntoEnumIterator;
#[derive(Debug, PartialEq, Eq, Default, ConfigurationOptions, Serialize, Deserialize)]
#[serde(deny_unknown_fields, rename_all = "kebab-case")]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
pub struct Options {
#[option(
default = r#"[]"#,
value_type = "list[str]",
example = r#"
# Allow minus-sign (U+2212), greek-small-letter-rho (U+03C1), and the asterisk-operator (U+2217),
# which could be confused for "-", "p", and "*", respectively.
allowed-confusables = ["−", "ρ", "∗"]
"#
)]
/// A list of allowed "confusable" Unicode characters to ignore when
/// enforcing `RUF001`, `RUF002`, and `RUF003`.
pub allowed_confusables: Option<Vec<char>>,
#[option(
default = r#"[]"#,
value_type = "list[str]",
example = r#"
builtins = ["_"]
"#
)]
/// A list of builtins to treat as defined references, in addition to the
/// system builtins.
pub builtins: Option<Vec<String>>,
#[option(
default = ".ruff_cache",
value_type = "str",
example = r#"cache-dir = "~/.cache/ruff""#
)]
/// A path to the cache directory.
///
/// By default, Ruff stores cache results in a `.ruff_cache` directory in
/// the current project root.
///
/// However, Ruff will also respect the `RUFF_CACHE_DIR` environment
/// variable, which takes precedence over that default.
///
/// This setting will override even the `RUFF_CACHE_DIR` environment
/// variable, if set.
pub cache_dir: Option<String>,
#[option(
default = r#""^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$""#,
value_type = "re.Pattern",
example = r#"
# Only ignore variables named "_".
dummy-variable-rgx = "^_$"
"#
)]
/// A regular expression used to identify "dummy" variables, or those which
/// should be ignored when enforcing (e.g.) unused-variable rules. The
/// default expression matches `_`, `__`, and `_var`, but not `_var_`.
pub dummy_variable_rgx: Option<String>,
#[option(
default = r#"[".bzr", ".direnv", ".eggs", ".git", ".git-rewrite", ".hg", ".mypy_cache", ".nox", ".pants.d", ".pytype", ".ruff_cache", ".svn", ".tox", ".venv", "__pypackages__", "_build", "buck-out", "build", "dist", "node_modules", "venv"]"#,
value_type = "list[str]",
example = r#"
exclude = [".venv"]
"#
)]
/// A list of file patterns to exclude from linting.
///
/// Exclusions are based on globs, and can be either:
///
/// - Single-path patterns, like `.mypy_cache` (to exclude any directory
/// named `.mypy_cache` in the tree), `foo.py` (to exclude any file named
/// `foo.py`), or `foo_*.py` (to exclude any file matching `foo_*.py` ).
/// - Relative patterns, like `directory/foo.py` (to exclude that specific
/// file) or `directory/*.py` (to exclude any Python files in
/// `directory`). Note that these paths are relative to the project root
/// (e.g., the directory containing your `pyproject.toml`).
///
/// For more information on the glob syntax, refer to the [`globset` documentation](https://docs.rs/globset/latest/globset/#syntax).
///
/// Note that you'll typically want to use
/// [`extend-exclude`](#extend-exclude) to modify the excluded paths.
pub exclude: Option<Vec<String>>,
#[option(
default = r#"None"#,
value_type = "str",
example = r#"
# Extend the `pyproject.toml` file in the parent directory.
extend = "../pyproject.toml"
# But use a different line length.
line-length = 100
"#
)]
/// A path to a local `pyproject.toml` file to merge into this
/// configuration. User home directory and environment variables will be
/// expanded.
///
/// To resolve the current `pyproject.toml` file, Ruff will first resolve
/// this base configuration file, then merge in any properties defined
/// in the current configuration file.
pub extend: Option<String>,
#[option(
default = "[]",
value_type = "list[str]",
example = r#"
# In addition to the standard set of exclusions, omit all tests, plus a specific file.
extend-exclude = ["tests", "src/bad.py"]
"#
)]
/// A list of file patterns to omit from linting, in addition to those
/// specified by `exclude`.
///
/// Exclusions are based on globs, and can be either:
///
/// - Single-path patterns, like `.mypy_cache` (to exclude any directory
/// named `.mypy_cache` in the tree), `foo.py` (to exclude any file named
/// `foo.py`), or `foo_*.py` (to exclude any file matching `foo_*.py` ).
/// - Relative patterns, like `directory/foo.py` (to exclude that specific
/// file) or `directory/*.py` (to exclude any Python files in
/// `directory`). Note that these paths are relative to the project root
/// (e.g., the directory containing your `pyproject.toml`).
///
/// For more information on the glob syntax, refer to the [`globset` documentation](https://docs.rs/globset/latest/globset/#syntax).
pub extend_exclude: Option<Vec<String>>,
#[option(
default = "[]",
value_type = "list[str]",
example = r#"
# In addition to the standard set of inclusions, include `.pyw` files.
extend-include = ["*.pyw"]
"#
)]
/// A list of file patterns to include when linting, in addition to those
/// specified by `include`.
///
/// Inclusion are based on globs, and should be single-path patterns, like
/// `*.pyw`, to include any file with the `.pyw` extension.
///
/// For more information on the glob syntax, refer to the [`globset` documentation](https://docs.rs/globset/latest/globset/#syntax).
pub extend_include: Option<Vec<String>>,
#[option(
default = "[]",
value_type = "list[RuleSelector]",
example = r#"
# Skip unused variable rules (`F841`).
extend-ignore = ["F841"]
"#
)]
/// A list of rule codes or prefixes to ignore, in addition to those
/// specified by `ignore`.
///
/// This option has been **deprecated** in favor of `ignore`
/// since its usage is now interchangeable with `ignore`.
#[cfg_attr(feature = "schemars", schemars(skip))]
pub extend_ignore: Option<Vec<RuleSelector>>,
#[option(
default = "[]",
value_type = "list[RuleSelector]",
example = r#"
# On top of the default `select` (`E`, `F`), enable flake8-bugbear (`B`) and flake8-quotes (`Q`).
extend-select = ["B", "Q"]
"#
)]
/// A list of rule codes or prefixes to enable, in addition to those
/// specified by `select`.
pub extend_select: Option<Vec<RuleSelector>>,
#[option(
default = r#"[]"#,
value_type = "list[RuleSelector]",
example = r#"
# Enable autofix for flake8-bugbear (`B`), on top of any rules specified by `fixable`.
extend-fixable = ["B"]
"#
)]
/// A list of rule codes or prefixes to consider autofixable, in addition to those
/// specified by `fixable`.
pub extend_fixable: Option<Vec<RuleSelector>>,
/// A list of rule codes or prefixes to consider non-auto-fixable, in addition to those
/// specified by `unfixable`.
///
/// This option has been **deprecated** in favor of `unfixable` since its usage is now
/// interchangeable with `unfixable`.
#[cfg_attr(feature = "schemars", schemars(skip))]
pub extend_unfixable: Option<Vec<RuleSelector>>,
#[option(
default = "[]",
value_type = "list[str]",
example = r#"
# Avoiding flagging (and removing) `V101` from any `# noqa`
# directives, despite Ruff's lack of support for `vulture`.
external = ["V101"]
"#
)]
/// A list of rule codes that are unsupported by Ruff, but should be
/// preserved when (e.g.) validating `# noqa` directives. Useful for
/// retaining `# noqa` directives that cover plugins not yet implemented
/// by Ruff.
pub external: Option<Vec<String>>,
#[option(default = "false", value_type = "bool", example = "fix = true")]
/// Enable autofix behavior by-default when running `ruff` (overridden
/// by the `--fix` and `--no-fix` command-line flags).
pub fix: Option<bool>,
#[option(default = "false", value_type = "bool", example = "fix-only = true")]
/// Like `fix`, but disables reporting on leftover violation. Implies `fix`.
pub fix_only: Option<bool>,
#[option(
default = r#"["ALL"]"#,
value_type = "list[RuleSelector]",
example = r#"
# Only allow autofix behavior for `E` and `F` rules.
fixable = ["E", "F"]
"#
)]
/// A list of rule codes or prefixes to consider autofixable. By default,
/// all rules are considered autofixable.
pub fixable: Option<Vec<RuleSelector>>,
#[option(
default = r#""text""#,
value_type = r#""text" | "json" | "junit" | "github" | "gitlab" | "pylint" | "azure""#,
example = r#"
# Group violations by containing file.
format = "grouped"
"#
)]
/// The style in which violation messages should be formatted: `"text"`
/// (default), `"grouped"` (group messages by file), `"json"`
/// (machine-readable), `"junit"` (machine-readable XML), `"github"` (GitHub
/// Actions annotations), `"gitlab"` (GitLab CI code quality report),
/// `"pylint"` (Pylint text format) or `"azure"` (Azure Pipeline logging commands).
pub format: Option<SerializationFormat>,
#[option(
default = r#"false"#,
value_type = "bool",
example = r#"
force-exclude = true
"#
)]
/// Whether to enforce `exclude` and `extend-exclude` patterns, even for
/// paths that are passed to Ruff explicitly. Typically, Ruff will lint
/// any paths passed in directly, even if they would typically be
/// excluded. Setting `force-exclude = true` will cause Ruff to
/// respect these exclusions unequivocally.
///
/// This is useful for [`pre-commit`](https://pre-commit.com/), which explicitly passes all
/// changed files to the [`ruff-pre-commit`](https://github.com/astral-sh/ruff-pre-commit)
/// plugin, regardless of whether they're marked as excluded by Ruff's own
/// settings.
pub force_exclude: Option<bool>,
#[option(
default = "[]",
value_type = "list[RuleSelector]",
example = r#"
# Skip unused variable rules (`F841`).
ignore = ["F841"]
"#
)]
/// A list of rule codes or prefixes to ignore. Prefixes can specify exact
/// rules (like `F841`), entire categories (like `F`), or anything in
/// between.
///
/// When breaking ties between enabled and disabled rules (via `select` and
/// `ignore`, respectively), more specific prefixes override less
/// specific prefixes.
pub ignore: Option<Vec<RuleSelector>>,
#[option(
default = "false",
value_type = "bool",
example = r#"
ignore-init-module-imports = true
"#
)]
/// Avoid automatically removing unused imports in `__init__.py` files. Such
/// imports will still be flagged, but with a dedicated message suggesting
/// that the import is either added to the module's `__all__` symbol, or
/// re-exported with a redundant alias (e.g., `import os as os`).
pub ignore_init_module_imports: Option<bool>,
#[option(
default = r#"["*.py", "*.pyi", "**/pyproject.toml"]"#,
value_type = "list[str]",
example = r#"
include = ["*.py"]
"#
)]
/// A list of file patterns to include when linting.
///
/// Inclusion are based on globs, and should be single-path patterns, like
/// `*.pyw`, to include any file with the `.pyw` extension. `pyproject.toml` is
/// included here not for configuration but because we lint whether e.g. the
/// `[project]` matches the schema.
///
/// For more information on the glob syntax, refer to the [`globset` documentation](https://docs.rs/globset/latest/globset/#syntax).
pub include: Option<Vec<String>>,
#[option(
default = "88",
value_type = "int",
example = r#"
# Allow lines to be as long as 120 characters.
line-length = 120
"#
)]
/// The line length to use when enforcing long-lines violations (like
/// `E501`). Must be greater than `0`.
pub line_length: Option<LineLength>,
#[option(
default = "4",
value_type = "int",
example = r#"
tab-size = 8
"#
)]
/// The tabulation size to calculate line length.
pub tab_size: Option<TabSize>,
#[option(
default = r#"[]"#,
value_type = "list[str]",
example = r#"logger-objects = ["logging_setup.logger"]"#
)]
/// A list of objects that should be treated equivalently to a
/// `logging.Logger` object.
///
/// This is useful for ensuring proper diagnostics (e.g., to identify
/// `logging` deprecations and other best-practices) for projects that
/// re-export a `logging.Logger` object from a common module.
///
/// For example, if you have a module `logging_setup.py` with the following
/// contents:
/// ```python
/// import logging
///
/// logger = logging.getLogger(__name__)
/// ```
///
/// Adding `"logging_setup.logger"` to `logger-objects` will ensure that
/// `logging_setup.logger` is treated as a `logging.Logger` object when
/// imported from other modules (e.g., `from logging_setup import logger`).
pub logger_objects: Option<Vec<String>>,
#[option(
default = "None",
value_type = "str",
example = r#"
required-version = "0.0.193"
"#
)]
/// Require a specific version of Ruff to be running (useful for unifying
/// results across many environments, e.g., with a `pyproject.toml`
/// file).
pub required_version: Option<Version>,
#[option(
default = "true",
value_type = "bool",
example = r#"
respect-gitignore = false
"#
)]
/// Whether to automatically exclude files that are ignored by `.ignore`,
/// `.gitignore`, `.git/info/exclude`, and global `gitignore` files.
/// Enabled by default.
pub respect_gitignore: Option<bool>,
#[option(
default = r#"["E", "F"]"#,
value_type = "list[RuleSelector]",
example = r#"
# On top of the defaults (`E`, `F`), enable flake8-bugbear (`B`) and flake8-quotes (`Q`).
select = ["E", "F", "B", "Q"]
"#
)]
/// A list of rule codes or prefixes to enable. Prefixes can specify exact
/// rules (like `F841`), entire categories (like `F`), or anything in
/// between.
///
/// When breaking ties between enabled and disabled rules (via `select` and
/// `ignore`, respectively), more specific prefixes override less
/// specific prefixes.
pub select: Option<Vec<RuleSelector>>,
#[option(
default = "false",
value_type = "bool",
example = r#"
# By default, always show source code snippets.
show-source = true
"#
)]
/// Whether to show source code snippets when reporting lint violations
/// (overridden by the `--show-source` command-line flag).
pub show_source: Option<bool>,
#[option(
default = "false",
value_type = "bool",
example = r#"
# Enumerate all fixed violations.
show-fixes = true
"#
)]
/// Whether to show an enumeration of all autofixed lint violations
/// (overridden by the `--show-fixes` command-line flag).
pub show_fixes: Option<bool>,
#[option(
default = r#"["."]"#,
value_type = "list[str]",
example = r#"
# Allow imports relative to the "src" and "test" directories.
src = ["src", "test"]
"#
)]
/// The directories to consider when resolving first- vs. third-party
/// imports.
///
/// As an example: given a Python package structure like:
///
/// ```text
/// my_project
/// ├── pyproject.toml
/// └── src
/// └── my_package
/// ├── __init__.py
/// ├── foo.py
/// └── bar.py
/// ```
///
/// The `./src` directory should be included in the `src` option
/// (e.g., `src = ["src"]`), such that when resolving imports,
/// `my_package.foo` is considered a first-party import.
///
/// When omitted, the `src` directory will typically default to the
/// directory containing the nearest `pyproject.toml`, `ruff.toml`, or
/// `.ruff.toml` file (the "project root"), unless a configuration file
/// is explicitly provided (e.g., via the `--config` command-line flag).
///
/// This field supports globs. For example, if you have a series of Python
/// packages in a `python_modules` directory, `src = ["python_modules/*"]`
/// would expand to incorporate all of the packages in that directory. User
/// home directory and environment variables will also be expanded.
pub src: Option<Vec<String>>,
#[option(
default = r#"[]"#,
value_type = "list[str]",
example = r#"
namespace-packages = ["airflow/providers"]
"#
)]
/// Mark the specified directories as namespace packages. For the purpose of
/// module resolution, Ruff will treat those directories as if they
/// contained an `__init__.py` file.
pub namespace_packages: Option<Vec<String>>,
#[option(
default = r#""py38""#,
value_type = r#""py37" | "py38" | "py39" | "py310" | "py311" | "py312""#,
example = r#"
# Always generate Python 3.7-compatible code.
target-version = "py37"
"#
)]
/// The minimum Python version to target, e.g., when considering automatic
/// code upgrades, like rewriting type annotations. Ruff will not propose
/// changes using features that are not available in the given version.
///
/// For example, to represent supporting Python >=3.10 or ==3.10
/// specify `target-version = "py310"`.
///
/// If omitted, and Ruff is configured via a `pyproject.toml` file, the
/// target version will be inferred from its `project.requires-python`
/// field (e.g., `requires-python = ">=3.8"`). If Ruff is configured via
/// `ruff.toml` or `.ruff.toml`, no such inference will be performed.
pub target_version: Option<PythonVersion>,
#[option(
default = "false",
value_type = "bool",
example = r#"
# Enable preview mode
preview-mode = true
"#
)]
/// Whether to enable preview mode. When preview mode is enabled, Ruff will
/// use unstable rules and fixes.
pub preview_mode: Option<bool>,
#[option(
default = r#"["TODO", "FIXME", "XXX"]"#,
value_type = "list[str]",
example = r#"task-tags = ["HACK"]"#
)]
/// A list of task tags to recognize (e.g., "TODO", "FIXME", "XXX").
///
/// Comments starting with these tags will be ignored by commented-out code
/// detection (`ERA`), and skipped by line-length rules (`E501`) if
/// `ignore-overlong-task-comments` is set to `true`.
pub task_tags: Option<Vec<String>>,
#[option(
default = r#"[]"#,
value_type = "list[str]",
example = r#"typing-modules = ["airflow.typing_compat"]"#
)]
/// A list of modules whose exports should be treated equivalently to
/// members of the `typing` module.
///
/// This is useful for ensuring proper type annotation inference for
/// projects that re-export `typing` and `typing_extensions` members
/// from a compatibility module. If omitted, any members imported from
/// modules apart from `typing` and `typing_extensions` will be treated
/// as ordinary Python objects.
pub typing_modules: Option<Vec<String>>,
#[option(
default = "[]",
value_type = "list[RuleSelector]",
example = r#"
# Disable autofix for unused imports (`F401`).
unfixable = ["F401"]
"#
)]
/// A list of rule codes or prefixes to consider non-autofix-able.
pub unfixable: Option<Vec<RuleSelector>>,
#[option_group]
/// Options for the `flake8-annotations` plugin.
pub flake8_annotations: Option<Flake8AnnotationsOptions>,
#[option_group]
/// Options for the `flake8-bandit` plugin.
pub flake8_bandit: Option<Flake8BanditOptions>,
#[option_group]
/// Options for the `flake8-bugbear` plugin.
pub flake8_bugbear: Option<Flake8BugbearOptions>,
#[option_group]
/// Options for the `flake8-builtins` plugin.
pub flake8_builtins: Option<Flake8BuiltinsOptions>,
#[option_group]
/// Options for the `flake8-comprehensions` plugin.
pub flake8_comprehensions: Option<Flake8ComprehensionsOptions>,
#[option_group]
/// Options for the `flake8-copyright` plugin.
pub flake8_copyright: Option<Flake8CopyrightOptions>,
#[option_group]
/// Options for the `flake8-errmsg` plugin.
pub flake8_errmsg: Option<Flake8ErrMsgOptions>,
#[option_group]
/// Options for the `flake8-quotes` plugin.
pub flake8_quotes: Option<Flake8QuotesOptions>,
#[option_group]
/// Options for the `flake8_self` plugin.
pub flake8_self: Option<Flake8SelfOptions>,
#[option_group]
/// Options for the `flake8-tidy-imports` plugin.
pub flake8_tidy_imports: Option<Flake8TidyImportsOptions>,
#[option_group]
/// Options for the `flake8-type-checking` plugin.
pub flake8_type_checking: Option<Flake8TypeCheckingOptions>,
#[option_group]
/// Options for the `flake8-gettext` plugin.
pub flake8_gettext: Option<Flake8GetTextOptions>,
#[option_group]
/// Options for the `flake8-implicit-str-concat` plugin.
pub flake8_implicit_str_concat: Option<Flake8ImplicitStrConcatOptions>,
#[option_group]
/// Options for the `flake8-import-conventions` plugin.
pub flake8_import_conventions: Option<Flake8ImportConventionsOptions>,
#[option_group]
/// Options for the `flake8-pytest-style` plugin.
pub flake8_pytest_style: Option<Flake8PytestStyleOptions>,
#[option_group]
/// Options for the `flake8-unused-arguments` plugin.
pub flake8_unused_arguments: Option<Flake8UnusedArgumentsOptions>,
#[option_group]
/// Options for the `isort` plugin.
pub isort: Option<IsortOptions>,
#[option_group]
/// Options for the `mccabe` plugin.
pub mccabe: Option<McCabeOptions>,
#[option_group]
/// Options for the `pep8-naming` plugin.
pub pep8_naming: Option<Pep8NamingOptions>,
#[option_group]
/// Options for the `pycodestyle` plugin.
pub pycodestyle: Option<PycodestyleOptions>,
#[option_group]
/// Options for the `pydocstyle` plugin.
pub pydocstyle: Option<PydocstyleOptions>,
#[option_group]
/// Options for the `pyflakes` plugin.
pub pyflakes: Option<PyflakesOptions>,
#[option_group]
/// Options for the `pylint` plugin.
pub pylint: Option<PylintOptions>,
#[option_group]
/// Options for the `pyupgrade` plugin.
pub pyupgrade: Option<PyUpgradeOptions>,
// Tables are required to go last.
#[option(
default = "{}",
value_type = "dict[str, list[RuleSelector]]",
example = r#"
# Ignore `E402` (import violations) in all `__init__.py` files, and in `path/to/file.py`.
[tool.ruff.per-file-ignores]
"__init__.py" = ["E402"]
"path/to/file.py" = ["E402"]
"#
)]
/// A list of mappings from file pattern to rule codes or prefixes to
/// exclude, when considering any matching files.
pub per_file_ignores: Option<FxHashMap<String, Vec<RuleSelector>>>,
#[option(
default = "{}",
value_type = "dict[str, list[RuleSelector]]",
example = r#"
# Also ignore `E402` in all `__init__.py` files.
[tool.ruff.extend-per-file-ignores]
"__init__.py" = ["E402"]
"#
)]
/// A list of mappings from file pattern to rule codes or prefixes to
/// exclude, in addition to any rules excluded by `per-file-ignores`.
pub extend_per_file_ignores: Option<FxHashMap<String, Vec<RuleSelector>>>,
}
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[derive(
Debug, PartialEq, Eq, Default, ConfigurationOptions, CombineOptions, Serialize, Deserialize,
)]
#[serde(deny_unknown_fields, rename_all = "kebab-case")]
pub struct Flake8AnnotationsOptions {
#[option(
default = "false",
value_type = "bool",
example = "mypy-init-return = true"
)]
/// Whether to allow the omission of a return type hint for `__init__` if at
/// least one argument is annotated.
pub mypy_init_return: Option<bool>,
#[option(
default = "false",
value_type = "bool",
example = "suppress-dummy-args = true"
)]
/// Whether to suppress `ANN000`-level violations for arguments matching the
/// "dummy" variable regex (like `_`).
pub suppress_dummy_args: Option<bool>,
#[option(
default = "false",
value_type = "bool",
example = "suppress-none-returning = true"
)]
/// Whether to suppress `ANN200`-level violations for functions that meet
/// either of the following criteria:
///
/// - Contain no `return` statement.
/// - Explicit `return` statement(s) all return `None` (explicitly or
/// implicitly).
pub suppress_none_returning: Option<bool>,
#[option(
default = "false",
value_type = "bool",
example = "allow-star-arg-any = true"
)]
/// Whether to suppress `ANN401` for dynamically typed `*args` and
/// `**kwargs` arguments.
pub allow_star_arg_any: Option<bool>,
#[option(
default = "false",
value_type = "bool",
example = "ignore-fully-untyped = true"
)]
/// Whether to suppress `ANN*` rules for any declaration
/// that hasn't been typed at all.
/// This makes it easier to gradually add types to a codebase.
pub ignore_fully_untyped: Option<bool>,
}
impl Flake8AnnotationsOptions {
pub fn into_settings(self) -> ruff::rules::flake8_annotations::settings::Settings {
ruff::rules::flake8_annotations::settings::Settings {
mypy_init_return: self.mypy_init_return.unwrap_or(false),
suppress_dummy_args: self.suppress_dummy_args.unwrap_or(false),
suppress_none_returning: self.suppress_none_returning.unwrap_or(false),
allow_star_arg_any: self.allow_star_arg_any.unwrap_or(false),
ignore_fully_untyped: self.ignore_fully_untyped.unwrap_or(false),
}
}
}
#[derive(
Debug, PartialEq, Eq, Default, Serialize, Deserialize, ConfigurationOptions, CombineOptions,
)]
#[serde(deny_unknown_fields, rename_all = "kebab-case")]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
pub struct Flake8BanditOptions {
#[option(
default = "[\"/tmp\", \"/var/tmp\", \"/dev/shm\"]",
value_type = "list[str]",
example = "hardcoded-tmp-directory = [\"/foo/bar\"]"
)]
/// A list of directories to consider temporary.
pub hardcoded_tmp_directory: Option<Vec<String>>,
#[option(
default = "[]",
value_type = "list[str]",
example = "extend-hardcoded-tmp-directory = [\"/foo/bar\"]"
)]
/// A list of directories to consider temporary, in addition to those
/// specified by `hardcoded-tmp-directory`.
pub hardcoded_tmp_directory_extend: Option<Vec<String>>,
#[option(
default = "false",
value_type = "bool",
example = "check-typed-exception = true"
)]
/// Whether to disallow `try`-`except`-`pass` (`S110`) for specific
/// exception types. By default, `try`-`except`-`pass` is only
/// disallowed for `Exception` and `BaseException`.
pub check_typed_exception: Option<bool>,
}
impl Flake8BanditOptions {
pub fn into_settings(self) -> ruff::rules::flake8_bandit::settings::Settings {
ruff::rules::flake8_bandit::settings::Settings {
hardcoded_tmp_directory: self
.hardcoded_tmp_directory
.unwrap_or_else(ruff::rules::flake8_bandit::settings::default_tmp_dirs)
.into_iter()
.chain(self.hardcoded_tmp_directory_extend.unwrap_or_default())
.collect(),
check_typed_exception: self.check_typed_exception.unwrap_or(false),
}
}
}
#[derive(
Debug, PartialEq, Eq, Default, Serialize, Deserialize, ConfigurationOptions, CombineOptions,
)]
#[serde(deny_unknown_fields, rename_all = "kebab-case")]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
pub struct Flake8BugbearOptions {
#[option(
default = r#"[]"#,
value_type = "list[str]",
example = r#"
# Allow default arguments like, e.g., `data: List[str] = fastapi.Query(None)`.
extend-immutable-calls = ["fastapi.Depends", "fastapi.Query"]
"#
)]
/// Additional callable functions to consider "immutable" when evaluating, e.g., the
/// `function-call-in-default-argument` rule (`B008`) or `function-call-in-dataclass-defaults`
/// rule (`RUF009`).
///
/// Expects to receive a list of fully-qualified names (e.g., `fastapi.Query`, rather than
/// `Query`).
pub extend_immutable_calls: Option<Vec<String>>,
}
impl Flake8BugbearOptions {
pub fn into_settings(self) -> ruff::rules::flake8_bugbear::settings::Settings {
ruff::rules::flake8_bugbear::settings::Settings {
extend_immutable_calls: self.extend_immutable_calls.unwrap_or_default(),
}
}
}
#[derive(
Debug, PartialEq, Eq, Default, Serialize, Deserialize, ConfigurationOptions, CombineOptions,
)]
#[serde(deny_unknown_fields, rename_all = "kebab-case")]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
pub struct Flake8BuiltinsOptions {
#[option(
default = r#"[]"#,
value_type = "list[str]",
example = "builtins-ignorelist = [\"id\"]"
)]
/// Ignore list of builtins.
pub builtins_ignorelist: Option<Vec<String>>,
}
impl Flake8BuiltinsOptions {
pub fn into_settings(self) -> ruff::rules::flake8_builtins::settings::Settings {
ruff::rules::flake8_builtins::settings::Settings {
builtins_ignorelist: self.builtins_ignorelist.unwrap_or_default(),
}
}
}
#[derive(
Debug, PartialEq, Eq, Default, Serialize, Deserialize, ConfigurationOptions, CombineOptions,
)]
#[serde(deny_unknown_fields, rename_all = "kebab-case")]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
pub struct Flake8ComprehensionsOptions {
#[option(
default = "false",
value_type = "bool",
example = "allow-dict-calls-with-keyword-arguments = true"
)]
/// Allow `dict` calls that make use of keyword arguments (e.g., `dict(a=1, b=2)`).
pub allow_dict_calls_with_keyword_arguments: Option<bool>,
}
impl Flake8ComprehensionsOptions {
pub fn into_settings(self) -> ruff::rules::flake8_comprehensions::settings::Settings {
ruff::rules::flake8_comprehensions::settings::Settings {
allow_dict_calls_with_keyword_arguments: self
.allow_dict_calls_with_keyword_arguments
.unwrap_or_default(),
}
}
}
#[derive(
Debug, PartialEq, Eq, Default, Serialize, Deserialize, ConfigurationOptions, CombineOptions,
)]
#[serde(deny_unknown_fields, rename_all = "kebab-case")]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
pub struct Flake8CopyrightOptions {
#[option(
default = r#"(?i)Copyright\s+(\(C\)\s+)?\d{4}([-,]\d{4})*"#,
value_type = "str",
example = r#"notice-rgx = "(?i)Copyright \\(C\\) \\d{4}""#
)]
/// The regular expression used to match the copyright notice, compiled
/// with the [`regex`](https://docs.rs/regex/latest/regex/) crate.
///
/// Defaults to `(?i)Copyright\s+(\(C\)\s+)?\d{4}(-\d{4})*`, which matches
/// the following:
/// - `Copyright 2023`
/// - `Copyright (C) 2023`
/// - `Copyright 2021-2023`
/// - `Copyright (C) 2021-2023`
pub notice_rgx: Option<String>,
#[option(default = "None", value_type = "str", example = r#"author = "Ruff""#)]
/// Author to enforce within the copyright notice. If provided, the
/// author must be present immediately following the copyright notice.
pub author: Option<String>,
#[option(
default = r#"0"#,
value_type = "int",
example = r#"
# Avoid enforcing a header on files smaller than 1024 bytes.
min-file-size = 1024
"#
)]
/// A minimum file size (in bytes) required for a copyright notice to
/// be enforced. By default, all files are validated.
pub min_file_size: Option<usize>,
}
impl Flake8CopyrightOptions {
pub fn try_into_settings(self) -> anyhow::Result<flake8_copyright::settings::Settings> {
Ok(flake8_copyright::settings::Settings {
notice_rgx: self
.notice_rgx
.map(|pattern| Regex::new(&pattern))
.transpose()?
.unwrap_or_else(|| flake8_copyright::settings::COPYRIGHT.clone()),
author: self.author,
min_file_size: self.min_file_size.unwrap_or_default(),
})
}
}
#[derive(
Debug, PartialEq, Eq, Default, Serialize, Deserialize, ConfigurationOptions, CombineOptions,
)]
#[serde(deny_unknown_fields, rename_all = "kebab-case")]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
pub struct Flake8ErrMsgOptions {
#[option(default = "0", value_type = "int", example = "max-string-length = 20")]
/// Maximum string length for string literals in exception messages.
pub max_string_length: Option<usize>,
}
impl Flake8ErrMsgOptions {
pub fn into_settings(self) -> flake8_errmsg::settings::Settings {
flake8_errmsg::settings::Settings {
max_string_length: self.max_string_length.unwrap_or_default(),
}
}
}
#[derive(
Debug, PartialEq, Eq, Default, Serialize, Deserialize, ConfigurationOptions, CombineOptions,
)]
#[serde(deny_unknown_fields, rename_all = "kebab-case")]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
pub struct Flake8GetTextOptions {
#[option(
default = r#"["_", "gettext", "ngettext"]"#,
value_type = "list[str]",
example = r#"function-names = ["_", "gettext", "ngettext", "ugettetxt"]"#
)]
/// The function names to consider as internationalization calls.
pub function_names: Option<Vec<String>>,
#[option(
default = r#"[]"#,
value_type = "list[str]",
example = r#"extend-function-names = ["ugettetxt"]"#
)]
/// Additional function names to consider as internationalization calls, in addition to those
/// included in `function-names`.
pub extend_function_names: Option<Vec<String>>,
}
impl Flake8GetTextOptions {
pub fn into_settings(self) -> flake8_gettext::settings::Settings {
flake8_gettext::settings::Settings {
functions_names: self
.function_names
.unwrap_or_else(flake8_gettext::settings::default_func_names)
.into_iter()
.chain(self.extend_function_names.unwrap_or_default())
.collect(),
}
}
}
#[derive(
Debug, PartialEq, Eq, Default, Serialize, Deserialize, ConfigurationOptions, CombineOptions,
)]
#[serde(deny_unknown_fields, rename_all = "kebab-case")]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
pub struct Flake8ImplicitStrConcatOptions {
#[option(
default = r#"true"#,
value_type = "bool",
example = r#"
allow-multiline = false
"#
)]
/// Whether to allow implicit string concatenations for multiline strings.
/// By default, implicit concatenations of multiline strings are
/// allowed (but continuation lines, delimited with a backslash, are
/// prohibited).
///
/// Note that setting `allow-multiline = false` should typically be coupled
/// with disabling `explicit-string-concatenation` (`ISC003`). Otherwise,
/// both explicit and implicit multiline string concatenations will be seen
/// as violations.
pub allow_multiline: Option<bool>,
}
impl Flake8ImplicitStrConcatOptions {
pub fn into_settings(self) -> flake8_implicit_str_concat::settings::Settings {
flake8_implicit_str_concat::settings::Settings {
allow_multiline: self.allow_multiline.unwrap_or(true),
}
}
}
#[derive(
Debug, PartialEq, Eq, Default, Serialize, Deserialize, ConfigurationOptions, CombineOptions,
)]
#[serde(deny_unknown_fields, rename_all = "kebab-case")]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
pub struct Flake8ImportConventionsOptions {
#[option(
default = r#"{"altair": "alt", "matplotlib": "mpl", "matplotlib.pyplot": "plt", "numpy": "np", "pandas": "pd", "seaborn": "sns", "tensorflow": "tf", "tkinter": "tk", "holoviews": "hv", "panel": "pn", "plotly.express": "px", "polars": "pl", "pyarrow": "pa"}"#,
value_type = "dict[str, str]",
example = r#"
[tool.ruff.flake8-import-conventions.aliases]
# Declare the default aliases.
altair = "alt"
"matplotlib.pyplot" = "plt"
numpy = "np"
pandas = "pd"
seaborn = "sns"
scipy = "sp"
"#
)]
/// The conventional aliases for imports. These aliases can be extended by
/// the `extend_aliases` option.
pub aliases: Option<FxHashMap<String, String>>,
#[option(
default = r#"{}"#,
value_type = "dict[str, str]",
example = r#"
[tool.ruff.flake8-import-conventions.extend-aliases]
# Declare a custom alias for the `matplotlib` module.
"dask.dataframe" = "dd"
"#
)]
/// A mapping from module to conventional import alias. These aliases will
/// be added to the `aliases` mapping.
pub extend_aliases: Option<FxHashMap<String, String>>,
#[option(
default = r#"{}"#,
value_type = "dict[str, list[str]]",
example = r#"
[tool.ruff.flake8-import-conventions.banned-aliases]
# Declare the banned aliases.
"tensorflow.keras.backend" = ["K"]