@@ -12,47 +12,55 @@ interface LintResult {
1212 c : number
1313 old : string
1414 new : string
15- serverity : number
15+ serverity : Severity
1616 } >
1717 error : string
1818}
1919
20+ enum Severity {
21+ Pass = 0 ,
22+ Error = 1 ,
23+ Warning = 2 ,
24+ }
25+
26+ const wasmUrl = import . meta. resolve ( 'autocorrect-wasm/autocorrect_wasm_bg.wasm' ) ;
27+ const wasm = readFileSync ( fileURLToPath ( wasmUrl ) ) ;
28+ initSync ( wasm ) ;
29+
2030const rule : Rule = {
2131 meta : {
2232 type : 'layout' ,
2333 fixable : 'whitespace' ,
2434 schema : [ ] ,
2535 messages : {
26- issue : 'Issue detected' ,
36+ error : 'Autocorrect error detected' ,
37+ warning : 'Autocorrect warning detected' ,
38+ } ,
39+ docs : {
40+ recommended : true ,
2741 } ,
2842 } ,
2943 create ( ctx ) {
30- const wasmUrl = import . meta. resolve ( 'autocorrect-wasm/autocorrect_wasm_bg.wasm' ) ;
31- const wasm = readFileSync ( fileURLToPath ( wasmUrl ) ) ;
32- initSync ( wasm ) ;
33-
3444 const sourceCode = ctx . sourceCode as SourceCode ;
35- return {
36- Program ( ) {
37- const res : LintResult = lintFor ( sourceCode . getText ( ) , ctx . filename ?? '' ) ;
38- for ( const line of res . lines ) {
39- const start = { line : line . l , column : line . c - 1 } ;
40- const end = { line : line . l , column : line . c - 1 + line . old . length } ;
41-
42- ctx . report ( {
43- messageId : 'issue' ,
44- loc : {
45- start : { line : line . l , column : 0 } ,
46- end : { line : line . l , column : line . old . length } ,
47- } ,
48- fix : f => f . replaceTextRange (
49- [ sourceCode . getIndexFromLoc ( start ) , sourceCode . getIndexFromLoc ( end ) ] ,
50- line . new ,
51- ) ,
52- } ) ;
53- }
54- } ,
45+ const res : LintResult = lintFor ( sourceCode . getText ( ) , ctx . filename ?? '' ) ;
46+
47+ for ( const line of res . lines ) {
48+ const start = { line : line . l , column : line . c - 1 } ;
49+ const end = { line : line . l , column : line . c - 1 + line . old . length } ;
50+ ctx . report ( {
51+ messageId : line . serverity === Severity . Error ? 'error' : 'warning' ,
52+ loc : {
53+ start : { line : line . l , column : 0 } ,
54+ end : { line : line . l , column : line . old . length } ,
55+ } ,
56+ fix : f => f . replaceTextRange (
57+ [ sourceCode . getIndexFromLoc ( start ) , sourceCode . getIndexFromLoc ( end ) ] ,
58+ line . new ,
59+ ) ,
60+ } ) ;
5561 } ;
62+
63+ return { } ;
5664 } ,
5765} ;
5866
0 commit comments