File created with mix of single and double quotes
#44Notes:
svelte-add
. I tried patching in their changes, which obviously only worked to some degree. But at least git recognizes that they authored those commits nowhooks.ts
filenew features:
placeholders
, and can provide a validate
function (implemented by @LorisSigrist)preInstall
& postInstall
hooks. This was necessary because this adder needs to generated multiple files past on a string
option inputtodos:
Closes #44
Benefits
svelte
ecosystemesrap
Downsides
esrap
Depends on Rich-Harris/esrap#13. Currently published as esrap-typescript-temp
for ease of use for testing. Otherwise, this would require using pnpm link
locally with the branch mentioned before.
If we want to proceed with this (which i think we should), this needs to be done
packages/ast-tooling/ts-estree.ts
seperately so that it can also be used inside esrap
. Later they should probably live inside acorn-typescript
once we fork itesrap
understand what a TSModuleDeclaration
is and how to print itesrap
according to the types above. This will probably also require way more types in this new packageesrap
and publish itCloses #44 Closes #118 Relates #100
This basically duplicates #100 at this point. See #100 for up and downsides of this approach.
I was initially intending to get rid of a lot more dependencies (like the dependencies for handling html) and use svelte-ast-print
instead, but this was opening too many issues at the same time. That's why I opted to "only" switch to acorn
and esrap
here, the rest can be done later.
Relevant PR's / issues
Benefits
svelte
ecosystemrecast
esrap
Downsides
TSEstree
as no good public alternative exists, that matches acorn
s output. We do have @typescript-eslint/types
but that was just the one with the smallest pain points. Still exploring other options.Can we just use single quotes everywhere?
The Drizzle adder creates the drizzle.config.ts
below currently:
if (!process.env.DATABASE_URL) throw new Error('DATABASE_URL is not set');
export default defineConfig({
schema: "./src/lib/server/db/schema.ts",
dbCredentials: {
url: process.env.DATABASE_URL
},
verbose: true,
strict: true,
dialect: "sqlite"
});
This case is a bit tricky because it's a newly created file so the code printer has no frame of reference to determine the style preferences. I guess we could poke around and find a similar file type, but im not quite sure if there's an existing recast
api that can help us determine the style preference of any given script.
Implementing #33 may be able to solve this as well.
I think we should assume single quotes by default since that's what the new template creation will spit out and is typically used in JS. We can try to get fancier later on, but it probably isn't necessary out of the gate
those defaults aren't set by us, they're set by recast
. if we were to force an override on the printer to use single quotes, then that override will apply to all generated code (even on existing code that uses double quotes), which isn't preferable
there may be a way to hack it now, but the better fix will be to implement #33, so we may as well hold off on this particular change until then
I mean for the moment we could also only set recast to default to double qoutes, if we know that the file had no content before our modification. But as @AdrianGonz97 suggested, i think we should solve the bigger picture in #33
Edit: Maybe the end result will be a combination of both.
#33 has been implemented. This is still an issue though. Can we change the default recast setting to single quotes to match the default style for newly created projects? It's not perfect as we'll still have issues for users using double quotes, but should affect fewer users overall
Also see: #67 (comment)