Giter Site home page Giter Site logo

Comments (5)

dsherret avatar dsherret commented on May 27, 2024 1

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.

bradzacher avatar bradzacher commented on May 27, 2024 1

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.

dsherret avatar dsherret commented on May 27, 2024

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.

bradzacher avatar bradzacher commented on May 27, 2024

@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.

dsherret avatar dsherret commented on May 27, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.