1
1
import type { Linter } from "eslint" ;
2
- import type { Range } from "./git" ;
3
- import { getDiffFileList , getDiffForFile , getRangesForDiff } from "./git" ;
2
+ import { getDiffFileList , getDiffForFile , getIgnorePatterns , getRangesForDiff , Range } from "./git" ;
3
+
4
4
5
5
const STAGED = true ;
6
6
7
7
const isLineWithinRange = ( line : number ) => ( range : Range ) =>
8
8
range . isWithinRange ( line ) ;
9
9
10
- const diff = {
11
- preprocess : (
12
- text : string ,
13
- filename : string
14
- ) : { text : string ; filename : string } [ ] =>
15
- getDiffFileList ( ) . includes ( filename ) ? [ { text, filename } ] : [ ] ,
16
10
11
+
12
+ const diff = {
17
13
postprocess : (
18
14
messages : Linter . LintMessage [ ] [ ] ,
19
15
filename : string
20
- ) : Linter . LintMessage [ ] =>
21
- messages
22
- . map ( ( message ) =>
23
- message . filter ( ( { line } ) =>
24
- getRangesForDiff ( getDiffForFile ( filename ) ) . some (
25
- isLineWithinRange ( line )
26
- )
27
- )
28
- )
29
- . reduce ( ( a , b ) => a . concat ( b ) , [ ] ) ,
16
+ ) : Linter . LintMessage [ ] => {
17
+ if ( ! getDiffFileList ( ) . includes ( filename ) ) {
18
+ console . log (
19
+ "🧠 skipping " +
20
+ JSON . stringify ( filename ) +
21
+ " because it's not in the diff list"
22
+ ) ;
23
+ return [ ] ;
24
+ }
25
+ const result = messages
26
+ . map ( ( message ) => {
27
+ console . log ( "diff/diff" , message , JSON . stringify ( filename ) ) ;
28
+ return message . filter ( ( { fatal, line } ) => {
29
+ if ( fatal ) {
30
+ console . log ( "❌ fatal error in " + JSON . stringify ( filename ) ) ;
31
+ return fatal ;
32
+ }
33
+
34
+ if (
35
+ ! getRangesForDiff ( getDiffForFile ( filename ) ) . some (
36
+ isLineWithinRange ( line )
37
+ )
38
+ ) {
39
+ console . log (
40
+ "🔵 skipping " +
41
+ JSON . stringify ( filename ) +
42
+ " because it's not in the diff list"
43
+ ) ;
44
+ }
45
+
46
+ return (
47
+ fatal ||
48
+ getRangesForDiff ( getDiffForFile ( filename ) ) . some (
49
+ isLineWithinRange ( line )
50
+ )
51
+ ) ;
52
+ } ) ;
53
+ } )
54
+ . reduce ( ( a , b ) => a . concat ( b ) , [ ] ) ;
55
+ console . log ( "diff kjrngkjsngksnj" , { result, filename, messages } ) ;
56
+ return result ;
57
+ } ,
30
58
31
59
supportsAutofix : true ,
32
60
} ;
@@ -39,14 +67,19 @@ const diffConfig = {
39
67
processor : "diff/diff" ,
40
68
} ,
41
69
] ,
70
+ ignorePatterns : getIgnorePatterns ( )
42
71
} ;
43
72
44
73
const staged = {
45
74
preprocess : (
46
75
text : string ,
47
76
filename : string
48
- ) : { text : string ; filename : string } [ ] =>
49
- getDiffFileList ( STAGED ) . includes ( filename ) ? [ { text, filename } ] : [ ] ,
77
+ ) : ( { text : string ; filename : string } & Record < any , any > ) [ ] => {
78
+ console . log ( { text : text , filename : filename , lol : "zooooooooooomg" } ) ;
79
+ return getDiffFileList ( STAGED ) . includes ( filename )
80
+ ? [ { text, filename } ]
81
+ : [ ] ;
82
+ } ,
50
83
51
84
postprocess : (
52
85
messages : Linter . LintMessage [ ] [ ] ,
0 commit comments