vue ESLint报No ESLint configuration found

本文介绍了ESLint在管理JavaScript代码风格中的作用,以及如何在VSCode中解决'No ESLint configuration found'的错误。通过npm初始化,安装eslint,然后使用eslint –init创建配置文件,最终生成.eslintrc.js进行自定义设置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.eslint简介

eslint是用来管理和检测js代码风格的工具,可以和编辑器搭配使用,如vscode的eslint插件

当有不符合配置文件内容的代码出现就会报错或者警告
2.安装eslint

(1)npm init -y

(2)npm install eslint –save-dev

(3)./node_modules/.bin/eslint –init 初始化配置文件

(4)init初始化配置

How would you like to use ESLint? (Use arrow keys)
  To check syntax only //只检查语法
> To check syntax and find problems//检查语法、发现问题
  To check syntax, find problems, and enforce code style//检查语法、发现问题并执行代码样式

您的项目使用什么类型的模块?

 What type of modules does your project use? (Use arrow keys)
> JavaScript modules (import/export)
  CommonJS (require/exports)
  None of these

项目中使用的什么框架?

Which framework does your project use? (Use arrow keys)
> React
  Vue.js
  None of these

你的代码运行在什么地方?

 Where does your code run? (Press <space> to select, <a> to toggle all, <i> to invert selection)
>(*) Browser
 ( ) Node
How would you like to define a style for your project? (Use arrow keys)
> Use a popular style guide   // 1. 使用大厂的
  Answer questions about your style  //2. 问问题
  Inspect your JavaScript file(s)  //3. 检查现有的代码自动生成

您希望配置文件的格式是什么?

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

(5).eslintrc.js,后续可以修改

module.exports = {
    env: {
        browser: true,
        es6: true,
      },
      extends: 'plugin:vue/essential',
      globals: {
        Atomics: 'readonly',
        SharedArrayBuffer: 'readonly',
      },
      parser: 'vue-eslint-parser',
      parserOptions: {
        ecmaVersion: 2018,
        sourceType: 'module',
        parser: 'babel-eslint',
      },
      plugins: ['vue'],
      rules: {
        'no-console': 0,
        'no-alert': 1, //提示alert
        'no-var': 2, //禁用var,用let和const代替
        'no-constant-condition': 2, //禁止在条件中使用常量表达式 if(true) if(1)
        'no-empty': 1, //块语句中的内容不能为空
        'no-irregular-whitespace': 2, //不能有不规则的空格
        'no-multi-spaces': 1, //不能用多余的空格
        'no-redeclare': 2, //禁止重复声明变量
        indent: [2, 2], // 使用缩进量为2
        // semi: [2, 'never'], // 不使用分号
        // quotes: [2, 'single'], // 使用单引号
      },
};
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值