@@ -9,10 +9,10 @@ import {
9
9
TodoConfig ,
10
10
TodoData ,
11
11
todoStorageFileExists ,
12
- Range ,
13
12
validateConfig ,
14
13
WriteTodoOptions ,
15
14
writeTodos ,
15
+ getSourceForRange ,
16
16
} from '@lint-todo/utils' ;
17
17
import { relative , join } from 'path' ;
18
18
import hasFlag from 'has-flag' ;
@@ -23,8 +23,6 @@ import { getBaseDir } from './get-base-dir';
23
23
import type { ESLint , Linter } from 'eslint' ;
24
24
import type { TodoFormatterOptions } from './types' ;
25
25
26
- const LINES_PATTERN = / ( .* ?(?: \r \n ? | \n | $ ) ) / gm;
27
-
28
26
export async function formatter ( results : ESLint . LintResult [ ] ) : Promise < string > {
29
27
const baseDir = getBaseDir ( ) ;
30
28
const todoConfigResult = validateConfig ( baseDir ) ;
@@ -221,10 +219,7 @@ export function buildMaybeTodos(
221
219
ruleId : message . ruleId || '' ,
222
220
range,
223
221
source : lintResult . source
224
- ? getSourceForRange (
225
- lintResult . source . match ( LINES_PATTERN ) || [ ] ,
226
- range
227
- )
222
+ ? getSourceForRange ( lintResult . source , range )
228
223
: '' ,
229
224
originalLintResult : message ,
230
225
} ,
@@ -240,35 +235,6 @@ export function buildMaybeTodos(
240
235
return todoData ;
241
236
}
242
237
243
- function getSourceForRange ( source : string [ ] , range : Range ) {
244
- const firstLine = range . start . line - 1 ;
245
- const lastLine = range . end . line - 1 ;
246
- let currentLine = firstLine - 1 ;
247
- const firstColumn = range . start . column - 1 ;
248
- const lastColumn = range . end . column - 1 ;
249
- const src = [ ] ;
250
- let line ;
251
-
252
- while ( currentLine < lastLine ) {
253
- currentLine ++ ;
254
- line = source [ currentLine ] ;
255
-
256
- if ( currentLine === firstLine ) {
257
- if ( firstLine === lastLine ) {
258
- src . push ( line . slice ( firstColumn , lastColumn ) ) ;
259
- } else {
260
- src . push ( line . slice ( firstColumn ) ) ;
261
- }
262
- } else if ( currentLine === lastLine ) {
263
- src . push ( line . slice ( 0 , lastColumn ) ) ;
264
- } else {
265
- src . push ( line ) ;
266
- }
267
- }
268
-
269
- return src . join ( '' ) ;
270
- }
271
-
272
238
function pushResult ( results : ESLint . LintResult [ ] , todo : TodoData ) {
273
239
const resultForFile = findResult ( results , todo ) ;
274
240
0 commit comments