Linter in Node App: Manage Code Quality
A lifelong learner. Love to travel. Listen to music.
Search for a command to run...
A lifelong learner. Love to travel. Listen to music.
No comments yet. Be the first to comment.
Get the final source code from here Environment Variable Environment variables are injected from outside the application. These variables are varied in a different stage of the application. For example, a web app has separate database addresses for ...
Best Practices for Path Structure, Versioning, and Error Handling

Understanding the Performance Implications of async and defer Attributes

Overview static: Default position. It does not allow setting properties like top, bottom, left, right, z-index relative: Acts the same as static. but allows positioning it relatively by putting properties like top, bottom, left, right, z-index absolu...

Overview When an element in the browser has a conflict of styles, the browser uses a set of rules to determine which style should be rendered. This set of rules is defined as CSS Selector Specificity. For instance, for an element, if we have the foll...

Master block, inline, flex, and grid to build better web layouts

You can get the final source code from here.
A linter tool analyzes code and warns for potential errors. Also, force to maintain a generic style and structure.
For example, when an application has multiple contributors, it is important to follow the same coding style. In this situation, Linter tools come quite handy.
Airbnb has an industry standard style guide and we are going to implement it.
To use the linter tool in node application, we are going to use,
Visual Studio Code (code editor)
eslint (npm package)
eslint-plugin-import (npm package)
eslint-config-airbnb-base (npm package)
ESLint (editor extension)
Install the editor for your suitable platform
Install Node.js in your machine
Make sure both node and npm is installed in your system
Open Visual Studio Code and install the ESLint extension.
To install ESLint extension in Visual Studio Code
Open the code editor
Open vs code extension panel (Crtl+Shift+X)
Search for ESLint
Install the extension
Create a directory, linterPractice and enter the directory.
mkdir linterPractice
cd linterPractice
Now in the root directory, create the project
npm init -y
Now open the directory in your code editor.
Create two files named index.js and .eslintrc.js
Your project directory should look like
├── ...
├── manageEnvironment
│ ├── index.js
│ ├── .eslintrc.js
│ └── package.json
├── ...
Install the npm packages from the root directory.
npm i -D eslint eslint-config-airbnb-base eslint-plugin-import
Now add linter configuration to .eslintrc.js file
module.exports = {
"extends": "airbnb-base",
"rules": {}
};
Now you are done setting linter tool in your node application. Let’s see some special use case of linter.
To override some rule, update your .eslintrc.js in rules section.
By default, linter does not allow under-score. So to use uder-score we have to override the rule and updated configuration will be
module.exports = {
"extends": "airbnb-base",
"rules": {
"no-underscore-dangle": 0
}
};
By default, eslint does not support linting. To override a rule in a specific file, we can comment to override the rule. In the following code blocks, I will override console rule in index.js file.
/* eslint-disable no-console */
console.log(‘Hello world’);
Stay tuned and if there is a confusing term or something, the response below. I will replay ASAP.