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

Commit

Permalink
typedef: Use AbstractWalker and fix error locations (#2460)
Browse files Browse the repository at this point in the history
  • Loading branch information
andy-hanson authored and nchen63 committed May 13, 2017
1 parent 2f9bdbf commit b6cc7e1
Show file tree
Hide file tree
Showing 10 changed files with 167 additions and 215 deletions.
298 changes: 128 additions & 170 deletions src/rules/typedefRule.ts

Large diffs are not rendered by default.

50 changes: 24 additions & 26 deletions test/rules/typedef/all/test.ts.lint
Expand Up @@ -4,67 +4,65 @@ try {
}

var NoTypeObjectLiteralWithPropertyGetter = {
~ [expected variable-declaration: 'NoTypeObjectLiteralWithPropertyGetter' to have a typedef]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [expected variable-declaration: 'NoTypeObjectLiteralWithPropertyGetter' to have a typedef]
Prop: "some property",

get PropDef() {
~ [expected call-signature: 'PropDef' to have a typedef]
~~~~~~~ [expected call-signature: 'PropDef' to have a typedef]
return this.Prop;
},

methodDef() {
~ [expected call-signature: 'methodDef' to have a typedef]
~~~~~~~~~ [expected call-signature: 'methodDef' to have a typedef]
return 'untyped';
},

anotherMethodDef: function() {
~ [expected call-signature to have a typedef]
~~ [expected call-signature to have a typedef]
return 'also untyped';
},

arrowMethodDef: () => {
~ [expected arrow-call-signature to have a typedef]
~~ [expected arrow-call-signature to have a typedef]
return 'also untyped';
}
};

interface NoTypeInterface {
Prop;
~ [expected property-declaration: 'Prop' to have a typedef]
~~~~ [expected property-declaration: 'Prop' to have a typedef]
PropWithType: string;
}

var NoTypesFn = function (
~ [expected variable-declaration: 'NoTypesFn' to have a typedef]
a,
~ [expected parameter: 'a' to have a typedef]
b) {
~ [expected call-signature to have a typedef]
~ [expected parameter: 'b' to have a typedef]
var NoTypesFn = function (a, b) {
~~~~~~~~~ [expected variable-declaration: 'NoTypesFn' to have a typedef]
~ [expected parameter: 'a' to have a typedef]
~ [expected parameter: 'b' to have a typedef]
~~~~~~ [expected call-signature to have a typedef]
var c = a + b,
~ [expected variable-declaration: 'c' to have a typedef]
~ [expected variable-declaration: 'c' to have a typedef]
d = a - b;
~ [expected variable-declaration: 'd' to have a typedef]
~ [expected variable-declaration: 'd' to have a typedef]

class TsLint {
helloWorld() {
~ [expected call-signature: 'helloWorld' to have a typedef]
~~~~~~~~~~ [expected call-signature: 'helloWorld' to have a typedef]
return 'Hello World';
};

regularMemberWithType: string = this.getValue();

regularMemberWithoutType = this.getValue();
~ [expected member-variable-declaration: 'regularMemberWithoutType' to have a typedef]
~~~~~~~~~~~~~~~~~~~~~~~~ [expected member-variable-declaration: 'regularMemberWithoutType' to have a typedef]

arrowHelloWorld = () => {
~ [expected arrow-call-signature to have a typedef]
~~ [expected arrow-call-signature to have a typedef]
return this.helloWorld();
};

arrowHelloWorldWithArgsNoTypedef = (arg1) => {
~ [expected member-variable-declaration: 'arg1' to have a typedef]
~ [expected arrow-call-signature to have a typedef]
~~~~ [expected member-variable-declaration: 'arg1' to have a typedef]
~~~~~~ [expected arrow-call-signature to have a typedef]
return this.helloWorld();
};

Expand All @@ -79,28 +77,28 @@ class TsLint {

setTimeout(() => {}, 1000);
setTimeout(function() {}, 1000);
~ [expected call-signature to have a typedef]
~~ [expected call-signature to have a typedef]

someFunc(n => n+1);
~ [expected arrow-parameter: 'n' to have a typedef]
~ [expected arrow-parameter: 'n' to have a typedef]
someFunc(n => {});
~ [expected arrow-parameter: 'n' to have a typedef]
~ [expected arrow-parameter: 'n' to have a typedef]

class A {
// property w/o an initializer
public foo;
~ [expected member-variable-declaration: 'foo' to have a typedef]
~~~ [expected member-variable-declaration: 'foo' to have a typedef]
private bar: number;
}


const { paramA, paramB } = { paramA: "test", paramB: 15 };
~ [expected object-destructuring: '{ paramA, paramB }' to have a typedef]
~~~~~~~~~~~~~~~~~~ [expected object-destructuring: '{ paramA, paramB }' to have a typedef]

const { paramA, paramB }: { paramA: string, paramB: number } = { paramA: "test", paramB: 15 };

const [ paramA, paramB ] = [15, 'test'];
~ [expected array-destructuring: '[ paramA, paramB ]' to have a typedef]
~~~~~~~~~~~~~~~~~~ [expected array-destructuring: '[ paramA, paramB ]' to have a typedef]

const [ paramA3, paramB3 ]: [ number, string ] = [15, 'test'];

2 changes: 1 addition & 1 deletion test/rules/typedef/array-destructuring/test.ts.lint
@@ -1,4 +1,4 @@
const [ paramA, paramB ] = [15, 'test'];
~ [expected array-destructuring: '[ paramA, paramB ]' to have a typedef]
~~~~~~~~~~~~~~~~~~ [expected array-destructuring: '[ paramA, paramB ]' to have a typedef]

const [ paramA3, paramB3 ]: { number: string, paramB1: string } = [15, 'test'];
4 changes: 2 additions & 2 deletions test/rules/typedef/arrow-call-signature/test.ts.lint
Expand Up @@ -6,15 +6,15 @@ class TsLint {
};

arrowHelloWorld = () => {
~ [expected arrow-call-signature to have a typedef]
~~ [expected arrow-call-signature to have a typedef]
return this.helloWorld();
};
}

var obj = {
foge: function() {},
bar: () => {}
~ [expected arrow-call-signature to have a typedef]
~~ [expected arrow-call-signature to have a typedef]
}

setTimeout(() => {}, 1000);
Expand Down
4 changes: 2 additions & 2 deletions test/rules/typedef/arrow-parameter/test.ts.lint
@@ -1,5 +1,5 @@
var NoTypesFn = function (a, b) {}

var NoTypesArrowFn = (a, b) => {}
~ [expected arrow-parameter: 'a' to have a typedef]
~ [expected arrow-parameter: 'b' to have a typedef]
~ [expected arrow-parameter: 'a' to have a typedef]
~ [expected arrow-parameter: 'b' to have a typedef]
8 changes: 4 additions & 4 deletions test/rules/typedef/call-signature/test.ts.lint
@@ -1,9 +1,9 @@
function foge() {}
~ [expected call-signature: 'foge' to have a typedef]
~~~~ [expected call-signature: 'foge' to have a typedef]

class TsLint {
helloWorld() {
~ [expected call-signature: 'helloWorld' to have a typedef]
~~~~~~~~~~ [expected call-signature: 'helloWorld' to have a typedef]
return 'Hello World';
};

Expand All @@ -14,13 +14,13 @@ class TsLint {

var obj = {
foge: function() {},
~ [expected call-signature to have a typedef]
~~ [expected call-signature to have a typedef]
bar: () => {}
}

setTimeout(() => {}, 1000);
setTimeout(function() {}, 1000);
~ [expected call-signature to have a typedef]
~~ [expected call-signature to have a typedef]

someFunc(n => n+1);
someFunc(n => {});
Expand Down
Expand Up @@ -12,5 +12,5 @@ class TypesInFunctionWithReturnMemberArrowFn {

class NoTypesMemberArrowFn {
fn = (param) => {}
~ [expected member-variable-declaration: 'param' to have a typedef]
~~~~~ [expected member-variable-declaration: 'param' to have a typedef]
}
5 changes: 1 addition & 4 deletions test/rules/typedef/object-destructuring/test.ts.lint
@@ -1,7 +1,4 @@


const { paramA, paramB } = { paramA: "test", paramB: 15 };
~ [expected object-destructuring: '{ paramA, paramB }' to have a typedef]

~~~~~~~~~~~~~~~~~~ [expected object-destructuring: '{ paramA, paramB }' to have a typedef]

const { paramA, paramB }: { paramA: string, paramB: number } = { paramA: "test", paramB: 15 };
4 changes: 2 additions & 2 deletions test/rules/typedef/parameter/test.ts.lint
@@ -1,6 +1,6 @@
var NoTypesFn = function (a, b) {
~ [expected parameter: 'a' to have a typedef]
~ [expected parameter: 'b' to have a typedef]
~ [expected parameter: 'a' to have a typedef]
~ [expected parameter: 'b' to have a typedef]
}

var NoTypesArrowFn = (a, b) => {}
Expand Down
5 changes: 2 additions & 3 deletions test/rules/typedef/variable-declaration/test.ts.lint
@@ -1,6 +1,5 @@
var NoTypeObjectLiteralWithPropertyGetter = { }
~ [expected variable-declaration: 'NoTypeObjectLiteralWithPropertyGetter' to have a typedef]

var v = { }
~ [expected variable-declaration: 'v' to have a typedef]

const { paramA, paramB } = { paramA: "test", paramB: 15 };
const [ paramA, paramB ] = [15, 'test'];

0 comments on commit b6cc7e1

Please sign in to comment.