【问题标题】:Should I lint my code after minification?缩小后我应该对代码进行 lint 处理吗?
【发布时间】:2014-02-05 07:56:22
【问题描述】:

我有一些 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 '='"

【问题讨论】:

  • 你在前后用什么棉绒?不同的应用程序(jshint 和在线 jslint)?您是否使用了不同的选项集?
  • 无论是之前还是之后,我都不使用任何选项
  • 显示一些来源,但我认为“缩小”会去掉几个花括号,而不仅仅是分号。如果您有一个带有 js 格式的 IDE,请重新格式化并检查错误。这样,您就可以看到缩小脚本的正确程度
  • 嗯,我的js真的很长。但我的问题更多:缩小后对代码进行 lint 处理是否常见?

标签: javascript jslint jshint uglifyjs


【解决方案1】:

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

缩小后的 Linting 毫无意义(您永远不应手动更改缩小后的代码,因此不会出现人为错误),如果您选择“修复”缩小后的代码,甚至会有害,因为它会增加大小。

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

【讨论】:

  • “linter 的目的是防止容易出现人为错误的编程风格”。说得好,非常感谢。
猜你喜欢
  • 1970-01-01
  • 2014-03-25
  • 1970-01-01
  • 2011-12-01
  • 1970-01-01
  • 2019-10-13
  • 2016-09-05
  • 2011-09-30
  • 2011-12-19
相关资源
最近更新 更多