Skip to content

fix: provide plugins the file path with the shebang's extension for files matched by a shebang - #1349

Merged
dsherret merged 12 commits into
mainfrom
fix-shebang-file-path-extension
Oct 11, 2026
Merged

dsherret merged 12 commits into
mainfrom
fix-shebang-file-path-extension

Conversation

@dsherret

@dsherret dsherret commented Oct 11, 2026 •

Copy link
Copy Markdown
Member

The CLI sends an extensionless file to a plugin based on the "shebangs" config, but the plugin received the file's real path. Plugins decide how to format a file based on its extension, so a plugin could end up doing nothing with a file it was sent. For example, the exec plugin matches its commands' exts against the path, so no command ran (dprint/dprint-plugin-exec#69).

Now a file that's formatted because of its shebang is given to the plugins with a marker and the mapped extension added to its path (ex. build.dprint-ext-added.sh for a file named build with "#!/bin/sh": "sh"). This works for every plugin without needing changes to them. The marker is there so a plugin can tell the path isn't the real one and get the real one by taking what's before .dprint-ext-added.

Only the path given to the plugins changes. Everything the CLI does with the path still uses the real one: includes and excludes, plugin "associations", plugin "overrides", the incremental cache and the output. A file that a plugin claims by its path (ex. "associations") keeps its real path.

Some details:

  • The incremental cache is invalidated for configs with "shebangs" by adding a version number to its hash, since a file a plugin previously did nothing with was recorded as formatted.
  • For dprint fmt/check, the path is decided once per file from its original text, the same as the plugins formatting it, so it stays the same when ensuring a stable format.
  • When a plugin asks the host to format text with the path it was given, it's matched the same way as before: the plugins' "associations" and "overrides" against the real path, and the plugins' extensions against the added one.

The path a plugin sees for these files doesn't exist on disk. It matters for something like an exec plugin command that reads the file at {{file_path}} instead of from stdin, which previously didn't run for these files. dprint/dprint-plugin-exec#70 makes the exec plugin use the real path for that.

This applies the same way to dprint fmt/check, --stdin, the editor service and the LSP. The tests cover dprint fmt and --stdin by having the test process plugin output the path it received, plus unit tests for building and reversing the path; the editor service and the LSP go through the same code as --stdin and don't have their own test.

@dsherret
dsherret requested a balanced review from Copilot October 11, 2026 22:06

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@dsherret
dsherret merged commit e97aa16 into main Oct 11, 2026
22 checks passed
@dsherret
dsherret deleted the fix-shebang-file-path-extension branch October 11, 2026 22:46
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.

2 participants