0

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
  • I think the only way you could do this is if the code generator puts some comments like // @begin-generated-code and // @end-generated-code to delimit the code that your analyser should ignore. Otherwise you could use heuristics like ignoring variables and functions whose names match some pattern. Commented Feb 28, 2022 at 17:06
  • In C# this attribute is widelly used by 3rd party tool where you have no control over such generation. Commented Feb 28, 2022 at 17:10

2 Answers 2

2

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
Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.