关于 vue3 lint 的问题

2021-12-14 20:25:37 +08:00
 chenqh

我的 .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 把!

1327 次点击
所在节点    Vue.js
6 条回复
noe132
2021-12-14 20:57:36 +08:00
你这是运行时错误,eslint 只检查语法错误。
chenqh
2021-12-14 21:00:49 +08:00
@noe132 我的意思是我这个 message 明显没有 import 呀,难道 eslint 检查不出来? eslint 这么弱吗?
noe132
2021-12-14 21:03:29 +08:00
@chenqh 你配置了相应规则吗?使用未定义变量需要配置 no-undef 规则。你也可以找配置好的 preset 直接使用
chenqh
2021-12-14 21:07:51 +08:00
@noe132 噗,我还以为 no-undef 一开始就是自带的呢,郁闷
chenqh
2021-12-14 21:11:16 +08:00
@noe132 添加了 ` no-undef ` 就好了,谢谢大佬,我还以为 no-undef 本来就好开的呢
gadfly3173
2021-12-15 10:43:37 +08:00
自带什么规则和你加了什么 plugin extends 有关。vue 这几个都没有常规 js 的检查,推荐再搞个 airbnb 之类的。我自己是 extends: ['plugin:vue/vue3-recommended', '@vue/airbnb'] ,然后自己再根据需要对着代码一行行改得配置了一些规则

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/822222

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX