At bitHound, we have a variety of critics in place to help ensure you are building your best software possible. From detecting outdated and insecure dependencies to finding those common lint errors – it doesn't take long for that list to start piling up.
One way you can reduce the number of items needing attention is to consider ways to avoid introducing them to begin with. In the post, we'll focus on how you make linting your code a part of your everyday workflow and how to effectively eliminate it from your todo list. Let's explore three different options:
Lint in Real-Time
A good practice to implement is to start linting in real time as part of your IDE. While that missing semicolon can be constant and recurring nuisance, failing to address lint errors can impact the structural quality of your code. Handling lint errors in your project as soon as they pop up will save you a lot of time and heartache down the road.
For example, if you are using JSHint, there are a variety of plugins you can use to bring the awesomeness of JSHint right into your text editor. A few of our favourites include jshint.vim and Syntastic for Vim and JSHint Gutter for Sublime Text. No matter what your preferred IDE is, chances are there is a JSHint plugin for it.
The Command Line
Another option is to run lint on the command line. A lint detecting tool like JSHint is available through opening up the terminal and running:
npm install jshint
While this won't allow you to make your changes in real-time, it will still give you a great diagnosis and ample time at the end to make the changes you need to make.
Pre Commit Hook
The pre-commit hook is a more advanced option but you can also make use of it to avoid lint errors. The pre-commit hook (like all hooks) run locally so there is no need to install anything. Pre-commit hooks will check what is about to be committed to see if you've forgotten anything or need to inspect something. The bonus: You can do all of this without ever having to leave Git. The Double bonus: You can also use something like Grunt or nfl/pre-commit-hook to do most of this for you. To see how pre-commit hooks are being used, check out this example.
So there you have it. We hope that one of these three quick and easy ways you can improve your lint habits will work for you. Choosing one of the above options will not only free you from the tedious and annoying nature of tidying up lint but will also give you time to focus on the more in-depth, pertinent issues you face when it comes to delivering great software.
Here are some additional resources we find quite helpful when it comes to linting:
- JSHint: Install JSHint Plugins for text editors and IDEs
- TSLint: A static analysis linter for TypeScript projects
- JSCS: A code linter for programmatically enforcing your own definable style guide
- Grunt: Automatically add Git pre-commit linting
- nfl/precommit-hook: Helps enforce code quality in Node.js projects and allows you to run any scripts defined in your package.json before a commit is made