Implement first custom linter rule async-suffix
This commit is contained in:
@@ -20,7 +20,4 @@ export class BlockchainLifecycle {
|
|||||||
throw new Error(`Snapshot with id #${snapshotId} failed to revert`);
|
throw new Error(`Snapshot with id #${snapshotId} failed to revert`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public async mineABlock(): Promise<void> {
|
|
||||||
await this.rpc.mineBlockAsync();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
1
packages/subproviders/src/globals.d.ts
vendored
1
packages/subproviders/src/globals.d.ts
vendored
@@ -5,6 +5,7 @@ declare module 'es6-promisify';
|
|||||||
|
|
||||||
// tslint:disable:max-classes-per-file
|
// tslint:disable:max-classes-per-file
|
||||||
// tslint:disable:class-name
|
// tslint:disable:class-name
|
||||||
|
// tslint:disable:async-suffix
|
||||||
// tslint:disable:completed-docs
|
// tslint:disable:completed-docs
|
||||||
|
|
||||||
// Ethereumjs-tx declarations
|
// Ethereumjs-tx declarations
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ export class RedundantRPCSubprovider extends Subprovider {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
// tslint:disable-next-line:async-suffix
|
||||||
public async handleRequest(payload: JSONRPCPayload, next: () => void,
|
public async handleRequest(payload: JSONRPCPayload, next: () => void,
|
||||||
end: (err: Error|null, data?: any) => void): Promise<void> {
|
end: (err: Error|null, data?: any) => void): Promise<void> {
|
||||||
const rpcsCopy = this.rpcs.slice();
|
const rpcsCopy = this.rpcs.slice();
|
||||||
|
|||||||
@@ -3,6 +3,11 @@
|
|||||||
"version": "0.2.1",
|
"version": "0.2.1",
|
||||||
"description": "Lint rules related to 0xProject for TSLint",
|
"description": "Lint rules related to 0xProject for TSLint",
|
||||||
"main": "tslint.json",
|
"main": "tslint.json",
|
||||||
|
"scripts": {
|
||||||
|
"build": "tsc",
|
||||||
|
"clean": "shx rm -rf lib",
|
||||||
|
"lint": "tslint --project . 'rules/**/*.ts'"
|
||||||
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"tslint.js",
|
"tslint.js",
|
||||||
"README.md",
|
"README.md",
|
||||||
@@ -29,10 +34,13 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/0xProject/0x.js/packages/tslint-config/README.md",
|
"homepage": "https://github.com/0xProject/0x.js/packages/tslint-config/README.md",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@types/lodash": "^4.14.86",
|
||||||
|
"shx": "^0.2.2",
|
||||||
"tslint": "5.8.0",
|
"tslint": "5.8.0",
|
||||||
"typescript": "~2.6.1"
|
"typescript": "~2.6.1"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"lodash": "^4.17.4",
|
||||||
"tslint-react": "^3.2.0"
|
"tslint-react": "^3.2.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
10
packages/tslint-config/rules/asyncSuffixRule.ts
Normal file
10
packages/tslint-config/rules/asyncSuffixRule.ts
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import * as Lint from 'tslint';
|
||||||
|
import * as ts from 'typescript';
|
||||||
|
|
||||||
|
import {AsyncSuffixWalker} from './walkers/async_suffix';
|
||||||
|
|
||||||
|
export class Rule extends Lint.Rules.AbstractRule {
|
||||||
|
public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
|
||||||
|
return this.applyWithWalker(new AsyncSuffixWalker(sourceFile, this.getOptions()));
|
||||||
|
}
|
||||||
|
}
|
||||||
23
packages/tslint-config/rules/walkers/async_suffix.ts
Normal file
23
packages/tslint-config/rules/walkers/async_suffix.ts
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
import * as _ from 'lodash';
|
||||||
|
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 visitMethodDeclaration(node: ts.MethodDeclaration): void {
|
||||||
|
const methodNameNode = node.name;
|
||||||
|
const methodName = methodNameNode.getText();
|
||||||
|
if (!_.isUndefined(node.type)) {
|
||||||
|
if (node.type.kind === ts.SyntaxKind.TypeReference) {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
super.visitMethodDeclaration(node);
|
||||||
|
}
|
||||||
|
}
|
||||||
15
packages/tslint-config/tsconfig.json
Normal file
15
packages/tslint-config/tsconfig.json
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"module": "commonjs",
|
||||||
|
"target": "es5",
|
||||||
|
"lib": [ "es2017", "dom"],
|
||||||
|
"outDir": "lib",
|
||||||
|
"sourceMap": true,
|
||||||
|
"declaration": true,
|
||||||
|
"noImplicitAny": true,
|
||||||
|
"strictNullChecks": true
|
||||||
|
},
|
||||||
|
"include": [
|
||||||
|
"./rules/**/*"
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -7,6 +7,7 @@
|
|||||||
"adjacent-overload-signatures": true,
|
"adjacent-overload-signatures": true,
|
||||||
"arrow-parens": [true, "ban-single-arg-parens"],
|
"arrow-parens": [true, "ban-single-arg-parens"],
|
||||||
"arrow-return-shorthand": true,
|
"arrow-return-shorthand": true,
|
||||||
|
"async-suffix": true,
|
||||||
"await-promise": true,
|
"await-promise": true,
|
||||||
"binary-expression-operand-order": true,
|
"binary-expression-operand-order": true,
|
||||||
"callable-types": true,
|
"callable-types": true,
|
||||||
@@ -101,5 +102,6 @@
|
|||||||
"jsx-self-close": true,
|
"jsx-self-close": true,
|
||||||
"jsx-wrap-multiline": false,
|
"jsx-wrap-multiline": false,
|
||||||
"jsx-no-bind": false
|
"jsx-no-bind": false
|
||||||
}
|
},
|
||||||
|
"rulesDirectory": "lib"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user