Skip to content

Commit db352c0

Browse files
srawlinsCommit Queue
authored andcommitted
analyzer: rename some variables in options_file_validator
I think it was me who renamed this variable `sourceIsOptionsForContextRoot` earlier, but that was a complete misunderstanding of it; the options file could be found anywhere, maybe in the context root, maybe in a _different_ context root, maybe in the parent of one, or a child directory of one. That is not what this field indicates; it indicates whether the options file is being analyzed as part of an include chain or not. Additionally, `_TopLevelOptionValidator.pluginName` made no sense; `sectionName` is a good name. Change-Id: Ifc96e18d3a5e6b4988b1bf1ba4fb588605c73315 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/449077 Commit-Queue: Samuel Rawlins <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]>
1 parent 812e834 commit db352c0

File tree

3 files changed

+22
-18
lines changed

3 files changed

+22
-18
lines changed

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ List<Diagnostic> analyzeAnalysisOptions(
4747
void addDirectErrorOrIncludedError(
4848
List<Diagnostic> validationErrors,
4949
Source source, {
50-
required bool sourceIsOptionsForContextRoot,
50+
required bool isSourcePrimary,
5151
}) {
52-
if (!sourceIsOptionsForContextRoot) {
52+
if (!isSourcePrimary) {
5353
// [source] is an included file, and we should only report errors in
5454
// [initialSource], noting that the included file has warnings.
5555
for (Diagnostic error in validationErrors) {
@@ -78,18 +78,18 @@ List<Diagnostic> analyzeAnalysisOptions(
7878

7979
// Validates the specified options and any included option files.
8080
void validate(Source source, YamlMap options) {
81-
var sourceIsOptionsForContextRoot = initialIncludeSpan == null;
81+
var isSourcePrimary = initialIncludeSpan == null;
8282
var validationErrors = OptionsFileValidator(
8383
source,
8484
sdkVersionConstraint: sdkVersionConstraint,
85-
sourceIsOptionsForContextRoot: sourceIsOptionsForContextRoot,
85+
isPrimarySource: isSourcePrimary,
8686
optionsProvider: optionsProvider,
8787
resourceProvider: resourceProvider,
8888
).validate(options);
8989
addDirectErrorOrIncludedError(
9090
validationErrors,
9191
source,
92-
sourceIsOptionsForContextRoot: sourceIsOptionsForContextRoot,
92+
isSourcePrimary: isSourcePrimary,
9393
);
9494

9595
var includeNode = options.valueAt(AnalysisOptionsFile.include);
@@ -99,7 +99,7 @@ List<Diagnostic> analyzeAnalysisOptions(
9999
addDirectErrorOrIncludedError(
100100
_validateLegacyPluginsOption(source, options: options),
101101
source,
102-
sourceIsOptionsForContextRoot: sourceIsOptionsForContextRoot,
102+
isSourcePrimary: isSourcePrimary,
103103
);
104104
return;
105105
}
@@ -178,7 +178,7 @@ List<Diagnostic> analyzeAnalysisOptions(
178178
firstEnabledPluginName: firstPluginName,
179179
),
180180
source,
181-
sourceIsOptionsForContextRoot: sourceIsOptionsForContextRoot,
181+
isSourcePrimary: isSourcePrimary,
182182
);
183183
} on OptionsFormatException catch (e) {
184184
var args = [
@@ -208,7 +208,7 @@ List<Diagnostic> analyzeAnalysisOptions(
208208
};
209209

210210
for (var includeValue in includes) {
211-
if (sourceIsOptionsForContextRoot) {
211+
if (isSourcePrimary) {
212212
initialIncludeSpan = null;
213213
includeChain.clear();
214214
}
@@ -296,7 +296,7 @@ class OptionsFileValidator {
296296
OptionsFileValidator(
297297
this._source, {
298298
VersionConstraint? sdkVersionConstraint,
299-
required bool sourceIsOptionsForContextRoot,
299+
required bool isPrimarySource,
300300
required AnalysisOptionsProvider optionsProvider,
301301
required ResourceProvider resourceProvider,
302302
}) : _validators = [
@@ -308,7 +308,7 @@ class OptionsFileValidator {
308308
resourceProvider: resourceProvider,
309309
optionsProvider: optionsProvider,
310310
sdkVersionConstraint: sdkVersionConstraint,
311-
sourceIsOptionsForContextRoot: sourceIsOptionsForContextRoot,
311+
isPrimarySource: isPrimarySource,
312312
),
313313
_PluginsOptionsValidator(),
314314
];
@@ -1077,12 +1077,12 @@ class _StrongModeOptionValueValidator extends OptionsValidator {
10771077
/// - lib/generated/
10781078
/// ```
10791079
class _TopLevelOptionValidator extends OptionsValidator {
1080-
final String pluginName;
1080+
final String sectionName;
10811081
final Set<String> supportedOptions;
10821082
final String _valueProposal;
10831083
final AnalysisOptionsWarningCode _warningCode;
10841084

1085-
_TopLevelOptionValidator(this.pluginName, this.supportedOptions)
1085+
_TopLevelOptionValidator(this.sectionName, this.supportedOptions)
10861086
: assert(supportedOptions.isNotEmpty),
10871087
_valueProposal = supportedOptions.quotedAndCommaSeparatedWithAnd,
10881088
_warningCode = supportedOptions.length == 1
@@ -1091,7 +1091,7 @@ class _TopLevelOptionValidator extends OptionsValidator {
10911091

10921092
@override
10931093
void validate(DiagnosticReporter reporter, YamlMap options) {
1094-
var node = options.valueAt(pluginName);
1094+
var node = options.valueAt(sectionName);
10951095
if (node == null) return;
10961096
if (node is YamlScalar && node.value == null) return;
10971097

@@ -1109,7 +1109,7 @@ class _TopLevelOptionValidator extends OptionsValidator {
11091109
reporter.atSourceSpan(
11101110
k.span,
11111111
_warningCode,
1112-
arguments: [pluginName, k.valueOrThrow, _valueProposal],
1112+
arguments: [sectionName, k.valueOrThrow, _valueProposal],
11131113
);
11141114
}
11151115
}

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,19 @@ class LinterRuleOptionsValidator extends OptionsValidator {
4747
];
4848

4949
final VersionConstraint? sdkVersionConstraint;
50-
final bool sourceIsOptionsForContextRoot;
50+
51+
/// Whether the linter section being validated as a "primary source;" that is,
52+
/// whether it is not being analyzed as part of a chain of 'include's.
53+
final bool isPrimarySource;
54+
5155
final AnalysisOptionsProvider optionsProvider;
5256
final ResourceProvider resourceProvider;
5357

5458
LinterRuleOptionsValidator({
5559
required this.resourceProvider,
5660
required this.optionsProvider,
5761
this.sdkVersionConstraint,
58-
this.sourceIsOptionsForContextRoot = true,
62+
this.isPrimarySource = true,
5963
});
6064

6165
bool currentSdkAllows(Version? since) {
@@ -400,7 +404,7 @@ class LinterRuleOptionsValidator extends OptionsValidator {
400404

401405
// Report removed or deprecated lint warnings defined directly (and not in
402406
// includes).
403-
if (sourceIsOptionsForContextRoot) {
407+
if (isPrimarySource) {
404408
var state = rule.state;
405409
if (state.isDeprecated && isDeprecatedInCurrentSdk(state)) {
406410
var replacedBy = state.replacedBy;

pkg/analyzer/test/src/options/options_file_validator_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class OptionsFileValidatorTest
7777
with LintRegistrationMixin, ResourceProviderMixin {
7878
late final OptionsFileValidator validator = OptionsFileValidator(
7979
TestSource(),
80-
sourceIsOptionsForContextRoot: true,
80+
isPrimarySource: true,
8181
optionsProvider: optionsProvider,
8282
resourceProvider: resourceProvider,
8383
);

0 commit comments

Comments
 (0)