Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions .github/workflows/flutter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v7

- name: Setup Flutter
uses: subosito/flutter-action@v2
Expand All @@ -24,17 +24,14 @@ jobs:
run: dart format . --set-exit-if-changed

- name: Run default analyzer
run: flutter analyze

- name: Run custom analyzer
run: dart run custom_lint
run: dart analyze

- name: Run tests
run: |
# run tests if `test` folder exists
if [ -d test ]
then
flutter test -r expanded
dart test -r expanded
else
echo "Tests not found."
fi
4 changes: 2 additions & 2 deletions lib/src/common/parameter_parser/analysis_options_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ class AnalysisOptionsParser {

Map<String, Object?> _toStandardMap(Map<dynamic, dynamic> map) =>
map.whereKeyType<String>().map(
(key, value) => MapEntry(key, _toStandardType(value)),
);
(key, value) => MapEntry(key, _toStandardType(value)),
);

Object? _toStandardType(Object? value) => switch (value) {
Map() => _toStandardMap(value),
Expand Down
4 changes: 1 addition & 3 deletions lib/src/common/parameter_parser/rules_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,5 @@ class RulesData {
const RulesData({required this.rules, required this.disabledRules});

/// Creates a new empty instance of [RulesData].
const RulesData.empty()
: rules = const {},
disabledRules = const {};
const RulesData.empty() : rules = const {}, disabledRules = const {};
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class AvoidDebugPrintInReleaseRule extends AnalysisRule {

/// Creates an instance of [AvoidDebugPrintInReleaseRule].
AvoidDebugPrintInReleaseRule()
: super(name: lintName, description: 'Avoid debugPrint in release mode.');
: super(name: lintName, description: 'Avoid debugPrint in release mode.');

@override
LintCode get diagnosticCode => _code;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,15 @@ class AvoidFinalWithGetterFix extends ResolvedCorrectionProducer {
@override
Future<void> compute(ChangeBuilder builder) async {
final getterNode = node;
if (getterNode
case MethodDeclaration(
isGetter: true,
declaredFragment: ExecutableFragment(
element: GetterElement(
isAbstract: false,
isPublic: true,
),
),
)) {
if (getterNode case MethodDeclaration(
isGetter: true,
declaredFragment: ExecutableFragment(
element: GetterElement(
isAbstract: false,
isPublic: true,
),
),
)) {
final compilationUnit = node.thisOrAncestorOfType<CompilationUnit>();
if (compilationUnit == null) return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ extension GetterReferenceId on MethodDeclaration {
statements: [
ReturnStatement(expression: final expr?),
],
)
) =>
expr,
),
) => expr,
_ => null,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,16 @@ class AvoidFinalWithGetterVisitor extends RecursiveAstVisitor<void> {
void visitMethodDeclaration(MethodDeclaration node) {
super.visitMethodDeclaration(node);

if (node
case MethodDeclaration(
isGetter: true,
declaredFragment: ExecutableFragment(
element: ExecutableElement(
isAbstract: false,
isPublic: true,
)
),
getterReferenceId: final getterId?,
)) {
if (node case MethodDeclaration(
isGetter: true,
declaredFragment: ExecutableFragment(
element: ExecutableElement(
isAbstract: false,
isPublic: true,
),
),
getterReferenceId: final getterId?,
)) {
_gettersPairLookup[getterId] = node;

if (_fieldsPairLookup.containsKey(getterId)) {
Expand All @@ -42,16 +41,15 @@ class AvoidFinalWithGetterVisitor extends RecursiveAstVisitor<void> {
void visitVariableDeclaration(VariableDeclaration node) {
super.visitVariableDeclaration(node);

if (node
case VariableDeclaration(
declaredFragment: VariableFragment(
element: VariableElement(
isPrivate: true,
isFinal: true,
id: final variableId,
)
)
)) {
if (node case VariableDeclaration(
declaredFragment: VariableFragment(
element: VariableElement(
isPrivate: true,
isFinal: true,
id: final variableId,
),
),
)) {
_fieldsPairLookup[variableId] = node;

if (_gettersPairLookup[variableId] case final getter?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,22 @@ class GetterVariableVisitor extends RecursiveAstVisitor<void> {

/// Creates a new instance of [GetterVariableVisitor]
GetterVariableVisitor(MethodDeclaration getter)
: _getterId = getter.getterReferenceId;
: _getterId = getter.getterReferenceId;

/// Is there a variable associated with the getter
VariableDeclaration? get variable => _variable;

@override
void visitVariableDeclaration(VariableDeclaration node) {
if (node
case VariableDeclaration(
declaredFragment: VariableFragment(
element: VariableElement(
isPrivate: true,
isFinal: true,
:final id,
)
)
) when id == _getterId) {
if (node case VariableDeclaration(
declaredFragment: VariableFragment(
element: VariableElement(
isPrivate: true,
isFinal: true,
:final id,
),
),
) when id == _getterId) {
_variable = node;
}

Expand Down
8 changes: 4 additions & 4 deletions lib/src/lints/avoid_global_state/avoid_global_state_rule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ class AvoidGlobalStateRule extends AnalysisRule {

/// Creates an instance of [AvoidGlobalStateRule].
AvoidGlobalStateRule()
: super(
name: lintName,
description: 'Avoid top-level or static mutable variables ',
);
: super(
name: lintName,
description: 'Avoid top-level or static mutable variables ',
);

@override
LintCode get diagnosticCode => _code;
Expand Down
10 changes: 5 additions & 5 deletions lib/src/lints/avoid_late_keyword/avoid_late_keyword_rule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ class AvoidLateKeywordRule extends SolidLintRule<AvoidLateKeywordParameters> {

/// Creates an instance of [AvoidLateKeywordRule].
AvoidLateKeywordRule({required super.analysisOptionsLoader})
: super.withParameters(
name: lintName,
description: 'Warns against using the late keyword.',
parametersParser: AvoidLateKeywordParameters.fromJson,
);
: super.withParameters(
name: lintName,
description: 'Warns against using the late keyword.',
parametersParser: AvoidLateKeywordParameters.fromJson,
);

@override
LintCode get diagnosticCode => _code;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ class AvoidReturningWidgetsVisitor extends RecursiveAstVisitor<void> {
final returnType = switch (node) {
Declaration(
declaredFragment: ExecutableFragment(
element: ExecutableElement(type: FunctionType(:final returnType))
)
element: ExecutableElement(type: FunctionType(:final returnType)),
),
) =>
returnType,
MethodDeclaration(returnType: TypeAnnotation(:final type)) => type,
Expand All @@ -70,8 +70,8 @@ class AvoidReturningWidgetsVisitor extends RecursiveAstVisitor<void> {
declaredFragment: Fragment(
element: Element(
name: final String name,
enclosingElement: final InterfaceElement enclosingElement
)
enclosingElement: final InterfaceElement enclosingElement,
),
),
) =>
enclosingElement.getInheritedMember(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ class AvoidUnnecessarySetStateRule extends AnalysisRule {
static const lintName = 'avoid_unnecessary_setstate';

/// The message shown when the lint rule is triggered.
static const _lintMessage = 'Avoid calling unnecessary setState. '
static const _lintMessage =
'Avoid calling unnecessary setState. '
'Consider changing the state directly.';

/// The lint code for this rule.
Expand All @@ -71,10 +72,10 @@ class AvoidUnnecessarySetStateRule extends AnalysisRule {

/// Creates a new instance of [AvoidUnnecessarySetStateRule].
AvoidUnnecessarySetStateRule()
: super(
name: lintName,
description: _lintMessage,
);
: super(
name: lintName,
description: _lintMessage,
);

@override
LintCode get diagnosticCode => _code;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ class AvoidUsingApiParameters {
final avoidUsingApi = json['avoid_using_api'];
return AvoidUsingApiParameters(
entries: List<AvoidUsingApiEntryParameters>.from(
(json['entries'] as Iterable?)
?.whereType<Map<dynamic, dynamic>>()
.map(
(json['entries'] as Iterable?)?.whereType<Map<dynamic, dynamic>>().map(
Comment thread
solid-illiaaihistov marked this conversation as resolved.
(e) {
if (e is YamlMap) {
return AvoidUsingApiEntryParameters.fromJson(e.toMap());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ class MemberOrderingParameters {

/// Factory for creating empty/default parameters.
factory MemberOrderingParameters.empty() => MemberOrderingParameters(
groupsOrder: MemberOrderingConfigParser.parseOrder(null),
widgetsGroupsOrder: MemberOrderingConfigParser.parseWidgetsOrder(null),
alphabetize: false,
alphabetizeByType: false,
);
groupsOrder: MemberOrderingConfigParser.parseOrder(null),
widgetsGroupsOrder: MemberOrderingConfigParser.parseWidgetsOrder(null),
alphabetize: false,
alphabetizeByType: false,
);

/// Method for creating from json data
factory MemberOrderingParameters.fromJson(Map<String, Object?> json) =>
Expand Down
6 changes: 4 additions & 2 deletions lib/src/lints/member_ordering/models/modifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ enum Modifier {
const Modifier(this.type);

/// Parses a String access modifier and returns instance of [Modifier]
static Modifier parse(String? name) => values
.firstWhere((type) => type.type == name, orElse: () => Modifier.unset);
static Modifier parse(String? name) => values.firstWhere(
(type) => type.type == name,
orElse: () => Modifier.unset,
);
}

/// Logical implication operation for access modifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,9 @@ class NamedParametersOrderingParameters {
/// Method for creating from json data
factory NamedParametersOrderingParameters.fromJson(
Map<String, Object?> json,
) =>
NamedParametersOrderingParameters(
order: NamedParametersConfigParser.parseOrder(
json[_orderConfig],
),
);
) => NamedParametersOrderingParameters(
order: NamedParametersConfigParser.parseOrder(
json[_orderConfig],
),
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ enum ParameterType {
return ParameterType.defaultValue;

case FieldFormalParameter(:final isRequired) ||
FunctionTypedFormalParameter(:final isRequired) ||
SimpleFormalParameter(:final isRequired):
FunctionTypedFormalParameter(:final isRequired) ||
SimpleFormalParameter(:final isRequired):
return isRequired ? ParameterType.required : ParameterType.nullable;
}
}
Expand Down
10 changes: 6 additions & 4 deletions lib/src/lints/no_empty_block/no_empty_block_rule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,13 @@ import 'package:solid_lints/src/models/solid_lint_rule.dart';
/// #### GOOD:
/// ```dart
/// int fn() {
// ignore: todo
/// // TODO: complete this
/// }
///
/// Function getCallback() {
/// return () {
// ignore: todo
/// // TODO: actually do something
/// };
/// }
Expand Down Expand Up @@ -81,10 +83,10 @@ class NoEmptyBlockRule extends SolidLintRule<NoEmptyBlockParameters> {
NoEmptyBlockRule({
required super.analysisOptionsLoader,
}) : super.withParameters(
name: lintName,
description: _code.problemMessage,
parametersParser: NoEmptyBlockParameters.fromJson,
);
name: lintName,
description: _code.problemMessage,
parametersParser: NoEmptyBlockParameters.fromJson,
);

@override
void registerNodeProcessors(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ class NoMagicNumberParameters {

/// Creates an empty/default instance of [NoMagicNumberParameters]
factory NoMagicNumberParameters.empty() => const NoMagicNumberParameters(
allowedNumbers: _defaultMagicNumbers,
allowedInWidgetParams: false,
);
allowedNumbers: _defaultMagicNumbers,
allowedInWidgetParams: false,
);

/// Method for creating from json data
factory NoMagicNumberParameters.fromJson(Map<String, Object?> json) {
Expand All @@ -62,8 +62,7 @@ class NoMagicNumberParameters {

return NoMagicNumberParameters(
allowedNumbers: allowedList,
allowedInWidgetParams:
json[_allowedInWidgetParamsConfigName] == true,
allowedInWidgetParams: json[_allowedInWidgetParamsConfigName] == true,
);
}
}
8 changes: 4 additions & 4 deletions lib/src/lints/no_magic_number/no_magic_number_rule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ class NoMagicNumberRule extends SolidLintRule<NoMagicNumberParameters> {
NoMagicNumberRule({
required super.analysisOptionsLoader,
}) : super.withParameters(
name: lintName,
description: 'Forbids having numbers without variable.',
parametersParser: NoMagicNumberParameters.fromJson,
);
name: lintName,
description: 'Forbids having numbers without variable.',
parametersParser: NoMagicNumberParameters.fromJson,
);

@override
void registerNodeProcessors(
Expand Down
Loading