Skip to content

Commit

Permalink
Merge branch 'release-v0.1.0' into proper_super_calls
Browse files Browse the repository at this point in the history
  • Loading branch information
maxxlab authored Nov 17, 2023
2 parents 1441a33 + 6aae62c commit 9ff1bf9
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 10 deletions.
7 changes: 0 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,8 @@ Then you can see suggestions in your IDE or you can run checks manually:

```bash
dart analyze;
dart run dart_code_metrics:metrics analyze lib test;
dart run dart_code_metrics:metrics check-unused-files lib test;
dart run dart_code_metrics:metrics check-unused-l10n lib test;
```
Beware that some of the `dart_code_metrics` checks are not displayed in IDE so running checks
manually or in your actions (CI) is essential.

Learn more: https://github.com/dart-code-checker/dart-code-metrics#cli
# Badge

To indicate that your project is using Solid Lints, you can use the following badge:
Expand Down
12 changes: 11 additions & 1 deletion lib/lints/no_magic_number/no_magic_number_rule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ class NoMagicNumberRule extends SolidLintRule<NoMagicNumberParameters> {
.where(_isNotInsideConstConstructor)
.where(_isNotInDateTime)
.where(_isNotInsideIndexExpression)
.where(_isNotInsideEnumConstantArguments);
.where(_isNotInsideEnumConstantArguments)
.where(_isNotDefaultValue)
.where(_isNotInConstructorInitializer);

for (final magicNumber in magicNumbers) {
reporter.reportErrorForNode(code, magicNumber);
Expand Down Expand Up @@ -122,4 +124,12 @@ class NoMagicNumberRule extends SolidLintRule<NoMagicNumberParameters> {
null;

bool _isNotInsideIndexExpression(Literal l) => l.parent is! IndexExpression;

bool _isNotDefaultValue(Literal literal) {
return literal.thisOrAncestorOfType<DefaultFormalParameter>() == null;
}

bool _isNotInConstructorInitializer(Literal literal) {
return literal.thisOrAncestorOfType<ConstructorInitializer>() == null;
}
}
35 changes: 33 additions & 2 deletions lint_test/no_magic_number_test.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// ignore_for_file: unused_local_variable, prefer_match_file_name
// ignore_for_file: unused_local_variable
// ignore_for_file: prefer_match_file_name
// ignore_for_file: avoid_unused_parameters
// ignore_for_file: no_empty_block

/// Check the `no_magic_number` rule
Expand Down Expand Up @@ -52,6 +55,34 @@ void fun() {
// Allowed in indexed expression
final result = list[1];

// Allowed in DateTime because it doesn't have cons constructor
// Allowed in DateTime because it doesn't have const constructor
final apocalypse = DateTime(2012, 12, 21);
}

// Allowed for defaults in constructors and methods.
class DefaultValues {
final int value;

DefaultValues.named({
this.value = 2,
});

DefaultValues.positional([
this.value = 3,
]);

void methodWithNamedParam({int value = 4}) {}

void methodWithPositionalParam([int value = 5]) {}
}

void topLevelFunctionWithDefaultParam({int value = 6}) {
({int value = 7}) {};
}

// Allowed for numbers in constructor initializer.
class ConstructorInitializer {
final int value;

ConstructorInitializer() : value = 10;
}

0 comments on commit 9ff1bf9

Please sign in to comment.