12
12
// Requirements
13
13
//------------------------------------------------------------------------------
14
14
15
- const path = require ( "path" ) ,
15
+ const
16
+ assert = require ( "assert" ) ,
17
+ path = require ( "path" ) ,
18
+ { Linter } = require ( "eslint" ) ,
16
19
shelljs = require ( "shelljs" ) ,
17
- testUtils = require ( "../../tools/test-utils" ) ;
20
+ testUtils = require ( "../../tools/test-utils" ) ,
21
+ parser = require ( "../../" ) ;
18
22
19
23
//------------------------------------------------------------------------------
20
24
// Setup
@@ -36,4 +40,56 @@ describe("basics", () => {
36
40
const code = shelljs . cat ( `${ path . resolve ( FIXTURES_DIR , filename ) } .src.js` ) ;
37
41
test ( `fixtures/${ filename } .src` , testUtils . createSnapshotTestBlock ( code ) ) ;
38
42
} ) ;
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
+ } ) ;
39
95
} ) ;
0 commit comments