如何强制项目的代码风格?
我目前正在开始使用 Node 在服务器端学习 JavaScript,我已经使用 NPM 创建了一个项目,实现了一些测试等。
困扰我的是能够在所有文件上强制使用代码样式,我已经一直在阅读有关 JSLint 的内容,它会警告您有关样式错误的信息,但我正在寻找一种可以修改代码以遵守特定标准的工具。
有没有任何工具可以完成这项任务?
编辑
我正在寻找一个命令行工具,这样我就可以使用 NPM 将任务添加到项目中,并且可以将其执行为:
npm format
I'm currently starting to learn about JavaScript on the server side with node, I've created a project with NPM, implemented some tests, etc.
Something that's bugging me is the ability to force a code style on all files, I've been reading about JSLint and it warns you about the style errors, but I'm looking for a tool that modifies your code to obey a certain standard.
Is there any tool that covers this task?
EDIT
I'm looking for a command line tool, so I can add a task to the project using NPM and I can execute it as:
npm format
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能想看看类似 https://github.com/wbecker/dvcs_hook- jslint-node (和 Mercurial 和 Git 中 JSLint 的预提交挂钩),它允许您可以使用 Node 运行 jslint,如果您使用兼容的版本控制系统,它可能会在每次提交时执行此操作(这是确保每个文件都遵循您的编码标准的好方法)。
You may want to have a look at something like https://github.com/wbecker/dvcs_hook-jslint-node (and Pre Commit Hook for JSLint in Mercurial and Git) which allows you to run jslint with node, and if you are using a compatible versioning system it may do so on each commit (which is a great way to ensure every file respect your coding standard).