aboutsummaryrefslogtreecommitdiffstats
path: root/packages/tslint-config
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2017-12-16 02:37:03 +0800
committerFabio Berger <me@fabioberger.com>2017-12-16 02:37:03 +0800
commitb46dd2e0a277340c19fa137a436981cc53c8cb80 (patch)
treed2814176fe8ffc5ec6a61534aa77487aae6bcc13 /packages/tslint-config
parent484dd4c33aa5786def1f0b159f5b51f99a585aa8 (diff)
parent3eb08735d4d0fe4b046dd6b74f5ed503cf5c64e3 (diff)
downloaddexon-sol-tools-b46dd2e0a277340c19fa137a436981cc53c8cb80.tar
dexon-sol-tools-b46dd2e0a277340c19fa137a436981cc53c8cb80.tar.gz
dexon-sol-tools-b46dd2e0a277340c19fa137a436981cc53c8cb80.tar.bz2
dexon-sol-tools-b46dd2e0a277340c19fa137a436981cc53c8cb80.tar.lz
dexon-sol-tools-b46dd2e0a277340c19fa137a436981cc53c8cb80.tar.xz
dexon-sol-tools-b46dd2e0a277340c19fa137a436981cc53c8cb80.tar.zst
dexon-sol-tools-b46dd2e0a277340c19fa137a436981cc53c8cb80.zip
Merge branch 'development' into createWethPage
* development: (54 commits) Fix redundant spaces Fix tests Fix website unused vars Fix connect unused vars Fix 0x.js unused vars Dissallow unused vars/imports Implement first custom linter rule async-suffix Reuse intervalutils in website Add a newline Name a variable Add a comment Fix a conditional Make migrations deterministic Fix linter error Fix linter errors Add a function to init token balances Rename tokenUtils.getNonProtocolTokens to tokenUtils.getDummyTokens Add DummyToken to gitignore Add DummyToken to artifacts list Increase mocha timeout ...
Diffstat (limited to 'packages/tslint-config')
-rw-r--r--packages/tslint-config/package.json9
-rw-r--r--packages/tslint-config/rules/asyncSuffixRule.ts10
-rw-r--r--packages/tslint-config/rules/walkers/async_suffix.ts24
-rw-r--r--packages/tslint-config/tsconfig.json15
-rw-r--r--packages/tslint-config/tslint.json9
5 files changed, 65 insertions, 2 deletions
diff --git a/packages/tslint-config/package.json b/packages/tslint-config/package.json
index a4b5d4466..888ff675a 100644
--- a/packages/tslint-config/package.json
+++ b/packages/tslint-config/package.json
@@ -3,6 +3,11 @@
"version": "0.2.1",
"description": "Lint rules related to 0xProject for TSLint",
"main": "tslint.json",
+ "scripts": {
+ "build": "tsc",
+ "clean": "shx rm -rf lib",
+ "lint": "tslint --project . 'rules/**/*.ts'"
+ },
"files": [
"tslint.js",
"README.md",
@@ -29,10 +34,14 @@
},
"homepage": "https://github.com/0xProject/0x.js/packages/tslint-config/README.md",
"devDependencies": {
+ "@types/lodash": "^4.14.86",
+ "shx": "^0.2.2",
"tslint": "5.8.0",
+ "tslint-eslint-rules": "^4.1.1",
"typescript": "~2.6.1"
},
"dependencies": {
+ "lodash": "^4.17.4",
"tslint-react": "^3.2.0"
}
}
diff --git a/packages/tslint-config/rules/asyncSuffixRule.ts b/packages/tslint-config/rules/asyncSuffixRule.ts
new file mode 100644
index 000000000..c6ae5189c
--- /dev/null
+++ b/packages/tslint-config/rules/asyncSuffixRule.ts
@@ -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()));
+ }
+}
diff --git a/packages/tslint-config/rules/walkers/async_suffix.ts b/packages/tslint-config/rules/walkers/async_suffix.ts
new file mode 100644
index 000000000..7fa7a78b8
--- /dev/null
+++ b/packages/tslint-config/rules/walkers/async_suffix.ts
@@ -0,0 +1,24 @@
+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) {
+ // 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);
+ }
+ }
+ }
+ super.visitMethodDeclaration(node);
+ }
+}
diff --git a/packages/tslint-config/tsconfig.json b/packages/tslint-config/tsconfig.json
new file mode 100644
index 000000000..7661a9d07
--- /dev/null
+++ b/packages/tslint-config/tsconfig.json
@@ -0,0 +1,15 @@
+{
+ "compilerOptions": {
+ "module": "commonjs",
+ "target": "es5",
+ "lib": [ "es2017", "dom"],
+ "outDir": "lib",
+ "sourceMap": true,
+ "declaration": true,
+ "noImplicitAny": true,
+ "strictNullChecks": true
+ },
+ "include": [
+ "./rules/**/*"
+ ]
+}
diff --git a/packages/tslint-config/tslint.json b/packages/tslint-config/tslint.json
index 0921a3954..acb6876c3 100644
--- a/packages/tslint-config/tslint.json
+++ b/packages/tslint-config/tslint.json
@@ -1,12 +1,14 @@
{
"extends": [
"tslint:latest",
- "tslint-react"
+ "tslint-react",
+ "tslint-eslint-rules"
],
"rules": {
"adjacent-overload-signatures": true,
"arrow-parens": [true, "ban-single-arg-parens"],
"arrow-return-shorthand": true,
+ "async-suffix": true,
"await-promise": true,
"binary-expression-operand-order": true,
"callable-types": true,
@@ -50,8 +52,10 @@
"no-string-throw": true,
"no-submodule-imports": false,
"no-unnecessary-type-assertion": true,
+ "no-unused-variable": [true, {"ignore-pattern": "^_\\d*"}],
"no-implicit-dependencies": [true, "dev"],
"number-literal-format": true,
+ "object-curly-spacing": [true, "never"],
"object-literal-sort-keys": false,
"ordered-imports": [
true,
@@ -101,5 +105,6 @@
"jsx-self-close": true,
"jsx-wrap-multiline": false,
"jsx-no-bind": false
- }
+ },
+ "rulesDirectory": "lib"
}