Table of Contents
Vue-cli is a scaffolding tool for Vue. In this article, we mainly share with you vue-cli vscode configuration eslint, hoping to help everyone. " >Vue-cli is a scaffolding tool for Vue. In this article, we mainly share with you vue-cli vscode configuration eslint, hoping to help everyone.
Effect" >Effect
How to configure" >How to configure
step1 vscode plug-in installation and configuration" >step1 vscode plug-in installation and configuration
step2 Installation and configuration of command line plug-in" >step2 Installation and configuration of command line plug-in
Home Web Front-end JS Tutorial Detailed example of vue-cli vscode configuration eslint

Detailed example of vue-cli vscode configuration eslint

Dec 22, 2017 pm 03:39 PM
vscode vue-cli Configuration

Vue-cli is a scaffolding tool for Vue. In this article, we mainly share with you vue-cli vscode configuration eslint, hoping to help everyone.

Effect

  • Can display non-compliant prompt information in vscode in real time

  • You can format all non-compliant code by running <span style="font-size: 14px;">npm run lint</span> and list all code that needs to be manually Modified code errors and positioning

  • You can customize the specification [The default specification JavaScript Standard Style recommended by eslint]

You can pass<span style="font-size: 14px;">/*eslint-disable */</span> to prevent the following code from accepting code specification checks and pass<span style="font-size: 14px;">/*eslint-enable */</span> Let the following code re-accept the code specification check and pass<span style="font-size: 14px;">// eslint-disable-line no- undef</span>Let a certain line of code not accept specification checking and may have undefined variables

How to configure

Mainly includes vscode plug-in installation and configuration and command line plug-in installation and configuration

step1 vscode plug-in installation and configuration

  1. Search for ESlint in vscode and install it

  2. Add the following code to the user settings of vscode:

<span style="font-size: 14px;">// 自动识别文件类型<br>    "emmet.syntaxProfiles": {<br>        "vue-html": "html",<br>        "vue": "html"<br>    },<br>    "eslint.autoFixOnSave": false,<br>    // 要lint的语言<br>    "eslint.validate": [<br>        "javascript",<br>        "javascriptreact",<br>        "html",<br>        "vue",<br>        {<br>            "language": "vue",<br>            "autoFix": true<br>        }<br>    ],<br>    "eslint.options": {<br>        "plugins": [<br>            "html"<br>        ]<br>    }<br></span>
Copy after login
  1. Create a new <span style="font-size: 14px;">eslintrc.json</span> file in the project root directory and add the following code:

<span style="font-size: 14px;">{<br>    "root": true,<br>    "parserOptions": {<br>        "sourceType": "module"<br>    },<br>    "env": {<br>        "browser": true,<br>        "es6": true<br>    },<br>    "extends": "eslint:recommended",<br>    "plugins": [<br>        "html"<br>    ],<br>    "rules": {<br>        "accessor-pairs": 2,<br>        "arrow-spacing": [2, {<br>          "before": true,<br>          "after": true<br>        }],<br>        "block-spacing": [2, "always"],<br>        "brace-style": [2, "1tbs", {<br>          "allowSingleLine": true<br>        }],<br>        "camelcase": [0, {<br>          "properties": "always"<br>        }],<br>        "comma-dangle": [2, "never"],<br>        "comma-spacing": [2, {<br>          "before": false,<br>          "after": true<br>        }],<br>        "comma-style": [2, "last"],<br>        "constructor-super": 2,<br>        "curly": [2, "multi-line"],<br>        "dot-location": [2, "property"],<br>        "eol-last": 2,<br>        // "eqeqeq": [2, "allow-null"],<br>        "eqeqeq": 0,<br>        "generator-star-spacing": [2, {<br>          "before": true,<br>          "after": true<br>        }],<br>        "handle-callback-err": [2, "^(err|error)$"],<br>        "indent": [2, 2, {<br>          "SwitchCase": 1<br>        }],<br>        "jsx-quotes": [2, "prefer-single"],<br>        "key-spacing": [2, {<br>          "beforeColon": false,<br>          "afterColon": true<br>        }],<br>        "keyword-spacing": [2, {<br>          "before": true,<br>          "after": true<br>        }],<br>        "new-cap": [2, {<br>          "newIsCap": true,<br>          "capIsNew": false<br>        }],<br>        "new-parens": 2,<br>        "no-array-constructor": 2,<br>        "no-caller": 2,<br>        "no-console": "off",<br>        "no-class-assign": 2,<br>        "no-cond-assign": 2,<br>        "no-const-assign": 2,<br>        "no-control-regex": 0,<br>        "no-delete-var": 2,<br>        "no-dupe-args": 2,<br>        "no-dupe-class-members": 2,<br>        "no-dupe-keys": 2,<br>        "no-duplicate-case": 2,<br>        "no-empty-character-class": 2,<br>        "no-empty-pattern": 2,<br>        "no-eval": 2,<br>        "no-ex-assign": 2,<br>        "no-extend-native": 2,<br>        "no-extra-bind": 2,<br>        "no-extra-boolean-cast": 2,<br>        "no-extra-parens": [2, "functions"],<br>        "no-fallthrough": 2,<br>        "no-floating-decimal": 2,<br>        "no-func-assign": 2,<br>        "no-implied-eval": 2,<br>        "no-inner-declarations": [2, "functions"],<br>        "no-invalid-regexp": 2,<br>        "no-irregular-whitespace": 2,<br>        "no-iterator": 2,<br>        "no-label-var": 2,<br>        "no-labels": [2, {<br>          "allowLoop": false,<br>          "allowSwitch": false<br>        }],<br>        "no-lone-blocks": 2,<br>        "no-mixed-spaces-and-tabs": 2,<br>        "no-multi-spaces": 2,<br>        "no-multi-str": 2,<br>        "no-multiple-empty-lines": [2, {<br>          "max": 1<br>        }],<br>        "no-native-reassign": 2,<br>        "no-negated-in-lhs": 2,<br>        "no-new-object": 2,<br>        "no-new-require": 2,<br>        "no-new-symbol": 2,<br>        "no-new-wrappers": 2,<br>        "no-obj-calls": 2,<br>        "no-octal": 2,<br>        "no-octal-escape": 2,<br>        "no-path-concat": 2,<br>        "no-proto": 2,<br>        "no-redeclare": 2,<br>        "no-regex-spaces": 2,<br>        "no-return-assign": [2, "except-parens"],<br>        "no-self-assign": 2,<br>        "no-self-compare": 2,<br>        "no-sequences": 2,<br>        "no-shadow-restricted-names": 2,<br>        "no-spaced-func": 2,<br>        "no-sparse-arrays": 2,<br>        "no-this-before-super": 2,<br>        "no-throw-literal": 2,<br>        "no-trailing-spaces": 2,<br>        "no-undef": 2,<br>        "no-undef-init": 2,<br>        "no-unexpected-multiline": 2,<br>        "no-unmodified-loop-condition": 2,<br>        "no-unneeded-ternary": [2, {<br>          "defaultAssignment": false<br>        }],<br>        "no-unreachable": 2,<br>        "no-unsafe-finally": 2,<br>        "no-unused-vars": [2, {<br>          "vars": "all",<br>          "args": "none"<br>        }],<br>        "no-useless-call": 2,<br>        "no-useless-computed-key": 2,<br>        "no-useless-constructor": 2,<br>        "no-useless-escape": 0,<br>        "no-whitespace-before-property": 2,<br>        "no-with": 2,<br>        "one-var": [2, {<br>          "initialized": "never"<br>        }],<br>        "operator-linebreak": [2, "after", {<br>          "overrides": {<br>            "?": "before",<br>            ":": "before"<br>          }<br>        }],<br>        "padded-blocks": [2, "never"],<br>        "quotes": [2, "single", {<br>          "avoidEscape": true,<br>          "allowTemplateLiterals": true<br>        }],<br>        "semi": [2, "never"],<br>        "semi-spacing": [2, {<br>          "before": false,<br>          "after": true<br>        }],<br>        "space-before-blocks": [2, "always"],<br>        "space-before-function-paren": [2, "never"],<br>        "space-in-parens": [2, "never"],<br>        "space-infix-ops": 2,<br>        "space-unary-ops": [2, {<br>          "words": true,<br>          "nonwords": false<br>        }],<br>        "spaced-comment": [2, "always", {<br>          "markers": ["global", "globals", "eslint", "eslint-disable", "*package", "!", ","]<br>        }],<br>        "template-curly-spacing": [2, "never"],<br>        "use-isnan": 2,<br>        "valid-typeof": 2,<br>        "wrap-iife": [2, "any"],<br>        "yield-star-spacing": [2, "both"],<br>        "yoda": [2, "never"],<br>        "prefer-const": 2,<br>        "object-curly-spacing": [2, "always", {<br>          "objectsInObjects": false<br>        }],<br>        "array-bracket-spacing": [2, "never"]<br>      }<br>}<br></span>
Copy after login

step2 Installation and configuration of command line plug-in

1. in the project root directory <span style="font-size: 14px;">package.json</span> Add the following code to the file:
<span style="font-size: 14px;">scripts</span> Next:

<span style="font-size: 14px;">"lint": "eslint --fix --ext .js,.vue src"<br></span>
Copy after login

and
<span style="font-size: 14px;">devDependencies</span> under:

<span style="font-size: 14px;">"eslint": "^3.19.0",<br>"eslint-plugin-vue": "^2.1.0",<br></span>
Copy after login
  1. Run in the project root directory terminal<span style="font-size: 14px;">cnpm i</span>

  2. ##done.

Related recommendations:

How to use vue-cli to develop multi-page applications

How Use vue-cli to build vue projects and webpack?

Summary related examples about Vue-cli

The above is the detailed content of Detailed example of vue-cli vscode configuration eslint. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to define header files for vscode How to define header files for vscode Apr 15, 2025 pm 09:09 PM

How to define header files using Visual Studio Code? Create a header file and declare symbols in the header file using the .h or .hpp suffix name (such as classes, functions, variables) Compile the program using the #include directive to include the header file in the source file. The header file will be included and the declared symbols are available.

What computer configuration is required for vscode What computer configuration is required for vscode Apr 15, 2025 pm 09:48 PM

VS Code system requirements: Operating system: Windows 10 and above, macOS 10.12 and above, Linux distribution processor: minimum 1.6 GHz, recommended 2.0 GHz and above memory: minimum 512 MB, recommended 4 GB and above storage space: minimum 250 MB, recommended 1 GB and above other requirements: stable network connection, Xorg/Wayland (Linux)

How to solve the problem of vscode Chinese annotations becoming question marks How to solve the problem of vscode Chinese annotations becoming question marks Apr 15, 2025 pm 11:36 PM

How to solve the problem that Chinese comments in Visual Studio Code become question marks: Check the file encoding and make sure it is "UTF-8 without BOM". Change the font to a font that supports Chinese characters, such as "Song Style" or "Microsoft Yahei". Reinstall the font. Enable Unicode support. Upgrade VSCode, restart the computer, and recreate the source file.

How to use VSCode How to use VSCode Apr 15, 2025 pm 11:21 PM

Visual Studio Code (VSCode) is a cross-platform, open source and free code editor developed by Microsoft. It is known for its lightweight, scalability and support for a wide range of programming languages. To install VSCode, please visit the official website to download and run the installer. When using VSCode, you can create new projects, edit code, debug code, navigate projects, expand VSCode, and manage settings. VSCode is available for Windows, macOS, and Linux, supports multiple programming languages ​​and provides various extensions through Marketplace. Its advantages include lightweight, scalability, extensive language support, rich features and version

Common commands for vscode terminal Common commands for vscode terminal Apr 15, 2025 pm 10:06 PM

Common commands for VS Code terminals include: Clear the terminal screen (clear), list the current directory file (ls), change the current working directory (cd), print the current working directory path (pwd), create a new directory (mkdir), delete empty directory (rmdir), create a new file (touch) delete a file or directory (rm), copy a file or directory (cp), move or rename a file or directory (mv) display file content (cat) view file content and scroll (less) view file content only scroll down (more) display the first few lines of the file (head)

vscode terminal usage tutorial vscode terminal usage tutorial Apr 15, 2025 pm 10:09 PM

vscode built-in terminal is a development tool that allows running commands and scripts within the editor to simplify the development process. How to use vscode terminal: Open the terminal with the shortcut key (Ctrl/Cmd). Enter a command or run the script. Use hotkeys (such as Ctrl L to clear the terminal). Change the working directory (such as the cd command). Advanced features include debug mode, automatic code snippet completion, and interactive command history.

Where to write code in vscode Where to write code in vscode Apr 15, 2025 pm 09:54 PM

Writing code in Visual Studio Code (VSCode) is simple and easy to use. Just install VSCode, create a project, select a language, create a file, write code, save and run it. The advantages of VSCode include cross-platform, free and open source, powerful features, rich extensions, and lightweight and fast.

How to switch Chinese mode with vscode How to switch Chinese mode with vscode Apr 15, 2025 pm 11:39 PM

VS Code To switch Chinese mode: Open the settings interface (Windows/Linux: Ctrl, macOS: Cmd,) Search for "Editor: Language" settings Select "Chinese" in the drop-down menu Save settings and restart VS Code

See all articles