Bump linter to include deprecated_member_use_from_same_package

We also stop reporting
`HintCode.DEPRECATED_MEMBER_USE_FROM_SAME_PACKAGE` and
`HintCode.DEPRECATED_MEMBER_USE_FROM_SAME_PACKAGE_WITH_MESSAGE`
as these are now replaced by the new lint rule.

The biggest change here is in the DEPRECATED_MEMBER_USE tests,
as most of these tests have
`DEPRECATED_MEMBER_USE_FROM_SAME_PACKAGE` reported (since it's
easier to write tests with files in one package). We move all
of those tests to `DEPRECATED_MEMBER_USE` tests, without losing
coverage.

Bug: https://github.com/dart-lang/sdk/issues/50796
Change-Id: I7cada44265cd0e1e47ab77d4354de9a5571db614
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/289444
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Kevin Moore <kevmoo@google.com>
Reviewed-by: Nate Bosch <nbosch@google.com>
This commit is contained in:
Sam Rawlins 2023-03-24 16:35:37 +00:00 committed by Commit Queue
parent 8f6325d650
commit fd4602f019
14 changed files with 1480 additions and 1382 deletions

2
DEPS
View file

@ -145,7 +145,7 @@ vars = {
"http_parser_rev": "b3b283b9f139640b932d604e8815460bbd3ecab5",
"intl_rev": "fca552f2ec5d682b5fa36f02bdd72a5a4e2edcee",
"json_rpc_2_rev": "0280ac6cb4f3905d81c47ba927123ba2b95f7940",
"linter_rev": "07c4d177bca9e3b670ab67a7c9a8cffeb90aa318", # disable rev_sdk_deps.dart
"linter_rev": "7c7db85d29b46af51e3f4a5e0a33440c4e3791fc", # disable rev_sdk_deps.dart
"lints_rev": "dfded5e265015f21ce154577fe8488dc244e33c2",
"logging_rev": "abef3717d958158eb8b0ddb2871f4b15a9804cd4",
"markdown_rev": "ecbffa9bf9109d490b9388e9cb1f2bb801aee63c",

View file

@ -35,10 +35,8 @@ const languageSourceName = 'dart';
final diagnosticTagsForErrorCode = <String, List<lsp.DiagnosticTag>>{
_errorCode(WarningCode.DEAD_CODE): [lsp.DiagnosticTag.Unnecessary],
_errorCode(HintCode.DEPRECATED_MEMBER_USE): [lsp.DiagnosticTag.Deprecated],
_errorCode(HintCode.DEPRECATED_MEMBER_USE_FROM_SAME_PACKAGE): [
lsp.DiagnosticTag.Deprecated
],
_errorCode(HintCode.DEPRECATED_MEMBER_USE_FROM_SAME_PACKAGE_WITH_MESSAGE): [
'deprecated_member_use_from_same_package': [lsp.DiagnosticTag.Deprecated],
'deprecated_member_use_from_same_package_with_message': [
lsp.DiagnosticTag.Deprecated
],
_errorCode(HintCode.DEPRECATED_MEMBER_USE_WITH_MESSAGE): [
@ -1360,9 +1358,8 @@ lsp.WorkspaceEdit toWorkspaceEdit(
final supportsDocumentChanges = capabilities.documentChanges;
if (supportsDocumentChanges) {
final supportsCreate = capabilities.createResourceOperations;
final changes = <
Either4<lsp.CreateFile, lsp.DeleteFile, lsp.RenameFile,
lsp.TextDocumentEdit>>[];
final changes = <Either4<lsp.CreateFile, lsp.DeleteFile, lsp.RenameFile,
lsp.TextDocumentEdit>>[];
// Convert each SourceEdit to either a TextDocumentEdit or a
// CreateFile + a TextDocumentEdit depending on whether it's a new

View file

@ -132,15 +132,9 @@ class BulkFixProcessor {
HintCode.DEPRECATED_MEMBER_USE: [
DataDriven.new,
],
HintCode.DEPRECATED_MEMBER_USE_FROM_SAME_PACKAGE: [
DataDriven.new,
],
HintCode.DEPRECATED_MEMBER_USE_WITH_MESSAGE: [
DataDriven.new,
],
HintCode.DEPRECATED_MEMBER_USE_FROM_SAME_PACKAGE_WITH_MESSAGE: [
DataDriven.new,
],
WarningCode.OVERRIDE_ON_NON_OVERRIDING_METHOD: [
DataDriven.new,
],
@ -457,6 +451,16 @@ class BulkFixProcessor {
if (isCancelled) {
return;
}
var multiGenerators = FixProcessor.lintMultiProducerMap[codeName];
if (multiGenerators != null) {
for (var multiGenerator in multiGenerators) {
var multiProducer = multiGenerator();
multiProducer.configure(context);
for (var producer in await multiProducer.producers) {
await _generateFix(context, producer, codeName);
}
}
}
} else {
var generators = FixProcessor.nonLintProducerMap[errorCode] ?? [];
await bulkApply(generators, codeName);

View file

@ -1637,6 +1637,14 @@ LintCode.depend_on_referenced_packages:
status: needsFix
LintCode.deprecated_consistency:
status: needsEvaluation
LintCode.deprecated_member_use_from_same_package:
status: needsFix
notes: |-
Should probably be able to use `DataDriven`.
LintCode.deprecated_member_use_from_same_package_with_message:
status: needsFix
notes: |-
Should probably be able to use `DataDriven`.
LintCode.diagnostic_describe_all_properties:
status: hasFix
LintCode.directives_ordering:

View file

@ -361,6 +361,13 @@ class FixInFileProcessor {
/// The computer for Dart fixes.
class FixProcessor extends BaseProcessor {
static final Map<String, List<MultiProducerGenerator>> lintMultiProducerMap =
{
LintNames.deprecated_member_use_from_same_package: [
DataDriven.new,
],
};
/// A map from the names of lint rules to a list of the generators that are
/// used to create correction producers. The generators are then used to build
/// fixes for those diagnostics. The generators used for non-lint diagnostics

View file

@ -57,6 +57,8 @@ class LintNames {
'curly_braces_in_flow_control_structures';
static const String dangling_library_doc_comments =
'dangling_library_doc_comments';
static const String deprecated_member_use_from_same_package =
'deprecated_member_use_from_same_package';
static const String diagnostic_describe_all_properties =
'diagnostic_describe_all_properties';
static const String directives_ordering = 'directives_ordering';

View file

@ -5,6 +5,7 @@
import 'dart:async';
import 'package:analysis_server/lsp_protocol/protocol.dart';
import 'package:analyzer/src/test_utilities/package_config_file_builder.dart';
import 'package:analyzer_plugin/protocol/protocol_common.dart' as plugin;
import 'package:analyzer_plugin/protocol/protocol_generated.dart' as plugin;
import 'package:linter/src/rules.dart';
@ -175,10 +176,18 @@ void f() {
}
Future<void> test_diagnosticTag_deprecated() async {
newFile(mainFilePath, '''
var onePackagePath = convertPath('/home/one');
writePackageConfig(
projectFolderPath,
config: PackageConfigFileBuilder()
..add(name: 'one', rootPath: onePackagePath),
);
newFile(convertPath('$onePackagePath/lib/one.dart'), '''
@deprecated
int? dep;
''');
newFile(mainFilePath, r'''
import 'package:one/one.dart';
void f() => print(dep);
''');
@ -189,15 +198,23 @@ void f() {
final diagnostics = await diagnosticsUpdate;
expect(diagnostics, hasLength(1));
final diagnostic = diagnostics!.first;
expect(diagnostic.code, equals('deprecated_member_use_from_same_package'));
expect(diagnostic.code, equals('deprecated_member_use'));
expect(diagnostic.tags, contains(DiagnosticTag.Deprecated));
}
Future<void> test_diagnosticTag_notSupported() async {
newFile(mainFilePath, '''
var onePackagePath = convertPath('/home/one');
writePackageConfig(
projectFolderPath,
config: PackageConfigFileBuilder()
..add(name: 'one', rootPath: onePackagePath),
);
newFile(convertPath('$onePackagePath/lib/one.dart'), '''
@deprecated
int? dep;
''');
newFile(mainFilePath, r'''
import 'package:one/one.dart';
void f() => print(dep);
''');
@ -206,7 +223,7 @@ void f() {
final diagnostics = await diagnosticsUpdate;
expect(diagnostics, hasLength(1));
final diagnostic = diagnostics!.first;
expect(diagnostic.code, equals('deprecated_member_use_from_same_package'));
expect(diagnostic.code, equals('deprecated_member_use'));
expect(diagnostic.tags, isNull);
}

View file

@ -61,6 +61,9 @@ class HintCode extends AnalyzerErrorCode {
/// Parameters:
/// 0: the name of the member
///
/// This code is deprecated in favor of the
/// 'deprecated_member_from_same_package' lint rule, and will be removed.
static const HintCode DEPRECATED_MEMBER_USE_FROM_SAME_PACKAGE = HintCode(
'DEPRECATED_MEMBER_USE_FROM_SAME_PACKAGE',
"'{0}' is deprecated and shouldn't be used.",
@ -72,6 +75,9 @@ class HintCode extends AnalyzerErrorCode {
/// Parameters:
/// 0: the name of the member
/// 1: message details
///
/// This code is deprecated in favor of the
/// 'deprecated_member_from_same_package' lint rule, and will be removed.
static const HintCode DEPRECATED_MEMBER_USE_FROM_SAME_PACKAGE_WITH_MESSAGE =
HintCode(
'DEPRECATED_MEMBER_USE_FROM_SAME_PACKAGE',

View file

@ -306,13 +306,14 @@ class DeprecatedMemberUseVerifier extends BaseDeprecatedMemberUseVerifier {
void reportError(
AstNode errorNode, Element element, String displayName, String? message) {
var library = element is LibraryElement ? element : element.library;
if (_isLibraryInWorkspacePackage(library)) {
return;
}
message = message?.trim();
if (message == null || message.isEmpty || message == '.') {
_errorReporter.reportErrorForNode(
_isLibraryInWorkspacePackage(library)
? HintCode.DEPRECATED_MEMBER_USE_FROM_SAME_PACKAGE
: HintCode.DEPRECATED_MEMBER_USE,
HintCode.DEPRECATED_MEMBER_USE,
errorNode,
[displayName],
);
@ -323,9 +324,7 @@ class DeprecatedMemberUseVerifier extends BaseDeprecatedMemberUseVerifier {
message = '$message.';
}
_errorReporter.reportErrorForNode(
_isLibraryInWorkspacePackage(library)
? HintCode.DEPRECATED_MEMBER_USE_FROM_SAME_PACKAGE_WITH_MESSAGE
: HintCode.DEPRECATED_MEMBER_USE_WITH_MESSAGE,
HintCode.DEPRECATED_MEMBER_USE_WITH_MESSAGE,
errorNode,
[displayName, message],
);

View file

@ -19377,6 +19377,9 @@ HintCode:
comment: |-
Parameters:
0: the name of the member
This code is deprecated in favor of the
'deprecated_member_from_same_package' lint rule, and will be removed.
documentation: |-
#### Description
@ -19407,6 +19410,9 @@ HintCode:
Parameters:
0: the name of the member
1: message details
This code is deprecated in favor of the
'deprecated_member_from_same_package' lint rule, and will be removed.
DIVISION_OPTIMIZATION:
problemMessage: The operator x ~/ y is more efficient than (x / y).toInt().
correctionMessage: "Try re-writing the expression to use the '~/' operator."

View file

@ -99,6 +99,8 @@ class DocumentationValidator {
'HintCode.DEPRECATED_COLON_FOR_DEFAULT_VALUE',
// The code has been replaced but is not yet removed.
'HintCode.DEPRECATED_MEMBER_USE',
// This is deprecated.
'HintCode.DEPRECATED_MEMBER_USE_FROM_SAME_PACKAGE',
// Produces two diagnostics when it should only produce one (see
// https://github.com/dart-lang/sdk/issues/43051)
'HintCode.UNNECESSARY_NULL_COMPARISON_FALSE',

View file

@ -360,7 +360,13 @@ void defineAnalyze() {
test('info implicit no --fatal-infos', () async {
p = project(
mainSrc: '$dartVersionFilePrefix2_9@deprecated var x = 1; var y = x;');
mainSrc: 'var x = 1; var y = x?.isEven;',
analysisOptions: r'''
analyzer:
errors:
INVALID_NULL_AWARE_OPERATOR: info
''',
);
var result = await p.runAnalyze([p.dirPath]);
expect(result.exitCode, 0);
@ -370,7 +376,13 @@ void defineAnalyze() {
test('info --fatal-infos', () async {
p = project(
mainSrc: '$dartVersionFilePrefix2_9@deprecated var x = 1; var y = x;');
mainSrc: 'var x = 1; var y = x?.isEven;',
analysisOptions: r'''
analyzer:
errors:
INVALID_NULL_AWARE_OPERATOR: info
''',
);
var result = await p.runAnalyze(['--fatal-infos', p.dirPath]);
expect(result.exitCode, 1);

View file

@ -348,14 +348,6 @@ class ValidateCommentCodeSamplesVisitor extends GeneralizingAstVisitor {
e.errorCode == HintCode.UNUSED_ELEMENT,
);
// Remove warnings about deprecated member use from the same library.
errors.removeWhere(
(e) =>
e.errorCode == HintCode.DEPRECATED_MEMBER_USE_FROM_SAME_PACKAGE ||
e.errorCode ==
HintCode.DEPRECATED_MEMBER_USE_FROM_SAME_PACKAGE_WITH_MESSAGE,
);
// Handle edge case around dart:_http
errors.removeWhere((e) {
if (e.message.contains("'dart:_http'")) {