{"record":{"id":"b10dfa90b62efe71","repo":"vitest-dev/vitest","slug":"vitest-range-location-filter-provided","errorCode":"VITEST_RANGE_LOCATION_FILTER_PROVIDED","errorMessage":"Found \"-\" in location filter ${filter}.  Note that range location filters are not supported.  Consider specifying the exact line numbers of your tests.","messagePattern":"Found \"-\" in location filter (.+?)\\.  Note that range location filters are not supported\\.  Consider specifying the exact line numbers of your tests\\.","errorType":"exception","errorClass":"RangeLocationFilterProvidedError","httpStatus":null,"severity":"error","filePath":"packages/vitest/src/node/cli/filter.ts","lineNumber":22,"sourceCode":"export function parseFilter(filter: string): FileFilter {\n  const colonIndex = filter.lastIndexOf(':')\n  if (colonIndex === -1) {\n    return { filename: filter }\n  }\n\n  const [parsedFilename, lineNumber] = [\n    filter.substring(0, colonIndex),\n    filter.substring(colonIndex + 1),\n  ]\n\n  if (/^\\d+$/.test(lineNumber)) {\n    return {\n      filename: parsedFilename,\n      lineNumber: Number.parseInt(lineNumber),\n    }\n  }\n  else if (/^\\d+-\\d+$/.test(lineNumber)) {\n    throw new RangeLocationFilterProvidedError(filter)\n  }\n  else {\n    return { filename: filter }\n  }\n}\n\nexport interface FileFilter {\n  filename: string\n  lineNumber?: undefined | number\n}\n\nexport function groupFilters(filters: FileFilter[]): Record<string, number[]> {\n  const groupedFilters_ = groupBy(filters, f => f.filename)\n  const groupedFilters = Object.fromEntries(Object.entries(groupedFilters_)\n    .map((entry) => {\n      const [filename, filters] = entry\n      const testLocations = filters.map(f => f.lineNumber)\n","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/vitest-dev/vitest/blob/1fa9837ec26533512fdcad8baebf249771bd340a/packages/vitest/src/node/cli/filter.ts#L4-L40","documentation":"`parseFilter` accepts a `filename:line` form but rejects `filename:start-end` ranges — range location filters are not supported. When the segment after the last colon matches `^\\d+-\\d+$`, it throws a `RangeLocationFilterProvidedError` (code `VITEST_RANGE_LOCATION_FILTER_PROVIDED`). The user is asked to specify exact line numbers instead.","triggerScenarios":"Passing `vitest src/foo.test.ts:10-20`, `vitest foo.test.ts:5-5`, or any location filter whose numeric part contains a hyphen. The same path through `parseFilter` is used by CLI argv and editor integrations.","commonSituations":"Copy-pasting a range from an IDE selection; assuming Vitest mirrors Jest's `:line` filter but extends it to ranges; a VS Code extension passing the selected line range.","solutions":["Pass a single exact line: `vitest src/foo.test.ts:10` (the test that starts on line 10).","Run the file without a line filter to execute the whole suite: `vitest src/foo.test.ts`.","If you need to run several tests, pass multiple `:line` filters as separate argv entries."],"exampleFix":"# before\nvitest src/foo.test.ts:10-20\n\n# after\nvitest src/foo.test.ts:10","handlingStrategy":"validation","validationCode":"function normalizeLocationFilter(filter: string): string {\n  // strip a `start-end` range down to its start line\n  return filter.replace(/:(\\d+)-\\d+$/, ':$1')\n}\n\nconst safe = normalizeLocationFilter(userFilter)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pass a single `:line` to target a specific test by its declaration line.","If an editor hands you a range, take the first number before the dash.","Drop the line filter to run the whole file when unsure."],"tags":["cli","filter","location","range","test-selection"],"backgroundTag":null,"analyzedSha":"1fa9837ec26533512fdcad8baebf249771bd340a","analyzedAt":"2026-08-11T16:11:39.638Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}