Skip to content

Commit

Permalink
Fixed analyzer issue, fixed linter (#177)
Browse files Browse the repository at this point in the history
  • Loading branch information
solid-glebvorobey authored Sep 18, 2024
1 parent e5fb3e9 commit fc6b52b
Show file tree
Hide file tree
Showing 31 changed files with 93 additions and 109 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ your `debugPrint` call in a `!kReleaseMode` check.""",
return;
}

reporter.reportErrorForNode(code, node);
reporter.atNode(node, code);
}

/// Returns null if doesn't have right operand
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,10 @@ class AvoidFinalWithGetterRule extends SolidLintRule {
node.accept(visitor);

for (final element in visitor.getters) {
reporter.reportErrorForNode(
code,
reporter.atNode(
element.getter,
null,
null,
element,
code,
data: element,
);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ extension on MethodDeclaration {
expression: SimpleIdentifier(
staticElement: Element(
declaration: PropertyAccessorElement(
variable: PropertyInducingElement(:final id)
variable2: PropertyInducingElement(:final id)
)
)
)
Expand Down
4 changes: 2 additions & 2 deletions lib/src/lints/avoid_global_state/avoid_global_state_rule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ class AvoidGlobalStateRule extends SolidLintRule {
context.registry.addTopLevelVariableDeclaration(
(node) => node.variables.variables
.where((variable) => variable.isPublicMutable)
.forEach((node) => reporter.reportErrorForNode(code, node)),
.forEach((node) => reporter.atNode(node, code)),
);
context.registry.addFieldDeclaration((node) {
if (!node.isStatic) return;
node.fields.variables
.where((variable) => variable.isPublicMutable)
.forEach((node) => reporter.reportErrorForNode(code, node));
.forEach((node) => reporter.atNode(node, code));
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class AvoidLateKeywordRule extends SolidLintRule<AvoidLateKeywordParameters> {
) {
context.registry.addVariableDeclaration((node) {
if (_shouldLint(node)) {
reporter.reportErrorForNode(code, node);
reporter.atNode(node, code);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class AvoidNonNullAssertionRule extends SolidLintRule {
}
}

reporter.reportErrorForNode(code, node);
reporter.atNode(node, code);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class AvoidReturningWidgetsRule
final isOverriden = node.declaredElement?.hasOverride ?? false;

if (isWidgetReturned && !isOverriden && !isIgnored) {
reporter.reportErrorForNode(code, node);
reporter.atNode(node, code);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class AvoidUnnecessarySetStateRule extends SolidLintRule {
final visitor = AvoidUnnecessarySetStateVisitor();
visitor.visitClassDeclaration(node);
for (final element in visitor.setStateInvocations) {
reporter.reportErrorForNode(code, element);
reporter.atNode(element, code);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ class AvoidUnnecessaryTypeAssertions extends SolidLintRule {
) {
context.registry.addIsExpression((node) {
if (_isUnnecessaryIsExpression(node)) {
reporter.reportErrorForNode(_unnecessaryIsCode, node);
reporter.atNode(node, _unnecessaryIsCode);
}
});

context.registry.addMethodInvocation((node) {
if (_isUnnecessaryWhereType(node)) {
reporter.reportErrorForNode(_unnecessaryWhereTypeCode, node);
reporter.atNode(node, _unnecessaryWhereTypeCode);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class AvoidUnnecessaryTypeCastsRule extends SolidLintRule {
visitor.visitAsExpression(node);

for (final element in visitor.expressions.entries) {
reporter.reportErrorForNode(code, element.key);
reporter.atNode(element.key, code);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ class AvoidUnrelatedTypeAssertionsRule extends SolidLintRule {
visitor.visitIsExpression(node);

for (final element in visitor.expressions.entries) {
reporter.reportErrorForNode(
code,
reporter.atNode(
element.key,
[element.value.toString()],
code,
arguments: [element.value.toString()],
);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class AvoidUnusedParametersRule extends SolidLintRule {
node.accept(visitor);

for (final element in visitor.unusedParameters) {
reporter.reportErrorForNode(code, element);
reporter.atNode(element, code);
}
});
}
Expand Down
28 changes: 17 additions & 11 deletions lib/src/lints/avoid_using_api/avoid_using_api_linter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class AvoidUsingApiLinter {
return;
}

reporter.reportErrorForNode(entryCode, node);
reporter.atNode(node, entryCode);
});

context.registry.addNamedType((node) {
Expand All @@ -72,7 +72,7 @@ class AvoidUsingApiLinter {
return;
}

reporter.reportErrorForNode(entryCode, node);
reporter.atNode(node, entryCode);
});
}

Expand All @@ -96,7 +96,7 @@ class AvoidUsingApiLinter {

switch (node.staticElement) {
case FunctionElement() || PropertyAccessorElement():
reporter.reportErrorForNode(entryCode, node);
reporter.atNode(node, entryCode);
}
});
}
Expand All @@ -118,7 +118,7 @@ class AvoidUsingApiLinter {
if (sourcePath == null || !_matchesSource(sourcePath, source)) {
return;
}
reporter.reportErrorForNode(entryCode, node);
reporter.atNode(node, entryCode);
});

context.registry.addSimpleIdentifier((node) {
Expand Down Expand Up @@ -162,7 +162,7 @@ class AvoidUsingApiLinter {
return;
}

reporter.reportErrorForNode(entryCode, parent);
reporter.atNode(parent, entryCode);
});

context.registry.addNamedType((node) {
Expand All @@ -176,9 +176,9 @@ class AvoidUsingApiLinter {
return;
}

reporter.reportErrorForNode(
entryCode,
reporter.atNode(
node.parent?.parent ?? node.parent ?? node,
entryCode,
);
});
}
Expand Down Expand Up @@ -219,23 +219,29 @@ class AvoidUsingApiLinter {
return;
}

reporter.reportErrorForNode(entryCode, node.parent ?? node);
reporter.atNode(
node.parent ?? node,
entryCode,
);
case SimpleIdentifier(:final staticElement?):
final parentElementName = staticElement.name;
if (parentElementName != className) {
return;
}

reporter.reportErrorForNode(entryCode, node.parent ?? node);
reporter.atNode(
node.parent ?? node,
entryCode,
);
case NamedType(:final element?):
final parentTypeName = element.name;
if (parentTypeName != className) {
return;
}

reporter.reportErrorForNode(
entryCode,
reporter.atNode(
node.parent?.parent ?? node.parent ?? node,
entryCode,
);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class CyclomaticComplexityRule

if (visitor.complexityEntities.length + 1 >
config.parameters.maxComplexity) {
reporter.reportErrorForNode(code, node);
reporter.atNode(node, code);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ class DoubleLiteralFormatRule extends SolidLintRule {
final lexeme = node.literal.lexeme;

if (lexeme.hasLeadingZero) {
reporter.reportErrorForNode(_leadingZeroCode, node);
reporter.atNode(node, _leadingZeroCode);
return;
}
if (lexeme.hasLeadingDecimalPoint) {
reporter.reportErrorForNode(_leadingDecimalCode, node);
reporter.atNode(node, _leadingDecimalCode);
return;
}
if (lexeme.hasTrailingZero) {
reporter.reportErrorForNode(_trailingZeroCode, node);
reporter.atNode(node, _trailingZeroCode);
return;
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,16 @@ class FunctionLinesOfCodeRule

if (visitor.linesWithCode.length > config.parameters.maxLines) {
if (node is! AnnotatedNode) {
return reporter.reportErrorForNode(code, node);
return reporter.atNode(node, code);
}

final startOffset = node.firstTokenAfterCommentAndMetadata.offset;
final lengthDifference = startOffset - node.offset;

reporter.reportErrorForOffset(
code,
startOffset,
node.length - lengthDifference,
reporter.atOffset(
offset: startOffset,
length: node.length - lengthDifference,
errorCode: code,
);
}
}
Expand Down
12 changes: 6 additions & 6 deletions lib/src/lints/member_ordering/member_ordering_rule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ class MemberOrderingRule extends SolidLintRule<MemberOrderingParameters> {
);

for (final memberInfo in wrongOrderMembers) {
reporter.reportErrorForNode(
_createWrongOrderLintCode(memberInfo),
reporter.atNode(
memberInfo.classMember,
_createWrongOrderLintCode(memberInfo),
);
}

Expand All @@ -137,9 +137,9 @@ class MemberOrderingRule extends SolidLintRule<MemberOrderingParameters> {
);

for (final memberInfo in alphabeticallyWrongOrderMembers) {
reporter.reportErrorForNode(
_createAlphabeticallyWrongOrderLintCode(memberInfo),
reporter.atNode(
memberInfo.classMember,
_createAlphabeticallyWrongOrderLintCode(memberInfo),
);
}
}
Expand All @@ -151,9 +151,9 @@ class MemberOrderingRule extends SolidLintRule<MemberOrderingParameters> {
);

for (final memberInfo in alphabeticallyByTypeWrongOrderMembers) {
reporter.reportErrorForNode(
_createAlphabeticallyByTypeWrongOrderLintCode(memberInfo),
reporter.atNode(
memberInfo.classMember,
_createAlphabeticallyByTypeWrongOrderLintCode(memberInfo),
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ class MemberOrderingVisitor extends RecursiveAstVisitor<List<MemberInfo>> {
memberOrder: _getOrder(
closestGroup,
declaration.fields.variables.first.name.lexeme,
declaration.fields.type?.type
?.getDisplayString(withNullability: false) ??
'_',
declaration.fields.type?.type?.getDisplayString() ?? '_',
isFlutterWidget,
),
),
Expand Down Expand Up @@ -132,9 +130,7 @@ class MemberOrderingVisitor extends RecursiveAstVisitor<List<MemberInfo>> {
memberOrder: _getOrder(
closestGroup,
declaration.name.lexeme,
declaration.returnType?.type
?.getDisplayString(withNullability: false) ??
'_',
declaration.returnType?.type?.getDisplayString() ?? '_',
isFlutterWidget,
),
),
Expand All @@ -151,9 +147,7 @@ class MemberOrderingVisitor extends RecursiveAstVisitor<List<MemberInfo>> {
memberOrder: _getOrder(
closestGroup,
declaration.name.lexeme,
declaration.returnType?.type
?.getDisplayString(withNullability: false) ??
'_',
declaration.returnType?.type?.getDisplayString() ?? '_',
isFlutterWidget,
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class NewlineBeforeReturnRule extends SolidLintRule {
visitor.visitReturnStatement(node);

for (final element in visitor.statements) {
reporter.reportErrorForNode(code, element);
reporter.atNode(element, code);
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/lints/no_empty_block/no_empty_block_rule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class NoEmptyBlockRule extends SolidLintRule {
node.accept(visitor);

for (final emptyBlock in visitor.emptyBlocks) {
reporter.reportErrorForNode(code, emptyBlock);
reporter.atNode(emptyBlock, code);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class NoEqualThenElseRule extends SolidLintRule {
node.accept(visitor);

for (final element in visitor.nodes) {
reporter.reportErrorForNode(code, element);
reporter.atNode(element, code);
}
});
}
Expand Down
8 changes: 3 additions & 5 deletions lib/src/lints/no_magic_number/no_magic_number_rule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ class NoMagicNumberRule extends SolidLintRule<NoMagicNumberParameters> {
.where(_isNotWidgetParameter);

for (final magicNumber in magicNumbers) {
reporter.reportErrorForNode(code, magicNumber);
reporter.atNode(magicNumber, code);
}
});
}
Expand Down Expand Up @@ -212,8 +212,7 @@ class NoMagicNumberRule extends SolidLintRule<NoMagicNumberParameters> {
l.thisOrAncestorMatching(
(a) =>
a is InstanceCreationExpression &&
a.staticType?.getDisplayString(withNullability: false) ==
'DateTime',
a.staticType?.getDisplayString() == 'DateTime',
) ==
null;

Expand Down Expand Up @@ -269,8 +268,7 @@ class NoMagicNumberRule extends SolidLintRule<NoMagicNumberParameters> {
if (staticType is! InterfaceType) return false;

final widgetSupertype = staticType.allSupertypes.firstWhereOrNull(
(supertype) =>
supertype.getDisplayString(withNullability: false) == 'Widget',
(supertype) => supertype.getDisplayString() == 'Widget',
);

return widgetSupertype != null;
Expand Down
Loading

0 comments on commit fc6b52b

Please sign in to comment.