diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index cd5f03c..bc822c0 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -17,11 +17,11 @@ jobs: strategy: fail-fast: false matrix: - sdk: [3.0.0, stable, beta] + sdk: [3.1, stable, beta] steps: - - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - uses: dart-lang/setup-dart@8a4b97ea2017cc079571daec46542f76189836b1 + - uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b + - uses: dart-lang/setup-dart@f0ead981b4d9a35b37f30d36160575d60931ec30 with: sdk: ${{ matrix.sdk }} diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b1032d..5950671 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,14 @@ +## 4.0.0 + +- `core`: + - added `library_annotations` (https://github.com/dart-lang/lints/issues/177) + - added `no_wildcard_variable_uses` (https://github.com/dart-lang/lints/issues/139) + - removed `package_prefixed_library_names` (https://github.com/dart-lang/lints/issues/172) +- `recommended`: + - removed `library_names` (https://github.com/dart-lang/lints/issues/181) +- Updated the SDK lower-bound to 3.1. +- Add a section on upgrading to the latest lint set to the readme. + ## 3.0.0 - `core`: @@ -9,7 +20,6 @@ - added `use_string_in_part_of_directives` - removed `iterable_contains_unrelated_type` - removed `list_remove_unrelated_type` - - removed `no_wildcard_variable_uses` - `recommended`: - added `unnecessary_to_list_in_spreads` - added `use_super_parameters` diff --git a/README.md b/README.md index 827228b..c43af1c 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ For existing apps or packages, you can enable these lints via: 1. In a terminal, located at the root of your package, run this command: ```terminal - dart pub add --dev lints + dart pub add dev:lints ``` 2. Create a new `analysis_options.yaml` file, next to the pubspec, that @@ -71,6 +71,14 @@ For existing apps or packages, you can enable these lints via: include: package:lints/core.yaml ``` +## Upgrading to the latest lints + +To upgrade to the latest version of the lint set, run: + +``` +dart pub add dev:lints +``` + ## Customizing the predefined lint sets For details on customizing static analysis above and beyond the predefined diff --git a/lib/core.yaml b/lib/core.yaml index e986edc..1cfe995 100644 --- a/lib/core.yaml +++ b/lib/core.yaml @@ -21,10 +21,11 @@ linter: - file_names - hash_and_equals - implicit_call_tearoffs + - library_annotations - no_duplicate_case_values + - no_wildcard_variable_uses - non_constant_identifier_names - null_check_on_nullable_type_parameter - - package_prefixed_library_names - prefer_generic_function_type_aliases - prefer_is_empty - prefer_is_not_empty diff --git a/lib/recommended.yaml b/lib/recommended.yaml index d9cd916..eda84d6 100644 --- a/lib/recommended.yaml +++ b/lib/recommended.yaml @@ -25,7 +25,6 @@ linter: - empty_statements - exhaustive_cases - implementation_imports - - library_names - library_prefixes - library_private_types_in_public_api - no_leading_underscores_for_library_prefixes diff --git a/pubspec.yaml b/pubspec.yaml index 647ffa7..66f7a8a 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: lints -version: 3.0.0 +version: 4.0.0 description: > Official Dart lint rules. Defines the 'core' and 'recommended' set of lints suggested by the Dart team. @@ -10,7 +10,7 @@ topics: - lints environment: - sdk: ^3.0.0 + sdk: ^3.1.0 # NOTE: Code is not allowed in this package - do not add dependencies. # dependencies: diff --git a/rules.md b/rules.md index 70dee71..8b44b0e 100644 --- a/rules.md +++ b/rules.md @@ -5,7 +5,7 @@ | Lint Rules | Description | [Fix][] | | :--------- | :---------- | ------- | -| [`avoid_empty_else`](https://dart.dev/lints/avoid_empty_else) | Avoid empty else statements. | ✅ | +| [`avoid_empty_else`](https://dart.dev/lints/avoid_empty_else) | Avoid empty statements in else clauses. | ✅ | | [`avoid_relative_lib_imports`](https://dart.dev/lints/avoid_relative_lib_imports) | Avoid relative imports for files in `lib/`. | ✅ | | [`avoid_shadowing_type_parameters`](https://dart.dev/lints/avoid_shadowing_type_parameters) | Avoid shadowing type parameters. | | | [`avoid_types_as_parameter_names`](https://dart.dev/lints/avoid_types_as_parameter_names) | Avoid types as parameter names. | ✅ | @@ -20,10 +20,11 @@ | [`file_names`](https://dart.dev/lints/file_names) | Name source files using `lowercase_with_underscores`. | | | [`hash_and_equals`](https://dart.dev/lints/hash_and_equals) | Always override `hashCode` if overriding `==`. | ✅ | | [`implicit_call_tearoffs`](https://dart.dev/lints/implicit_call_tearoffs) | Explicitly tear-off `call` methods when using an object as a Function. | ✅ | +| [`library_annotations`](https://dart.dev/lints/library_annotations) | Attach library annotations to library directives. | ✅ | | [`no_duplicate_case_values`](https://dart.dev/lints/no_duplicate_case_values) | Don't use more than one case with same value. | ✅ | +| [`no_wildcard_variable_uses`](https://dart.dev/lints/no_wildcard_variable_uses) | Don't use wildcard parameters or variables. | | | [`non_constant_identifier_names`](https://dart.dev/lints/non_constant_identifier_names) | Name non-constant identifiers using lowerCamelCase. | ✅ | | [`null_check_on_nullable_type_parameter`](https://dart.dev/lints/null_check_on_nullable_type_parameter) | Don't use null check on a potentially nullable type parameter. | ✅ | -| [`package_prefixed_library_names`](https://dart.dev/lints/package_prefixed_library_names) | Prefix library names with the package name and a dot-separated path. | | | [`prefer_generic_function_type_aliases`](https://dart.dev/lints/prefer_generic_function_type_aliases) | Prefer generic function type aliases. | ✅ | | [`prefer_is_empty`](https://dart.dev/lints/prefer_is_empty) | Use `isEmpty` for Iterables and Maps. | ✅ | | [`prefer_is_not_empty`](https://dart.dev/lints/prefer_is_not_empty) | Use `isNotEmpty` for Iterables and Maps. | ✅ | @@ -58,7 +59,6 @@ | [`empty_statements`](https://dart.dev/lints/empty_statements) | Avoid empty statements. | ✅ | | [`exhaustive_cases`](https://dart.dev/lints/exhaustive_cases) | Define case clauses for all constants in enum-like classes. | ✅ | | [`implementation_imports`](https://dart.dev/lints/implementation_imports) | Don't import implementation files from another package. | | -| [`library_names`](https://dart.dev/lints/library_names) | Name libraries using `lowercase_with_underscores`. | | | [`library_prefixes`](https://dart.dev/lints/library_prefixes) | Use `lowercase_with_underscores` when specifying a library prefix. | | | [`library_private_types_in_public_api`](https://dart.dev/lints/library_private_types_in_public_api) | Avoid using private types in public APIs. | | | [`no_leading_underscores_for_library_prefixes`](https://dart.dev/lints/no_leading_underscores_for_library_prefixes) | Avoid leading underscores for library prefixes. | ✅ | diff --git a/tool/gen_docs.dart b/tool/gen_docs.dart index bbbbaef..7a33107 100644 --- a/tool/gen_docs.dart +++ b/tool/gen_docs.dart @@ -90,14 +90,8 @@ String _createRuleTable( final ruleMeta = lintMeta.firstWhereOrNull((meta) => meta['name'] == rule); - if (ruleMeta == null) { - print('rules.json data for rule \'$rule\' not found.'); - print('Update lib/rules.json from ' - 'https://raw.githubusercontent.com/dart-lang/site-www/main/src/_data/linter_rules.json.'); - exit(1); - } - final description = ruleMeta['description'] as String?; - final hasFix = ruleMeta['fixStatus'] == 'hasFix'; + final description = ruleMeta?['description'] as String? ?? ''; + final hasFix = ruleMeta?['fixStatus'] == 'hasFix'; final fixDesc = hasFix ? '✅' : ''; return '| [`$rule`](https://dart.dev/lints/$rule) | $description | $fixDesc |'; diff --git a/tool/rules.json b/tool/rules.json index 72f8b06..fdf9ec9 100644 --- a/tool/rules.json +++ b/tool/rules.json @@ -11,7 +11,7 @@ }, { "name": "avoid_empty_else", - "description": "Avoid empty else statements.", + "description": "Avoid empty statements in else clauses.", "fixStatus": "hasFix" }, { @@ -27,7 +27,7 @@ { "name": "avoid_returning_null_for_future", "description": "Avoid returning null for Future.", - "fixStatus": "hasFix" + "fixStatus": "noFix" }, { "name": "avoid_slow_async_io", @@ -44,6 +44,11 @@ "description": "Avoid types as parameter names.", "fixStatus": "hasFix" }, + { + "name": "avoid_unstable_final_fields", + "description": "Avoid overriding a final field to return different values if called multiple times.", + "fixStatus": "noFix" + }, { "name": "avoid_web_libraries_in_flutter", "description": "Avoid using web-only libraries outside Flutter web plugin packages.", @@ -67,7 +72,7 @@ { "name": "comment_references", "description": "Only reference in scope identifiers in doc comments.", - "fixStatus": "noFix" + "fixStatus": "hasFix" }, { "name": "control_flow_in_finally", @@ -77,7 +82,7 @@ { "name": "deprecated_member_use_from_same_package", "description": "Avoid using deprecated elements from within the package in which they are declared.", - "fixStatus": "needsFix" + "fixStatus": "hasFix" }, { "name": "diagnostic_describe_all_properties", @@ -129,6 +134,11 @@ "description": "Boolean expression composed only with literals.", "fixStatus": "noFix" }, + { + "name": "missing_code_block_language_in_doc_comment", + "description": "A code block is missing a specified language.", + "fixStatus": "needsEvaluation" + }, { "name": "no_adjacent_strings_in_list", "description": "Don't use adjacent strings in list.", @@ -174,6 +184,11 @@ "description": "Avoid `throw` in finally block.", "fixStatus": "noFix" }, + { + "name": "unintended_html_in_doc_comment", + "description": "Use of angle brackets in a doc comment is treated as HTML by Markdown.", + "fixStatus": "needsEvaluation" + }, { "name": "unnecessary_statements", "description": "Avoid using unnecessary statements.", @@ -242,7 +257,7 @@ { "name": "always_require_non_null_named_parameters", "description": "Specify `@required` on named parameters without defaults.", - "fixStatus": "hasFix" + "fixStatus": "noFix" }, { "name": "always_specify_types", @@ -517,7 +532,7 @@ { "name": "flutter_style_todos", "description": "Use Flutter TODO format: // TODO(username): message, https://URL-to-issue.", - "fixStatus": "noFix" + "fixStatus": "hasFix" }, { "name": "implementation_imports", @@ -866,7 +881,7 @@ }, { "name": "require_trailing_commas", - "description": "Use trailing commas for all function calls and declarations.", + "description": "Use trailing commas for all parameter lists and argument lists.", "fixStatus": "hasFix" }, { @@ -979,6 +994,11 @@ "description": "Avoid library directives unless they have documentation comments or annotations.", "fixStatus": "hasFix" }, + { + "name": "unnecessary_library_name", + "description": "Don't have a library name in a `library` declaration.", + "fixStatus": "hasFix" + }, { "name": "unnecessary_new", "description": "Unnecessary new keyword.",