Skip to content

Commit 3f7df09

Browse files
srawlinsCommit Queue
authored andcommitted
analyzer: Rename analysis options YAML keys variables
We rename `AnalyzerOptions` to `AnalysisFileOptions`, and change it's comment from "`analyzer` analysis options constants." to avoid anyone thinking it is specifying options for the `analyzer` section. Additionally I privatize some of the static values that are only present for validation - they are not meant to be used outside of `options.dart`: `AnalyzerSection._trueOrFalse`, `AnalyzerSection._options`, `AnalyzerSection._strongModeOptions`, `AnalyzerSection._languageOptions`, `LinterSection._options`. I also rename `_TopLevelAnalyzerOptionsValidator` to `_AnalyzerTopLevelOptionsValidator` to align with `_LinterTopLevelOptionsValidator`. Change-Id: I4f5735d8bda8edbaf066387b473c05969c3ba7d5 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/395060 Commit-Queue: Samuel Rawlins <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]>
1 parent 95d25df commit 3f7df09

File tree

8 files changed

+193
-161
lines changed

8 files changed

+193
-161
lines changed

pkg/analysis_server/lib/src/services/completion/yaml/analysis_options_generator.dart

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,29 @@ class AnalysisOptionsGenerator extends YamlCompletionGenerator {
2121
// For example, the lint rules can either be a list or a map, but we only
2222
// suggest list items.
2323
static MapProducer analysisOptionsProducer = MapProducer({
24-
AnalyzerOptions.analyzer: MapProducer({
25-
AnalyzerOptions.enableExperiment: ListProducer(_ExperimentProducer()),
26-
AnalyzerOptions.errors: _ErrorProducer(),
27-
AnalyzerOptions.exclude: EmptyProducer(),
28-
AnalyzerOptions.language: MapProducer({
29-
AnalyzerOptions.strictCasts: EmptyProducer(),
30-
AnalyzerOptions.strictInference: EmptyProducer(),
31-
AnalyzerOptions.strictRawTypes: EmptyProducer(),
24+
AnalysisOptionsFile.analyzer: MapProducer({
25+
AnalysisOptionsFile.enableExperiment: ListProducer(_ExperimentProducer()),
26+
AnalysisOptionsFile.errors: _ErrorProducer(),
27+
AnalysisOptionsFile.exclude: EmptyProducer(),
28+
AnalysisOptionsFile.language: MapProducer({
29+
AnalysisOptionsFile.strictCasts: EmptyProducer(),
30+
AnalysisOptionsFile.strictInference: EmptyProducer(),
31+
AnalysisOptionsFile.strictRawTypes: EmptyProducer(),
3232
}),
33-
AnalyzerOptions.optionalChecks: MapProducer({
34-
AnalyzerOptions.chromeOsManifestChecks: EmptyProducer(),
33+
AnalysisOptionsFile.optionalChecks: MapProducer({
34+
AnalysisOptionsFile.chromeOsManifestChecks: EmptyProducer(),
3535
}),
36-
AnalyzerOptions.plugins: EmptyProducer(),
37-
AnalyzerOptions.propagateLinterExceptions: EmptyProducer(),
36+
AnalysisOptionsFile.plugins: EmptyProducer(),
37+
AnalysisOptionsFile.propagateLinterExceptions: EmptyProducer(),
3838
}),
39-
AnalyzerOptions.codeStyle: MapProducer({
40-
AnalyzerOptions.format: BooleanProducer(),
39+
AnalysisOptionsFile.codeStyle: MapProducer({
40+
AnalysisOptionsFile.format: BooleanProducer(),
4141
}),
42-
AnalyzerOptions.formatter: MapProducer({
43-
AnalyzerOptions.pageWidth: EmptyProducer(),
42+
AnalysisOptionsFile.formatter: MapProducer({
43+
AnalysisOptionsFile.pageWidth: EmptyProducer(),
4444
}),
4545
// TODO(brianwilkerson): Create a producer to produce `package:` URIs.
46-
AnalyzerOptions.include: EmptyProducer(),
46+
AnalysisOptionsFile.include: EmptyProducer(),
4747
// TODO(brianwilkerson): Create constants for 'linter' and 'rules'.
4848
'linter': MapProducer({'rules': ListProducer(_LintRuleProducer())}),
4949
});

pkg/analysis_server/test/src/services/completion/yaml/analysis_options_generator_test.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class AnalysisOptionsGeneratorTest extends YamlGeneratorTest {
5151
analyzer:
5252
^
5353
''');
54-
assertSuggestion('${AnalyzerOptions.enableExperiment}:');
54+
assertSuggestion('${AnalysisOptionsFile.enableExperiment}:');
5555
}
5656

5757
void test_analyzer_enableExperiment() {
@@ -112,7 +112,7 @@ analyzer:
112112
code-style:
113113
^
114114
''');
115-
assertSuggestion('${AnalyzerOptions.format}: ');
115+
assertSuggestion('${AnalysisOptionsFile.format}: ');
116116
}
117117

118118
void test_codeStyle_format() {
@@ -126,10 +126,10 @@ code-style:
126126

127127
void test_empty() {
128128
getCompletions('^');
129-
assertSuggestion('${AnalyzerOptions.analyzer}: ');
130-
assertSuggestion('${AnalyzerOptions.codeStyle}: ');
131-
assertSuggestion('${AnalyzerOptions.formatter}: ');
132-
assertSuggestion('${AnalyzerOptions.include}: ');
129+
assertSuggestion('${AnalysisOptionsFile.analyzer}: ');
130+
assertSuggestion('${AnalysisOptionsFile.codeStyle}: ');
131+
assertSuggestion('${AnalysisOptionsFile.formatter}: ');
132+
assertSuggestion('${AnalysisOptionsFile.include}: ');
133133
// TODO(brianwilkerson): Replace this with a constant.
134134
assertSuggestion('linter: ');
135135
}
@@ -139,7 +139,7 @@ code-style:
139139
formatter:
140140
^
141141
''');
142-
assertSuggestion('${AnalyzerOptions.pageWidth}: ');
142+
assertSuggestion('${AnalysisOptionsFile.pageWidth}: ');
143143
}
144144

145145
void test_linter() {
@@ -257,7 +257,7 @@ analyzer:
257257
- '*.g.dart'
258258
^
259259
''');
260-
assertSuggestion('${AnalyzerOptions.include}: ');
260+
assertSuggestion('${AnalysisOptionsFile.include}: ');
261261
}
262262

263263
@failingTest

pkg/analyzer/lib/source/error_processor.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class ErrorConfig {
3838

3939
code = code.toUpperCase();
4040
var action = v.value.toString().toLowerCase();
41-
if (AnalyzerOptions.ignoreSynonyms.contains(action)) {
41+
if (AnalysisOptionsFile.ignoreSynonyms.contains(action)) {
4242
processors.add(ErrorProcessor.ignore(code));
4343
} else {
4444
var severity = severityMap[action];

pkg/analyzer/lib/src/analysis_options/analysis_options_provider.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class AnalysisOptionsProvider {
7373
if (_sourceFactory == null) {
7474
return options;
7575
}
76-
var includeValue = options.valueAt(AnalyzerOptions.include);
76+
var includeValue = options.valueAt(AnalysisOptionsFile.include);
7777
if (includeValue case YamlScalar(value: String path)) {
7878
var includeUri = _sourceFactory.resolveUri(source, path);
7979
if (includeUri != null) {

pkg/analyzer/lib/src/dart/analysis/analysis_options.dart

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ final class AnalysisOptionsBuilder {
8787
void _applyCodeStyleOptions(YamlNode? codeStyle) {
8888
var useFormatter = false;
8989
if (codeStyle is YamlMap) {
90-
var formatNode = codeStyle.valueAt(AnalyzerOptions.format);
90+
var formatNode = codeStyle.valueAt(AnalysisOptionsFile.format);
9191
if (formatNode != null) {
9292
var formatValue = toBool(formatNode);
9393
if (formatValue is bool) {
@@ -110,7 +110,7 @@ final class AnalysisOptionsBuilder {
110110
void _applyFormatterOptions(YamlNode? formatter) {
111111
int? pageWidth;
112112
if (formatter is YamlMap) {
113-
var formatNode = formatter.valueAt(AnalyzerOptions.pageWidth);
113+
var formatNode = formatter.valueAt(AnalysisOptionsFile.pageWidth);
114114
var formatValue = formatNode?.value;
115115
if (formatValue is int && formatValue > 0) {
116116
pageWidth = formatValue;
@@ -135,11 +135,11 @@ final class AnalysisOptionsBuilder {
135135
}
136136

137137
switch (feature) {
138-
case AnalyzerOptions.strictCasts:
138+
case AnalysisOptionsFile.strictCasts:
139139
strictCasts = boolValue;
140-
case AnalyzerOptions.strictInference:
140+
case AnalysisOptionsFile.strictInference:
141141
strictInference = boolValue;
142-
case AnalyzerOptions.strictRawTypes:
142+
case AnalysisOptionsFile.strictRawTypes:
143143
strictRawTypes = boolValue;
144144
}
145145
});
@@ -177,19 +177,19 @@ final class AnalysisOptionsBuilder {
177177
if (key is YamlScalar && value is YamlScalar) {
178178
if (value.boolValue case var boolValue?) {
179179
switch ('${key.value}') {
180-
case AnalyzerOptions.chromeOsManifestChecks:
180+
case AnalysisOptionsFile.chromeOsManifestChecks:
181181
chromeOsManifestChecks = boolValue;
182-
case AnalyzerOptions.propagateLinterExceptions:
182+
case AnalysisOptionsFile.propagateLinterExceptions:
183183
propagateLinterExceptions = boolValue;
184184
}
185185
}
186186
}
187187
}
188188
case YamlScalar():
189189
switch ('${config.value}') {
190-
case AnalyzerOptions.chromeOsManifestChecks:
190+
case AnalysisOptionsFile.chromeOsManifestChecks:
191191
chromeOsManifestChecks = true;
192-
case AnalyzerOptions.propagateLinterExceptions:
192+
case AnalysisOptionsFile.propagateLinterExceptions:
193193
propagateLinterExceptions = true;
194194
}
195195
}
@@ -226,12 +226,12 @@ final class AnalysisOptionsBuilder {
226226
// TODO(srawlins): In adition to 'version' and 'path', try 'git'.
227227

228228
PluginSource? source;
229-
var versionSource = pluginNode.valueAt(AnalyzerOptions.version);
229+
var versionSource = pluginNode.valueAt(AnalysisOptionsFile.version);
230230
if (versionSource case YamlScalar(:String value)) {
231231
// TODO(srawlins): Handle the 'hosted' key.
232232
source = VersionedPluginSource(constraint: value);
233233
} else {
234-
var pathSource = pluginNode.valueAt(AnalyzerOptions.path);
234+
var pathSource = pluginNode.valueAt(AnalysisOptionsFile.path);
235235
if (pathSource case YamlScalar(:String value)) {
236236
source = PathPluginSource(path: value);
237237
}
@@ -243,7 +243,7 @@ final class AnalysisOptionsBuilder {
243243
return;
244244
}
245245

246-
var diagnostics = pluginNode.valueAt(AnalyzerOptions.diagnostics);
246+
var diagnostics = pluginNode.valueAt(AnalysisOptionsFile.diagnostics);
247247
var diagnosticConfigurations = diagnostics == null
248248
? const <String, RuleConfig>{}
249249
: parseDiagnosticsSection(diagnostics);
@@ -262,7 +262,7 @@ final class AnalysisOptionsBuilder {
262262
return;
263263
}
264264
var stringValues = cannotIgnore.whereType<String>().toSet();
265-
for (var severity in AnalyzerOptions.severities) {
265+
for (var severity in AnalysisOptionsFile.severities) {
266266
if (stringValues.contains(severity)) {
267267
// [severity] is a marker denoting all error codes with severity
268268
// equal to [severity].
@@ -383,14 +383,15 @@ class AnalysisOptionsImpl implements AnalysisOptions {
383383
{required YamlMap optionsMap, File? file}) {
384384
var builder = AnalysisOptionsBuilder()..file = file;
385385

386-
var analyzer = optionsMap.valueAt(AnalyzerOptions.analyzer);
386+
var analyzer = optionsMap.valueAt(AnalysisOptionsFile.analyzer);
387387
if (analyzer is YamlMap) {
388388
// Process filters.
389-
var filters = analyzer.valueAt(AnalyzerOptions.errors);
389+
var filters = analyzer.valueAt(AnalysisOptionsFile.errors);
390390
builder.errorProcessors = ErrorConfig(filters).processors;
391391

392392
// Process enabled experiments.
393-
var experimentNames = analyzer.valueAt(AnalyzerOptions.enableExperiment);
393+
var experimentNames =
394+
analyzer.valueAt(AnalysisOptionsFile.enableExperiment);
394395
if (experimentNames is YamlList) {
395396
var enabledExperiments = <String>[];
396397
for (var element in experimentNames.nodes) {
@@ -407,31 +408,31 @@ class AnalysisOptionsImpl implements AnalysisOptions {
407408
}
408409

409410
// Process optional checks options.
410-
var optionalChecks = analyzer.valueAt(AnalyzerOptions.optionalChecks);
411+
var optionalChecks = analyzer.valueAt(AnalysisOptionsFile.optionalChecks);
411412
builder._applyOptionalChecks(optionalChecks);
412413

413414
// Process language options.
414-
var language = analyzer.valueAt(AnalyzerOptions.language);
415+
var language = analyzer.valueAt(AnalysisOptionsFile.language);
415416
builder._applyLanguageOptions(language);
416417

417418
// Process excludes.
418-
var excludes = analyzer.valueAt(AnalyzerOptions.exclude);
419+
var excludes = analyzer.valueAt(AnalysisOptionsFile.exclude);
419420
builder._applyExcludes(excludes);
420421

421-
var cannotIgnore = analyzer.valueAt(AnalyzerOptions.cannotIgnore);
422+
var cannotIgnore = analyzer.valueAt(AnalysisOptionsFile.cannotIgnore);
422423
builder._applyUnignorables(cannotIgnore);
423424

424425
// Process legacy plugins.
425-
var legacyPlugins = analyzer.valueAt(AnalyzerOptions.plugins);
426+
var legacyPlugins = analyzer.valueAt(AnalysisOptionsFile.plugins);
426427
builder._applyLegacyPlugins(legacyPlugins);
427428
}
428429

429430
// Process the 'formatter' option.
430-
var formatter = optionsMap.valueAt(AnalyzerOptions.formatter);
431+
var formatter = optionsMap.valueAt(AnalysisOptionsFile.formatter);
431432
builder._applyFormatterOptions(formatter);
432433

433434
// Process the 'plugins' option.
434-
var plugins = optionsMap.valueAt(AnalyzerOptions.plugins);
435+
var plugins = optionsMap.valueAt(AnalysisOptionsFile.plugins);
435436
builder._applyPluginsOptions(plugins);
436437

437438
var ruleConfigs = parseLinterSection(optionsMap);
@@ -444,7 +445,7 @@ class AnalysisOptionsImpl implements AnalysisOptions {
444445
}
445446

446447
// Process the 'code-style' option.
447-
var codeStyle = optionsMap.valueAt(AnalyzerOptions.codeStyle);
448+
var codeStyle = optionsMap.valueAt(AnalysisOptionsFile.codeStyle);
448449
builder._applyCodeStyleOptions(codeStyle);
449450

450451
return builder.build();

pkg/analyzer/lib/src/dart/analysis/context_locator.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -576,9 +576,10 @@ class ContextLocatorImpl {
576576
AnalysisOptionsProvider(workspace.createSourceFactory(null, null))
577577
.getOptionsFromFile(optionsFile);
578578

579-
var analyzerOptions = doc.valueAt(AnalyzerOptions.analyzer);
579+
var analyzerOptions = doc.valueAt(AnalysisOptionsFile.analyzer);
580580
if (analyzerOptions is YamlMap) {
581-
var excludeOptions = analyzerOptions.valueAt(AnalyzerOptions.exclude);
581+
var excludeOptions =
582+
analyzerOptions.valueAt(AnalysisOptionsFile.exclude);
582583
if (excludeOptions is YamlList) {
583584
var pathContext = resourceProvider.pathContext;
584585

pkg/analyzer/lib/src/lint/config.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ Map<String, RuleConfig>? parseLinterSection(YamlMap optionsMap) {
6363
var options = optionsMap.valueAt('linter');
6464
// Quick check of basic contract.
6565
if (options is YamlMap) {
66-
var rulesNode = options.valueAt(AnalyzerOptions.rules);
66+
var rulesNode = options.valueAt(AnalysisOptionsFile.rules);
6767
return {
6868
if (rulesNode != null) ...parseDiagnosticsSection(rulesNode),
6969
};

0 commit comments

Comments
 (0)