javascript - 我应该在缩小后检查我的代码吗?

标签 javascript jslint jshint uglifyjs

我有一些 javascript 在缩小之前通过了 linter,但之后没有。 我是否应该担心错误/警告,例如:

"Expected an assignment or function call and instead saw an expression"
"Use '!==' to compare with 'null'"
"Don't make functions within a loop"
"Missing '()' invoking a constructor."
"Expected a conditional expression and instead saw an assignment"
"Confusing use of '!'"
"A leading decimal point can be confused with a dot: '.5'"
"Expected an operator and instead saw ','"
"Expected an identifier and instead saw '}'"
"Expected ')' to match '(' from line 9 and instead saw '{'"
"Expected an identifier and instead saw '='"

最佳答案

我认为您对 lint-ing 代码的作用感到困惑。 linter 的目的是防止编程风格容易出现人为错误。压缩器的作用是将源代码压缩为尽可能少的字符。

缩小后的 linting 是没有意义的(你永远不应该手动更改缩小代码,所以不会有人为错误),如果你选择“修复”你的缩小代码甚至是有害的,因为它会增加大小。

使用这些工具的正确方法是对代码进行 lint 以删除容易出现人为错误的常见模式,然后将其缩小到尽可能小以用于生产。如果您想检查缩小器的正确性,您需要使用测试,在缩小过程之前和之后测试代码,结果应该是相同的。请记住,根据压缩器的积极程度,可以完全删除未使用的代码,可以内联函数等,因此测试压缩代码绝对不是一件容易的事。

关于javascript - 我应该在缩小后检查我的代码吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21161289/

相关文章:

javascript - 删除过去的日期 - Jquery Datepicker

javascript - `tsc` 命令是否接受 .d.ts 文件?

javascript - 为什么 JQuery 没有通过 JSLint?

javascript - 如何使用 jslint 和 instanceof?

ecmascript-6 - babel 仅在单引号而不是双引号中转换 es6 模板字符串

javascript - 了解这段 javascript 代码的输出

javascript - 将局部变量传递给带参数的 lambda 函数?

javascript - jslint 停在 $(document).ready 行

javascript - 如何使用 JSHint 显示 JavaScript 错误?

jshint - 在 WebStorm IDE 中配置 *all* JSHint 设置