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

Support chained Dart method/prop calls #2228

Open
valerauko opened this issue Dec 4, 2023 · 7 comments
Open

Support chained Dart method/prop calls #2228

valerauko opened this issue Dec 4, 2023 · 7 comments

Comments

@valerauko
Copy link

To upvote this issue, give it a thumbs up. See this list for the most upvoted issues.

Is your feature request related to a problem? Please describe.

In ClojureDart you can chain property/method calls. The following is valid:

(require '["package:flutter/material.dart" :as m :refer [MainAxisAlignment]])
m/EdgeInsets.zero
(m/EdgeInsets.symmetric .horizontal 10 .vertical 5)
MainAxisAlignment.center

Describe the solution you'd like

Teach clj-kondo to recognize this syntax and warn only about the first bit (eg if a class name is used but never referred)

(require '["package:flutter/material.dart" :as m])
EdgeInsets.zero ;; this should be m/EdgeInsets.zero

Describe alternatives you've considered

Currently we either ignore the unresolved symbol warnings where the chaining is used, or unpack the chaining like below

;; instead of ns-alias/SomeClass.prop.prop
(.-prop (.-prop ns-alias/SomeClass))

Additional context

I'd love to help implementing this, but I have no idea where to start

@borkdude
Copy link
Member

borkdude commented Dec 4, 2023

In normal Clojure(Script) you can write this as:

(.. m/EdgeInsets.symmetric (horizontal 10) (vertical 5))

Why does ClojureDart need to deviate from this?

@valerauko
Copy link
Author

Those are not separate methods, but named parameters to the EdgeInsets constructor symmetric

https://api.flutter.dev/flutter/painting/EdgeInsets/EdgeInsets.symmetric.html

@valerauko
Copy link
Author

valerauko commented Dec 4, 2023

For example

;; :require ["package:flutter/material.dart" :as m]
(=
 (m/WidgetsBinding.instance.removeObserver some-observer)
 (.removeObserver (.-instance m/WidgetsBinding) some-observer)
 (-> m/WidgetsBinding .-instance (.removeObserver some-observer)))

@borkdude
Copy link
Member

borkdude commented Dec 4, 2023

I understand those interop forms, but I don't understand your remark about "those are not separate methods" and then saying "for example" where no named parameters occur in the example, or am I missing something?

@borkdude
Copy link
Member

borkdude commented Dec 4, 2023

ClojureDart could support:

(m/EdgeInsets.symmetric :.horizontal 10 :.vertical 5)

or similar for named parameters, has this been considered?

@borkdude
Copy link
Member

borkdude commented Dec 4, 2023

I misunderstood the issue. MainAxisAlignment.center gives a false positive, but the rest works.

When you lint the above as CLJS it does work:

clj-kondo --lint tmp/dart.cljd --lang cljs
linting took 41ms, errors: 0, warnings: 0

So we just have to convince clj-kondo to do the same as ClojureScript when using ClojureDart

@valerauko
Copy link
Author

valerauko commented Dec 4, 2023

Yeah it's very similar to the js/console.log kind of cljs syntax. Gotta add a possible refer to the mix though (the false positive you mention)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants