Enable the prefer_function_declarations_over_variables lint in the analysis server
Change-Id: I53a6cd3c5d3be1c66173f52a7f01d8df63fd9350 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/249727 Commit-Queue: Brian Wilkerson <brianwilkerson@google.com> Reviewed-by: Samuel Rawlins <srawlins@google.com>
This commit is contained in:
committed by
Commit Bot
parent
9f5942df4c
commit
e0820bb508
@@ -18,7 +18,6 @@ analyzer:
|
||||
implementation_imports: ignore
|
||||
non_constant_identifier_names: ignore
|
||||
overridden_fields: ignore
|
||||
prefer_function_declarations_over_variables: ignore
|
||||
prefer_void_to_null: ignore
|
||||
provide_deprecation_message: ignore
|
||||
|
||||
|
||||
@@ -10,18 +10,6 @@ import 'package:analyzer_plugin/utilities/assist/assist.dart';
|
||||
///
|
||||
/// Clients may not extend, implement or mix-in this class.
|
||||
class Assist {
|
||||
/// A comparator that can be used to sort assists by their relevance. The most
|
||||
/// relevant assists will be sorted before assists with a lower relevance.
|
||||
/// Assists with the same relevance are sorted alphabetically.
|
||||
static final Comparator<Assist> SORT_BY_RELEVANCE = (Assist a, Assist b) {
|
||||
if (a.kind.priority != b.kind.priority) {
|
||||
// A higher priority indicates a higher relevance
|
||||
// and should be sorted before a lower priority.
|
||||
return b.kind.priority - a.kind.priority;
|
||||
}
|
||||
return a.change.message.compareTo(b.change.message);
|
||||
};
|
||||
|
||||
/// A description of the assist being proposed.
|
||||
final AssistKind kind;
|
||||
|
||||
@@ -35,4 +23,17 @@ class Assist {
|
||||
String toString() {
|
||||
return 'Assist(kind=$kind, change=$change)';
|
||||
}
|
||||
|
||||
/// A function that can be used to sort assists by their relevance.
|
||||
///
|
||||
/// The most relevant assists will be sorted before assists with a lower
|
||||
/// relevance. Assists with the same relevance are sorted alphabetically.
|
||||
static int compareAssists(Assist a, Assist b) {
|
||||
if (a.kind.priority != b.kind.priority) {
|
||||
// A higher priority indicates a higher relevance
|
||||
// and should be sorted before a lower priority.
|
||||
return b.kind.priority - a.kind.priority;
|
||||
}
|
||||
return a.change.message.compareTo(b.change.message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,18 +11,6 @@ import 'package:analyzer_plugin/utilities/fixes/fixes.dart';
|
||||
///
|
||||
/// Clients may not extend, implement or mix-in this class.
|
||||
class Fix {
|
||||
/// A comparator that can be used to sort fixes by their relevance. The most
|
||||
/// relevant fixes will be sorted before fixes with a lower relevance. Fixes
|
||||
/// with the same relevance are sorted alphabetically.
|
||||
static final Comparator<Fix> SORT_BY_RELEVANCE = (Fix a, Fix b) {
|
||||
if (a.kind.priority != b.kind.priority) {
|
||||
// A higher priority indicates a higher relevance
|
||||
// and should be sorted before a lower priority.
|
||||
return b.kind.priority - a.kind.priority;
|
||||
}
|
||||
return a.change.message.compareTo(b.change.message);
|
||||
};
|
||||
|
||||
/// A description of the fix being proposed.
|
||||
final FixKind kind;
|
||||
|
||||
@@ -36,6 +24,19 @@ class Fix {
|
||||
String toString() {
|
||||
return 'Fix(kind=$kind, change=$change)';
|
||||
}
|
||||
|
||||
/// A finction that can be used to sort fixes by their relevance.
|
||||
///
|
||||
/// The most relevant fixes will be sorted before fixes with a lower
|
||||
/// relevance. Fixes with the same relevance are sorted alphabetically.
|
||||
static int compareFixes(Fix a, Fix b) {
|
||||
if (a.kind.priority != b.kind.priority) {
|
||||
// A higher priority indicates a higher relevance
|
||||
// and should be sorted before a lower priority.
|
||||
return b.kind.priority - a.kind.priority;
|
||||
}
|
||||
return a.change.message.compareTo(b.change.message);
|
||||
}
|
||||
}
|
||||
|
||||
/// An object used to provide context information for [FixContributor]s.
|
||||
|
||||
@@ -37,7 +37,7 @@ class CiderAssistsComputer {
|
||||
);
|
||||
final processor = AssistProcessor(context);
|
||||
final assists = await processor.compute();
|
||||
assists.sort(Assist.SORT_BY_RELEVANCE);
|
||||
assists.sort(Assist.compareAssists);
|
||||
result.addAll(assists);
|
||||
} on InconsistentAnalysisException {
|
||||
// If an InconsistentAnalysisException occurs, it's likely the user modified
|
||||
|
||||
@@ -58,7 +58,7 @@ class CiderFixesComputer {
|
||||
);
|
||||
|
||||
var fixes = await DartFixContributor().computeFixes(context);
|
||||
fixes.sort(Fix.SORT_BY_RELEVANCE);
|
||||
fixes.sort(Fix.compareFixes);
|
||||
|
||||
result.add(
|
||||
CiderErrorFixes(error: error, fixes: fixes, lineInfo: lineInfo),
|
||||
|
||||
@@ -101,7 +101,7 @@ class EditGetAssistsHandler extends LegacyHandler
|
||||
try {
|
||||
var processor = AssistProcessor(context);
|
||||
var assists = await processor.compute();
|
||||
assists.sort(Assist.SORT_BY_RELEVANCE);
|
||||
assists.sort(Assist.compareAssists);
|
||||
for (var assist in assists) {
|
||||
changes.add(assist.change);
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ class EditGetFixesHandler extends LegacyHandler
|
||||
resourceProvider, error, content, options);
|
||||
var fixes = await generator.computeFixes();
|
||||
if (fixes.isNotEmpty) {
|
||||
fixes.sort(Fix.SORT_BY_RELEVANCE);
|
||||
fixes.sort(Fix.compareFixes);
|
||||
var lineInfo = LineInfo.fromContent(content);
|
||||
var result = engine.ErrorsResultImpl(
|
||||
session, file, Uri.file(file), lineInfo, false, errors);
|
||||
@@ -179,7 +179,7 @@ error.errorCode: ${error.errorCode}
|
||||
}
|
||||
|
||||
if (fixes.isNotEmpty) {
|
||||
fixes.sort(Fix.SORT_BY_RELEVANCE);
|
||||
fixes.sort(Fix.compareFixes);
|
||||
var serverError = newAnalysisError_fromEngine(result, error);
|
||||
var errorFixes = AnalysisErrorFixes(serverError);
|
||||
errorFixesList.add(errorFixes);
|
||||
@@ -227,7 +227,7 @@ error.errorCode: ${error.errorCode}
|
||||
PubspecFixGenerator(resourceProvider, error, content, document);
|
||||
var fixes = await generator.computeFixes();
|
||||
if (fixes.isNotEmpty) {
|
||||
fixes.sort(Fix.SORT_BY_RELEVANCE);
|
||||
fixes.sort(Fix.compareFixes);
|
||||
var lineInfo = LineInfo.fromContent(content);
|
||||
var result = engine.ErrorsResultImpl(
|
||||
session, file, Uri.file(file), lineInfo, false, errors);
|
||||
|
||||
@@ -35,22 +35,6 @@ class CodeActionHandler
|
||||
// CodeAction class).
|
||||
final codeActionPriorities = Expando<int>();
|
||||
|
||||
/// A comparator that can be used to sort [CodeActions]s using priorities
|
||||
/// in [codeActionPriorities].
|
||||
///
|
||||
/// The highest number priority will be sorted before lower number priorities.
|
||||
/// Items with the same priority are sorted alphabetically by their title.
|
||||
late final Comparator<CodeAction> _codeActionComparator =
|
||||
(CodeAction a, CodeAction b) {
|
||||
// We should never be sorting actions without priorities.
|
||||
final aPriority = codeActionPriorities[a] ?? 0;
|
||||
final bPriority = codeActionPriorities[b] ?? 0;
|
||||
if (aPriority != bPriority) {
|
||||
return bPriority - aPriority;
|
||||
}
|
||||
return a.title.compareTo(b.title);
|
||||
};
|
||||
|
||||
CodeActionHandler(super.server);
|
||||
|
||||
@override
|
||||
@@ -200,6 +184,21 @@ class CodeActionHandler
|
||||
: Either2<CodeAction, Command>.t2(command);
|
||||
}
|
||||
|
||||
/// A function that can be used to sort [CodeActions]s using priorities
|
||||
/// in [codeActionPriorities].
|
||||
///
|
||||
/// The highest number priority will be sorted before lower number priorities.
|
||||
/// Items with the same priority are sorted alphabetically by their title.
|
||||
int _compareCodeActions(CodeAction a, CodeAction b) {
|
||||
// We should never be sorting actions without priorities.
|
||||
final aPriority = codeActionPriorities[a] ?? 0;
|
||||
final bPriority = codeActionPriorities[b] ?? 0;
|
||||
if (aPriority != bPriority) {
|
||||
return bPriority - aPriority;
|
||||
}
|
||||
return a.title.compareTo(b.title);
|
||||
}
|
||||
|
||||
/// Creates a CodeAction to apply this assist. Note: This code will fetch the
|
||||
/// version of each document being modified so it's important to call this
|
||||
/// immediately after computing edits to ensure the document is not modified
|
||||
@@ -318,7 +317,7 @@ class CodeActionHandler
|
||||
}));
|
||||
|
||||
final dedupedCodeActions = _dedupeActions(codeActions, range.start);
|
||||
dedupedCodeActions.sort(_codeActionComparator);
|
||||
dedupedCodeActions.sort(_compareCodeActions);
|
||||
|
||||
return dedupedCodeActions
|
||||
.where((action) => shouldIncludeKind(action.kind))
|
||||
@@ -450,7 +449,7 @@ class CodeActionHandler
|
||||
codeActions.addAll(pluginFixActions);
|
||||
|
||||
final dedupedActions = _dedupeActions(codeActions, range.start);
|
||||
dedupedActions.sort(_codeActionComparator);
|
||||
dedupedActions.sort(_compareCodeActions);
|
||||
|
||||
return dedupedActions
|
||||
.where((action) => shouldIncludeKind(action.kind))
|
||||
|
||||
@@ -1433,7 +1433,7 @@ class FixProcessor extends BaseProcessor {
|
||||
|
||||
Future<Fix?> computeFix() async {
|
||||
await _addFromProducers();
|
||||
fixes.sort(Fix.SORT_BY_RELEVANCE);
|
||||
fixes.sort(Fix.compareFixes);
|
||||
return fixes.isNotEmpty ? fixes.first : null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user