Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I lint my code after minification?

I have some javascript that passes the linter before minification, but not after. Should I worry about errors/warnings like:

"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 '='"
like image 391
JMaylin Avatar asked Jan 16 '14 12:01

JMaylin


1 Answers

I think you are confused about the role of lint-ing the code. A linter's purpose is to prevent a programming style prone to human errors. A minifier's role is to squeeze the source code to have as few characters as possible.

Linting after minification is pointless (you should never manually change minified code, so there can be no human error) and even detrimental if you choose to "fix" your minified code, because it increases the size.

The correct way to use these tools is to lint the code to remove common patterns that are prone to human error and then to minify it to be as small as possible for production. If you want to check the correctness of the minifier you need to use testing, test the code before the minification process and afterwards and the results should be the same. Keep in mind that depending on how aggressive the minifier is, unused code can be removed entirely, functions can be inlined, etc, so testing minified code is definitely not trivial.

like image 154
Tibos Avatar answered Oct 04 '22 14:10

Tibos