UNPKG

@lint-todo/utils

Version:

![CI Build](https://github.com/lint-todo/utils/workflows/CI%20Build/badge.svg) [![npm version](https://badge.fury.io/js/%40lint-todo%2Futils.svg)](https://badge.fury.io/js/%40lint-todo%2Futils) [![License](https://img.shields.io/npm/l/@checkup/cli.svg)](h

142 lines 7.69 kB
import { FilePath, TodoData, TodoBatchCounts, TodoBatches, WriteTodoOptions, Operation, OperationOrConflictLine, ReadTodoOptions } from './types'; import TodoMatcher from './todo-matcher'; /** * Determines if the .lint-todo storage file exists. * * @param baseDir - The base directory that contains the .lint-todo storage file. * @returns - true if the todo storage file exists, otherwise false. */ export declare function todoStorageFileExists(baseDir: string): boolean; /** * Creates, or ensures the creation of, the .lint-todo file. * * @param baseDir - The base directory that contains the .lint-todo storage file. * @returns - The todo storage file path. */ export declare function ensureTodoStorageFile(baseDir: string): string; /** * @param baseDir - The base directory that contains the .lint-todo storage file. * @returns - The todo storage file path. */ export declare function getTodoStorageFilePath(baseDir: string): string; /** * Determines if the .lint-todo storage file has conflicts. * * @param todoContents - The unparsed contents of the .lint-todo file. * @returns true if the file has conflicts, otherwise false. */ export declare function hasConflicts(todoContents: string): boolean; /** * Resolves git conflicts in todo operations by removing any lines that match conflict markers. * * @param operations - An array of string operations that are used to recreate todos. * @returns An array of string operations excluding any operations that were identified as git conflict lines. */ export declare function resolveConflicts(operations: OperationOrConflictLine[]): Operation[]; /** * Reads the .lint-todo storage file. * * @param todoStorageFilePath - The .lint-todo storage file path. * @returns A array of todo operations. */ export declare function readTodoStorageFile(todoStorageFilePath: string): Operation[]; /** * Writes the operations to the .lint-todo storage file to the path provided by todoStorageFilePath. * * @param todoStorageFilePath - The .lint-todo storage file path. * @param operations - An array of string operations that are used to recreate todos. */ export declare function writeTodoStorageFile(todoStorageFilePath: string, operations: Operation[]): void; /** * Appends the operations to the .lint-todo storage file to the path provided by the todoStorageFilePath * * @param todoStorageFilePath - The .lint-todo storage file path. * @param operations - An array of string operations that are used to recreate todos. */ export declare function appendTodoStorageFile(todoStorageFilePath: string, operations: Operation[]): void; /** * Writes files for todo lint violations. One file is generated for each violation, using a generated * hash to identify each. * * Given a list of todo lint violations, this function will also delete existing files that no longer * have a todo lint violation. * * @param baseDir - The base directory that contains the .lint-todo storage file. * @param maybeTodos - The linting data, converted to TodoData format. * @param options - An object containing write options. * @returns - The counts of added and removed todos. */ export declare function writeTodos(baseDir: string, maybeTodos: Set<TodoData>, options: WriteTodoOptions): TodoBatchCounts; /** * Reads all todo files in the .lint-todo file. * * @param baseDir - The base directory that contains the .lint-todo storage file. * @param options - An object containing read options. * @param shouldLock - True if the .lint-todo storage file should be locked, otherwise false. Default: true. * @returns - A {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map|Map} of {@link https://github.com/lint-todo/utils/blob/master/src/types/todo.ts#L25|FilePath}/{@link https://github.com/lint-todo/utils/blob/master/src/todo-matcher.ts#L4|TodoMatcher}. */ export declare function readTodos(baseDir: string, options: ReadTodoOptions, shouldLock?: boolean): Map<FilePath, TodoMatcher>; /** * Reads todo files in the .lint-todo file for a specific filePath. * * @param baseDir - The base directory that contains the .lint-todo storage file. * @param options - An object containing read options. * @param shouldLock - True if the .lint-todo storage file should be locked, otherwise false. Default: true. * @returns - A {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map|Map} of {@link https://github.com/lint-todo/utils/blob/master/src/types/todo.ts#L25|FilePath}/{@link https://github.com/lint-todo/utils/blob/master/src/todo-matcher.ts#L4|TodoMatcher}. */ export declare function readTodosForFilePath(baseDir: string, options: ReadTodoOptions, shouldLock?: boolean): Map<FilePath, TodoMatcher>; /** * Reads todos in the .lint-todo file and returns Todo data in an array. * * @param baseDir - The base directory that contains the .lint-todo storage file. * @param options - An object containing read options. * @returns An array of {@link https://github.com/lint-todo/utils/blob/master/src/types/todo.ts#L61|TodoData} */ export declare function readTodoData(baseDir: string, options: ReadTodoOptions): Set<TodoData>; /** * Reads todos for a single filePath in the .lint-todo file and returns Todo data in an array. * * @param baseDir - The base directory that contains the .lint-todo storage file. * @param options - An object containing read options. * @returns An array of {@link https://github.com/lint-todo/utils/blob/master/src/types/todo.ts#L61|TodoData} */ export declare function readTodoDataForFilePath(baseDir: string, options: ReadTodoOptions): Set<TodoData>; /** * Gets 4 data structures containing todo items to add, remove, those that are expired, and those that are stable (not to be modified). * * @param baseDir - The base directory that contains the .lint-todo storage file. * @param maybeTodos - The linting data for violations. * @param options - An object containing write options. * @returns - An object of {@link https://github.com/lint-todo/utils/blob/master/src/types/todo.ts#L36|TodoBatches}. */ export declare function generateTodoBatches(baseDir: string, maybeTodos: Set<TodoData>, options: Partial<WriteTodoOptions>): TodoBatches; /** * Gets 4 data structures containing todo items to add, remove, those that are expired, and those that are stable (not to be modified). * * @param maybeTodos - The linting data for violations. * @param existing - Existing todo lint data. * @param options - An object containing write options. * @returns - An object of {@link https://github.com/lint-todo/utils/blob/master/src/types/todo.ts#L36|TodoBatches}. */ export declare function getTodoBatches(maybeTodos: Set<TodoData>, existing: Map<FilePath, TodoMatcher>, options: Partial<WriteTodoOptions>): TodoBatches; /** * Applies todo changes, either adding or removing, based on batches from `getTodoBatches`. * * @param baseDir - The base directory that contains the .lint-todo storage file. * @param add - Batch of todos to add. * @param remove - Batch of todos to remove. * @param shouldLock - True if the .lint-todo storage file should be locked, otherwise false. Default: true. */ export declare function applyTodoChanges(baseDir: string, add: Set<TodoData>, remove: Set<TodoData>, shouldLock?: boolean): void; /** * Compacts the .lint-todo storage file. * * @param baseDir - The base directory that contains the .lint-todo storage file. * @returns The count of compacted todos. */ export declare function compactTodoStorageFile(baseDir: string): { originalOperations: Operation[]; compactedOperations: Operation[]; compacted: number; }; //# sourceMappingURL=io.d.ts.map