/
line-comment-position.js
147 lines (140 loc) · 4.41 KB
/
line-comment-position.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/**
* @fileoverview enforce position of line comments
* @author Alberto Rodríguez
*/
"use strict";
//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
const rule = require("../../../lib/rules/line-comment-position"),
RuleTester = require("../../../lib/testers/rule-tester");
//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------
const ruleTester = new RuleTester();
ruleTester.run("line-comment-position", rule, {
valid: [
"// valid comment\n1 + 1;",
"/* block comments are skipped */\n1 + 1;",
"1 + 1; /* block comments are skipped */",
"1 + 1; /* eslint eqeqeq: 'error' */",
"1 + 1; /* eslint-disable */",
"1 + 1; /* eslint-enable */",
"1 + 1; // eslint-disable-line",
"// eslint-disable-next-line\n1 + 1;",
"1 + 1; // global MY_GLOBAL, ANOTHER",
"1 + 1; // globals MY_GLOBAL: true",
"1 + 1; // exported MY_GLOBAL, ANOTHER",
"1 + 1; // fallthrough",
"1 + 1; // fall through",
"1 + 1; // falls through",
"1 + 1; // jslint vars: true",
"1 + 1; // jshint ignore:line",
"1 + 1; // istanbul ignore next",
{
code: "1 + 1; // linter excepted comment",
options: [{position: "above", ignorePattern: "linter" } ]
},
{
code: "1 + 1; // valid comment",
options: ["beside"]
},
{
code: "// jscs: disable\n1 + 1;",
options: ["beside"]
},
{
code: "// jscs: enable\n1 + 1;",
options: ["beside"]
},
{
code: "/* block comments are skipped */\n1 + 1;",
options: ["beside"]
},
{
code: "/*block comment*/\n/*block comment*/\n1 + 1;",
options: ["beside"]
},
{
code: "1 + 1; /* block comment are skipped */",
options: ["beside"]
},
{
code: "1 + 1; // jshint strict: true",
options: ["beside"]
},
{
code: "// pragma valid comment\n1 + 1;",
options: [{position: "beside", ignorePattern: "pragma|linter" } ]
}
],
invalid: [
{
code: "1 + 1; // invalid comment",
errors: [{
message: "Expected comment to be above code.",
type: "Line",
line: 1,
column: 8
}]
},
{
code: "1 + 1; // globalization is a word",
errors: [{
message: "Expected comment to be above code.",
type: "Line",
line: 1,
column: 8
}]
},
{
code: "// jscs: disable\n1 + 1;",
options: [{ position: "beside", applyDefaultPatterns: false }],
errors: [{
message: "Expected comment to be beside code.",
type: "Line",
line: 1,
column: 1
}]
},
{
code: "1 + 1; // mentioning falls through",
errors: [{
message: "Expected comment to be above code.",
type: "Line",
line: 1,
column: 8
}]
},
{
code: "// invalid comment\n1 + 1;",
options: ["beside"],
errors: [{
message: "Expected comment to be beside code.",
type: "Line",
line: 1,
column: 1
}]
},
{
code: "// pragma\n// invalid\n1 + 1;",
options: [{ position: "beside", ignorePattern: "pragma" }],
errors: [{
message: "Expected comment to be beside code.",
type: "Line",
line: 2,
column: 1
}]
},
{
code: "1 + 1; // linter\n2 + 2; // invalid comment",
options: [{position: "above", ignorePattern: "linter" } ],
errors: [{
message: "Expected comment to be above code.",
type: "Line",
line: 2,
column: 8
}]
}
]
});