Skip to content

fix: use the real file path for a file dprint matched by its shebang - #70

Merged
dsherret merged 4 commits into
mainfrom
fix-shebang-real-file-path
Oct 11, 2026
Merged

dsherret merged 4 commits into
mainfrom
fix-shebang-real-file-path

Conversation

@dsherret

@dsherret dsherret commented Oct 11, 2026 •

Copy link
Copy Markdown
Member

dprint is changing what file path it gives plugins for an extensionless file it matched by its shebang (dprint/dprint#1349): instead of the real path it gives the path with a marker and the mapped extension added (ex. build.dprint-ext-added.sh for a file named build). That makes a command's exts match such a file, which fixes #69, but that path doesn't exist on disk.

This makes the plugin use the path of the file on disk for everything other than matching by extension:

  • {{file_path}} is the real path (ex. build), so a command that reads the file from that path works.
  • A command's associations are matched against the real path.

A command's exts are still matched against the path dprint provides.

Since {{file_path}} no longer tells a command the kind of file for these files, this also adds an {{ext}} variable: the extension without a leading period (ex. sh), or an empty string when there's none. It comes from the path dprint provides, so it's the extension the shebang maps to (ex. prettier --stdin-filepath file.{{ext}}).

This only has an effect with a dprint version that includes the linked PR, which isn't merged yet, so the marker text (.dprint-ext-added.) needs to stay in sync with it if it changes there.

Closes #69

@dsherret
dsherret merged commit b9c0533 into main Oct 11, 2026
20 checks passed
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.

Shebang support

1 participant