Skip to content

Commit

Permalink
Version 3.7.0-48.0.dev
Browse files Browse the repository at this point in the history
Merge 1c86ca0 into dev
  • Loading branch information
Dart CI committed Oct 21, 2024
2 parents 86ac622 + 1c86ca0 commit c6514a2
Show file tree
Hide file tree
Showing 21 changed files with 1,349 additions and 245 deletions.
6 changes: 3 additions & 3 deletions DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ vars = {
"sync_http_rev": "91c0dd5ef9a008f0277aadcfd83036f82e572d09",
"tar_rev": "5a1ea943e70cdf3fa5e1102cdbb9418bd9b4b81a",
"term_glyph_rev": "19d8c08a4e81122639129c62049896021910c932",
"test_rev": "8e8a83607d90a7a6813fa378b2d1962a2fc0d44b",
"test_rev": "73e30fb9441878abed529e242ddd3c6d6826c0dc",
"test_descriptor_rev": "a3db1efe3dc725dcae9ee61647d3bfc19b3231ac",
"test_process_rev": "52ee3f5ab70ed965bb7122c1d499081fbccd0bde",
"test_reflective_loader_rev": "598af2f503955020af0eaa82558d574a03934078",
Expand All @@ -206,9 +206,9 @@ vars = {
# meant to be downloaded by users for local testing. You can self-service
# update these by following the go/dart-engprod/browsers.md instructions.
"download_chrome": False,
"chrome_tag": "130.0.6723.31",
"chrome_tag": "131.0.6778.3",
"download_firefox": False,
"firefox_tag": "131.0",
"firefox_tag": "131.0.3",

# Emscripten is used in dart2wasm tests.
"download_emscripten": False,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ConvertIntoGetter extends ResolvedCorrectionProducer {
if (fieldDeclaration == null) {
return;
}
// The field must be final and has only one variable.
// The field must be final and have only one variable.
var fieldList = fieldDeclaration.fields;
var finalKeyword = fieldList.keyword;
if (finalKeyword == null || fieldList.variables.length != 1) {
Expand All @@ -64,7 +64,9 @@ class ConvertIntoGetter extends ResolvedCorrectionProducer {
code += ' ${field.name.lexeme}';
code += ' => ${utils.getNodeText(initializer)}';
code += ';';
var replacementRange = range.startEnd(finalKeyword, fieldDeclaration);

var startingKeyword = fieldList.lateKeyword ?? finalKeyword;
var replacementRange = range.startEnd(startingKeyword, fieldDeclaration);
await builder.addDartFileEdit(file, (builder) {
builder.addSimpleReplacement(replacementRange, code);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@ class ConvertIntoGetterTest extends AssistProcessorTest {
@override
AssistKind get kind => DartAssistKind.CONVERT_INTO_GETTER;

Future<void> test_late() async {
await resolveTestCode('''
class A {
late final int f = 1 + 2;
}
''');
await assertHasAssistAt('f =', '''
class A {
int get f => 1 + 2;
}
''');
}

Future<void> test_noInitializer() async {
verifyNoTestUnitErrors = false;
await resolveTestCode('''
Expand Down
12 changes: 12 additions & 0 deletions pkg/analyzer/lib/dart/analysis/analysis_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,18 @@ abstract class AnalysisOptions {
@Deprecated('Use `PubWorkspacePackage.sdkVersionConstraint` instead')
VersionConstraint? get sdkVersionConstraint;

/// Whether implicit casts should be reported as potential problems.
bool get strictCasts;

/// Whether inference failures are allowed, off by default.
bool get strictInference;

/// Whether raw types (types without explicit type arguments, such as `List`)
/// should be reported as potential problems.
///
/// Raw types are a common source of `dynamic` being introduced implicitly.
bool get strictRawTypes;

/// Return `true` if analysis is to generate warning results (e.g. best
/// practices and analysis based on certain annotations).
bool get warning;
Expand Down
10 changes: 0 additions & 10 deletions pkg/analyzer/lib/dart/element/element2.dart
Original file line number Diff line number Diff line change
Expand Up @@ -278,19 +278,9 @@ abstract class ConstructorFragment implements ExecutableFragment {
@override
ConstructorFragmentName? get name2;

/// The offset of the end of the name in this fragment.
///
/// Returns `null` if the fragment has no name.
int? get nameEnd;

@override
ConstructorFragment? get nextFragment;

/// The offset of the `.` before the constructor name.
///
/// Returns `null` if the constructor is unnamed.
int? get periodOffset;

@override
ConstructorFragment? get previousFragment;
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/analyzer/lib/source/error_processor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ class ErrorProcessor {
code == error.errorCode.name ||
code == error.errorCode.name.toUpperCase();

@override
String toString() => "ErrorProcessor[code='$code', severity=$severity]";

/// Return an error processor associated in the [analysisOptions] for the
/// given [error], or `null` if none is found.
static ErrorProcessor? getProcessor(
Expand Down
12 changes: 3 additions & 9 deletions pkg/analyzer/lib/src/generated/engine.dart
Original file line number Diff line number Diff line change
Expand Up @@ -424,19 +424,13 @@ class AnalysisOptionsImpl implements AnalysisOptions {
/// re-throwing them).
bool propagateLinterExceptions;

/// Whether implicit casts should be reported as potential problems.
@override
final bool strictCasts;

/// A flag indicating whether inference failures are allowed, off by default.
///
/// This option is experimental and subject to change.
@override
final bool strictInference;

/// Whether raw types (types without explicit type arguments, such as `List`)
/// should be reported as potential problems.
///
/// Raw types are a common source of `dynamic` being introduced implicitly.
/// This often leads to cast failures later on in the program.
@override
final bool strictRawTypes;

@override
Expand Down
230 changes: 192 additions & 38 deletions pkg/analyzer/test/src/options/options_provider_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ import 'package:test_reflective_loader/test_reflective_loader.dart';
main() {
defineReflectiveSuite(() {
defineReflectiveTests(OptionsProviderTest);

// TODO(srawlins): add tests for multiple includes.
// TODO(srawlins): add tests with duplicate legacy plugin names.
// https://github.com/dart-lang/sdk/issues/50980
});
}

Expand Down Expand Up @@ -79,62 +83,212 @@ analyzer:
expect(options.enabledLegacyPluginNames, unorderedEquals(['plugin_ddd']));
}

test_mergeIncludedOptions() {
// TODO(srawlins): Split this into smaller tests.
// TODO(srawlins): add tests for multiple includes.
// TODO(srawlins): add tests with duplicate legacy plugin names.
// https://github.com/dart-lang/sdk/issues/50980
test_include_analyzerErrorSeveritiesAreMerged() {
newFile('/other_options.yaml', '''
analyzer:
errors:
toplevelerror: warning
''');
newFile(optionsFilePath, r'''
include: other_options.yaml
analyzer:
errors:
lowlevelerror: warning
''');

var options = _getOptionsObject('/');

expect(
options.errorProcessors,
unorderedMatches([
ErrorProcessorMatcher(
ErrorProcessor('toplevelerror', ErrorSeverity.WARNING)),
ErrorProcessorMatcher(
ErrorProcessor('lowlevelerror', ErrorSeverity.WARNING)),
]),
);
}

test_include_analyzerErrorSeveritiesAreMerged_multipleIncludes() {
newFile('/first_options.yaml', '''
analyzer:
errors:
error_1: error
''');
newFile('/second_options.yaml', '''
include: first_options.yaml
analyzer:
errors:
error_2: warning
''');
newFile(optionsFilePath, r'''
include: second_options.yaml
''');

var options = _getOptionsObject('/');

expect(
options.errorProcessors,
contains(
ErrorProcessorMatcher(ErrorProcessor('error_1', ErrorSeverity.ERROR)),
),
);
}

test_include_analyzerErrorSeveritiesAreMerged_outermostWins() {
newFile('/other_options.yaml', '''
analyzer:
errors:
error_1: warning
error_2: warning
''');
newFile(optionsFilePath, r'''
include: other_options.yaml
analyzer:
errors:
error_1: ignore
''');

var options = _getOptionsObject('/');

expect(
options.errorProcessors,
unorderedMatches([
// We want to explicitly state the expected severity.
// ignore: avoid_redundant_argument_values
ErrorProcessorMatcher(ErrorProcessor('error_1', null)),
ErrorProcessorMatcher(ErrorProcessor('error_2', ErrorSeverity.WARNING)),
]),
);
}

test_include_analyzerExcludeListsAreMerged() {
newFile('/other_options.yaml', '''
analyzer:
exclude:
- toplevelexclude.dart
plugins:
toplevelplugin:
enabled: true
errors:
toplevelerror: warning
linter:
rules:
- toplevellint
''');
String code = r'''
newFile(optionsFilePath, r'''
include: other_options.yaml
analyzer:
exclude:
- lowlevelexclude.dart
errors:
lowlevelerror: warning
''');

var options = _getOptionsObject('/');

expect(
options.excludePatterns,
unorderedEquals(['toplevelexclude.dart', 'lowlevelexclude.dart']),
);
}

test_include_analyzerLanguageModesAreMerged() {
newFile('/other_options.yaml', '''
analyzer:
language:
strict-casts: true
''');
newFile(optionsFilePath, r'''
include: other_options.yaml
analyzer:
language:
strict-inference: true
''');

var options = _getOptionsObject('/');

expect(options.strictCasts, true);
expect(options.strictInference, true);
expect(options.strictRawTypes, false);
}

test_include_linterRulesAreMerged() {
newFile('/other_options.yaml', '''
linter:
rules:
- lowlevellint
''';
newFile(optionsFilePath, code);

var lowlevellint = TestRule.withName('lowlevellint');
var toplevellint = TestRule.withName('toplevellint');
Registry.ruleRegistry.register(lowlevellint);
Registry.ruleRegistry.register(toplevellint);
- top_level_lint
''');
newFile(optionsFilePath, r'''
include: other_options.yaml
linter:
rules:
- low_level_lint
''');

var lowLevelLint = TestRule.withName('low_level_lint');
var topLevelLint = TestRule.withName('top_level_lint');
Registry.ruleRegistry.register(lowLevelLint);
Registry.ruleRegistry.register(topLevelLint);
var options = _getOptionsObject('/');

expect(options.lintRules, unorderedEquals([topLevelLint, lowLevelLint]));
}

test_include_linterRulesAreMerged_differentFormats() {
newFile('/other_options.yaml', '''
linter:
rules:
top_level_lint: true
''');
newFile(optionsFilePath, r'''
include: other_options.yaml
linter:
rules:
- low_level_lint
''');

var lowLevelLint = TestRule.withName('low_level_lint');
var topLevelLint = TestRule.withName('top_level_lint');
Registry.ruleRegistry.register(lowLevelLint);
Registry.ruleRegistry.register(topLevelLint);
var options = _getOptionsObject('/');

expect(options.lintRules, unorderedEquals([topLevelLint, lowLevelLint]));
}

test_include_linterRulesAreMerged_outermostWins() {
newFile('/other_options.yaml', '''
linter:
rules:
- top_level_lint
''');
newFile(optionsFilePath, r'''
include: other_options.yaml
linter:
rules:
top_level_lint: false
''');

var topLevelLint = TestRule.withName('top_level_lint');
Registry.ruleRegistry.register(topLevelLint);
var options = _getOptionsObject('/');

expect(options.lintRules, isNot(contains(topLevelLint)));
}

test_include_pluginCanBeIncluded() {
newFile('/other_options.yaml', '''
analyzer:
plugins:
toplevelplugin:
enabled: true
''');
newFile(optionsFilePath, r'''
include: other_options.yaml
''');

var options = _getOptionsObject('/');

expect(options.lintRules, unorderedEquals([toplevellint, lowlevellint]));
expect(
options.enabledLegacyPluginNames, unorderedEquals(['toplevelplugin']));
expect(options.excludePatterns,
unorderedEquals(['toplevelexclude.dart', 'lowlevelexclude.dart']));
expect(
options.errorProcessors,
unorderedMatches([
ErrorProcessorMatcher(
ErrorProcessor('toplevelerror', ErrorSeverity.WARNING)),
ErrorProcessorMatcher(
ErrorProcessor('lowlevelerror', ErrorSeverity.WARNING))
]));
options.enabledLegacyPluginNames,
unorderedEquals(['toplevelplugin']),
);
}

AnalysisOptions _getOptionsObject(String posixPath) =>
AnalysisOptions _getOptionsObject(String filePath) =>
AnalysisOptionsImpl.fromYaml(
optionsMap: provider.getOptions(getFolder(posixPath)));
optionsMap: provider.getOptions(getFolder(filePath)));
}

class TestRule extends LintRule {
Expand Down
Loading

0 comments on commit c6514a2

Please sign in to comment.