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

Commit

Permalink
Merge pull request #952 from pe8ter/master
Browse files Browse the repository at this point in the history
Identify multiline literals with single property correctly.
  • Loading branch information
jkillian committed Feb 1, 2016
2 parents e3476a7 + d97d126 commit 40c37dc
Show file tree
Hide file tree
Showing 5 changed files with 171 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/rules/trailingCommaRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class TrailingCommaWalker extends Lint.RuleWalker {
private lintNode(node: ts.Node) {
const child = node.getChildAt(1);
if (child != null && child.kind === ts.SyntaxKind.SyntaxList) {
const isMultiline = child.getText().match(/\n|\r/);
const isMultiline = node.getText().match(/\n|\r/);
const option = this.getOption(isMultiline ? "multiline" : "singleline");
const grandChildren = child.getChildren();

Expand Down
45 changes: 45 additions & 0 deletions test/rules/trailing-comma/multiline-always/test.ts.lint
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ var x = [{
}];
~ [missing trailing comma]

var s = {
sA: 6,
};

var t = {
tA: 7
~ [missing trailing comma]
}

var y = {
yA: 42,
yB: 24,
Expand All @@ -25,6 +34,15 @@ var z = {
~ [missing trailing comma]
};

var ss = [
6,
];

var tt = [
7
~ [missing trailing comma]
];

var yy = [
42,
24,
Expand All @@ -48,6 +66,15 @@ var cc = [42, 24,];

var dd = [2, 1];

var {
sA,
} = s;

var {
tA
~ [missing trailing comma]
} = t;

var {
yA,
yB,
Expand All @@ -59,6 +86,15 @@ var {
~ [missing trailing comma]
} = z;

var [
ssA,
] = ss;

var [
ttA
~ [missing trailing comma]
] = tt;

var [
yyA,
yyB,
Expand All @@ -78,6 +114,15 @@ var [ccA, ccB,] = cc;

var [ddOne, ddTwo] = dd;

import {
ClassS,
} from "module";

import {
ClassT
~ [missing trailing comma]
} from "module";

import {
ClassV,
ClassX,
Expand Down
45 changes: 45 additions & 0 deletions test/rules/trailing-comma/multiline-never/test.ts.lint
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ var x = [{
c: (a + b)
}];

var s = {
sA: 6,
~ [trailing comma]
};

var t = {
tA: 7
}

var y = {
yA: 42,
yB: 24,
Expand All @@ -25,6 +34,15 @@ var z = {
zTwo: 1
};

var ss = [
6,
~ [trailing comma]
];

var tt = [
7
];

var yy = [
42,
24,
Expand All @@ -48,6 +66,15 @@ var cc = [42, 24,];

var dd = [2, 1];

var {
sA,
~ [trailing comma]
} = s;

var {
tA
} = t;

var {
yA,
yB,
Expand All @@ -59,6 +86,15 @@ var {
zTwo
} = z;

var [
ssA,
~ [trailing comma]
] = ss;

var [
ttA
] = tt;

var [
yyA,
yyB,
Expand All @@ -78,6 +114,15 @@ var [ccA, ccB,] = cc;

var [ddOne, ddTwo] = dd;

import {
ClassS,
~ [trailing comma]
} from "module";

import {
ClassT
} from "module";

import {
ClassV,
ClassX,
Expand Down
40 changes: 40 additions & 0 deletions test/rules/trailing-comma/singleline-always/test.ts.lint
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ var x = [{
c: (a + b)
}];

var s = {
sA: 6,
};

var t = {
tA: 7
}

var y = {
yA: 42,
yB: 24,
Expand All @@ -22,6 +30,14 @@ var z = {
zTwo: 1
};

var ss = [
6,
];

var tt = [
7
];

var yy = [
42,
24,
Expand All @@ -48,6 +64,14 @@ var cc = [42, 24,];
var dd = [2, 1];
~ [missing trailing comma]

var {
sA,
} = s;

var {
tA
} = t;

var {
yA,
yB,
Expand All @@ -58,6 +82,14 @@ var {
zTwo
} = z;

var [
ssA,
] = ss;

var [
ttA
] = tt;

var [
yyA,
yyB,
Expand All @@ -78,6 +110,14 @@ var [ccA, ccB,] = cc;
var [ddOne, ddTwo] = dd;
~ [missing trailing comma]

import {
ClassS,
} from "module";

import {
ClassT
} from "module";

import {
ClassV,
ClassX,
Expand Down
40 changes: 40 additions & 0 deletions test/rules/trailing-comma/singleline-never/test.ts.lint
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ var x = [{
c: (a + b)
}];

var s = {
sA: 6,
};

var t = {
tA: 7
}

var y = {
yA: 42,
yB: 24,
Expand All @@ -22,6 +30,14 @@ var z = {
zTwo: 1
};

var ss = [
6,
];

var tt = [
7
];

var yy = [
42,
24,
Expand All @@ -48,6 +64,14 @@ var cc = [42, 24,];

var dd = [2, 1];

var {
sA,
} = s;

var {
tA
} = t;

var {
yA,
yB,
Expand All @@ -58,6 +82,14 @@ var {
zTwo
} = z;

var [
ssA,
] = ss;

var [
ttA
] = tt;

var [
yyA,
yyB,
Expand All @@ -78,6 +110,14 @@ var [ccA, ccB,] = cc;

var [ddOne, ddTwo] = dd;

import {
ClassS,
} from "module";

import {
ClassT
} from "module";

import {
ClassV,
ClassX,
Expand Down

0 comments on commit 40c37dc

Please sign in to comment.