eslint vscode 自动修复

  1. 建立.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 <space> to select, <a> to toggle all, <i> 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
复制代码

配置以上规则。

  1. 安装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
复制代码
  1. 打开 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使之生效。

转载于:https://juejin.im/post/5c807fc1f265da2dcd7a0cbc

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值