How to recognize that TypeScript code is generated

112 Views Asked by At

I maintain some analysers for C# code and TypeScript code. Those analysers shall skip generated code.

In C# it is rather simple because such class has attrribute System.CodeDom.Compiler.GeneratedCode.

But how about TypeScript? How can I generically recognize that the code is generated?

2

There are 2 best solutions below

0
On BEST ANSWER

There is no generic way of doing this - generated typescript code can be indistinguishable from any other piece of typescript code.

The normal way of getting a tool to ignore generate TS code is to have to configuration that says which files/directories to ignore. This config is specific to each tool. For example eslint can use a .eslintignore file which might contain a lines like

dist
**/generated
0
On

Name the generated file as something like "myClientAuto.ts", and have the static code analysis to skip files with suffix Auto, or some prefix if you want. For generated C#, even the System.CodeDom.Compiler.GeneratedCode is not really needed, if you put the generated codes in its own csproj project, and just opt out the project from CA.