View profile

The Role of Linters

Linters like ESLint analyze your code for common issues. Linters are a form of "static analysis": the
The Role of Linters
By Mastering JS Weekly • Issue #16 • View online
Linters like ESLint analyze your code for common issues. Linters are a form of “static analysis”: they look at your code as it is written, but they don’t actually run any of your code.
Generally speaking, the issues that linters find can be broken up into 3 groups:
1) Ambiguous syntax. Your code can be syntactically valid and still have a glaring issue. For example, the below code is perfectly valid JavaScript, but when you run the below code JavaScript throws a “TypeError: 42 is not a function.”

Missing semi-colons are a common cause of baffling errors
Missing semi-colons are a common cause of baffling errors
ESLint would help you catch the above error by warning you that you’re missing a semi-colon.
2) Best practices. For example, you generally shouldn’t use JavaScript’s double-equals operator `==` unless you are checking for a nullish value, or you are certain you know what you’re doing. ESLint helps you automatically check for best practices across your whole codebase, like avoiding `eval()` and unnecessary `console.log()` statements.
3) Readability and other non-functional issues. ESLint can also enforce rules like consistent spacing, newlines at the end of files, line length, and other details that don’t have any impact on how your code runs.
ESLint focuses primarily on (1) and (2). Code formatters, like Prettier, tend to focus primarily on (3).
Groups (1) and (2) represent the most important issues to catch. If you choose to write your JavaScript without semi-colons (not recommended!) you absolutely must use an up-to-date linter - new JavaScript syntax can affect automatic semi-colon insertion, so semi-colon-less JavaScript is not future-proof.

New Tutorials
Did you enjoy this issue?
Mastering JS Weekly

A weekly summary of our tutorials

If you don't want these updates anymore, please unsubscribe here.
If you were forwarded this newsletter and you like it, you can subscribe here.
Powered by Revue