Comments (5)
Seems reasonable if this is opt-in via a config property or cli flag. I'm wondering if it's worth it to have plugins say whether they can format a shebang. Maybe this is knowledge that should just live in the cli for simplicity as a shebang to extension mapping.
from dprint.
Yeah that sounds like the best option, I don't think dprint should do this by default as not every codebase is Unix or uses hashbang files, and I don't think dprint itself should have a baked-in mapping considering hashbangs can take any form - but a user-configurable option to opt-in sounds really reasonable.
The user could specify a mapping of hashbang to extension, maybe? First thought would be something like
{
"hashbangs": {
"#!/usr/bin/env bash": ".sh",
"#!/usr/bin/env node": ".js"
}
}
Then dprint could probably essentially do path + mappedExt
to resolve the file against the config and format it.
from dprint.
I think this is out of scope because it would be too slow to find the shebang patterns since it requires reading the files? The way to do this today would be to manually specify the file in a config using the "associations" feature: https://dprint.dev/config/#associations
from dprint.
@dsherret the issue is that more often than not hashbang'd files have no extension and are often uniquely named - so it's hard to keep them formatted as you need to remember to update each time you add / rename one of them.
I wonder if there's a way we can limit this to just extensionless files? I.e. Dprint always ignores file contents if the file has an extension, and if it has no extension then dprint will read the first 2 bytes, check if it is #!
, ignore the file if it isn't, or read the first line if it is.
That would keep things as cheap as feasibly possible by limiting the scope and effort.
from dprint.
I like that. Takes the complexity out of handling different scenarios and leaves it up to the user to have full control.
from dprint.
Related Issues (20)
- Ignore known template/backup file suffixes when determining file type HOT 3
- Config update traverses dir hierarchy downwards
- Add a CLI command to output the config that shall be used for a given file HOT 2
- "not include"s are ignored when paths are passed via CLI HOT 1
- dprint: /lib64/libm.so.6: version `GLIBC_2.29' not found HOT 1
- Future plugin system improvements HOT 1
- Regression - 0.43.2 finds fewer files than 0.43.1 HOT 5
- Feature: Formatting HTML files HOT 1
- LSP - Figure out completions for dprint.json files
- Document using lsp in various editors
- Can't remove BOM HOT 1
- CI GH Actions compile error HOT 5
- Possible to have `dprint` `biome` point to `biome.json` for configuration? HOT 3
- Can't Format Files In Hardlink Folder
- Include / exclude behavior differs with `--stdin`
- JSON config schema file HOT 1
- Offline process plugin installation instructions
- Config - Ability to include subset of another arbitrary JSON file
- Programatic API for TS (Node/Bun/Deno/etc.) HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dprint.