Automating large Regression Test Suites with Postman and Newman
February 15, 2021Keying data in NoSQL
March 11, 2021One of the many things that I like to do as a developer is to find ways to streamline and ease the process of doing my job. Whether it is a new tool or developing a new skill, I am always trying to learn and grow. So when I came across a linting feature that will automatically fix my syntax mistakes, I jumped right on board.
I will be setting this up in a npm Node.js project and my editor of choice is VS Code.
In order to set up this properly, we will first have to initialize the project by entering the command
npm init
After the project has been initialized, you can then install eslint
npm install eslint --save-dev
Now run this command
./node_modules/.bin/eslint --init
this will take you through the setup process
Follow these steps to install
Select To check syntax, find problems, and enforce code style
Depending on the project that you are working on, your selection of the following prompts may be different. Here is what I selected.
Next step is to configure your ESLint. Navigate back to VS Code and go to the Extensions tab and search for eslint.
Install the eslint plugin by Dirk Baeumer.
Now that you have this plugin installed, you should see some highlighting in your project if your formatting is off. This highlighting indicates formatting issues or errors with your code.
Next step will be to change your VS Code settings to allow formatting on save.
Navigate to your settings by clicking on the cog wheel in the lower left corner of your editor and click on Settings.
Search for Code Actions On Save this should be your first result.
Click on Edit in settings.json and paste the following JSON into your file.
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"eslint.validate": ["javascript"]
Now navigate to any JS file and mess up some of your code. Here is an example of some poorly formatted code.
As you can see, there I added and removed some spacing and overall I am not following a consistent spacing theme. I also removed a semicolon after declaring my clock variable.
After saving, the auto formatter fixed those issues and now my code looks good again.
If you want to make edits to a project that a lot of people might be working on, then setting up eslint and enabling auto formatting on save will greatly improve the overall uniformity of the code.