Skip to content
This repository was archived by the owner on Jan 19, 2019. It is now read-only.

Commit 044563b

Browse files
committed
add test for #476
1 parent 14e2499 commit 044563b

File tree

1 file changed

+58
-2
lines changed

1 file changed

+58
-2
lines changed

tests/lib/basics.js

+58-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,13 @@
1212
// Requirements
1313
//------------------------------------------------------------------------------
1414

15-
const path = require("path"),
15+
const
16+
assert = require("assert"),
17+
path = require("path"),
18+
{ Linter } = require("eslint"),
1619
shelljs = require("shelljs"),
17-
testUtils = require("../../tools/test-utils");
20+
testUtils = require("../../tools/test-utils"),
21+
parser = require("../../");
1822

1923
//------------------------------------------------------------------------------
2024
// Setup
@@ -36,4 +40,56 @@ describe("basics", () => {
3640
const code = shelljs.cat(`${path.resolve(FIXTURES_DIR, filename)}.src.js`);
3741
test(`fixtures/${filename}.src`, testUtils.createSnapshotTestBlock(code));
3842
});
43+
44+
test("https://github.com/eslint/typescript-eslint-parser/issues/476", () => {
45+
const linter = new Linter();
46+
const code = `
47+
export const Price: React.SFC<PriceProps> = function Price(props) {}
48+
`;
49+
const config = {
50+
parser: "typescript-eslint-parser",
51+
rules: {
52+
test: "error"
53+
}
54+
};
55+
56+
linter.defineParser("typescript-eslint-parser", parser);
57+
linter.defineRule("test", context => ({
58+
TSTypeReference(node) {
59+
const name = context.getSourceCode().getText(node.typeName);
60+
context.report({
61+
node,
62+
message: "called on {{name}}",
63+
data: { name }
64+
});
65+
}
66+
}));
67+
68+
const messages = linter.verify(code, config, { filename: "issue.ts" });
69+
70+
assert.deepStrictEqual(messages, [
71+
{
72+
column: 21,
73+
endColumn: 42,
74+
endLine: 2,
75+
line: 2,
76+
message: "called on React.SFC",
77+
nodeType: "TSTypeReference",
78+
ruleId: "test",
79+
severity: 2,
80+
source: "export const Price: React.SFC<PriceProps> = function Price(props) {}"
81+
},
82+
{
83+
column: 31,
84+
endColumn: 41,
85+
endLine: 2,
86+
line: 2,
87+
message: "called on PriceProps",
88+
nodeType: "TSTypeReference",
89+
ruleId: "test",
90+
severity: 2,
91+
source: "export const Price: React.SFC<PriceProps> = function Price(props) {}"
92+
}
93+
]);
94+
});
3995
});

0 commit comments

Comments
 (0)