Search code examples
typescriptcode-generationsourceanalyser

How to recognize that TypeScript code is generated


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?


Solution

  • 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