Skip to content
Open
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
20 changes: 17 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@ dev_dependencies:
solid_lints: <INSERT LATEST VERSION>
```

And then include `solid_lints` into your project top-level `analysis_options.yaml`:
Enable the plugin and include `solid_lints` in your project's top-level `analysis_options.yaml`:

```yaml
include: package:solid_lints/analysis_options.yaml

plugins:
solid_lints:
```

Also you can use a specialized rule set designed for Dart tests.
Also, you can use a specialized rule set designed for Dart tests.
Add an `analysis_options.yaml` file under the `test/` directory, and include the ruleset:

```yaml
Expand All @@ -36,7 +39,18 @@ Then you can see suggestions in your IDE or you can run checks manually:

```bash
dart analyze;
dart run custom_lint;
```

# Configuration

You can customize individual rule settings in your `analysis_options.yaml` under the `solid_lints` configuration block:

```yaml
solid_lints:
diagnostics:
cyclomatic_complexity:
max_complexity: 10
avoid_non_null_assertion: true
```

# Badge
Expand Down
6 changes: 6 additions & 0 deletions doc/docusaurus/docs/1_rulesets/test.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ Given the quite large threshold configured for this metric we considered extract

Both options didn't look right, so we decided that tests are ok to be long.

## cyclomatic_complexity

State: **Disabled**.

Since we're not using the `function_lines_of_code` rule, the `main()` function in tests can have high cyclomatic complexity. For the rationale against splitting up `main()` in tests, see the comments for `function_lines_of_code` above.

## prefer_match_file_name

State: **Disabled**.
Expand Down
4 changes: 2 additions & 2 deletions doc/docusaurus/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"typecheck": "tsc"
},
"dependencies": {
"@docusaurus/core": "^3.1.0",
"@docusaurus/preset-classic": "^3.1.0",
"@docusaurus/core": "^3.10.1",
"@docusaurus/preset-classic": "^3.10.1",
"@easyops-cn/docusaurus-search-local": "^0.40.1",
"@mdx-js/react": "^3.0.0",
"clsx": "^2.1.0",
Expand Down
4,724 changes: 4,365 additions & 359 deletions doc/docusaurus/yarn.lock

Large diffs are not rendered by default.

33 changes: 16 additions & 17 deletions example/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
include: package:solid_lints/analysis_options.yaml

analyzer:
plugins:
- custom_lint
plugins:
solid_lints:

custom_lint:
rules:
- cyclomatic_complexity:
solid_lints:
diagnostics:
cyclomatic_complexity:
max_complexity: 4
- number_of_parameters:
number_of_parameters:
max_parameters: 2
- function_lines_of_code:
function_lines_of_code:
max_lines: 50
- avoid_non_null_assertion
- avoid_late_keyword
- avoid_global_state
- avoid_returning_widgets
- avoid_unnecessary_setstate
- double_literal_format
- avoid_unnecessary_type_assertions
- avoid_debug_print_in_release
- avoid_using_api:
avoid_non_null_assertion: true
avoid_late_keyword: true
avoid_global_state: true
avoid_returning_widgets: true
avoid_unnecessary_setstate: true
double_literal_format: true
avoid_unnecessary_type_assertions: true
avoid_debug_print_in_release: true
avoid_using_api:
severity: info
entries:
- class_name: Future
Expand Down
1 change: 0 additions & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ dependencies:
sdk: flutter

dev_dependencies:
custom_lint: ^0.8.1
solid_lints:
path: ../
test: ^1.25.14
2 changes: 0 additions & 2 deletions lib/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
analyzer:
plugins:
- custom_lint
exclude:
# General generated files
- "**/*.g.dart"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import 'package:analyzer/dart/ast/ast.dart';
/// A parameter model representing excluded annotations for linting.
/// It defines class-level annotations that indicate when class members
/// should be ignored during analysis.
///
/// @docType String | List<String>
class ExcludedAnnotationsListParameter {
/// The set of excluded annotation names.
final Set<String> excludedAnnotations;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import 'package:analyzer/dart/ast/ast.dart';
/// A model representing "exclude_entity" parameters for linting, defining
/// identifiers (classes, mixins, enums, extensions) to be ignored during
/// analysis.
/// Supported entities:
/// - mixin
/// - extension
/// - enum
///
/// @docType String | List<String>
class ExcludedEntitiesListParameter {
/// The parameter model
final Set<String> excludedEntityNames;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import 'package:solid_lints/src/common/parameters/excluded_identifier_parameter.

/// A model representing "exclude" parameters for linting, defining
/// identifiers (classes, methods, functions) to be ignored during analysis.
///
/// @docType String | Map | List<String | Map>
class ExcludedIdentifiersListParameter {
/// A list of identifiers (classes, methods, functions) that should be
/// excluded from the lint.
Expand Down
22 changes: 12 additions & 10 deletions lib/src/lints/avoid_late_keyword/avoid_late_keyword_rule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ import 'package:solid_lints/src/models/solid_lint_rule.dart';
/// ### Example config:
///
/// ```yaml
/// custom_lint:
/// rules:
/// - avoid_late_keyword:
/// allow_initialized: false
/// ignored_types:
/// - AnimationController
/// - ColorTween
/// plugins:
/// solid_lints:
/// diagnostics:
/// avoid_late_keyword:
/// allow_initialized: false
/// ignored_types:
/// - AnimationController
/// - ColorTween
/// ```
///
/// ### Example
Expand All @@ -47,17 +48,18 @@ import 'package:solid_lints/src/models/solid_lint_rule.dart';
/// }
/// ```
class AvoidLateKeywordRule extends SolidLintRule<AvoidLateKeywordParameters> {
static const String _lintName = 'avoid_late_keyword';
/// The lint rule name. Must be public to generate docs.
static const String lintName = 'avoid_late_keyword';

static const LintCode _code = LintCode(
_lintName,
lintName,
'Avoid using the "late" keyword. It may result in runtime exceptions.',
);

/// Creates an instance of [AvoidLateKeywordRule].
AvoidLateKeywordRule({required super.analysisOptionsLoader})
: super.withParameters(
name: _lintName,
name: lintName,
description: 'Warns against using the late keyword.',
parametersParser: AvoidLateKeywordParameters.fromJson,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ class AvoidLateKeywordParameters {
final bool allowInitialized;

/// Types that would be ignored by avoid-late rule
///
/// Example:
///
/// ```yaml
/// custom_lint:
/// rules:
/// - avoid_late_keyword:
/// ignored_types:
/// - ColorTween
/// plugins:
/// solid_lints:
/// diagnostics:
/// avoid_late_keyword:
/// ignored_types:
/// - ColorTween
/// ```
///
/// ```dart
Expand All @@ -37,7 +37,8 @@ class AvoidLateKeywordParameters {
factory AvoidLateKeywordParameters.fromJson(Map<String, Object?> json) =>
AvoidLateKeywordParameters(
allowInitialized: json['allow_initialized'] as bool? ?? false,
ignoredTypes:
List<String>.from(json['ignored_types'] as Iterable? ?? []),
ignoredTypes: List<String>.from(
json['ignored_types'] as Iterable? ?? [],
),
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@ import 'package:solid_lints/src/models/solid_lint_rule.dart';
/// "Bang" operator with Maps is allowed, as [Dart docs](https://dart.dev/null-safety/understanding-null-safety#the-map-index-operator-is-nullable)
/// recommend using it for accessing Map values that are known to be present.
///
/// ### Example config:
///
/// ```yaml
/// plugins:
/// solid_lints:
/// diagnostics:
/// avoid_non_null_assertion:
/// ignored_types:
/// - IMap
/// - BuiltMap
/// ```
///
/// ### Example
/// #### BAD:
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@ import 'package:solid_lints/src/models/solid_lint_rule.dart';
///
/// More details: https://github.com/flutter/flutter/issues/19269
///
/// ### Example config:
///
/// ```yaml
/// plugins:
/// solid_lints:
/// diagnostics:
/// avoid_returning_widgets:
/// exclude:
/// - class_name: MyWidget
/// method_name: buildCustomButton
/// ```
///
/// ### Example
///
/// #### BAD:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ import 'package:solid_lints/src/lints/avoid_unnecessary_return_variable/visitors
/// ```
///
class AvoidUnnecessaryReturnVariableRule extends AnalysisRule {
/// The name of the lint rule.
static const _lintName = 'avoid_unnecessary_return_variable';
/// The lint rule name. Must be public to generate docs.
static const lintName = 'avoid_unnecessary_return_variable';

/// The message shown when the lint is triggered.
static const String _lintMessage = """
Expand All @@ -40,14 +40,14 @@ Rewrite the variable evaluation into return statement instead.""";

/// Lint code.
static const LintCode _code = LintCode(
_lintName,
lintName,
_lintMessage,
);

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,23 @@ import 'package:solid_lints/src/lints/avoid_unnecessary_setstate/visitors/avoid_
/// }
/// ```
class AvoidUnnecessarySetStateRule extends AnalysisRule {
/// The name of the lint rule.
static const _lintName = 'avoid_unnecessary_setstate';
/// The lint rule name. Must be public to generate docs.
static const lintName = 'avoid_unnecessary_setstate';

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

/// The lint code for this rule.
static const _code = LintCode(
_lintName,
lintName,
_lintMessage,
);

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import 'package:solid_lints/src/utils/typecast_utils.dart';
///
/// ### Example:
/// {@template solid_lints.avoid_unnecessary_type_assertions.example_is}
/// #### BAD:
/// #### `is` operator
///
/// ##### BAD:
/// ```dart
/// final testList = [1.0, 2.0, 3.0];
/// final result = testList is List<double>; // LINT
Expand All @@ -18,7 +20,7 @@ import 'package:solid_lints/src/utils/typecast_utils.dart';
/// final casted = d is double; // LINT
/// ```
///
/// #### GOOD:
/// ##### GOOD:
/// ```dart
/// final double? nullableD = 2.0;
/// // casting `Type? is Type` is allowed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ import 'package:solid_lints/src/utils/typecast_utils.dart';
///
/// ### Example:
/// {@template solid_lints.avoid_unnecessary_type_assertions.example_where}
/// #### BAD:
/// #### `whereType` method
///
/// ##### BAD:
/// ```dart
/// final testList = [1.0, 2.0, 3.0];
/// testList.whereType<double>(); // LINT
/// ```
///
/// #### GOOD:
/// ##### GOOD:
/// ```dart
/// final dynamicList = <dynamic>[1.0, 2.0];
/// dynamicList.whereType<double>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@ import 'package:solid_lints/src/lints/avoid_unrelated_type_assertions/visitors/a
/// A `avoid_unrelated_type_assertions` rule which
/// warns about unnecessary usage of `as` operator
class AvoidUnrelatedTypeAssertionsRule extends AnalysisRule {
/// The name of the lint rule.
static const _lintName = 'avoid_unrelated_type_assertions';
/// The lint rule name. Must be public to generate docs.
static const lintName = 'avoid_unrelated_type_assertions';

/// The message shown when the lint rule is triggered.
static const _lintMessage =
'Avoid unrelated "is" assertion. The result is always "{0}".';

/// Lint code for this rule.
static const LintCode _code = LintCode(
_lintName,
lintName,
_lintMessage,
);

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

Expand Down
Loading
Loading