43081j / 43081j/eslint-plugin-wc

Guard super call with typeof check

未关闭
#134 5 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
TypeScript
星标
113
派生
19
平均合并
3 小时 14 分钟
30 天内合并 PR
2

描述

It's better (more explicit) to guard a super call with a typeof check rather than a "truthy" check. Here's a patch to do that.

```
diff --git a/node_modules/eslint-plugin-wc/lib/rules/guard-super-call.js b/node_modules/eslint-plugin-wc/lib/rules/guard-super-call.js
index 873ec0d..ad659e4
--- a/node_modules/eslint-plugin-wc/lib/rules/guard-super-call.js
+++ b/node_modules/eslint-plugin-wc/lib/rules/guard-super-call.js
@@ -65,6 +65,19 @@ const rule = {
node.expression.type === 'CallExpression' &&
isSuperHook(node.expression.callee, hook));
}
+ /**
+ * Determines if an if statement is a correct super hook guard
+ * @param {ESTree.IfStatement} node Node to test
+ * @param {string} hook hook to test
+ * @return {boolean}
+ */
+ function isCorrectSuperHookGuard(node, hook) {
+ return node.test.type === 'BinaryExpression' &&
+ node.test.left.operator === 'typeof' &&
+ isSuperHook(node.test.left.argument, hook) &&
+ node.test.right.type === 'Literal' &&
+ node.test.right.value === 'function';
+ }
/**
* Determines if a statement is an unguarded super hook
* @param {ESTree.Statement} node Node to test
@@ -76,7 +89,7 @@ const rule = {
errNode = node;
return true;
}
- else if (node.type === 'IfStatement' && !isSuperHook(node.test, hook)) {
+ else if (node.type === 'IfStatement' && !isCorrectSuperHookGuard(node, hook)) {
return isUnguardedSuperHook(node.consequent, hook);
}
else if (node.type === 'BlockStatement' &&
```

贡献指南

这个仓库没有索引到贡献指南

调研方向

该 issue 为文件 node_modules/eslint-plugin-wc/lib/rules/guard-super-call.js 提供了一个补丁。首先在仓库中找到实际的源文件(可能位于 src/ 或 lib/ 下)。了解现有的 isSuperHook 函数,以及新的 isCorrectSuperHookGuard 应如何集成。运行此规则现有的测试,以确保更改不会破坏任何内容,并为新的 guard 逻辑添加一个测试用例。

由索引模型根据 Issue 内容生成。

评估

技术栈
javascript
领域
devtools, testing-qa
Issue 类型
重构
难度
2/5
预计耗时
1-3 小时
活跃度
停滞
描述清晰度
描述清楚
新手友好度
45/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。