aboutsummaryrefslogtreecommitdiffstats
path: root/packages/tslint-config
diff options
context:
space:
mode:
Diffstat (limited to 'packages/tslint-config')
-rw-r--r--packages/tslint-config/CHANGELOG.json10
-rw-r--r--packages/tslint-config/CHANGELOG.md4
-rw-r--r--packages/tslint-config/package.json2
-rw-r--r--packages/tslint-config/rules/walkers/async_suffix.ts39
-rw-r--r--packages/tslint-config/tslint.json1
5 files changed, 40 insertions, 16 deletions
diff --git a/packages/tslint-config/CHANGELOG.json b/packages/tslint-config/CHANGELOG.json
index 9f504216c..0070a5b81 100644
--- a/packages/tslint-config/CHANGELOG.json
+++ b/packages/tslint-config/CHANGELOG.json
@@ -1,5 +1,15 @@
[
{
+ "version": "2.0.0",
+ "changes": [
+ {
+ "note": "Improve async-suffix rule to check functions too, not just methods",
+ "pr": 1425
+ }
+ ],
+ "timestamp": 1544739608
+ },
+ {
"version": "1.0.10",
"changes": [
{
diff --git a/packages/tslint-config/CHANGELOG.md b/packages/tslint-config/CHANGELOG.md
index f5cacb5d1..3cebb1e95 100644
--- a/packages/tslint-config/CHANGELOG.md
+++ b/packages/tslint-config/CHANGELOG.md
@@ -5,6 +5,10 @@ Edit the package's CHANGELOG.json file only.
CHANGELOG
+## v2.0.0 - _December 13, 2018_
+
+ * Improve async-suffix rule to check functions too, not just methods (#1425)
+
## v1.0.10 - _November 9, 2018_
* Dependencies updated
diff --git a/packages/tslint-config/package.json b/packages/tslint-config/package.json
index 2914f31e2..64ec1e967 100644
--- a/packages/tslint-config/package.json
+++ b/packages/tslint-config/package.json
@@ -1,6 +1,6 @@
{
"name": "@0x/tslint-config",
- "version": "1.0.10",
+ "version": "2.0.0",
"engines": {
"node": ">=6.12"
},
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);
}
}
diff --git a/packages/tslint-config/tslint.json b/packages/tslint-config/tslint.json
index fd1849dd0..e8de6221e 100644
--- a/packages/tslint-config/tslint.json
+++ b/packages/tslint-config/tslint.json
@@ -92,6 +92,7 @@
"prefer-function-over-method": true,
"prefer-object-spread": true,
"prefer-readonly": true,
+ "prefer-template": true,
"promise-function-async": true,
"quotemark": [true, "single", "avoid-escape", "jsx-double"],
"restrict-plus-operands": true,