sqlc-dev / sqlc-gen-typescript

364 stars 17 forks source link

add "Code generated by sqlc. DO NOT EDIT." header comment #9

Closed yshrsmz closed 9 months ago

yshrsmz commented 10 months ago

to prevent devs from editing the generated file.

yshrsmz commented 10 months ago

I can achieve this behavior by just modifying here

   const printer = createPrinter({ newLine: NewLineKind.LineFeed });
-  let output = "";
+  let output = "// Code generated by sqlc. DO NOT EDIT.\n\n";
   for (let node of nodes) {
     output += printer.printNode(EmitHint.Unspecified, node, resultFile);
     output += "\n\n";
   }
   return output;

But I'm not sure if it's OK or should be handled in another place.

tamsanh commented 10 months ago

Might be better off somewhere that has access to the configuration, so that a user can either turn that comment on or off or can supply their own header, like a copyright string.

kyleconroy commented 9 months ago

The Go code generator adds the header by default and you can't turn it off. I think it's a good idea to always add it.