如何识别 TypeScript 代码已生成
我维护一些 C# 代码和 TypeScript 代码分析器。这些分析器应跳过生成的代码。
在 C# 中,这相当简单,因为此类具有 System.CodeDom.Compiler.GenerateCode 属性。
但是 TypeScript 怎么样? 我如何才能一般性地识别代码已生成?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
没有通用的方法可以做到这一点 - 生成的打字稿代码与任何其他打字稿代码都无法区分。
让工具忽略生成 TS 代码的正常方法是必须进行配置,说明要忽略哪些文件/目录。此配置特定于每个工具。例如 eslint 可以使用 .eslintignore 文件,其中可能包含类似以下的行
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
将生成的文件命名为“myClientAuto.ts”之类的名称,并进行静态代码分析以跳过带有后缀 Auto 或某些前缀(如果需要)的文件。
对于生成的 C#,如果您将生成的代码放入其自己的 csproj 项目中,并且只需从 CA 中选择退出该项目,则甚至不需要 System.CodeDom.Compiler.GenerateCode。
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.