Option: format named macro usage with standard module/function/... formatter
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 7k
- Forks
- 1.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 24
Description
So, #8 says "format macros" (hard in general); #3445 suggests formatting macros using { .. } braces as a Block; #2905 proposes formatting expression-like macros...
... general solutions are hard and probably require matching the macro by path (including crate of origin) ...
... can we get half-way there with per-project configuration?
Configuration
So: could we opt-in to macro formatting by adding this to lib.rs?
// example: widget! macro (used below)
#![rustfmt::fmt_as_module(widget)]
(Or to the rustfmt.toml?)
Example: widget
KAS (master) has a widget! macro which can be formatted like a module:
widget! {
/// A frame around content
///
/// This widget provides a simple abstraction: drawing a frame around its
/// contents.
#[autoimpl(Deref, DerefMut on self.inner)]
#[autoimpl(class_traits where W: trait on self.inner)]
#[derive(Clone, Debug, Default)]
#[handler(msg = <W as Handler>::Msg)]
#[widget{
layout = frame(self.inner, kas::theme::FrameStyle::Frame);
}]
pub struct Frame<W: Widget> {
#[widget_core]
core: CoreData,
#[widget]
pub inner: W,
}
// NOTE: `impl Self` is not valid Rust syntax, but rustfmt handles it fine
impl Self {
/// Construct a frame
#[inline]
pub fn new(inner: W) -> Self {
Frame {
core: Default::default(),
inner,
}
}
}
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the related discussions in issues #8, #3445, and #2905, then examine the proposed lib.rs attribute or rustfmt.toml configuration for the widget! example. Done would be an agreed design and implementation for opting in to formatting named macro usage like a standard module, including the configuration syntax and macro matching behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100