Skip to content

Commit 81ec189

Browse files
refactor: revert code in custom_analyzer_converter and move logic to the client
1 parent c4802f3 commit 81ec189

File tree

2 files changed

+54
-24
lines changed

2 files changed

+54
-24
lines changed

packages/custom_lint_builder/lib/src/client.dart

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -991,12 +991,21 @@ class _ClientAnalyzerPlugin extends analyzer_plugin.ServerPlugin {
991991
CustomLintEvent.analyzerPluginNotification(
992992
analyzer_plugin.AnalysisErrorsParams(
993993
path,
994-
CustomAnalyzerConverter().convertAnalysisErrors(
994+
CustomAnalyzerConverter()
995+
.convertAnalysisErrors(
995996
allAnalysisErrors,
996997
lineInfo: resolver.lineInfo,
997998
options: analysisContext.getAnalysisOptionsForFile(file),
998-
configSeverities: configs.configs.errors,
999-
),
999+
)
1000+
.map((error) {
1001+
var severity = error.severity;
1002+
if (configs.configs.errors[error.code]
1003+
case final ErrorSeverity errorSeverity) {
1004+
severity = CustomAnalyzerConverter()
1005+
.convertErrorSeverity(errorSeverity);
1006+
}
1007+
return error.copyWith(severity: severity);
1008+
}).toList(),
10001009
).toNotification(),
10011010
),
10021011
);
@@ -1241,3 +1250,29 @@ extension on ChangeReporterBuilder {
12411250
);
12421251
}
12431252
}
1253+
1254+
extension on analyzer_plugin.AnalysisError {
1255+
analyzer_plugin.AnalysisError copyWith({
1256+
analyzer_plugin.AnalysisErrorSeverity? severity,
1257+
String? correction,
1258+
analyzer_plugin.Location? location,
1259+
String? message,
1260+
analyzer_plugin.AnalysisErrorType? type,
1261+
String? code,
1262+
String? url,
1263+
List<analyzer_plugin.DiagnosticMessage>? contextMessages,
1264+
bool? hasFix,
1265+
}) {
1266+
return analyzer_plugin.AnalysisError(
1267+
severity ?? this.severity,
1268+
type ?? this.type,
1269+
location ?? this.location,
1270+
message ?? this.message,
1271+
code ?? this.code,
1272+
correction: correction ?? this.correction,
1273+
url: url ?? this.url,
1274+
contextMessages: contextMessages ?? this.contextMessages,
1275+
hasFix: hasFix ?? this.hasFix,
1276+
);
1277+
}
1278+
}

packages/custom_lint_builder/lib/src/custom_analyzer_converter.dart

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -72,28 +72,23 @@ class CustomAnalyzerConverter {
7272
/// start column. If an analysis [options] is provided then the severities of
7373
/// the errors will be altered based on those options.
7474
List<plugin.AnalysisError> convertAnalysisErrors(
75-
List<analyzer.AnalysisError> errors, {
76-
analyzer.LineInfo? lineInfo,
77-
analyzer.AnalysisOptions? options,
78-
Map<String, analyzer.ErrorSeverity>? configSeverities,
79-
}) {
80-
final serverErrors = <plugin.AnalysisError>[];
81-
for (final error in errors) {
82-
final processor = analyzer.ErrorProcessor.getProcessor(options, error);
83-
final configSeverity = configSeverities?[error.errorCode.name];
84-
// Config severities override processor severities
85-
final severity = configSeverity ?? processor?.severity;
86-
87-
// Errors with ignore severity are filtered out.
88-
if (severity == analyzer.ErrorSeverity.NONE) {
89-
continue;
75+
List<analyzer.AnalysisError> errors,
76+
{analyzer.LineInfo? lineInfo,
77+
analyzer.AnalysisOptions? options}) {
78+
var serverErrors = <plugin.AnalysisError>[];
79+
for (var error in errors) {
80+
var processor = analyzer.ErrorProcessor.getProcessor(options, error);
81+
if (processor != null) {
82+
var severity = processor.severity;
83+
// Errors with null severity are filtered out.
84+
if (severity != null) {
85+
// Specified severities override.
86+
serverErrors.add(convertAnalysisError(error,
87+
lineInfo: lineInfo, severity: severity));
88+
}
89+
} else {
90+
serverErrors.add(convertAnalysisError(error, lineInfo: lineInfo));
9091
}
91-
92-
serverErrors.add(convertAnalysisError(
93-
error,
94-
lineInfo: lineInfo,
95-
severity: severity,
96-
));
9792
}
9893
return serverErrors;
9994
}

0 commit comments

Comments
 (0)