AlloyTeam / eslint-config-alloy

Progressive ESLint config for your React/Vue/TypeScript projects
https://alloyteam.github.io/eslint-config-alloy/
2.65k stars 317 forks source link

为什么在vue.js中eqeqeq是off二不是error? #238

Closed Cuixote closed 1 year ago

Cuixote commented 1 year ago

base.jseqeqeq是["error", "always"],但是却被vue.js中的eqeqeq: "off"覆盖。

xcatliu commented 1 year ago

这个是 eslint-config-alloy 的构建脚本自动添加的。

因为 eslint-plugin-vue 的 eqeqeq 规则继承了 coreRule:

https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/eqeqeq.js#L9 https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/utils/index.js#L505

Cuixote commented 1 year ago

不过如vue-plugin-vue所说,这并不是他们要做的事情,而应该是alloy 要做的事情。所以,我们要打开这条规则吗?

xcatliu commented 1 year ago

现在 vue 规则是关闭了 eqeqeq 开启了 vue/eqeqeq。这样子做会有什么问题吗?

image
xcatliu commented 1 year ago

因为 typescript 规则里,所有继承 coreRule 的规则,都需要先关闭 core rule 再开启 ts rule,否则执行 eslint 检查时会有 bug。

所以这个构建流程也继承到了 vue 规则里

Cuixote commented 1 year ago

我的期望正如注释中所写必须使用 === 或 !==,禁止使用 == 或 !=,但是目前使用extends: ["alloy", "alloy/vue"]的配置。无论是在*.js文件或者在*.vue文件的script标签中,== 或者!=都不会出现ESLint的报错。

Cuixote commented 1 year ago

在我另一个使用了extends: ["alloy", "alloy/typescript"],配置的项目中,最终规则却是"eqeqeq": [ "error", "always" ],,并且在*.ts*.js中都是生效的,所以vue/eqeqeq这条规则,目前看来是有问题的。

xcatliu commented 1 year ago

无论是在*.js文件或者在*.vue文件的script标签中,== 或者!=都不会出现ESLint的报错。

*.vue 文件中应该是生效的,可以 clone 本项目,在这个文件 https://github.com/AlloyTeam/eslint-config-alloy/blob/master/test/vue/eqeqeq/bad.vue 中应该可以看到有报错信息

xcatliu commented 1 year ago

*.ts*.js 文件中不生效可能是有问题的,我考虑一下 vue 不要去使用 ts 同样的构建流程吧。可能在 vue 中还是需要 eqeqeqvue/eqeqeq 都开启

Cuixote commented 1 year ago

无论是在*.js文件或者在*.vue文件的script标签中,== 或者!=都不会出现ESLint的报错。

*.vue 文件中应该是生效的,可以 clone 本项目,在这个文件 https://github.com/AlloyTeam/eslint-config-alloy/blob/master/test/vue/eqeqeq/bad.vue 中应该可以看到有报错信息

这个确实可以,但是是在*.vue文件的template中生效,并没有在*.vue文件的script标签中生效,建议你把这个测试用例中加入script的测试。

xcatliu commented 1 year ago

已修复,请下载 v4.9.0 版本