ArticleZip > How To Configure Vue Cli 4 With Eslint Airbnb Rules Typescript Stylelint For Scss In Vs Code Editor With Autofix On Save

How To Configure Vue Cli 4 With Eslint Airbnb Rules Typescript Stylelint For Scss In Vs Code Editor With Autofix On Save

Vue CLI 4 is a game-changer for frontend developers, combining powerful tools and an intuitive user interface to streamline the project setup process. When it comes to maintaining code quality and consistency, integrating ESLint with Airbnb rules, TypeScript, and Stylelint for SCSS can make a significant difference. When you add the magic touch of enabling autofix on save in your favorite Visual Studio Code editor, your coding experience reaches a new level of efficiency.

Let's break down the steps to configure Vue CLI 4 with ESLint using Airbnb rules, TypeScript, and Stylelint for SCSS in the Visual Studio Code editor with the autofix feature enabled on save.

Step 1: Setting up Vue CLI 4
Start by installing Vue CLI 4 globally on your machine if you haven't already. You can do this using npm:

Plaintext

npm install -g @vue/cli

Create a new Vue project by running:

Plaintext

vue create your-project-name

Navigate into your project directory:

Plaintext

cd your-project-name

Step 2: Integrating ESLint with Airbnb Rules and TypeScript
Add the necessary packages for ESLint with Airbnb rules and TypeScript by running the following commands:

Plaintext

vue add eslint
vue add @vue/eslint-config-airbnb

Next, install TypeScript and the ESLint TypeScript plugin:

Plaintext

npm install typescript @typescript-eslint/parser @typescript-eslint/eslint-plugin --save-dev

Ensure that your ESLint configuration file `.eslintrc.js` includes TypeScript. You can use the following template:

Javascript

module.exports = {
  root: true,
  env: {
    node: true,
  },
  extends: [
    'plugin:vue/essential',
    '@vue/airbnb',
    '@vue/typescript',
  ],
};

Step 3: Adding Stylelint for SCSS Support
To include Stylelint for SCSS in your project, install the required dependencies:

Plaintext

npm install stylelint stylelint-scss stylelint-config-standard --save-dev

Create a Stylelint configuration file `.stylelintrc.js` with the following content:

Javascript

module.exports = {
  extends: ['stylelint-config-standard'],
  rules: {},
};

Step 4: Enabling Autofix on Save in Visual Studio Code
Launch Visual Studio Code and install the ESLint and Stylelint extensions from the marketplace. Open your project in VS Code and navigate to `settings.json`. Add the following settings:

Json

"editor.codeActionsOnSave": {
  "source.fixAll.eslint": true,
  "source.fixAll.stylelint": true
},

With these configurations in place, your Vue CLI 4 project will now be equipped with ESLint using Airbnb rules, TypeScript support, Stylelint for SCSS, and the convenience of autofix on save in the Visual Studio Code editor.

By following these steps, you not only ensure a consistent coding style across your project but also benefit from automatic linting and code formatting that saves you time and enhances your productivity. Elevate your coding experience with these essential configurations for Vue CLI 4 and unleash your coding potential!

×