vscode 新版eslint自动修复_eslint vscode 自动修复

本文介绍了如何在VSCode中设置和配置ESLint以实现自动修复功能。首先,通过创建`.eslintrc.js`文件并定义规则,然后根据项目类型(如Vue或React)安装相应的npm包。接着,更新VSCode配置文件,启用`eslint.autoFixOnSave`选项,以及针对不同文件类型的自动修复。最后,重启VSCode以应用更改。
摘要由CSDN通过智能技术生成

建立.eslintrc.js文件

0.1 可以选择自己手动建立

在根目录建立文件.eslintrc.js

const pkg = require('./package.json');

module.exports = {

env: {

browser: true,

amd: true,

es6: true,

node: true

},

extends: ['airbnb'],

plugins: ['react', 'react-hooks'],

parser: 'babel-eslint'

};

复制代码

0.2 使用ESLint自动创建规则

npm init

eslint --init

eslint --init

How would you like to use ESLint? To check syntax, find problems, and enforce code style

What type of modules does your project use? JavaScript modules (import/export)

Which framework does your project use? None of these

Where does your code run? (Press to select, to toggle all, to invert selection)Browser

How would you like to define a style for your project? Use a popular style guide

Which style guide do you want to follow? Standard (https://github.com/standard/standard)

What format do you want your config file to be in? JavaScript

复制代码

配置以上规则。

安装npm包

针对vue

npm install --save-dev eslint-friendly-formatter eslint-loader eslint-plugin-html eslint-plugin-vue eslint-plugin-react eslint-config-standard

复制代码

针对react airbnb

npm install --save-dev eslint-friendly-formatter eslint-loader eslint-plugin-html eslint-plugin-react eslint-config-airbnb eslint-plugin-react-hooks

复制代码打开 vscode 修改配置文件

{

"eslint.autoFixOnSave": true,

"eslint.validate": [

"javascript", // 用eslint的规则检测js文件

{

"language": "vue", // 检测vue文件

"autoFix": true // 为vue文件开启保存自动修复的功能

},

{

"language": "react",

"autoFix": true

},

{

"language": "html",

"autoFix": true

},

],

"files.associations": {

"*.cjson": "jsonc",

"*.wxss": "css",

"*.wxs": "javascript"

},

"emmet.includeLanguages": {

"wxml": "html"

}

}

复制代码

重启VSCode使之生效。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值