aboutsummaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2018-12-13 02:54:49 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2018-12-13 02:54:49 +0800
commit2b523a36c58b207a27dee4078237919d628dc588 (patch)
treed9e580b90e2b18118edd1869208b2a303fd3eb82 /packages
parent78a6d236599857e2c9478b3c23a751101a6e233b (diff)
downloaddexon-sol-tools-2b523a36c58b207a27dee4078237919d628dc588.tar
dexon-sol-tools-2b523a36c58b207a27dee4078237919d628dc588.tar.gz
dexon-sol-tools-2b523a36c58b207a27dee4078237919d628dc588.tar.bz2
dexon-sol-tools-2b523a36c58b207a27dee4078237919d628dc588.tar.lz
dexon-sol-tools-2b523a36c58b207a27dee4078237919d628dc588.tar.xz
dexon-sol-tools-2b523a36c58b207a27dee4078237919d628dc588.tar.zst
dexon-sol-tools-2b523a36c58b207a27dee4078237919d628dc588.zip
Check functions Async suffix
Diffstat (limited to 'packages')
-rw-r--r--packages/tslint-config/CHANGELOG.json8
-rw-r--r--packages/tslint-config/rules/walkers/async_suffix.ts39
2 files changed, 32 insertions, 15 deletions
diff --git a/packages/tslint-config/CHANGELOG.json b/packages/tslint-config/CHANGELOG.json
index 9f504216c..9915d6f9a 100644
--- a/packages/tslint-config/CHANGELOG.json
+++ b/packages/tslint-config/CHANGELOG.json
@@ -1,5 +1,13 @@
[
{
+ "version": "2.0.0",
+ "changes": [
+ {
+ "note": "Improve async-suffix rule to check functions too, not just methods"
+ }
+ ]
+ },
+ {
"version": "1.0.10",
"changes": [
{
diff --git a/packages/tslint-config/rules/walkers/async_suffix.ts b/packages/tslint-config/rules/walkers/async_suffix.ts
index eaec9c5f6..4e12152e8 100644
--- a/packages/tslint-config/rules/walkers/async_suffix.ts
+++ b/packages/tslint-config/rules/walkers/async_suffix.ts
@@ -3,24 +3,33 @@ import * as Lint from 'tslint';
import * as ts from 'typescript';
export class AsyncSuffixWalker extends Lint.RuleWalker {
- public static FAILURE_STRING = 'async functions must have an Async suffix';
+ public static FAILURE_STRING = 'async functions/methods must have an Async suffix';
+ public visitFunctionDeclaration(node: ts.FunctionDeclaration): void {
+ this._visitFunctionOrMethodDeclaration(node);
+ super.visitFunctionDeclaration(node);
+ }
public visitMethodDeclaration(node: ts.MethodDeclaration): void {
- const methodNameNode = node.name;
- const methodName = methodNameNode.getText();
- if (!_.isUndefined(node.type)) {
- if (node.type.kind === ts.SyntaxKind.TypeReference) {
- // tslint:disable-next-line:no-unnecessary-type-assertion
- const returnTypeName = (node.type as ts.TypeReferenceNode).typeName.getText();
- if (returnTypeName === 'Promise' && !methodName.endsWith('Async')) {
- const failure = this.createFailure(
- methodNameNode.getStart(),
- methodNameNode.getWidth(),
- AsyncSuffixWalker.FAILURE_STRING,
- );
- this.addFailure(failure);
+ this._visitFunctionOrMethodDeclaration(node);
+ super.visitMethodDeclaration(node);
+ }
+ private _visitFunctionOrMethodDeclaration(node: ts.MethodDeclaration | ts.FunctionDeclaration): void {
+ const nameNode = node.name;
+ if (!_.isUndefined(nameNode)) {
+ const name = nameNode.getText();
+ if (!_.isUndefined(node.type)) {
+ if (node.type.kind === ts.SyntaxKind.TypeReference) {
+ // tslint:disable-next-line:no-unnecessary-type-assertion
+ const returnTypeName = (node.type as ts.TypeReferenceNode).typeName.getText();
+ if (returnTypeName === 'Promise' && !name.endsWith('Async')) {
+ const failure = this.createFailure(
+ nameNode.getStart(),
+ nameNode.getWidth(),
+ AsyncSuffixWalker.FAILURE_STRING,
+ );
+ this.addFailure(failure);
+ }
}
}
}
- super.visitMethodDeclaration(node);
}
}