43081j / 43081j/eslint-plugin-wc

Guard super call with typeof check

Aberta
#134 5 comentários 0 reações 0 responsáveis Ver no GitHub
Linguagem predominante
TypeScript
Estrelas
113
Forks
19
Merge médio
3h 14min
PRs com merge (30d)
2

Descrição

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' &&
```

Guia de contribuição

Nenhum guia de contribuição indexado para este repositório

Direção de pesquisa

The issue provides a patch for the file node_modules/eslint-plugin-wc/lib/rules/guard-super-call.js. Start by locating the actual source file in the repository (likely under src/ or lib/). Understand the existing isSuperHook function and how the new isCorrectSuperHookGuard should integrate. Run the existing tests for this rule to ensure the change doesn't break anything, and add a test case for the new guard logic.

Escrita pelo modelo de indexação a partir do texto da issue.

Avaliação

Stack de tecnologia
eslint, javascript, typescript
Domínio
devtools, testing-qa
Tipo de issue
Refatoração
Dificuldade
2/5
Tempo estimado
1-3 horas
Status de atividade
Estagnada
Clareza
Claramente especificada
Facilidade para iniciantes
45/100

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.