Skip to content
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

Bugfix/add custom_lint_core dependency and import it #90

Merged
merged 2 commits into from
Sep 2, 2024

Conversation

manuel-plavsic
Copy link
Collaborator

dart run custom_lint does not run successfully due to import collision of the analyzer and custom_lint_core packages. They both have a LintCode class, but only the custom_lint_core is the one that solidart_lint directly uses.

You can also see the package doesn't pass the static analysis at the moment (https://pub.dev/packages/solidart_lint/score).

Copy link

codecov bot commented Sep 1, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (f24e1b6) to head (e226f2f).
Report is 1 commits behind head on dev.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##               dev       #90   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           20        20           
  Lines         1166      1166           
=========================================
  Hits          1166      1166           

@nank1ro
Copy link
Owner

nank1ro commented Sep 1, 2024

Does it work now?
Thanks for the PR 🙏

@manuel-plavsic
Copy link
Collaborator Author

manuel-plavsic commented Sep 1, 2024

Yes, it works now :) I tested it with a pubspec_overrides.yaml.

However, it works for me only if I temporarily comment out some packages in my pubspec.yaml (in my case they are sqlite3_flutter_libs, path_provider, device_info_plus and shared_preferences). If I don't comment them out, I get failures similar to this one:

❯ dart run custom_lint
Building package executable... (2.9s)
Built custom_lint:custom_lint.
Failed to decode .dart_tool/package_config.json at /run/host/unsynced/manuel/Workspace/photos/code/app/linux/flutter/ephemeral/.plugin_symlinks/path_provider_linux. Make sure to run `pub get` first.
PathNotFoundException: Cannot open file, path = '/run/host/unsynced/manuel/Workspace/photos/code/app/linux/flutter/ephemeral/.plugin_symlinks/path_provider_linux/.dart_tool/package_config.json' (OS Error: No such file or directory, errno = 2)
#0      _checkForErrorResponse (dart:io/common.dart:55:9)
#1      _File.open.<anonymous closure> (dart:io/file_impl.dart:381:7)
#2      _rootRunUnary (dart:async/zone.dart:1407:47)
#3      _CustomZone.runUnary (dart:async/zone.dart:1308:19)
<asynchronous suspension>
#4      _File.readAsBytes.<anonymous closure> (dart:io/file_impl.dart:562:24)
<asynchronous suspension>
#5      parsePackageConfig (package:custom_lint_core/src/package_utils.dart:161:5)
<asynchronous suspension>
#6      CustomLintProject.parse (package:custom_lint/src/workspace.dart:1025:34)
<asynchronous suspension>
#7      Future.wait.<anonymous closure> (dart:async/future.dart:534:21)
<asynchronous suspension>
#8      CustomLintWorkspace.fromContextRoots (package:custom_lint/src/workspace.dart:516:22)
<asynchronous suspension>
#9      _runServer.<anonymous closure> (package:custom_lint/custom_lint.dart:90:25)
<asynchronous suspension>
#10     _AsyncCompleter.complete (dart:async/future_impl.dart:41:3)
<asynchronous suspension>
#11     _runServer.<anonymous closure> (package:custom_lint/custom_lint.dart:126:19)
<asynchronous suspension>
#12     _runServer (package:custom_lint/custom_lint.dart:86:3)
<asynchronous suspension>
#13     customLint (package:custom_lint/custom_lint.dart:50:5)
<asynchronous suspension>
#14     entrypoint (file:///unsynced/manuel/.pub-cache/hosted/pub.dev/custom_lint-0.6.5/bin/custom_lint.dart:68:3)
<asynchronous suspension>
#15     main (file:///unsynced/manuel/.pub-cache/hosted/pub.dev/custom_lint-0.6.5/bin/custom_lint.dart:80:5)
<asynchronous suspension>

#0      CustomLintProject.parse.<anonymous closure> (package:custom_lint/src/workspace.dart:1028:7)
#1      _rootRunBinary (dart:async/zone.dart:1423:47)
#2      _CustomZone.runBinary (dart:async/zone.dart:1315:19)
#3      _FutureListener.handleError (dart:async/future_impl.dart:178:22)
#4      Future._propagateToListeners.handleError (dart:async/future_impl.dart:873:47)
#5      Future._propagateToListeners (dart:async/future_impl.dart:894:13)
#6      Future._completeError (dart:async/future_impl.dart:674:5)
<asynchronous suspension>

The /run/host/unsynced/manuel/Workspace/photos/code/app/linux/flutter/ephemeral/.plugin_symlinks/path_provider_linux/.dart_tool/ folder does not exist, although its parent folder is present on my machine. I didn't further debug this issue, so I don't know if it is a solidart_lint issue or something wrong with my setup. Maybe do you know what this is caused by? And can you test if you get the same kind of error?

Note: The issue I just brought up is not introduced by this PR. It was already present before.

@manuel-plavsic
Copy link
Collaborator Author

manuel-plavsic commented Sep 1, 2024

Since it is actually a separate issue I opened #91 and we can continue the conversation there.

@nank1ro
Copy link
Owner

nank1ro commented Sep 2, 2024

Hey there,
I just tried the "github-search" example, the "dart run custom_lint" command works correctly without the fixes you provided.
Maybe some dependencies are old in your pc.
Can you try the following commands in your project (not the examples inside solidart, something external)

rm pubspec.lock
flutter clean
flutter pub get
dart run custom_lint

Before doing this delete the custom_lint.log file.
Then reopen the project, await for the analysis server to start and see if you remove the type from a Provider you get an error (which is correct).
In case something doesn't work, paste the content of the custom_lint.log file

@manuel-plavsic
Copy link
Collaborator Author

I just tried by cloning your current dev branch and running dart run custom_lint from within github-example (making sure custom_lint.log and pubspec.lock are removed and then flutter clean is run), but it generates this failure:

❯ dart run custom_lint
Building package executable... (2.8s)
Built custom_lint:custom_lint.
/run/host/unsynced/manuel/Downloads/solidart-dev(1)/solidart-dev/packages/solidart_lint/lib/src/lints/avoid_dynamic_provider.dart:11:24: Error: 'LintCode' is imported from both 'package:analyzer/src/dart/error/lint_codes.dart' and 'package:custom_lint_core/src/lint_codes.dart'.
  static const _code = LintCode(
                       ^^^^^^^^
/run/host/unsynced/manuel/Downloads/solidart-dev(1)/solidart-dev/packages/solidart_lint/lib/src/lints/invalid_update_type.dart:10:24: Error: 'LintCode' is imported from both 'package:analyzer/src/dart/error/lint_codes.dart' and 'package:custom_lint_core/src/lint_codes.dart'.
  static const _code = LintCode(
                       ^^^^^^^^
/run/host/unsynced/manuel/Downloads/solidart-dev(1)/solidart-dev/packages/solidart_lint/lib/src/lints/missing_solid_get_type.dart:10:24: Error: 'LintCode' is imported from both 'package:analyzer/src/dart/error/lint_codes.dart' and 'package:custom_lint_core/src/lint_codes.dart'.
  static const _code = LintCode(
                       ^^^^^^^^


Failed to start plugins
The request analysis.setContextRoots failed with the following error:
RequestErrorCode.PLUGIN_ERROR
Bad state: Failed to start the plugins.
at:
#0      SocketCustomLintServerToClientChannel._checkInitializationFail.<anonymous closure> (package:custom_lint/src/v2/server_to_client_channel.dart:223:11)
<asynchronous suspension>
#1      Future.any.onValue (dart:async/future.dart:628:5)
<asynchronous suspension>

_PrettyRequestFailure: {"code":"PLUGIN_ERROR","message":"Bad state: Failed to start the plugins.","stackTrace":"#0      SocketCustomLintServerToClientChannel._checkInitializationFail.<anonymous closure> (package:custom_lint/src/v2/server_to_client_channel.dart:223:11)\n<asynchronous suspension>\n#1      Future.any.onValue (dart:async/future.dart:628:5)\n<asynchronous suspension>\n"}
#0      ChannelBase.sendRequest (package:custom_lint/src/server_isolate_channel.dart:82:7)
<asynchronous suspension>
#1      CustomLintRunner.initialize.<anonymous closure> (package:custom_lint/src/runner.dart:43:5)
<asynchronous suspension>
#2      _runServer.<anonymous closure> (package:custom_lint/custom_lint.dart:96:7)
<asynchronous suspension>
#3      _AsyncCompleter.complete (dart:async/future_impl.dart:41:3)
<asynchronous suspension>
#4      _runServer.<anonymous closure> (package:custom_lint/custom_lint.dart:126:19)
<asynchronous suspension>
#5      _runServer (package:custom_lint/custom_lint.dart:86:3)
<asynchronous suspension>
#6      customLint (package:custom_lint/custom_lint.dart:50:5)
<asynchronous suspension>
#7      entrypoint (file:///unsynced/manuel/.pub-cache/hosted/pub.dev/custom_lint-0.6.5/bin/custom_lint.dart:68:3)
<asynchronous suspension>
#8      main (file:///unsynced/manuel/.pub-cache/hosted/pub.dev/custom_lint-0.6.5/bin/custom_lint.dart:80:5)
<asynchronous suspension>

Also, the language server detects the problem anyway:

Screenshot from 2024-09-02 17-34-35

Which is the same error pub.dev detects.

This PR will definitely fix this bug.

@manuel-plavsic
Copy link
Collaborator Author

The custom_lint.log contains the following:

The request analysis.setContextRoots failed with the following error:
RequestErrorCode.PLUGIN_ERROR
The package "solidart_lint" has incompatible version constraints in the project:
- "^2.0.0-dev.1"
  from "example" at "./../../unsynced/manuel/Downloads/solidart-dev(1)/solidart-dev/packages/flutter_solidart/example/pubspec.yaml".
- "../"
  from "example" at "./../../unsynced/manuel/Downloads/solidart-dev(1)/solidart-dev/packages/solidart_lint/example/pubspec.yaml".
- "^2.0.0-dev.1"
  from "github_search" at "./../../unsynced/manuel/Downloads/solidart-dev(1)/solidart-dev/examples/github_search/pubspec.yaml".
- "^2.0.0-dev.1"
  from "todos" at "./../../unsynced/manuel/Downloads/solidart-dev(1)/solidart-dev/examples/todos/pubspec.yaml".
- "^2.0.0-dev.1"
  from "toggle_theme" at "./../../unsynced/manuel/Downloads/solidart-dev(1)/solidart-dev/examples/toggle_theme/pubspec.yaml".

at:
#0      _buildDependencyConstraint.throws (package:custom_lint/src/workspace.dart:40:23)
#1      _buildDependencyConstraint (package:custom_lint/src/workspace.dart:107:9)
#2      CustomLintWorkspace._writePubspecDependencies (package:custom_lint/src/workspace.dart:665:13)
#3      CustomLintWorkspace.computePubspec (package:custom_lint/src/workspace.dart:565:5)
#4      CustomLintWorkspace.resolvePluginHost (package:custom_lint/src/workspace.dart:824:28)
#5      SocketCustomLintServerToClientChannel._startProcess (package:custom_lint/src/v2/server_to_client_channel.dart:151:24)
#6      SocketCustomLintServerToClientChannel.init (package:custom_lint/src/v2/server_to_client_channel.dart:110:22)
#7      CustomLintServer._maybeSpawnCustomLintPlugin (package:custom_lint/src/v2/custom_lint_analyzer_plugin.dart:394:25)
<asynchronous suspension>
#8      CustomLintServer._handleAnalysisSetContextRoots.<anonymous closure> (package:custom_lint/src/v2/custom_lint_analyzer_plugin.dart:341:9)
<asynchronous suspension>
#9      PendingOperation.run (package:custom_lint/src/async_operation.dart:22:14)
<asynchronous suspension>
#10     CustomLintServer._handleRequest (package:custom_lint/src/v2/custom_lint_analyzer_plugin.dart:173:22)
<asynchronous suspension>

[custom_lint] 2024-09-02T15:51:46.132603 /run/host/unsynced/manuel/Downloads/solidart-dev(1)/solidart-dev/packages/solidart_lint/lib/src/lints/avoid_dynamic_provider.dart:11:24: Error: 'LintCode' is imported from both 'package:analyzer/src/dart/error/lint_codes.dart' and 'package:custom_lint_core/src/lint_codes.dart'.
[custom_lint] 2024-09-02T15:51:46.132603   static const _code = LintCode(
[custom_lint] 2024-09-02T15:51:46.132603                        ^^^^^^^^
[custom_lint] 2024-09-02T15:51:46.132603 /run/host/unsynced/manuel/Downloads/solidart-dev(1)/solidart-dev/packages/solidart_lint/lib/src/lints/invalid_update_type.dart:10:24: Error: 'LintCode' is imported from both 'package:analyzer/src/dart/error/lint_codes.dart' and 'package:custom_lint_core/src/lint_codes.dart'.
[custom_lint] 2024-09-02T15:51:46.132603   static const _code = LintCode(
[custom_lint] 2024-09-02T15:51:46.132603                        ^^^^^^^^
[custom_lint] 2024-09-02T15:51:46.132603 /run/host/unsynced/manuel/Downloads/solidart-dev(1)/solidart-dev/packages/solidart_lint/lib/src/lints/missing_solid_get_type.dart:10:24: Error: 'LintCode' is imported from both 'package:analyzer/src/dart/error/lint_codes.dart' and 'package:custom_lint_core/src/lint_codes.dart'.
[custom_lint] 2024-09-02T15:51:46.132603   static const _code = LintCode(
[custom_lint] 2024-09-02T15:51:46.132603                        ^^^^^^^^
[custom_lint] 2024-09-02T15:51:46.132603
[custom_lint] 2024-09-02T15:51:46.132603
Failed to start pluginsThe request analysis.setContextRoots failed with the following error:
RequestErrorCode.PLUGIN_ERROR
Bad state: Failed to start the plugins.
at:
#0      SocketCustomLintServerToClientChannel._checkInitializationFail.<anonymous closure> (package:custom_lint/src/v2/server_to_client_channel.dart:223:11)
<asynchronous suspension>
#1      Future.any.onValue (dart:async/future.dart:628:5)
<asynchronous suspension>

[custom_lint] 2024-09-02T15:51:46.291199 _PrettyRequestFailure: {"code":"PLUGIN_ERROR","message":"Bad state: Failed to start the plugins.","stackTrace":"#0      SocketCustomLintServerToClientChannel._checkInitializationFail.<anonymous closure> (package:custom_lint/src/v2/server_to_client_channel.dart:223:11)\n<asynchronous suspension>\n#1      Future.any.onValue (dart:async/future.dart:628:5)\n<asynchronous suspension>\n"}
[custom_lint] 2024-09-02T15:51:46.291199 #0      ChannelBase.sendRequest (package:custom_lint/src/server_isolate_channel.dart:82:7)
[custom_lint] 2024-09-02T15:51:46.291199 <asynchronous suspension>
[custom_lint] 2024-09-02T15:51:46.291199 #1      CustomLintRunner.initialize.<anonymous closure> (package:custom_lint/src/runner.dart:43:5)
[custom_lint] 2024-09-02T15:51:46.291199 <asynchronous suspension>
[custom_lint] 2024-09-02T15:51:46.291199 #2      _runServer.<anonymous closure> (package:custom_lint/custom_lint.dart:96:7)
[custom_lint] 2024-09-02T15:51:46.291199 <asynchronous suspension>
[custom_lint] 2024-09-02T15:51:46.291199 #3      _AsyncCompleter.complete (dart:async/future_impl.dart:41:3)
[custom_lint] 2024-09-02T15:51:46.291199 <asynchronous suspension>
[custom_lint] 2024-09-02T15:51:46.291199 #4      _runServer.<anonymous closure> (package:custom_lint/custom_lint.dart:126:19)
[custom_lint] 2024-09-02T15:51:46.291199 <asynchronous suspension>
[custom_lint] 2024-09-02T15:51:46.291199 #5      _runServer (package:custom_lint/custom_lint.dart:86:3)
[custom_lint] 2024-09-02T15:51:46.291199 <asynchronous suspension>
[custom_lint] 2024-09-02T15:51:46.291199 #6      customLint (package:custom_lint/custom_lint.dart:50:5)
[custom_lint] 2024-09-02T15:51:46.291199 <asynchronous suspension>
[custom_lint] 2024-09-02T15:51:46.291199 #7      entrypoint (file:///unsynced/manuel/.pub-cache/hosted/pub.dev/custom_lint-0.6.5/bin/custom_lint.dart:68:3)
[custom_lint] 2024-09-02T15:51:46.291199 <asynchronous suspension>
[custom_lint] 2024-09-02T15:51:46.291199 #8      main (file:///unsynced/manuel/.pub-cache/hosted/pub.dev/custom_lint-0.6.5/bin/custom_lint.dart:80:5)
[custom_lint] 2024-09-02T15:51:46.291199 <asynchronous suspension>
[custom_lint] 2024-09-02T15:51:46.291199

@manuel-plavsic
Copy link
Collaborator Author

manuel-plavsic commented Sep 2, 2024

import 'package:custom_lint_builder/custom_lint_builder.dart'; exports package:custom_lint_core/src/lint_codes.dart.

import 'package:analyzer/error/error.dart'; exports 'package:analyzer/src/dart/error/lint_codes.dart' show LintCode;.

So, I don't know why you are not experiencing the conflict, but there definitely is one.

There is probably an even better way to solve this: let's change the import in the lint files from:

import 'package:analyzer/error/error.dart';

to

import 'package:analyzer/error/error.dart' hide LintCode;

This way we can remove the extra dependency and the extra import. I'll soon create another commit and push it.

@nank1ro
Copy link
Owner

nank1ro commented Sep 2, 2024

I still don't know why the issue doesn't happen in my machine, maybe I have something cached.
Please update the PR with the hide, so we don't add another dependency

@nank1ro nank1ro added the bug Something isn't working label Sep 2, 2024
@nank1ro nank1ro self-assigned this Sep 2, 2024
@nank1ro nank1ro merged commit ad00a73 into nank1ro:dev Sep 2, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants