V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
chenqh
V2EX  ›  Vue.js

关于 vue3 lint 的问题

  •  
  •   chenqh · 2021-12-14 20:25:37 +08:00 · 1325 次点击
    这是一个创建于 862 天前的主题,其中的信息可能已经有所发展或是发生改变。

    我的 .eslintrc.js 是这样的

    module.exports = {
    	root: true,
    	parserOptions: {
    		sourceType: 'module'
    	},
    	parser: 'vue-eslint-parser',
    	extends: ['plugin:vue/vue3-essential', 'plugin:vue/vue3-strongly-recommended', 'plugin:vue/vue3-recommended'],
    	env: {
    		browser: true,
    		node: true,
    		es6: true
    	},
    	rules: {
    		// 'comma-dangle': 'off',
    		'no-console': 'off',
    		'vue/prop-name-casing': 'off',
    		"vue/max-attributes-per-line": "off",
    		"vue/html-closing-bracket-newline":"off",
    		"vue/no-setup-props-destructure": "off",
    		'comma-dangle': 'off' //禁止使用拖尾逗号
    	}
    }
    

    也能跑

    但是有问题

    因为我的 vue 代码还是有问题,Uncaught (in promise) ReferenceError: message is not defined 但是 eslint 检查不出来? 有什么办法可见检测这种东西吗? 总不可能我一定要上 ts 把!

    6 条回复    2021-12-15 10:43:37 +08:00
    noe132
        1
    noe132  
       2021-12-14 20:57:36 +08:00
    你这是运行时错误,eslint 只检查语法错误。
    chenqh
        2
    chenqh  
    OP
       2021-12-14 21:00:49 +08:00
    @noe132 我的意思是我这个 message 明显没有 import 呀,难道 eslint 检查不出来? eslint 这么弱吗?
    noe132
        3
    noe132  
       2021-12-14 21:03:29 +08:00   ❤️ 1
    @chenqh 你配置了相应规则吗?使用未定义变量需要配置 no-undef 规则。你也可以找配置好的 preset 直接使用
    chenqh
        4
    chenqh  
    OP
       2021-12-14 21:07:51 +08:00
    @noe132 噗,我还以为 no-undef 一开始就是自带的呢,郁闷
    chenqh
        5
    chenqh  
    OP
       2021-12-14 21:11:16 +08:00
    @noe132 添加了 ` no-undef ` 就好了,谢谢大佬,我还以为 no-undef 本来就好开的呢
    gadfly3173
        6
    gadfly3173  
       2021-12-15 10:43:37 +08:00   ❤️ 1
    自带什么规则和你加了什么 plugin extends 有关。vue 这几个都没有常规 js 的检查,推荐再搞个 airbnb 之类的。我自己是 extends: ['plugin:vue/vue3-recommended', '@vue/airbnb'] ,然后自己再根据需要对着代码一行行改得配置了一些规则
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3566 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 10:53 · PVG 18:53 · LAX 03:53 · JFK 06:53
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.