1
1
import test from 'ava' ;
2
2
import stripAnsi from 'strip-ansi' ;
3
+ import ansiEscapes from 'ansi-escapes' ;
4
+ import chalk from 'chalk' ;
3
5
import m from '..' ;
4
6
import defaultFixture from './fixtures/default' ;
5
7
import noLineNumbers from './fixtures/no-line-numbers' ;
6
8
import lineNumbers from './fixtures/line-numbers' ;
7
9
import sortOrder from './fixtures/sort-by-severity-then-line-then-column' ;
8
10
11
+ const enableHyperlinks = ( ) => {
12
+ process . env . FORCE_HYPERLINK = '1' ;
13
+ } ;
14
+
15
+ const disableHyperlinks = ( ) => {
16
+ process . env . FORCE_HYPERLINK = '0' ;
17
+ } ;
18
+
9
19
test ( 'output' , t => {
20
+ disableHyperlinks ( ) ;
10
21
const output = m ( defaultFixture ) ;
11
22
console . log ( output ) ;
12
23
t . regex ( stripAnsi ( output ) , / i n d e x \. j s : 8 : 2 \n / ) ;
13
24
t . regex ( stripAnsi ( output ) , / ✖ [ ] { 3 } 1 : 1 [ ] { 2 } A V A s h o u l d b e i m p o r t e d a s t e s t .[ ] { 6 } a v a \/ u s e - t e s t / ) ;
14
25
} ) ;
15
26
16
27
test ( 'no line numbers' , t => {
28
+ disableHyperlinks ( ) ;
17
29
const output = m ( noLineNumbers ) ;
18
30
console . log ( output ) ;
19
31
t . regex ( stripAnsi ( output ) , / i n d e x \. j s \n / ) ;
20
32
t . regex ( stripAnsi ( output ) , / ✖ [ ] { 2 } A V A s h o u l d b e i m p o r t e d a s t e s t .[ ] { 6 } a v a \/ u s e - t e s t / ) ;
21
33
} ) ;
22
34
23
35
test ( 'show line numbers' , t => {
36
+ disableHyperlinks ( ) ;
24
37
const output = m ( lineNumbers ) ;
25
38
console . log ( output ) ;
26
39
t . regex ( stripAnsi ( output ) , / ⚠ [ ] { 3 } 0 : 0 [ ] { 2 } U n e x p e c t e d t o d o c o m m e n t .[ ] { 13 } n o - w a r n i n g - c o m m e n t s / ) ;
27
40
t . regex ( stripAnsi ( output ) , / ✖ [ ] { 3 } 1 : 1 [ ] { 2 } A V A s h o u l d b e i m p o r t e d a s t e s t .[ ] { 6 } a v a \/ u s e - t e s t / ) ;
28
41
} ) ;
29
42
43
+ test ( 'link rules to documentation when terminal supports links' , t => {
44
+ enableHyperlinks ( ) ;
45
+ const output = m ( defaultFixture ) ;
46
+ console . log ( output ) ;
47
+ t . true ( output . includes ( ansiEscapes . link ( chalk . dim ( 'no-warning-comments' ) , 'https://eslint.org/docs/rules/no-warning-comments' ) ) ) ;
48
+ } ) ;
49
+
30
50
test ( 'sort by severity, then line number, then column number' , t => {
51
+ disableHyperlinks ( ) ;
31
52
const output = m ( sortOrder ) ;
32
53
const sanitized = stripAnsi ( output ) ;
33
54
const indexes = [
@@ -43,6 +64,7 @@ test('sort by severity, then line number, then column number', t => {
43
64
} ) ;
44
65
45
66
test ( 'display warning total before error total' , t => {
67
+ disableHyperlinks ( ) ;
46
68
const output = m ( sortOrder ) ;
47
69
const sanitized = stripAnsi ( output ) ;
48
70
const indexes = [
0 commit comments