@@ -19,7 +19,30 @@ const RuleTester = require("./fixtures/eslint/lib/testers/rule-tester")
19
19
20
20
const RULES_ROOT = path . join ( __dirname , "fixtures/eslint/tests/lib/rules" )
21
21
const PARSER_PATH = path . resolve ( __dirname , "../index.js" )
22
+ const EXCEPTIONS = new Set ( [
23
+ // Those rules check outside `<script>` tag as well.
24
+ // It cannot fix the behavior in vue-eslint-parser side.
25
+ "eol-last" ,
26
+ "max-len" ,
27
+ "max-lines" ,
28
+
29
+ // Wrapper includes line-breaks, so it changed the number of errors.
30
+ // It cannot test this rule correctly.
31
+ "linebreak-style" ,
32
+
33
+ // Tests about the head/last of source code failed because "<script>" tokens
34
+ // are added.
35
+ // It cannot test this rule correctly.
36
+ "lines-around-comment" ,
37
+ "lines-around-directive" ,
38
+ "newline-after-var" ,
39
+ "no-multiple-empty-lines" ,
40
+
41
+ // The inside of "<script>" tags is not related to Unicode BOM.
42
+ "unicode-bom" ,
43
+ ] )
22
44
const originalRun = RuleTester . prototype . run
45
+ const processed = new Set ( )
23
46
24
47
/**
25
48
* Wrap the given code with a `<script>` tag.
@@ -28,7 +51,11 @@ const originalRun = RuleTester.prototype.run
28
51
* @returns {string } The wrapped code.
29
52
*/
30
53
function wrapCode ( code ) {
31
- const eol = code . indexOf ( "\r\n" ) !== - 1 ? "\r\n" : "\n"
54
+ const eol = "\n"
55
+
56
+ if ( code . charCodeAt ( 0 ) === 0xFEFF ) {
57
+ return `\uFEFF<script>${ eol } ${ code . slice ( 1 ) } ${ eol } </script>`
58
+ }
32
59
return `<script>${ eol } ${ code } ${ eol } </script>`
33
60
}
34
61
@@ -40,13 +67,19 @@ function wrapCode(code) {
40
67
*/
41
68
function modifyPattern ( pattern ) {
42
69
if ( typeof pattern === "string" ) {
70
+ if ( pattern . startsWith ( "#!" ) ) {
71
+ return null
72
+ }
43
73
return {
44
74
code : wrapCode ( pattern ) ,
45
75
filename : "test.vue" ,
46
76
parser : PARSER_PATH ,
47
77
}
48
78
}
49
- if ( pattern . parser != null || pattern . filename != null ) {
79
+ if ( pattern . parser != null ||
80
+ pattern . filename != null ||
81
+ pattern . code . startsWith ( "#!" )
82
+ ) {
50
83
return null
51
84
}
52
85
@@ -58,12 +91,14 @@ function modifyPattern(pattern) {
58
91
}
59
92
if ( Array . isArray ( pattern . errors ) ) {
60
93
for ( const error of pattern . errors ) {
61
- if ( typeof error === "object" ) {
94
+ if ( typeof error === "object" && ! processed . has ( error ) ) {
95
+ processed . add ( error )
96
+
62
97
if ( error . line != null ) {
63
- error . line += 1
98
+ error . line = Number ( error . line ) + 1
64
99
}
65
100
if ( error . endLine != null ) {
66
- error . endLine += 1
101
+ error . endLine = Number ( error . endLine ) + 1
67
102
}
68
103
}
69
104
}
@@ -97,10 +132,17 @@ RuleTester.prototype.run = overrideRun
97
132
try {
98
133
describe ( "Tests of ESLint core rules" , ( ) => {
99
134
for ( const fileName of fs . readdirSync ( RULES_ROOT ) ) {
135
+ if ( path . extname ( fileName ) !== ".js" ||
136
+ EXCEPTIONS . has ( path . basename ( fileName , ".js" ) )
137
+ ) {
138
+ continue
139
+ }
140
+
100
141
require ( path . join ( RULES_ROOT , fileName ) )
101
142
}
102
143
} )
103
144
}
104
145
finally {
105
146
RuleTester . prototype . run = originalRun
147
+ processed . clear ( )
106
148
}
0 commit comments