Linters are tools that enforce source code writing style based on a set of rules. It helps impose coding styleguides in an automated way. A linter will check decisions such as:
- Syntax errors
- Tabs or spaces for indentation
- Naming of variables and functions
- Use of whitespace
- Patterns to use and to avoid
It's important to keep your coding style consistent. Even if it's mostly subjective, a consistent style helps maintain developer sanity and code readability.
Linting should be part of your automated test suite. This lets you catch style violations before pull requests are merged. Here's an example using Travis CI:
Why use a linter
Linting helps reviewers by catching style violations in automated tests so they don't have to. This means less effort needed for reviewing, and instant feedback for contributors.
Choose a coding style
There are many established styleguides and linter presets. Pick one and customize it if preferred. It doesn't matter which you choose, what's important is that your team has an authoritative set of rules that are enforced by a linter. This prevents petty "bikeshedding" arguments within your team. Here are some popular examples:
Next: Make sure your project has a Readme file.