-
-
Notifications
You must be signed in to change notification settings - Fork 299
Update analyzer 8 #1301
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update analyzer 8 #1301
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| ## Unreleased 0.1.0 | ||
| ## Unreleased patch | ||
|
|
||
| Support new Analyzer API and custom_lint | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| import 'package:analyzer/diagnostic/diagnostic.dart'; | ||
| import 'package:analyzer/error/error.dart' hide LintCode; | ||
| import 'package:analyzer/error/listener.dart' show ErrorReporter; | ||
| import 'package:analyzer/error/listener.dart' show DiagnosticReporter; | ||
| import 'package:custom_lint_builder/custom_lint_builder.dart'; | ||
| import 'package:freezed_lint/src/tools/element_extensions.dart'; | ||
| import 'package:freezed_lint/src/tools/freezed_annotation_checker.dart'; | ||
|
|
@@ -13,13 +14,13 @@ class MissingPrivateEmptyCtor extends DartLintRule { | |
| correctionMessage: | ||
| 'Freezed classes containing methods, fields or accessors,' | ||
| 'requires a {0}', | ||
| errorSeverity: ErrorSeverity.ERROR, | ||
| errorSeverity: DiagnosticSeverity.ERROR, | ||
| ); | ||
|
|
||
| @override | ||
| void run( | ||
| CustomLintResolver resolver, | ||
| ErrorReporter reporter, | ||
| DiagnosticReporter reporter, | ||
| CustomLintContext context, | ||
| ) { | ||
| context.registry.addClassDeclaration((node) { | ||
|
|
@@ -29,17 +30,17 @@ class MissingPrivateEmptyCtor extends DartLintRule { | |
| final annotation = freezedAnnotationChecker.hasAnnotationOfExact(element); | ||
| if (!annotation) return; | ||
|
|
||
| final methods = element.methods2.where((method) => !method.isStatic); | ||
| final fields = element.fields2.where((field) => !field.isStatic); | ||
| final methods = element.methods.where((method) => !method.isStatic); | ||
| final fields = element.fields.where((field) => !field.isStatic); | ||
|
|
||
| final accessors = [ | ||
| ...element.getters2, | ||
| ...element.setters2, | ||
| ...element.getters, | ||
| ...element.setters, | ||
| ].where((accessor) => !accessor.isStatic); | ||
| if (methods.isEmpty && fields.isEmpty && accessors.isEmpty) return; | ||
|
|
||
| final ctors = element.constructors2.where((ctor) => | ||
| ctor.isPrivate && ctor.formalParameters.isEmpty && ctor.name3 == '_'); | ||
| final ctors = element.constructors.where((ctor) => | ||
| ctor.isPrivate && ctor.formalParameters.isEmpty && ctor.name == '_'); | ||
| if (ctors.isNotEmpty) return; | ||
|
|
||
| final constToken = element.constToken(); | ||
|
|
@@ -58,8 +59,8 @@ class _AddPrivateEmptyCtorFix extends DartFix { | |
| CustomLintResolver resolver, | ||
| ChangeReporter reporter, | ||
| CustomLintContext context, | ||
| AnalysisError analysisError, | ||
| List<AnalysisError> others, | ||
| Diagnostic analysisError, | ||
| List<Diagnostic> others, | ||
| ) { | ||
|
Comment on lines
+62
to
64
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainVerify
🌐 Web query: 💡 Result: Do you want an example extension (code) that converts a custom_lint/analysis Diagnostic into a source range (offset+length or a SourceRange/TextRange), or do you need links/docs about existing utilities (RangeFactory / custom_lint) that do this? 🏁 Script executed: #!/bin/bash
# Search for any usage of `sourceRange` in Dart files
rg -n "sourceRange" -C3 --glob "*.dart"
# Check locked version of custom_lint_builder in pubspec.lock
grep -R "custom_lint_builder" -n pubspec.lockLength of output: 1419 🏁 Script executed: #!/bin/bash
# Check pubspec.yaml files for custom_lint_builder version
fd "pubspec.yaml" --exec grep -Hn "custom_lint_builder" {}
# Look for imports of custom_lint_builder in the file that uses sourceRange
head -20 packages/freezed_lint/lib/src/missing_private_empty_ctor.dart
# Check if sourceRange is defined on Diagnostic type by looking at imports and usage
rg -n "import.*custom_lint" packages/freezed_lint/lib/src/missing_private_empty_ctor.dartLength of output: 948 🌐 Web query: 💡 Result: No. custom_lint_builder adds a sourceRange extension on AnalysisError (and on SyntacticEntity), not on analyzer Diagnostic. [1][2] Sources:
Use AnalysisError for .sourceRange extension
🤖 Prompt for AI Agents |
||
| context.registry.addClassDeclaration((node) { | ||
| if (!analysisError.sourceRange.intersects(node.sourceRange)) return; | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,13 +1,13 @@ | ||||||||||||||||||||||||||
| import 'package:analyzer/dart/element/element2.dart'; | ||||||||||||||||||||||||||
| import 'package:analyzer/dart/element/element.dart'; | ||||||||||||||||||||||||||
| import 'package:analyzer/dart/element/type.dart'; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| extension DartTypeExt on DartType { | ||||||||||||||||||||||||||
| bool hasName(String name) => getDisplayString() == name; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| extension ClassElementExt on ClassElement2 { | ||||||||||||||||||||||||||
| extension ClassElementExt on ClassElement { | ||||||||||||||||||||||||||
| String? constToken() { | ||||||||||||||||||||||||||
| if (constructors2.any((c) => c.isConst)) return 'const '; | ||||||||||||||||||||||||||
| if (constructors.any((c) => c.isConst)) return 'const '; | ||||||||||||||||||||||||||
| return null; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
Comment on lines
+8
to
13
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug:
Fix by returning an empty string instead of null and adjusting the signature: -extension ClassElementExt on ClassElement {
- String? constToken() {
- if (constructors.any((c) => c.isConst)) return 'const ';
- return null;
- }
+extension ClassElementExt on ClassElement {
+ String constToken() {
+ return constructors.any((c) => c.isConst) ? 'const ' : '';
+ }
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,12 +9,12 @@ environment: | |
| sdk: ">=3.0.0 <4.0.0" | ||
|
|
||
| dependencies: | ||
| analyzer: ^7.0.0 | ||
| analyzer: ^8.0.0 | ||
| analyzer_plugin: ^0.13.0 | ||
| custom_lint_builder: ^0.8.0 | ||
| custom_lint_builder: ^0.8.1 | ||
| freezed_annotation: 3.1.0 | ||
|
|
||
| dev_dependencies: | ||
| custom_lint: ^0.8.0 | ||
| custom_lint: ^0.8.1 | ||
| build_verify: ^3.1.0 | ||
|
Comment on lines
+12
to
19
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainConfirm analyzer/custom_lint compatibility and consider widening
Would you like me to check the latest compatibility notes for these versions? 🌐 Web query: 💡 Result: Short summary and recommended fixes:
What to do:
Sources: If you want, tell me your pubspec.yaml and I’ll suggest exact version pins to make your build_runner/custom_lint setup work. Citations:
Update analyzer_plugin to ^0.13.6 and widen freezed_annotation
🤖 Prompt for AI Agents |
||
| test: ^1.22.2 | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
🧩 Analysis chain
Confirm
DiagnosticReporter.atElement2availability.Ensure the
atElement2helper exists forDiagnosticReporterincustom_lint_builder:^0.8.1. If not, switch to the supported reporter API/util in that version.🌐 Web query:
💡 Result:
I searched pub.dev and couldn't find any package or API named "atElement2 DiagnosticReporter". I did find the custom_lint package/docs (related to custom lint plugins) if that helps. Would you like me to search the wider web (GitHub, analyzer API, or Dart SDK) for "atElement2" or "DiagnosticReporter"? [1]
Sources:
[1] custom_lint package docs — pub.dev. (pub.dev)
Citations:
Replace non-existent
atElement2with supportedreportError*API.The
DiagnosticReporter.atElement2helper isn’t provided bycustom_lint_builder:^0.8.1; update any calls to use theErrorReporter.reportErrorForNode(or another availablereportError*) method instead.🤖 Prompt for AI Agents