Eslint 用法

安装

npm i eslint

自动生成文件

npm init @eslint/config

配置

module.exports = {

root: true,

parserOptions: {

ecmaVersion: 11,

sourceType: 'module',

},

extends: [

'eslint:recommended', 推荐的规则表

'airbnb-base',

],

plugins: [

'vue',

],

rules: {

'semi':2 例如: 所有文件都需要加上分号

},

};

vite与eslint关联

1 安装

npm i vite-plugin-eslint

2 设置

vite.config.ts

import eslint form 'vite-plugin-eslint'

export default defineConfig({

plugins:[vue(),eslint()]

})

eslintrc.cjs中添加

module.exports = {

"env":{"node":true}

}
目前还没法验证vue文件的语法 会直接报错 因为出现了 template标签 解决方案:npm i eslint-plugin-vue
设置 extends:["plugin:vue/vue3-essential"]

无法验证ts语法一些符号 例如泛型括号 解决方案:npm i @vue/eslint-config-typescript
设置 extends:["plugin:vue/vue3-essential","@vue/eslint-config-typescript"]

如果要验证更多文件 在.vscode 文件中添加文件 setting.json
{
"eslint.validate":["javescript",'vue','typescript']
}

遇见eslint报错 其他解决方案

安装eslint插件 1 ctrl+shift+p ---> Eslint:fix all suto-fixable

problems

或者 设置保存自动修复所有问题 打开eslint插件中的setting.json

"editor.codeActionsOnSave":{"sourcefixAll.eslint":true}

相关推荐
Forever7_3 小时前
Electron 淘汰!新的桌面端框架 更强大、更轻量化
前端·vue.js
不会敲代码13 小时前
前端组件化样式隔离实战:React CSS Modules、styled-components 与 Vue scoped 对比
css·vue.js·react.js
Angelial3 小时前
Vue3 嵌套路由 KeepAlive:动态缓存与反向配置方案
前端·vue.js
SuperEugene4 小时前
Vue状态管理扫盲篇:如何设计一个合理的全局状态树 | 用户、权限、字典、布局配置
前端·vue.js·面试
阿懂在掘金5 小时前
defineModel 是进步还是边界陷阱?双数据源组件的选择逻辑
vue.js·源码阅读
李剑一5 小时前
要闹哪样?又出现了一款新的格式化插件,尤雨溪力荐,速度提升了惊人的45倍!
前端·vue.js
阿虎儿6 小时前
React Context 详解:从入门到性能优化
前端·vue.js·react.js
滕青山8 小时前
文本行过滤/筛选 在线工具核心JS实现
前端·javascript·vue.js
时光不负努力8 小时前
ts+vue3开发规范
vue.js·typescript
梦想CAD控件9 小时前
在线CAD开发包结构与功能说明
前端·javascript·vue.js