Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

Enable "no-unnecessary-callback-wrapper" #2744

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 3 additions & 27 deletions src/rules/typedefRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,37 +221,13 @@ class TypedefWalker extends Lint.RuleWalker {
private checkTypeAnnotation(option: string,
location: number,
typeAnnotation: ts.TypeNode | undefined,
name?: ts.Node) {
if (this.hasOption(option) && typeAnnotation == null) {
this.addFailureAt(location, 1, "expected " + option + getName(name, ": '", "'") + " to have a typedef");
name?: ts.PropertyName | ts.BindingName) {
if (this.hasOption(option) && typeAnnotation === undefined) {
this.addFailureAt(location, 1, `expected ${option}${name === undefined ? "" : `: '${name.getText()}'`} to have a typedef`);
}
}
}

function getName(name?: ts.Node, prefix = "", suffix = ""): string {
let ns = "";

if (name != null) {
switch (name.kind) {
case ts.SyntaxKind.Identifier:
ns = (name as ts.Identifier).text;
break;
case ts.SyntaxKind.BindingElement:
ns = getName((name as ts.BindingElement).name);
break;
case ts.SyntaxKind.ArrayBindingPattern:
ns = `[ ${(name as ts.ArrayBindingPattern).elements.map( (n) => getName(n) ).join(", ")} ]`;
break;
case ts.SyntaxKind.ObjectBindingPattern:
ns = `{ ${(name as ts.ObjectBindingPattern).elements.map( (n) => getName(n) ).join(", ")} }`;
break;
default:
break;
}
}
return ns === "" ? "" : `${prefix}${ns}${suffix}`;
}

function isTypedPropertyDeclaration(node: ts.Node): boolean {
return utils.isPropertyDeclaration(node) && node.type != null;
}
1 change: 0 additions & 1 deletion tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
"no-null-keyword": false,
"no-require-imports": false,
"no-unbound-method": false,
"no-unnecessary-callback-wrapper": false,
"no-unnecessary-type-assertion": false,
"no-unnecessary-qualifier": false,
"no-use-before-declare": false,
Expand Down