Skip to content

feat(fmt): apply object spacing to import/export lines - #30371

Merged
dsherret merged 1 commit into
denoland:mainfrom
mologie:fmt-import-export
Aug 28, 2025
Merged

dsherret merged 1 commit into
denoland:mainfrom
mologie:fmt-import-export

Conversation

@mologie

@mologie mologie commented Aug 10, 2025

Copy link
Copy Markdown
Contributor

Hi Deno folks!

I stumbled over an issue during formatting a project that I'm moving to Deno, where curly braces would be handled inconsistently by deno fmt, and thought this would make for a nice first contribution.

This lets spacing in named import/export lines follow the config for objects. Spaces would always be added before, which looked odd in projects that otherwise used no spaces for object syntax.

There is no change for users who leave spaceSurroundingProperties at the default value (on).

Config:

{
  "fmt": {"spaceSurroundingProperties": false}
}

Old formatting:

// spaces always added here:
import { foo } from "bar";

const baz = {a: 1};

New formatting with this PR applied:

import {foo} from "bar";

const baz = {a: 1};

With this change, the behavior roughly matches that of stylistic's curly rule, which seems reasonable to me. For me this simplified migration to deno a lot, because import braces were 90% of formatting changes caused by deno fmt w/o option to change them before.

As alternative to this change I considered adding a new property, but exposing all of dprint's internals does not seem right to me. Stylistic does not have an option to configure import/exports and objects separately either.

The documentation already mentions that the given property applies to "object-like nodes", so no change should be needed there.

This lets spacing in named import/export lines follow the config for
objects. Spaces would always be added before, which looked odd in
projects that otherwise used no spaces for objects.

The documentation already mentions that the given property applies to
"object-like nodes", so no change is needed there.

Comparing with other formatters, Stylistic groups spacing of import
and export lines with that of other curly object spacing too, hence
this simplifies migration.
@CLAassistant

CLAassistant commented Aug 10, 2025 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@bartlomieju
bartlomieju requested a review from dsherret August 11, 2025 09:13
@dsherret dsherret added this to the 2.5.0 milestone Aug 22, 2025

@dsherret dsherret left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks!

@dsherret
dsherret merged commit 7b16237 into denoland:main Aug 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants