Skip to content

Commit

Permalink
Remove all support for all 'strong-mode' analysis options
Browse files Browse the repository at this point in the history
Fixes #50679

Change-Id: I3572faf51276f5c7551d35b7725c799567189413
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/274921
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
  • Loading branch information
srawlins authored and Commit Queue committed Dec 13, 2022
1 parent 1b62424 commit ea120b5
Show file tree
Hide file tree
Showing 50 changed files with 34 additions and 1,851 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@
[`MAX_USER_TAGS`]: https://api.dart.dev/stable/dart-developer/UserTag/MAX_USER_TAGS-constant.html
[`maxUserTags`]: https://api.dart.dev/beta/2.19.0-255.2.beta/dart-developer/UserTag/maxUserTags-constant.html

### Tools

#### Analyzer

- Remove deprecated 'strong-mode' analysis options from `analysis_options.yaml`
files. These options are replaced by the supported "strict" options
documented at
[dart.dev](https://dart.dev/guides/language/analysis-options#enabling-additional-type-checks).

## 2.19.0

### Language
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@ class AnalysisOptionsGenerator extends YamlCompletionGenerator {
}),
AnalyzerOptions.plugins: EmptyProducer(),
AnalyzerOptions.propagateLinterExceptions: EmptyProducer(),
AnalyzerOptions.strongMode: MapProducer({
AnalyzerOptions.declarationCasts: EmptyProducer(),
AnalyzerOptions.implicitCasts: EmptyProducer(),
AnalyzerOptions.implicitDynamic: EmptyProducer(),
}),
}),
AnalyzerOptions.codeStyle: MapProducer({
AnalyzerOptions.format: BooleanProducer(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ AnalysisOptionsErrorCode.PARSE_ERROR:
AnalysisOptionsHintCode.PREVIEW_DART_2_SETTING_DEPRECATED:
status: needsFix
notes: Fixed.
AnalysisOptionsHintCode.STRONG_MODE_SETTING_DEPRECATED:
status: needsFix
notes: Fixed.
AnalysisOptionsWarningCode.INCLUDE_FILE_NOT_FOUND:
status: noFix
notes: |-
Expand All @@ -66,10 +63,6 @@ AnalysisOptionsWarningCode.INVALID_OPTION:
replace the invalid option with the selected replacement.
AnalysisOptionsWarningCode.INVALID_SECTION_FORMAT:
status: needsEvaluation
AnalysisOptionsWarningCode.SPEC_MODE_REMOVED:
status: needsFix
notes: |-
Provide a fix to remove the deprecated setting.
AnalysisOptionsWarningCode.UNRECOGNIZED_ERROR_CODE:
status: needsEvaluation
AnalysisOptionsWarningCode.UNSUPPORTED_OPTION_WITH_LEGAL_VALUE:
Expand Down Expand Up @@ -1714,56 +1707,6 @@ HintCode.UNUSED_RESULT_WITH_MESSAGE:
There is no predictable common way in which a result _should_ be used.
HintCode.UNUSED_SHOWN_NAME:
status: hasFix
LanguageCode.IMPLICIT_DYNAMIC_FIELD:
status: needsFix
notes: |-
The correction says to add an explicit type or remove implicit-dynamic from
analysis options. We can add a fix to add an explicit `dynamic`.
LanguageCode.IMPLICIT_DYNAMIC_FUNCTION:
status: needsFix
notes: |-
The correction says to add an explicit type or remove implicit-dynamic from
analysis options. We can add a fix to add an explicit `dynamic`.
LanguageCode.IMPLICIT_DYNAMIC_INVOKE:
status: needsFix
notes: |-
The correction says to add an explicit type or remove implicit-dynamic from
analysis options. We can add a fix to add an explicit `dynamic`.
LanguageCode.IMPLICIT_DYNAMIC_LIST_LITERAL:
status: needsFix
notes: |-
The correction says to add an explicit type or remove implicit-dynamic from
analysis options. We can add a fix to add an explicit `dynamic`.
LanguageCode.IMPLICIT_DYNAMIC_MAP_LITERAL:
status: needsFix
notes: |-
The correction says to add an explicit type or remove implicit-dynamic from
analysis options. We can add a fix to add an explicit `dynamic`.
LanguageCode.IMPLICIT_DYNAMIC_METHOD:
status: needsFix
notes: |-
The correction says to add an explicit type or remove implicit-dynamic from
analysis options. We can add a fix to add an explicit `dynamic`.
LanguageCode.IMPLICIT_DYNAMIC_PARAMETER:
status: needsFix
notes: |-
The correction says to add an explicit type or remove implicit-dynamic from
analysis options. We can add a fix to add an explicit `dynamic`.
LanguageCode.IMPLICIT_DYNAMIC_RETURN:
status: needsFix
notes: |-
The correction says to add an explicit type or remove implicit-dynamic from
analysis options. We can add a fix to add an explicit `dynamic`.
LanguageCode.IMPLICIT_DYNAMIC_TYPE:
status: needsFix
notes: |-
The correction says to add an explicit type or remove implicit-dynamic from
analysis options. We can add a fix to add an explicit `dynamic`.
LanguageCode.IMPLICIT_DYNAMIC_VARIABLE:
status: needsFix
notes: |-
The correction says to add an explicit type or remove implicit-dynamic from
analysis options. We can add a fix to add an explicit `dynamic`.
LintCode.always_declare_return_types:
status: hasFix
LintCode.always_put_control_body_on_new_line:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ class AnalysisOptionsFixGenerator {
if (errorCode ==
AnalysisOptionsHintCode.PREVIEW_DART_2_SETTING_DEPRECATED) {
await _addFix_removeSetting(coveringNodePath);
} else if (errorCode ==
AnalysisOptionsHintCode.STRONG_MODE_SETTING_DEPRECATED) {
await _addFix_removeSetting(coveringNodePath);
} else if (errorCode == DEPRECATED_LINT_HINT) {
await _addFix_removeLint(coveringNodePath);
// } else if (errorCode == AnalysisOptionsWarningCode.INCLUDED_FILE_WARNING) {
Expand Down
2 changes: 0 additions & 2 deletions pkg/analysis_server/lib/src/status/diagnostics.dart
Original file line number Diff line number Diff line change
Expand Up @@ -452,8 +452,6 @@ class ContextsPage extends DiagnosticPageWithNav {
String describe(AnalysisOptionsImpl options) {
var b = StringBuffer();

b.write(writeOption('Implicit dynamic', options.implicitDynamic));
b.write(writeOption('Implicit casts', options.implicitCasts));
b.write(writeOption('Feature set', options.contextFeatures.toString()));
b.write('<br>');

Expand Down
8 changes: 1 addition & 7 deletions pkg/analysis_server/test/abstract_context.dart
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,11 @@ class AbstractContextTest with ResourceProviderMixin {
void createAnalysisOptionsFile({
List<String>? experiments,
List<String>? cannotIgnore,
bool? implicitCasts,
List<String>? lints,
}) {
var buffer = StringBuffer();

if (experiments != null || implicitCasts != null || cannotIgnore != null) {
if (experiments != null || cannotIgnore != null) {
buffer.writeln('analyzer:');
}

Expand All @@ -121,11 +120,6 @@ class AbstractContextTest with ResourceProviderMixin {
}
}

if (implicitCasts != null) {
buffer.writeln(' strong-mode:');
buffer.writeln(' implicit-casts: $implicitCasts');
}

if (cannotIgnore != null) {
buffer.writeln(' cannot-ignore:');
for (var unignorable in cannotIgnore) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class AnalysisOptionsFileNotificationTest extends PubPackageAnalysisServerTest {
final testSource = '''
void f() {
var x = '';
int y = x; // Not assignable in strong-mode
int y = x; // Not assignable.
print(y);
}''';

Expand Down
7 changes: 0 additions & 7 deletions pkg/analysis_server/test/analysis_server_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,13 @@ import 'src/utilities/mock_packages.dart';
/// TODO(scheglov) this is duplicate
class AnalysisOptionsFileConfig {
final List<String> experiments;
final bool implicitCasts;
final bool implicitDynamic;
final List<String> lints;
final bool strictCasts;
final bool strictInference;
final bool strictRawTypes;

AnalysisOptionsFileConfig({
this.experiments = const [],
this.implicitCasts = true,
this.implicitDynamic = true,
this.lints = const [],
this.strictCasts = false,
this.strictInference = false,
Expand All @@ -58,9 +54,6 @@ class AnalysisOptionsFileConfig {
buffer.writeln(' strict-casts: $strictCasts');
buffer.writeln(' strict-inference: $strictInference');
buffer.writeln(' strict-raw-types: $strictRawTypes');
buffer.writeln(' strong-mode:');
buffer.writeln(' implicit-casts: $implicitCasts');
buffer.writeln(' implicit-dynamic: $implicitDynamic');

buffer.writeln('linter:');
buffer.writeln(' rules:');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,13 +359,12 @@ class AnalyticsManagerTest with ResourceProviderMixin {
String? path,
Map<String, String>? errors,
List<String>? experiments,
bool? implicitCasts,
List<String>? lints,
}) {
path ??= '$testPackageRootPath/analysis_options.yaml';
var buffer = StringBuffer();

if (errors != null || experiments != null || implicitCasts != null) {
if (errors != null || experiments != null) {
buffer.writeln('analyzer:');
}

Expand All @@ -383,11 +382,6 @@ class AnalyticsManagerTest with ResourceProviderMixin {
}
}

if (implicitCasts != null) {
buffer.writeln(' strong-mode:');
buffer.writeln(' implicit-casts: $implicitCasts');
}

if (lints != null) {
buffer.writeln('linter:');
buffer.writeln(' rules:');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class FlutterNotificationOutlineTest extends PubPackageAnalysisServerTest {
);
newAnalysisOptionsYamlFile(testPackageRootPath, '''
analyzer:
strong-mode: true
language: true
''');
await pumpEventQueue();
await server.onAnalysisComplete;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,4 @@ analyzer:
''', '''
''');
}

Future<void> test_strong_mode_settings_deprecated() async {
await assertHasFix('''
analyzer:
strong-mode: true
''', '');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// BSD-style license that can be found in the LICENSE file.

import 'package:analysis_server/src/services/correction/fix.dart';
import 'package:analyzer/src/error/codes.dart';
import 'package:analyzer_plugin/utilities/fixes/fixes.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';

Expand Down Expand Up @@ -119,16 +118,4 @@ f() {
}
''');
}

Future<void> test_synthetic_implicitCast() async {
createAnalysisOptionsFile(implicitCasts: false);
await resolveTestCode('''
int foo =
''');
await assertNoFix(
errorFilter: (e) {
return e.errorCode == CompileTimeErrorCode.INVALID_ASSIGNMENT;
},
);
}
}
19 changes: 0 additions & 19 deletions pkg/analyzer/lib/src/analysis_options/error/option_codes.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,6 @@ class AnalysisOptionsHintCode extends ErrorCode {
correctionMessage: "It is no longer necessary to explicitly enable Dart 2.",
);

/// An error code indicating that strong-mode: true is deprecated.
static const AnalysisOptionsHintCode STRONG_MODE_SETTING_DEPRECATED =
AnalysisOptionsHintCode(
'STRONG_MODE_SETTING_DEPRECATED',
"The 'strong-mode: true' setting is deprecated.",
correctionMessage:
"It is no longer necessary to explicitly enable strong mode.",
);

/// Initialize a newly created error code to have the given [name].
const AnalysisOptionsHintCode(
String name,
Expand Down Expand Up @@ -146,16 +137,6 @@ class AnalysisOptionsWarningCode extends ErrorCode {
"Invalid format for the '{0}' section.",
);

/// An error code indicating that strong-mode: false is has been removed.
static const AnalysisOptionsWarningCode SPEC_MODE_REMOVED =
AnalysisOptionsWarningCode(
'SPEC_MODE_REMOVED',
"The option 'strong-mode: false' is no longer supported.",
correctionMessage:
"It's recommended to remove the 'strong-mode:' setting (and make your "
"code Dart 2 compliant).",
);

/// An error code indicating that an unrecognized error code is being used to
/// specify an error filter.
///
Expand Down
4 changes: 0 additions & 4 deletions pkg/analyzer/lib/src/context/context.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,11 @@ class AnalysisContextImpl implements AnalysisContext {

// TODO() remove this method as well
_typeSystemLegacy?.updateOptions(
implicitCasts: analysisOptions.implicitCasts,
strictCasts: analysisOptions.strictCasts,
strictInference: analysisOptions.strictInference,
);

_typeSystemNonNullableByDefault?.updateOptions(
implicitCasts: analysisOptions.implicitCasts,
strictCasts: analysisOptions.strictCasts,
strictInference: analysisOptions.strictInference,
);
Expand Down Expand Up @@ -91,15 +89,13 @@ class AnalysisContextImpl implements AnalysisContext {
}

_typeSystemLegacy = TypeSystemImpl(
implicitCasts: analysisOptions.implicitCasts,
isNonNullableByDefault: false,
strictCasts: analysisOptions.strictCasts,
strictInference: analysisOptions.strictInference,
typeProvider: legacy,
);

_typeSystemNonNullableByDefault = TypeSystemImpl(
implicitCasts: analysisOptions.implicitCasts,
isNonNullableByDefault: true,
strictCasts: analysisOptions.strictCasts,
strictInference: analysisOptions.strictInference,
Expand Down
1 change: 0 additions & 1 deletion pkg/analyzer/lib/src/dart/constant/value.dart
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,6 @@ class DartObjectImpl implements DartObject {
DartObjectImpl isIdentical(
TypeProvider typeProvider, DartObjectImpl rightOperand) {
var typeSystem = TypeSystemImpl(
implicitCasts: false,
isNonNullableByDefault: false,
strictCasts: false,
strictInference: false,
Expand Down
15 changes: 3 additions & 12 deletions pkg/analyzer/lib/src/dart/element/type_system.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,6 @@ class TypeSystemImpl implements TypeSystem {
/// The provider of types for the system.
final TypeProviderImpl typeProvider;

/// False if implicit casts should always be disallowed.
///
/// This affects the behavior of [isAssignableTo].
bool implicitCasts;

/// True if "strict casts" should be enforced.
///
/// This affects the behavior of [isAssignableTo].
Expand Down Expand Up @@ -89,7 +84,6 @@ class TypeSystemImpl implements TypeSystem {
late final SubtypeHelper _subtypeHelper;

TypeSystemImpl({
required this.implicitCasts,
required this.isNonNullableByDefault,
required this.strictCasts,
required this.strictInference,
Expand Down Expand Up @@ -686,10 +680,9 @@ class TypeSystemImpl implements TypeSystem {
}
}

// First make sure that the static analysis options, `implicit-casts: false`
// and `strict-casts: true` disable all downcasts, including casts from
// `dynamic`.
if (!implicitCasts || strictCasts) {
// First make sure that the static analysis option, `strict-casts: true`,
// disables all downcasts, including casts from `dynamic`.
if (strictCasts) {
return false;
}

Expand Down Expand Up @@ -1638,11 +1631,9 @@ class TypeSystemImpl implements TypeSystem {
}

void updateOptions({
required bool implicitCasts,
required bool strictCasts,
required bool strictInference,
}) {
this.implicitCasts = implicitCasts;
this.strictCasts = strictCasts;
this.strictInference = strictInference;
}
Expand Down
1 change: 0 additions & 1 deletion pkg/analyzer/lib/src/dart/micro/resolve_file.dart
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,6 @@ class FileResolver {
}

var analysisOptions = AnalysisOptionsImpl()
..implicitCasts = fileAnalysisOptions.implicitCasts
..strictInference = fileAnalysisOptions.strictInference;

if (fsState == null) {
Expand Down
Loading

0 comments on commit ea120b5

Please sign in to comment.