dart-lang / dart-lang/language

How could macros and linters share logic?

Open
#3,233 7 comments 0 reactions 0 assignees View on GitHub
request
Dominant language
TeX
Stars
2.9k
Forks
239
Avg merge
2d 18h
Merged PRs (30d)
14

Description

Hello! This is a general question with regards to metaprogramming and sharing logic with non-macros toolings.

I personally like offering various tools for my packages, and I sure hope that the Dart community starts doing so more over time.
For example, Riverpod has:
- the linter
- the code-generator
- a diagram generator based on static analysis https://github.com/rrousselGit/riverpod/tree/master/packages/riverpod_graph
- a migration tool

And possibly more (devtools, ...)

The fortunate thing is that at the moment, all of these tools rely on `analyzer`.
So I was able to build a custom package for sharing the parsing logic, by implementing a custom Ast/Element tree matching the Riverpod syntax – which is then depended on by the various tools mentioned above.
This ensures all tools have a consistent way of parsing the syntax and ease up maintenance.

But since macros apparently won't rely on `analyzer`, I'm concerned that this would be much more difficult.
I would likely have to reimplement the parsing logic to whatever new API macros have.

I don't necessarily have a specific solution in mind. But I thought this use case would be an interesting one to share.

Contributor guide

Open the contributing guide

Research direction

Start with this issue and the Riverpod example, especially the riverpod_graph package, to understand how shared parsing currently works through analyzer. Compare that approach with the macro APIs discussed in the issue, and document whether a practical shared-logic path exists for macros, linters, generators, and migration tools.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart
Domain
compilers, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.