我应该在缩小后将我的代码丢失吗?

JMa*_*lin 5 javascript jslint uglifyjs jshint

我有一些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 '='"
Run Code Online (Sandbox Code Playgroud)

Tib*_*bos 13

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

缩小后的Linting是没有意义的(你不应该手动更改缩小的代码,因此不存在人为错误),如果你选择"修复"缩小的代码,甚至是有害的,因为它会增加大小.

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

  • "linter的目的是防止编程风格容易出现人为错误".说得好,非常感谢你. (2认同)