|
| 1 | +// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file |
| 2 | +// for details. All rights reserved. Use of this source code is governed by a |
| 3 | +// BSD-style license that can be found in the LICENSE file. |
| 4 | + |
| 5 | +import 'package:analyzer/source/error_processor.dart'; |
| 6 | +import 'package:analyzer/src/utilities/extensions/string.dart'; |
| 7 | + |
| 8 | +/// Options (keys) that can be specified in an analysis options file. |
| 9 | +final class AnalysisOptionsFile { |
| 10 | + // Top-level options. |
| 11 | + static const String analyzer = 'analyzer'; |
| 12 | + static const String codeStyle = 'code-style'; |
| 13 | + static const String formatter = 'formatter'; |
| 14 | + static const String linter = 'linter'; |
| 15 | + |
| 16 | + /// The shared key for top-level plugins and `analyzer`-level plugins. |
| 17 | + static const String plugins = 'plugins'; |
| 18 | + |
| 19 | + // `analyzer` analysis options. |
| 20 | + static const String cannotIgnore = 'cannot-ignore'; |
| 21 | + static const String enableExperiment = 'enable-experiment'; |
| 22 | + static const String errors = 'errors'; |
| 23 | + static const String exclude = 'exclude'; |
| 24 | + static const String include = 'include'; |
| 25 | + static const String language = 'language'; |
| 26 | + static const String optionalChecks = 'optional-checks'; |
| 27 | + static const String strongMode = 'strong-mode'; |
| 28 | + |
| 29 | + // Optional checks options. |
| 30 | + static const String chromeOsManifestChecks = 'chrome-os-manifest-checks'; |
| 31 | + |
| 32 | + // Strong mode options (see AnalysisOptionsImpl for documentation). |
| 33 | + static const String declarationCasts = 'declaration-casts'; |
| 34 | + static const String implicitCasts = 'implicit-casts'; |
| 35 | + static const String implicitDynamic = 'implicit-dynamic'; |
| 36 | + |
| 37 | + // Language options (see AnalysisOptionsImpl for documentation). |
| 38 | + static const String strictCasts = 'strict-casts'; |
| 39 | + static const String strictInference = 'strict-inference'; |
| 40 | + static const String strictRawTypes = 'strict-raw-types'; |
| 41 | + |
| 42 | + // Code style options. |
| 43 | + static const String format = 'format'; |
| 44 | + |
| 45 | + /// Ways to say `ignore`. |
| 46 | + static const List<String> ignoreSynonyms = ['ignore', 'false']; |
| 47 | + |
| 48 | + /// Valid error `severity`s. |
| 49 | + static final List<String> severities = List.unmodifiable(severityMap.keys); |
| 50 | + |
| 51 | + /// Ways to say `include`. |
| 52 | + static const List<String> includeSynonyms = ['include', 'true']; |
| 53 | + |
| 54 | + // Formatter options. |
| 55 | + static const String pageWidth = 'page_width'; |
| 56 | + static const String trailingCommas = 'trailing_commas'; |
| 57 | + |
| 58 | + // Linter options. |
| 59 | + static const String rules = 'rules'; |
| 60 | + |
| 61 | + // Plugins options. |
| 62 | + static const String diagnostics = 'diagnostics'; |
| 63 | + static const String path = 'path'; |
| 64 | + static const String version = 'version'; |
| 65 | + |
| 66 | + /// Supported 'plugins' options. |
| 67 | + static const Set<String> pluginsOptions = {diagnostics, path, version}; |
| 68 | + |
| 69 | + static const String propagateLinterExceptions = 'propagate-linter-exceptions'; |
| 70 | + |
| 71 | + /// Ways to say `true` or `false`. |
| 72 | + static const List<String> trueOrFalse = ['true', 'false']; |
| 73 | + |
| 74 | + /// Supported top-level `analyzer` options. |
| 75 | + static const Set<String> analyzerOptions = { |
| 76 | + cannotIgnore, |
| 77 | + enableExperiment, |
| 78 | + errors, |
| 79 | + exclude, |
| 80 | + language, |
| 81 | + optionalChecks, |
| 82 | + plugins, |
| 83 | + strongMode, |
| 84 | + }; |
| 85 | + |
| 86 | + /// Supported `analyzer` strong-mode options. |
| 87 | + /// |
| 88 | + /// This section is deprecated. |
| 89 | + static const Set<String> strongModeOptions = { |
| 90 | + declarationCasts, |
| 91 | + implicitCasts, |
| 92 | + implicitDynamic, |
| 93 | + }; |
| 94 | + |
| 95 | + /// Supported `analyzer` language options. |
| 96 | + static const Set<String> languageOptions = { |
| 97 | + strictCasts, |
| 98 | + strictInference, |
| 99 | + strictRawTypes, |
| 100 | + }; |
| 101 | + |
| 102 | + /// Supported 'linter' options. |
| 103 | + static const Set<String> linterOptions = {rules}; |
| 104 | + |
| 105 | + /// Supported 'analyzer' optional checks options. |
| 106 | + static const Set<String> optionalChecksOptions = { |
| 107 | + chromeOsManifestChecks, |
| 108 | + propagateLinterExceptions, |
| 109 | + }; |
| 110 | + |
| 111 | + /// Proposed values for a `true` or `false` option. |
| 112 | + static String get trueOrFalseProposal => |
| 113 | + AnalysisOptionsFile.trueOrFalse.quotedAndCommaSeparatedWithAnd; |
| 114 | +} |
0 commit comments