Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ember-template-lint/todo-utils

Package Overview
Dependencies
Maintainers
4
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ember-template-lint/todo-utils - npm Package Compare versions

Comparing version 10.0.0 to 11.0.0-alpha.0

125

CHANGELOG.md

@@ -1,149 +0,94 @@

## v10.0.0 (2021-08-15)
## v11.0.0-alpha.0 (2021-11-29)
#### :boom: Breaking Change
* [#279](https://github.com/ember-template-lint/ember-template-lint-todo-utils/pull/279) Change return value of writeTodos to object ([@scalvert](https://github.com/scalvert))
* [#276](https://github.com/ember-template-lint/ember-template-lint-todo-utils/pull/276) Change public API to take V2 format data over lint results ([@scalvert](https://github.com/scalvert))
* [#264](https://github.com/ember-template-lint/ember-template-lint-todo-utils/pull/264) Adding test cases for fuzzy matching ([@scalvert](https://github.com/scalvert))
* [#252](https://github.com/ember-template-lint/ember-template-lint-todo-utils/pull/252) Adding expanded todo batching functionality to account for fuzzy matching ([@scalvert](https://github.com/scalvert))
* [#250](https://github.com/ember-template-lint/ember-template-lint-todo-utils/pull/250) Renaming FilePath type to improve code readability ([@scalvert](https://github.com/scalvert))
#### :rocket: Enhancement
* [#277](https://github.com/ember-template-lint/ember-template-lint-todo-utils/pull/277) Adds match agnostic lint result identity referencing ([@scalvert](https://github.com/scalvert))
* [#270](https://github.com/ember-template-lint/ember-template-lint-todo-utils/pull/270) Adds new readTodoData API for convenience reading of TodoDataV2 ([@scalvert](https://github.com/scalvert))
* [#264](https://github.com/ember-template-lint/ember-template-lint-todo-utils/pull/264) Adding test cases for fuzzy matching ([@scalvert](https://github.com/scalvert))
* [#257](https://github.com/ember-template-lint/ember-template-lint-todo-utils/pull/257) Expands todo data into v2 format ([@scalvert](https://github.com/scalvert))
* [#252](https://github.com/ember-template-lint/ember-template-lint-todo-utils/pull/252) Adding expanded todo batching functionality to account for fuzzy matching ([@scalvert](https://github.com/scalvert))
## v10.0.0 (2021-08-15)
#### :bug: Bug Fix
* [#269](https://github.com/ember-template-lint/ember-template-lint-todo-utils/pull/269) Converts the remove Set back to a Map, which is required for consumers ([@scalvert](https://github.com/scalvert))
* [#268](https://github.com/ember-template-lint/ember-template-lint-todo-utils/pull/268) Adds missing export to public API ([@scalvert](https://github.com/scalvert))
#### :house: Internal
* [#250](https://github.com/ember-template-lint/ember-template-lint-todo-utils/pull/250) Renaming FilePath type to improve code readability ([@scalvert](https://github.com/scalvert))
#### Committers: 1
- Steve Calvert ([@scalvert](https://github.com/scalvert))
## v10.0.0-beta.5 (2021-08-12)
#### :boom: Breaking Change
* [#279](https://github.com/ember-template-lint/ember-template-lint-todo-utils/pull/279) Change return value of writeTodos to object ([@scalvert](https://github.com/scalvert))
#### Committers: 1
- Steve Calvert ([@scalvert](https://github.com/scalvert))
- [#279](https://github.com/ember-template-lint/ember-template-lint-todo-utils/pull/279) Change return value of writeTodos to object ([@scalvert](https://github.com/scalvert))
- [#276](https://github.com/ember-template-lint/ember-template-lint-todo-utils/pull/276) Change public API to take V2 format data over lint results ([@scalvert](https://github.com/scalvert))
- [#264](https://github.com/ember-template-lint/ember-template-lint-todo-utils/pull/264) Adding test cases for fuzzy matching ([@scalvert](https://github.com/scalvert))
- [#252](https://github.com/ember-template-lint/ember-template-lint-todo-utils/pull/252) Adding expanded todo batching functionality to account for fuzzy matching ([@scalvert](https://github.com/scalvert))
- [#250](https://github.com/ember-template-lint/ember-template-lint-todo-utils/pull/250) Renaming FilePath type to improve code readability ([@scalvert](https://github.com/scalvert))
## v10.0.0-beta.4 (2021-08-11)
#### :boom: Breaking Change
* [#276](https://github.com/ember-template-lint/ember-template-lint-todo-utils/pull/276) Change public API to take V2 format data over lint results ([@scalvert](https://github.com/scalvert))
#### :rocket: Enhancement
* [#277](https://github.com/ember-template-lint/ember-template-lint-todo-utils/pull/277) Adds match agnostic lint result identity referencing ([@scalvert](https://github.com/scalvert))
#### Committers: 1
- Steve Calvert ([@scalvert](https://github.com/scalvert))
- [#277](https://github.com/ember-template-lint/ember-template-lint-todo-utils/pull/277) Adds match agnostic lint result identity referencing ([@scalvert](https://github.com/scalvert))
- [#270](https://github.com/ember-template-lint/ember-template-lint-todo-utils/pull/270) Adds new readTodoData API for convenience reading of TodoData ([@scalvert](https://github.com/scalvert))
- [#264](https://github.com/ember-template-lint/ember-template-lint-todo-utils/pull/264) Adding test cases for fuzzy matching ([@scalvert](https://github.com/scalvert))
- [#257](https://github.com/ember-template-lint/ember-template-lint-todo-utils/pull/257) Expands todo data into v2 format ([@scalvert](https://github.com/scalvert))
- [#252](https://github.com/ember-template-lint/ember-template-lint-todo-utils/pull/252) Adding expanded todo batching functionality to account for fuzzy matching ([@scalvert](https://github.com/scalvert))
## v10.0.0-beta.3 (2021-07-26)
#### :rocket: Enhancement
* [#270](https://github.com/ember-template-lint/ember-template-lint-todo-utils/pull/270) Adds new readTodoData API for convenience reading of TodoDataV2 ([@scalvert](https://github.com/scalvert))
#### Committers: 1
- Steve Calvert ([@scalvert](https://github.com/scalvert))
## v10.0.0-beta.2 (2021-07-23)
#### :bug: Bug Fix
* [#269](https://github.com/ember-template-lint/ember-template-lint-todo-utils/pull/269) Converts the remove Set back to a Map, which is required for consumers ([@scalvert](https://github.com/scalvert))
#### Committers: 1
- Steve Calvert ([@scalvert](https://github.com/scalvert))
- [#269](https://github.com/ember-template-lint/ember-template-lint-todo-utils/pull/269) Converts the remove Set back to a Map, which is required for consumers ([@scalvert](https://github.com/scalvert))
- [#268](https://github.com/ember-template-lint/ember-template-lint-todo-utils/pull/268) Adds missing export to public API ([@scalvert](https://github.com/scalvert))
#### :house: Internal
## v10.0.0-beta.1 (2021-07-21)
- [#250](https://github.com/ember-template-lint/ember-template-lint-todo-utils/pull/250) Renaming FilePath type to improve code readability ([@scalvert](https://github.com/scalvert))
#### :bug: Bug Fix
* [#268](https://github.com/ember-template-lint/ember-template-lint-todo-utils/pull/268) Adds missing export to public API ([@scalvert](https://github.com/scalvert))
#### Committers: 1
- Steve Calvert ([@scalvert](https://github.com/scalvert))
## v10.0.0-beta.0 (2021-07-20)
#### :boom: Breaking Change
* [#264](https://github.com/ember-template-lint/ember-template-lint-todo-utils/pull/264) Adding test cases for fuzzy matching ([@scalvert](https://github.com/scalvert))
* [#252](https://github.com/ember-template-lint/ember-template-lint-todo-utils/pull/252) Adding expanded todo batching functionality to account for fuzzy matching ([@scalvert](https://github.com/scalvert))
* [#250](https://github.com/ember-template-lint/ember-template-lint-todo-utils/pull/250) Renaming FilePath type to improve code readability ([@scalvert](https://github.com/scalvert))
#### :rocket: Enhancement
* [#264](https://github.com/ember-template-lint/ember-template-lint-todo-utils/pull/264) Adding test cases for fuzzy matching ([@scalvert](https://github.com/scalvert))
* [#257](https://github.com/ember-template-lint/ember-template-lint-todo-utils/pull/257) Expands todo data into v2 format ([@scalvert](https://github.com/scalvert))
* [#252](https://github.com/ember-template-lint/ember-template-lint-todo-utils/pull/252) Adding expanded todo batching functionality to account for fuzzy matching ([@scalvert](https://github.com/scalvert))
#### :house: Internal
* [#250](https://github.com/ember-template-lint/ember-template-lint-todo-utils/pull/250) Renaming FilePath type to improve code readability ([@scalvert](https://github.com/scalvert))
#### Committers: 1
- Steve Calvert ([@scalvert](https://github.com/scalvert))
## v9.1.2 (2021-06-10)
## v9.1.1 (2021-06-10)
#### :bug: Bug Fix
* [#247](https://github.com/ember-template-lint/ember-template-lint-todo-utils/pull/247) Exporting new date-utils APIs ([@scalvert](https://github.com/scalvert))
- [#247](https://github.com/ember-template-lint/ember-template-lint-todo-utils/pull/247) Exporting new date-utils APIs ([@scalvert](https://github.com/scalvert))
#### Committers: 1
- Steve Calvert ([@scalvert](https://github.com/scalvert))
## v9.1.0 (2021-06-10)
#### :rocket: Enhancement
* [#242](https://github.com/ember-template-lint/ember-template-lint-todo-utils/pull/242) Adds new validateConfig function ([@scalvert](https://github.com/scalvert))
* [#238](https://github.com/ember-template-lint/ember-template-lint-todo-utils/pull/238) Adds new date utils: differenceInDays and format ([@scalvert](https://github.com/scalvert))
- [#242](https://github.com/ember-template-lint/ember-template-lint-todo-utils/pull/242) Adds new validateConfig function ([@scalvert](https://github.com/scalvert))
- [#238](https://github.com/ember-template-lint/ember-template-lint-todo-utils/pull/238) Adds new date utils: differenceInDays and format ([@scalvert](https://github.com/scalvert))
#### Committers: 1
- Steve Calvert ([@scalvert](https://github.com/scalvert))
## v9.0.1 (2021-06-10)
#### :bug: Bug Fix
* [#237](https://github.com/ember-template-lint/ember-template-lint-todo-utils/pull/237) Tweak `getDatePart` to use UTC date ([@rwjblue](https://github.com/rwjblue))
- [#237](https://github.com/ember-template-lint/ember-template-lint-todo-utils/pull/237) Tweak `getDatePart` to use UTC date ([@rwjblue](https://github.com/rwjblue))
#### Committers: 2
- Robert Jackson ([@rwjblue](https://github.com/rwjblue))
- [@dependabot-preview[bot]](https://github.com/apps/dependabot-preview)
## v9.0.0 (2021-06-08)
#### :boom: Breaking Change
* [#213](https://github.com/ember-template-lint/ember-template-lint-todo-utils/pull/213) Extends todo configuration to support configuring days to decay by rule ID. ([@scalvert](https://github.com/scalvert))
* [#212](https://github.com/ember-template-lint/ember-template-lint-todo-utils/pull/212) Removes unsued APIs for write/ensure todo config ([@scalvert](https://github.com/scalvert))
- [#213](https://github.com/ember-template-lint/ember-template-lint-todo-utils/pull/213) Extends todo configuration to support configuring days to decay by rule ID. ([@scalvert](https://github.com/scalvert))
- [#212](https://github.com/ember-template-lint/ember-template-lint-todo-utils/pull/212) Removes unsued APIs for write/ensure todo config ([@scalvert](https://github.com/scalvert))
#### :memo: Documentation
* [#225](https://github.com/ember-template-lint/ember-template-lint-todo-utils/pull/225) Update docs with new getTodoConfig API changes ([@scalvert](https://github.com/scalvert))
- [#225](https://github.com/ember-template-lint/ember-template-lint-todo-utils/pull/225) Update docs with new getTodoConfig API changes ([@scalvert](https://github.com/scalvert))
#### Committers: 1
- Steve Calvert ([@scalvert](https://github.com/scalvert))
## v8.1.0 (2021-05-04)
#### :rocket: Enhancement
* [#185](https://github.com/ember-template-lint/ember-template-lint-todo-utils/pull/185) Adding expired batch to getTodoBatches ([@scalvert](https://github.com/scalvert))
- [#185](https://github.com/ember-template-lint/ember-template-lint-todo-utils/pull/185) Adding expired batch to getTodoBatches ([@scalvert](https://github.com/scalvert))
#### Committers: 1
- Steve Calvert ([@scalvert](https://github.com/scalvert))
## v8.0.0 (2021-03-09)

@@ -150,0 +95,0 @@

@@ -1,4 +0,9 @@

import { GenericLintData, TodoConfig, TodoData, TodoDataV2 } from './types';
import { FilePath, GenericLintData, Operation, TodoConfig, TodoData } from './types';
import TodoMatcher from './todo-matcher';
export declare function buildFromTodoOperations(todoOperations: string[]): Map<FilePath, TodoMatcher>;
export declare function buildTodoOperations(add: Set<TodoData>, remove: Set<TodoData>): string;
export declare function toTodoDatum(todoOperation: string): [Operation, TodoData];
export declare function toOperation(operation: Operation, todoDatum: TodoData): string;
/**
* Adapts a {@link https://github.com/ember-template-lint/ember-template-lint-todo-utils/blob/master/src/types/lint.ts#L31|LintResult} to a {@link https://github.com/ember-template-lint/ember-template-lint-todo-utils/blob/master/src/types/todo.ts#L61|TodoDataV2}. FilePaths are absolute
* Adapts a {@link https://github.com/ember-template-lint/ember-template-lint-todo-utils/blob/master/src/types/lint.ts#L31|LintResult} to a {@link https://github.com/ember-template-lint/ember-template-lint-todo-utils/blob/master/src/types/todo.ts#L61|TodoData}. FilePaths are absolute
* when received from a lint result, so they're converted to relative paths for stability in

@@ -10,7 +15,6 @@ * serializing the contents to disc.

* @param todoConfig - An object containing the warn or error days, in integers.
* @returns - A {@link https://github.com/ember-template-lint/ember-template-lint-todo-utils/blob/master/src/types/todo.ts#L61|TodoDataV2} object.
* @returns - A {@link https://github.com/ember-template-lint/ember-template-lint-todo-utils/blob/master/src/types/todo.ts#L61|TodoData} object.
*/
export declare function buildTodoDatum(baseDir: string, genericLintData: GenericLintData, todoConfig?: TodoConfig): TodoDataV2;
export declare function normalizeToV2(todoDatum: TodoData): TodoDataV2;
export declare function buildTodoDatum(baseDir: string, genericLintData: GenericLintData, todoConfig?: TodoConfig): TodoData;
export declare function generateHash(input: string, algorithm?: string): string;
//# sourceMappingURL=builders.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.generateHash = exports.normalizeToV2 = exports.buildTodoDatum = void 0;
exports.generateHash = exports.buildTodoDatum = exports.toOperation = exports.toTodoDatum = exports.buildTodoOperations = exports.buildFromTodoOperations = void 0;
const tslib_1 = require("tslib");
const path_1 = require("path");
const os_1 = require("os");
const slash = require("slash");
const crypto_1 = require("crypto");
const types_1 = require("./types");
const date_utils_1 = require("./date-utils");
const todo_matcher_1 = tslib_1.__importDefault(require("./todo-matcher"));
const SEPARATOR = '|';
function buildFromTodoOperations(todoOperations) {
const existingTodos = new Map();
for (const todoOperation of todoOperations) {
const [operation, todoDatum] = toTodoDatum(todoOperation);
if (!existingTodos.has(todoDatum.filePath)) {
existingTodos.set(todoDatum.filePath, new todo_matcher_1.default());
}
const matcher = existingTodos.get(todoDatum.filePath);
matcher === null || matcher === void 0 ? void 0 : matcher.addOrRemove(operation, todoDatum);
}
for (const [filePath, matcher] of existingTodos.entries()) {
if (matcher.unprocessed.size === 0) {
existingTodos.delete(filePath);
}
}
return existingTodos;
}
exports.buildFromTodoOperations = buildFromTodoOperations;
function buildTodoOperations(add, remove) {
if (add.size === 0 && remove.size === 0) {
return '';
}
const ops = [];
for (const todoDatum of add) {
ops.push(toOperation('add', todoDatum));
}
for (const todoDatum of remove) {
ops.push(toOperation('remove', todoDatum));
}
return ops.join(os_1.EOL) + os_1.EOL;
}
exports.buildTodoOperations = buildTodoOperations;
function toTodoDatum(todoOperation) {
const [operation, engine, ruleId, line, column, endLine, endColumn, source, createdDate, warnDate, errorDate, ...filePathSegments] = todoOperation.split(SEPARATOR);
// The only case where we need to join back on the separator is when the filePath itself
// contains a pipe ('|') char. The vast majority of normal filePaths will simply join without
// the separator.
const filePath = filePathSegments.join(SEPARATOR);
return [
operation,
{
engine,
ruleId,
filePath,
range: {
start: {
line: Number.parseInt(line, 10),
column: Number.parseInt(column, 10),
},
end: {
line: Number.parseInt(endLine, 10),
column: Number.parseInt(endColumn, 10),
},
},
source,
createdDate: Number.parseInt(createdDate, 10),
warnDate: warnDate ? Number.parseInt(warnDate, 10) : undefined,
errorDate: errorDate ? Number.parseInt(errorDate, 10) : undefined,
},
];
}
exports.toTodoDatum = toTodoDatum;
function toOperation(operation, todoDatum) {
return [
operation,
todoDatum.engine,
todoDatum.ruleId,
todoDatum.range.start.line,
todoDatum.range.start.column,
todoDatum.range.end.line,
todoDatum.range.end.column,
todoDatum.source,
todoDatum.createdDate,
todoDatum.warnDate,
todoDatum.errorDate,
todoDatum.filePath,
].join(SEPARATOR);
}
exports.toOperation = toOperation;
/**
* Adapts a {@link https://github.com/ember-template-lint/ember-template-lint-todo-utils/blob/master/src/types/lint.ts#L31|LintResult} to a {@link https://github.com/ember-template-lint/ember-template-lint-todo-utils/blob/master/src/types/todo.ts#L61|TodoDataV2}. FilePaths are absolute
* Adapts a {@link https://github.com/ember-template-lint/ember-template-lint-todo-utils/blob/master/src/types/lint.ts#L31|LintResult} to a {@link https://github.com/ember-template-lint/ember-template-lint-todo-utils/blob/master/src/types/todo.ts#L61|TodoData}. FilePaths are absolute
* when received from a lint result, so they're converted to relative paths for stability in

@@ -17,3 +99,3 @@ * serializing the contents to disc.

* @param todoConfig - An object containing the warn or error days, in integers.
* @returns - A {@link https://github.com/ember-template-lint/ember-template-lint-todo-utils/blob/master/src/types/todo.ts#L61|TodoDataV2} object.
* @returns - A {@link https://github.com/ember-template-lint/ember-template-lint-todo-utils/blob/master/src/types/todo.ts#L61|TodoData} object.
*/

@@ -29,3 +111,2 @@ function buildTodoDatum(baseDir, genericLintData, todoConfig) {

filePath: slash(filePath),
fileFormat: types_1.TodoFileFormat.Version2,
}, getTodoDates(genericLintData.ruleId, todoConfig));

@@ -35,27 +116,2 @@ return todoDatum;

exports.buildTodoDatum = buildTodoDatum;
function normalizeToV2(todoDatum) {
// if we have a range property, we're already in V2 format
if ('range' in todoDatum) {
todoDatum.fileFormat = types_1.TodoFileFormat.Version2;
return todoDatum;
}
const todoDatumV1 = todoDatum;
const todoDatumV2 = {
engine: todoDatumV1.engine,
filePath: todoDatumV1.filePath,
ruleId: todoDatumV1.ruleId,
range: getRange(todoDatumV1),
source: '',
createdDate: todoDatumV1.createdDate,
fileFormat: types_1.TodoFileFormat.Version1,
};
if (todoDatumV1.warnDate) {
todoDatumV2.warnDate = todoDatumV1.warnDate;
}
if (todoDatumV1.errorDate) {
todoDatumV2.errorDate = todoDatumV1.errorDate;
}
return todoDatumV2;
}
exports.normalizeToV2 = normalizeToV2;
function generateHash(input, algorithm = 'sha1') {

@@ -79,17 +135,2 @@ return crypto_1.createHash(algorithm).update(input).digest('hex');

}
function getRange(loc) {
var _a, _b;
return {
start: {
line: loc.line,
column: loc.column,
},
end: {
// eslint-disable-next-line unicorn/no-null
line: (_a = loc.endLine) !== null && _a !== void 0 ? _a : loc.line,
// eslint-disable-next-line unicorn/no-null
column: (_b = loc.endColumn) !== null && _b !== void 0 ? _b : loc.column,
},
};
}
function getDaysToDecay(ruleId, todoConfig) {

@@ -96,0 +137,0 @@ if (!todoConfig) {

@@ -1,2 +0,2 @@

import { Severity, TodoDataV2 } from './types';
import { Severity, TodoData } from './types';
/**

@@ -9,3 +9,3 @@ * Returns the correct severity level based on the todo data's decay dates.

*/
export declare function getSeverity(todo: TodoDataV2, today?: number): Severity;
export declare function getSeverity(todo: TodoData, today?: number): Severity;
//# sourceMappingURL=get-severity.d.ts.map
export { buildTodoDatum } from './builders';
export { applyTodoChanges, ensureTodoStorageDir, getTodoBatches, getTodoStorageDirPath, readTodos, readTodosForFilePath, readTodoData, todoStorageDirExists, todoDirFor, todoFileNameFor, todoFilePathFor, writeTodos, } from './io';
export { applyTodoChanges, compactTodoStorageFile, ensureTodoStorageFile, hasConflicts, getTodoBatches, getTodoStorageFilePath, readTodos, readTodosForFilePath, readTodoData, readTodoStorageFile, resolveConflicts, todoStorageFileExists, writeTodos, writeTodoStorageFile, ADD_OPERATIONS_ONLY, EXCLUDE_EXPIRED, } from './io';
export { getTodoConfig, validateConfig } from './todo-config';

@@ -4,0 +4,0 @@ export { getSeverity } from './get-severity';

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isExpired = exports.getDatePart = exports.format = exports.differenceInDays = exports.getSeverity = exports.validateConfig = exports.getTodoConfig = exports.writeTodos = exports.todoFilePathFor = exports.todoFileNameFor = exports.todoDirFor = exports.todoStorageDirExists = exports.readTodoData = exports.readTodosForFilePath = exports.readTodos = exports.getTodoStorageDirPath = exports.getTodoBatches = exports.ensureTodoStorageDir = exports.applyTodoChanges = exports.buildTodoDatum = void 0;
exports.isExpired = exports.getDatePart = exports.format = exports.differenceInDays = exports.getSeverity = exports.validateConfig = exports.getTodoConfig = exports.EXCLUDE_EXPIRED = exports.ADD_OPERATIONS_ONLY = exports.writeTodoStorageFile = exports.writeTodos = exports.todoStorageFileExists = exports.resolveConflicts = exports.readTodoStorageFile = exports.readTodoData = exports.readTodosForFilePath = exports.readTodos = exports.getTodoStorageFilePath = exports.getTodoBatches = exports.hasConflicts = exports.ensureTodoStorageFile = exports.compactTodoStorageFile = exports.applyTodoChanges = exports.buildTodoDatum = void 0;
const tslib_1 = require("tslib");

@@ -9,13 +9,17 @@ var builders_1 = require("./builders");

Object.defineProperty(exports, "applyTodoChanges", { enumerable: true, get: function () { return io_1.applyTodoChanges; } });
Object.defineProperty(exports, "ensureTodoStorageDir", { enumerable: true, get: function () { return io_1.ensureTodoStorageDir; } });
Object.defineProperty(exports, "compactTodoStorageFile", { enumerable: true, get: function () { return io_1.compactTodoStorageFile; } });
Object.defineProperty(exports, "ensureTodoStorageFile", { enumerable: true, get: function () { return io_1.ensureTodoStorageFile; } });
Object.defineProperty(exports, "hasConflicts", { enumerable: true, get: function () { return io_1.hasConflicts; } });
Object.defineProperty(exports, "getTodoBatches", { enumerable: true, get: function () { return io_1.getTodoBatches; } });
Object.defineProperty(exports, "getTodoStorageDirPath", { enumerable: true, get: function () { return io_1.getTodoStorageDirPath; } });
Object.defineProperty(exports, "getTodoStorageFilePath", { enumerable: true, get: function () { return io_1.getTodoStorageFilePath; } });
Object.defineProperty(exports, "readTodos", { enumerable: true, get: function () { return io_1.readTodos; } });
Object.defineProperty(exports, "readTodosForFilePath", { enumerable: true, get: function () { return io_1.readTodosForFilePath; } });
Object.defineProperty(exports, "readTodoData", { enumerable: true, get: function () { return io_1.readTodoData; } });
Object.defineProperty(exports, "todoStorageDirExists", { enumerable: true, get: function () { return io_1.todoStorageDirExists; } });
Object.defineProperty(exports, "todoDirFor", { enumerable: true, get: function () { return io_1.todoDirFor; } });
Object.defineProperty(exports, "todoFileNameFor", { enumerable: true, get: function () { return io_1.todoFileNameFor; } });
Object.defineProperty(exports, "todoFilePathFor", { enumerable: true, get: function () { return io_1.todoFilePathFor; } });
Object.defineProperty(exports, "readTodoStorageFile", { enumerable: true, get: function () { return io_1.readTodoStorageFile; } });
Object.defineProperty(exports, "resolveConflicts", { enumerable: true, get: function () { return io_1.resolveConflicts; } });
Object.defineProperty(exports, "todoStorageFileExists", { enumerable: true, get: function () { return io_1.todoStorageFileExists; } });
Object.defineProperty(exports, "writeTodos", { enumerable: true, get: function () { return io_1.writeTodos; } });
Object.defineProperty(exports, "writeTodoStorageFile", { enumerable: true, get: function () { return io_1.writeTodoStorageFile; } });
Object.defineProperty(exports, "ADD_OPERATIONS_ONLY", { enumerable: true, get: function () { return io_1.ADD_OPERATIONS_ONLY; } });
Object.defineProperty(exports, "EXCLUDE_EXPIRED", { enumerable: true, get: function () { return io_1.EXCLUDE_EXPIRED; } });
var todo_config_1 = require("./todo-config");

@@ -22,0 +26,0 @@ Object.defineProperty(exports, "getTodoConfig", { enumerable: true, get: function () { return todo_config_1.getTodoConfig; } });

@@ -1,47 +0,50 @@

import { TodoFileHash, TodoDataV2, TodoBatchCounts, WriteTodoOptions, TodoFilePathHash, TodoBatches } from './types';
import { FilePath, TodoData, TodoBatchCounts, TodoBatches, WriteTodoOptions } from './types';
import TodoMatcher from './todo-matcher';
/**
* Determines if the .lint-todo storage directory exists.
* Determines if the .lint-todo storage file exists.
*
* @param baseDir - The base directory that contains the .lint-todo storage directory.
* @returns - true if the todo storage directory exists, otherwise false.
* @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 todoStorageDirExists(baseDir: string): boolean;
export declare function todoStorageFileExists(baseDir: string): boolean;
/**
* Creates, or ensures the creation of, the .lint-todo directory.
* Creates, or ensures the creation of, the .lint-todo file.
*
* @param baseDir - The base directory that contains the .lint-todo storage directory.
* @returns - The todo storage directory path.
* @param baseDir - The base directory that contains the .lint-todo storage file.
* @returns - The todo storage file path.
*/
export declare function ensureTodoStorageDir(baseDir: string): string;
export declare function ensureTodoStorageFile(baseDir: string): string;
/**
* @param baseDir - The base directory that contains the .lint-todo storage directory.
* @returns - The todo storage directory path.
* @param baseDir - The base directory that contains the .lint-todo storage file.
* @returns - The todo storage file path.
*/
export declare function getTodoStorageDirPath(baseDir: string): string;
export declare function getTodoStorageFilePath(baseDir: string): string;
/**
* Creates a file path from the linting data. Excludes extension.
* Determines if the .lint-todo storage file has conflicts.
*
* @example
* 42b8532cff6da75c5e5895a6f33522bf37418d0c/6e3be839
* @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 baseDir - The base directory that contains the .lint-todo storage directory.
* @param todoData - The linting data for an individual violation.
* @returns - The todo file path for a {@link https://github.com/ember-template-lint/ember-template-lint-todo-utils/blob/master/src/types/todo.ts#L61|TodoDataV2} object.
* @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 todoFilePathFor(todoData: TodoDataV2): string;
export declare function resolveConflicts(operations: string[]): string[];
/**
* Creates a short hash for the todo's file path.
* Reads the .lint-todo storage file.
*
* @param filePath - The filePath from linting data for an individual violation.
* @returns - The todo directory for a specific filepath.
* @param todoStorageFilePath - The .lint-todo storage file path.
* @returns A array of todo operations.
*/
export declare function todoDirFor(filePath: string): string;
export declare function readTodoStorageFile(todoStorageFilePath: string): string[];
/**
* Generates a unique filename for a todo lint data.
* Writes the operations to the .lint-todo storage file to the path provided by todoStorageFilePath.
*
* @param todoData - The linting data for an individual violation.
* @returns - The todo file name for a {@link https://github.com/ember-template-lint/ember-template-lint-todo-utils/blob/master/src/types/todo.ts#L61|TodoDataV2} object.
* @param todoStorageFilePath - The .lint-todo storage file path.
* @param operations - An array of string operations that are used to recreate todos.
*/
export declare function todoFileNameFor(todoData: TodoDataV2): string;
export declare function writeTodoStorageFile(todoStorageFilePath: string, operations: string[]): void;
/**

@@ -55,7 +58,7 @@ * Writes files for todo lint violations. One file is generated for each violation, using a generated

* @param baseDir - The base directory that contains the .lint-todo storage directory.
* @param maybeTodos - The linting data, converted to TodoDataV2 format.
* @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<TodoDataV2>, options?: Partial<WriteTodoOptions>): TodoBatchCounts;
export declare function writeTodos(baseDir: string, maybeTodos: Set<TodoData>, options?: Partial<WriteTodoOptions>): TodoBatchCounts;
/**

@@ -65,5 +68,5 @@ * Reads all todo files in the .lint-todo directory.

* @param baseDir - The base directory that contains the .lint-todo storage directory.
* @returns - A {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map|Map} of {@link https://github.com/ember-template-lint/ember-template-lint-todo-utils/blob/master/src/types/todo.ts#L26|TodoFilePathHash}/{@link https://github.com/ember-template-lint/ember-template-lint-todo-utils/blob/master/src/todo-matcher.ts#L4|TodoMatcher}.
* @returns - A {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map|Map} of {@link https://github.com/ember-template-lint/ember-template-lint-todo-utils/blob/master/src/types/todo.ts#L25|FilePath}/{@link https://github.com/ember-template-lint/ember-template-lint-todo-utils/blob/master/src/todo-matcher.ts#L4|TodoMatcher}.
*/
export declare function readTodos(baseDir: string): Map<TodoFilePathHash, TodoMatcher>;
export declare function readTodos(baseDir: string): Map<FilePath, TodoMatcher>;
/**

@@ -74,5 +77,5 @@ * Reads todo files in the .lint-todo directory for a specific filePath.

* @param filePath - The relative file path of the file to return todo items for.
* @returns - A {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map|Map} of {@link https://github.com/ember-template-lint/ember-template-lint-todo-utils/blob/master/src/types/todo.ts#L26|TodoFilePathHash}/{@link https://github.com/ember-template-lint/ember-template-lint-todo-utils/blob/master/src/todo-matcher.ts#L4|TodoMatcher}.
* @returns - A {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map|Map} of {@link https://github.com/ember-template-lint/ember-template-lint-todo-utils/blob/master/src/types/todo.ts#L25|FilePath}/{@link https://github.com/ember-template-lint/ember-template-lint-todo-utils/blob/master/src/todo-matcher.ts#L4|TodoMatcher}.
*/
export declare function readTodosForFilePath(baseDir: string, filePath: string): Map<TodoFilePathHash, TodoMatcher>;
export declare function readTodosForFilePath(baseDir: string, filePath: string): Map<FilePath, TodoMatcher>;
/**

@@ -82,5 +85,5 @@ * Reads todo files in the .lint-todo directory and returns Todo data in an array.

* @param baseDir - The base directory that contains the .lint-todo storage directory.
* @returns An array of {@link https://github.com/ember-template-lint/ember-template-lint-todo-utils/blob/master/src/types/todo.ts#L61|TodoDataV2}
* @returns An array of {@link https://github.com/ember-template-lint/ember-template-lint-todo-utils/blob/master/src/types/todo.ts#L61|TodoData}
*/
export declare function readTodoData(baseDir: string): TodoDataV2[];
export declare function readTodoData(baseDir: string): Set<TodoData>;
/**

@@ -94,11 +97,33 @@ * Gets 4 maps containing todo items to add, remove, those that are expired, or those that are stable (not to be modified).

*/
export declare function getTodoBatches(maybeTodos: Set<TodoDataV2>, existing: Map<TodoFilePathHash, TodoMatcher>, options: Partial<WriteTodoOptions>): 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 todoStorageDir - The .lint-todo storage directory.
* @param todoStorageFilePath - The .lint-todo storage file path.
* @param add - Batch of todos to add.
* @param remove - Batch of todos to remove.
* @param options - An object containing write options.
*/
export declare function applyTodoChanges(todoStorageDir: string, add: Map<TodoFileHash, TodoDataV2>, remove: Map<TodoFileHash, TodoDataV2>): void;
export declare function applyTodoChanges(todoStorageFilePath: string, add: Set<TodoData>, remove: Set<TodoData>): void;
/**
* Compact strategy to leave only add operations in the todo storage file.
*
* @param operation - The single line operation read from the todo storage file.
* @returns True if the line matches an add operation, otherwise false.
*/
export declare const ADD_OPERATIONS_ONLY: (operation: string) => boolean;
/**
* Compact strategy to remove all expired operations from the todo storage file.
*
* @param operation - The single line operation read from the todo storage file.
* @returns True if the operation is not expired, otherwise false.
*/
export declare const EXCLUDE_EXPIRED: (operation: string) => boolean;
/**
* Compacts the .lint-todo storage file based on the compact strategy.
*
* @param baseDir - The base directory that contains the .lint-todo storage directory.
* @param compactStrategy - The strategy to use when compacting the storage file. Default: ADD_OPERATIONS_ONLY
*/
export declare function compactTodoStorageFile(baseDir: string, compactStrategy?: (operation: string) => boolean): void;
//# sourceMappingURL=io.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.applyTodoChanges = exports.getTodoBatches = exports.readTodoData = exports.readTodosForFilePath = exports.readTodos = exports.writeTodos = exports.todoFileNameFor = exports.todoDirFor = exports.todoFilePathFor = exports.getTodoStorageDirPath = exports.ensureTodoStorageDir = exports.todoStorageDirExists = void 0;
exports.compactTodoStorageFile = exports.EXCLUDE_EXPIRED = exports.ADD_OPERATIONS_ONLY = exports.applyTodoChanges = exports.getTodoBatches = exports.readTodoData = exports.readTodosForFilePath = exports.readTodos = exports.writeTodos = exports.writeTodoStorageFile = exports.readTodoStorageFile = exports.resolveConflicts = exports.hasConflicts = exports.getTodoStorageFilePath = exports.ensureTodoStorageFile = exports.todoStorageFileExists = void 0;
const tslib_1 = require("tslib");
/* eslint-disable @typescript-eslint/no-non-null-assertion */
const path_1 = require("path");
const os_1 = require("os");
const proper_lockfile_1 = require("proper-lockfile");
const fs_extra_1 = require("fs-extra");
const todo_matcher_1 = tslib_1.__importDefault(require("./todo-matcher"));
const todo_batch_generator_1 = tslib_1.__importDefault(require("./todo-batch-generator"));
const builders_1 = require("./builders");
const date_utils_1 = require("./date-utils");
const CONFLICT_PATTERN = /\|{7,}|<{7,}|={7,}|>{7,}/;
/**
* Determines if the .lint-todo storage directory exists.
* Determines if the .lint-todo storage file exists.
*
* @param baseDir - The base directory that contains the .lint-todo storage directory.
* @returns - true if the todo storage directory exists, otherwise false.
* @param baseDir - The base directory that contains the .lint-todo storage file.
* @returns - true if the todo storage file exists, otherwise false.
*/
function todoStorageDirExists(baseDir) {
return fs_extra_1.existsSync(getTodoStorageDirPath(baseDir));
function todoStorageFileExists(baseDir) {
try {
return !fs_extra_1.lstatSync(getTodoStorageFilePath(baseDir)).isDirectory();
}
catch (error) {
if (error.code === 'ENOENT') {
return false;
}
throw error;
}
}
exports.todoStorageDirExists = todoStorageDirExists;
exports.todoStorageFileExists = todoStorageFileExists;
/**
* Creates, or ensures the creation of, the .lint-todo directory.
* Creates, or ensures the creation of, the .lint-todo file.
*
* @param baseDir - The base directory that contains the .lint-todo storage directory.
* @returns - The todo storage directory path.
* @param baseDir - The base directory that contains the .lint-todo storage file.
* @returns - The todo storage file path.
*/
function ensureTodoStorageDir(baseDir) {
const path = getTodoStorageDirPath(baseDir);
fs_extra_1.ensureDirSync(path);
function ensureTodoStorageFile(baseDir) {
const path = getTodoStorageFilePath(baseDir);
fs_extra_1.ensureFileSync(path);
return path;
}
exports.ensureTodoStorageDir = ensureTodoStorageDir;
exports.ensureTodoStorageFile = ensureTodoStorageFile;
/**
* @param baseDir - The base directory that contains the .lint-todo storage directory.
* @returns - The todo storage directory path.
* @param baseDir - The base directory that contains the .lint-todo storage file.
* @returns - The todo storage file path.
*/
function getTodoStorageDirPath(baseDir) {
function getTodoStorageFilePath(baseDir) {
return path_1.posix.join(baseDir, '.lint-todo');
}
exports.getTodoStorageDirPath = getTodoStorageDirPath;
exports.getTodoStorageFilePath = getTodoStorageFilePath;
/**
* Creates a file path from the linting data. Excludes extension.
* Determines if the .lint-todo storage file has conflicts.
*
* @example
* 42b8532cff6da75c5e5895a6f33522bf37418d0c/6e3be839
* @param todoContents - The unparsed contents of the .lint-todo file.
* @returns true if the file has conflicts, otherwise false.
*/
function hasConflicts(todoContents) {
return CONFLICT_PATTERN.test(todoContents);
}
exports.hasConflicts = hasConflicts;
/**
* Resolves git conflicts in todo operations by removing any lines that match conflict markers.
*
* @param baseDir - The base directory that contains the .lint-todo storage directory.
* @param todoData - The linting data for an individual violation.
* @returns - The todo file path for a {@link https://github.com/ember-template-lint/ember-template-lint-todo-utils/blob/master/src/types/todo.ts#L61|TodoDataV2} object.
* @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.
*/
function todoFilePathFor(todoData) {
return path_1.posix.join(todoDirFor(todoData.filePath), todoFileNameFor(todoData));
function resolveConflicts(operations) {
return operations.filter((operation) => !CONFLICT_PATTERN.test(operation));
}
exports.todoFilePathFor = todoFilePathFor;
exports.resolveConflicts = resolveConflicts;
/**
* Creates a short hash for the todo's file path.
* Reads the .lint-todo storage file.
*
* @param filePath - The filePath from linting data for an individual violation.
* @returns - The todo directory for a specific filepath.
* @param todoStorageFilePath - The .lint-todo storage file path.
* @returns A array of todo operations.
*/
function todoDirFor(filePath) {
return builders_1.generateHash(filePath);
function readTodoStorageFile(todoStorageFilePath) {
const todoContents = fs_extra_1.readFileSync(todoStorageFilePath, {
encoding: 'utf-8',
});
let operations = todoContents.split(os_1.EOL);
if (hasConflicts(todoContents)) {
operations = resolveConflicts(operations);
writeTodoStorageFile(todoStorageFilePath, operations);
}
return operations.filter(Boolean);
}
exports.todoDirFor = todoDirFor;
exports.readTodoStorageFile = readTodoStorageFile;
/**
* Generates a unique filename for a todo lint data.
* Writes the operations to the .lint-todo storage file to the path provided by todoStorageFilePath.
*
* @param todoData - The linting data for an individual violation.
* @returns - The todo file name for a {@link https://github.com/ember-template-lint/ember-template-lint-todo-utils/blob/master/src/types/todo.ts#L61|TodoDataV2} object.
* @param todoStorageFilePath - The .lint-todo storage file path.
* @param operations - An array of string operations that are used to recreate todos.
*/
function todoFileNameFor(todoData) {
const fileContentsHash = `${todoData.engine}${todoData.ruleId}${todoData.range.start.line}${todoData.range.start.column}`;
return builders_1.generateHash(fileContentsHash, 'sha256').slice(0, 8);
function writeTodoStorageFile(todoStorageFilePath, operations) {
const release = lockStorageFile(todoStorageFilePath);
fs_extra_1.writeFileSync(todoStorageFilePath, operations.join(os_1.EOL));
release();
}
exports.todoFileNameFor = todoFileNameFor;
exports.writeTodoStorageFile = writeTodoStorageFile;
/**

@@ -84,3 +109,3 @@ * Writes files for todo lint violations. One file is generated for each violation, using a generated

* @param baseDir - The base directory that contains the .lint-todo storage directory.
* @param maybeTodos - The linting data, converted to TodoDataV2 format.
* @param maybeTodos - The linting data, converted to TodoData format.
* @param options - An object containing write options.

@@ -90,4 +115,4 @@ * @returns - The counts of added and removed todos.

function writeTodos(baseDir, maybeTodos, options) {
options = Object.assign({ shouldRemove: () => true }, options !== null && options !== void 0 ? options : {});
const todoStorageDir = ensureTodoStorageDir(baseDir);
options = Object.assign({ shouldRemove: () => true, overwrite: false }, options);
const todoStorageFilePath = ensureTodoStorageFile(baseDir);
const existing = options.filePath

@@ -97,3 +122,3 @@ ? readTodosForFilePath(baseDir, options.filePath)

const { add, remove, stable, expired } = getTodoBatches(maybeTodos, existing, options);
applyTodoChanges(todoStorageDir, add, remove);
applyTodoChanges(todoStorageFilePath, add, remove);
return {

@@ -107,2 +132,3 @@ addedCount: add.size,

exports.writeTodos = writeTodos;
// TODO: change from using TodoFilePathHash to just FilePath, but do that once this is all working
/**

@@ -112,20 +138,7 @@ * Reads all todo files in the .lint-todo directory.

* @param baseDir - The base directory that contains the .lint-todo storage directory.
* @returns - A {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map|Map} of {@link https://github.com/ember-template-lint/ember-template-lint-todo-utils/blob/master/src/types/todo.ts#L26|TodoFilePathHash}/{@link https://github.com/ember-template-lint/ember-template-lint-todo-utils/blob/master/src/todo-matcher.ts#L4|TodoMatcher}.
* @returns - A {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map|Map} of {@link https://github.com/ember-template-lint/ember-template-lint-todo-utils/blob/master/src/types/todo.ts#L25|FilePath}/{@link https://github.com/ember-template-lint/ember-template-lint-todo-utils/blob/master/src/todo-matcher.ts#L4|TodoMatcher}.
*/
function readTodos(baseDir) {
const existingTodos = new Map();
const todoStorageDir = ensureTodoStorageDir(baseDir);
const todoFileDirs = fs_extra_1.readdirSync(todoStorageDir);
for (const todoFileDir of todoFileDirs) {
const todoFileHashes = fs_extra_1.readdirSync(path_1.posix.join(todoStorageDir, todoFileDir));
if (!existingTodos.has(todoFileDir)) {
existingTodos.set(todoFileDir, new todo_matcher_1.default());
}
const matcher = existingTodos.get(todoFileDir);
for (const todoFileHash of todoFileHashes) {
const todoDatum = fs_extra_1.readJSONSync(path_1.posix.join(todoStorageDir, todoFileDir, todoFileHash));
matcher.add(builders_1.normalizeToV2(todoDatum));
}
}
return existingTodos;
const todoOperations = readTodoStorageFile(getTodoStorageFilePath(baseDir));
return builders_1.buildFromTodoOperations(todoOperations);
}

@@ -138,27 +151,9 @@ exports.readTodos = readTodos;

* @param filePath - The relative file path of the file to return todo items for.
* @returns - A {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map|Map} of {@link https://github.com/ember-template-lint/ember-template-lint-todo-utils/blob/master/src/types/todo.ts#L26|TodoFilePathHash}/{@link https://github.com/ember-template-lint/ember-template-lint-todo-utils/blob/master/src/todo-matcher.ts#L4|TodoMatcher}.
* @returns - A {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map|Map} of {@link https://github.com/ember-template-lint/ember-template-lint-todo-utils/blob/master/src/types/todo.ts#L25|FilePath}/{@link https://github.com/ember-template-lint/ember-template-lint-todo-utils/blob/master/src/todo-matcher.ts#L4|TodoMatcher}.
*/
function readTodosForFilePath(baseDir, filePath) {
const existingTodos = new Map();
const todoStorageDir = ensureTodoStorageDir(baseDir);
const todoFileDir = todoDirFor(filePath);
const todoFilePathDir = path_1.posix.join(todoStorageDir, todoFileDir);
try {
if (!existingTodos.has(todoFileDir)) {
existingTodos.set(todoFileDir, new todo_matcher_1.default());
}
const matcher = existingTodos.get(todoFileDir);
const fileNames = fs_extra_1.readdirSync(todoFilePathDir);
for (const fileName of fileNames) {
const todoDatum = fs_extra_1.readJSONSync(path_1.posix.join(todoFilePathDir, fileName));
matcher === null || matcher === void 0 ? void 0 : matcher.add(builders_1.normalizeToV2(todoDatum));
}
}
catch (error) {
if (error.code === 'ENOENT') {
return existingTodos;
}
throw error;
}
return existingTodos;
const todoOperations = fs_extra_1.readFileSync(getTodoStorageFilePath(baseDir), {
encoding: 'utf-8',
}).split(os_1.EOL);
return builders_1.buildFromTodoOperations(todoOperations.filter((operation) => operation.endsWith(filePath)));
}

@@ -170,8 +165,8 @@ exports.readTodosForFilePath = readTodosForFilePath;

* @param baseDir - The base directory that contains the .lint-todo storage directory.
* @returns An array of {@link https://github.com/ember-template-lint/ember-template-lint-todo-utils/blob/master/src/types/todo.ts#L61|TodoDataV2}
* @returns An array of {@link https://github.com/ember-template-lint/ember-template-lint-todo-utils/blob/master/src/types/todo.ts#L61|TodoData}
*/
function readTodoData(baseDir) {
return [...readTodos(baseDir).values()].reduce((matcherResults, matcher) => {
return new Set([...readTodos(baseDir).values()].reduce((matcherResults, matcher) => {
return [...matcherResults, ...matcher.unprocessed];
}, []);
}, []));
}

@@ -195,22 +190,54 @@ exports.readTodoData = readTodoData;

*
* @param todoStorageDir - The .lint-todo storage directory.
* @param todoStorageFilePath - The .lint-todo storage file path.
* @param add - Batch of todos to add.
* @param remove - Batch of todos to remove.
* @param options - An object containing write options.
*/
function applyTodoChanges(todoStorageDir, add, remove) {
for (const [fileHash, todoDatum] of add) {
const { dir } = path_1.posix.parse(fileHash);
fs_extra_1.ensureDirSync(path_1.posix.join(todoStorageDir, dir));
fs_extra_1.writeJsonSync(path_1.posix.join(todoStorageDir, `${fileHash}.json`), todoDatum);
function applyTodoChanges(todoStorageFilePath, add, remove) {
const ops = builders_1.buildTodoOperations(add, remove);
const release = lockStorageFile(todoStorageFilePath);
fs_extra_1.appendFileSync(todoStorageFilePath, ops);
release();
}
exports.applyTodoChanges = applyTodoChanges;
/**
* Compact strategy to leave only add operations in the todo storage file.
*
* @param operation - The single line operation read from the todo storage file.
* @returns True if the line matches an add operation, otherwise false.
*/
const ADD_OPERATIONS_ONLY = (operation) => /^add.*/.test(operation);
exports.ADD_OPERATIONS_ONLY = ADD_OPERATIONS_ONLY;
/**
* Compact strategy to remove all expired operations from the todo storage file.
*
* @param operation - The single line operation read from the todo storage file.
* @returns True if the operation is not expired, otherwise false.
*/
const EXCLUDE_EXPIRED = (operation) => {
const [, todoDatum] = builders_1.toTodoDatum(operation);
return !date_utils_1.isExpired(todoDatum.errorDate);
};
exports.EXCLUDE_EXPIRED = EXCLUDE_EXPIRED;
/**
* Compacts the .lint-todo storage file based on the compact strategy.
*
* @param baseDir - The base directory that contains the .lint-todo storage directory.
* @param compactStrategy - The strategy to use when compacting the storage file. Default: ADD_OPERATIONS_ONLY
*/
function compactTodoStorageFile(baseDir, compactStrategy = exports.ADD_OPERATIONS_ONLY) {
const todoStorageFilePath = getTodoStorageFilePath(baseDir);
const operations = readTodoStorageFile(todoStorageFilePath).filter((operation) => compactStrategy(operation));
writeTodoStorageFile(todoStorageFilePath, operations);
}
exports.compactTodoStorageFile = compactTodoStorageFile;
function lockStorageFile(todoStorageFilePath) {
try {
return proper_lockfile_1.lockSync(todoStorageFilePath);
}
for (const [fileHash] of remove) {
const { dir } = path_1.posix.parse(fileHash);
const todoDir = path_1.posix.join(todoStorageDir, dir);
fs_extra_1.unlinkSync(path_1.posix.join(todoStorageDir, `${fileHash}.json`));
if (fs_extra_1.readdirSync(todoDir).length === 0) {
fs_extra_1.rmdirSync(todoDir);
}
catch (_a) {
// eslint-disable-next-line @typescript-eslint/no-empty-function
return () => { };
}
}
exports.applyTodoChanges = applyTodoChanges;
//# sourceMappingURL=io.js.map
import TodoMatcher from './todo-matcher';
import { TodoBatches, TodoDataV2, TodoFilePathHash, WriteTodoOptions } from './types';
import { TodoBatches, TodoData, FilePath, WriteTodoOptions } from './types';
/**

@@ -15,3 +15,3 @@ * Creates todo batches based on lint results.

/**
* Matches todos to their associated {@link https://github.com/ember-template-lint/ember-template-lint-todo-utils/blob/master/src/types/todo.ts#L61|TodoDataV2} object.
* Matches todos to their associated {@link https://github.com/ember-template-lint/ember-template-lint-todo-utils/blob/master/src/types/todo.ts#L61|TodoData} object.
*

@@ -46,8 +46,8 @@ * The matching algorithm uses the following logic:

*
* @param maybeTodos - The linting data, converted to TodoDataV2 format.
* @param maybeTodos - The linting data, converted to TodoData format.
* @param existingTodos - Existing todo lint data.
* @returns
*/
generate(maybeTodos: Set<TodoDataV2>, existingTodos: Map<TodoFilePathHash, TodoMatcher>): TodoBatches;
generate(maybeTodos: Set<TodoData>, existingTodos: Map<FilePath, TodoMatcher>): TodoBatches;
}
//# sourceMappingURL=todo-batch-generator.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const date_utils_1 = require("./date-utils");
const io_1 = require("./io");
function copyLintResult(todoDatum, unmatchedTodoData) {

@@ -26,3 +25,3 @@ // this is a key transfer of information that allows us to match the identify

/**
* Matches todos to their associated {@link https://github.com/ember-template-lint/ember-template-lint-todo-utils/blob/master/src/types/todo.ts#L61|TodoDataV2} object.
* Matches todos to their associated {@link https://github.com/ember-template-lint/ember-template-lint-todo-utils/blob/master/src/types/todo.ts#L61|TodoData} object.
*

@@ -57,3 +56,3 @@ * The matching algorithm uses the following logic:

*
* @param maybeTodos - The linting data, converted to TodoDataV2 format.
* @param maybeTodos - The linting data, converted to TodoData format.
* @param existingTodos - Existing todo lint data.

@@ -64,20 +63,18 @@ * @returns

var _a, _b, _c, _d, _e;
const add = new Map();
const expired = new Map();
const stable = new Map();
let remove = new Map();
const add = new Set();
const expired = new Set();
const stable = new Set();
let remove = new Set();
maybeTodos = new Set(maybeTodos);
for (const unmatchedTodoData of maybeTodos) {
const todoFilePathHash = io_1.todoDirFor(unmatchedTodoData.filePath);
const matcher = existingTodos.get(todoFilePathHash);
const matcher = existingTodos.get(unmatchedTodoData.filePath);
if (matcher) {
const todoDatum = matcher.exactMatch(unmatchedTodoData);
if (todoDatum) {
const todoFilePath = io_1.todoFilePathFor(todoDatum);
if (date_utils_1.isExpired(todoDatum.errorDate) && ((_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.shouldRemove) === null || _b === void 0 ? void 0 : _b.call(_a, todoDatum))) {
expired.set(todoFilePath, todoDatum);
expired.add(todoDatum);
}
else {
copyLintResult(todoDatum, unmatchedTodoData);
stable.set(todoFilePath, todoDatum);
stable.add(todoDatum);
}

@@ -89,22 +86,20 @@ maybeTodos.delete(unmatchedTodoData);

for (const unmatchedTodoData of maybeTodos) {
const todoFilePathHash = io_1.todoDirFor(unmatchedTodoData.filePath);
const matcher = existingTodos.get(todoFilePathHash);
const matcher = existingTodos.get(unmatchedTodoData.filePath);
if (matcher) {
const todoDatum = matcher.fuzzyMatch(unmatchedTodoData);
if (todoDatum) {
const todoFilePath = io_1.todoFilePathFor(todoDatum);
if (date_utils_1.isExpired(todoDatum.errorDate) && ((_d = (_c = this.options) === null || _c === void 0 ? void 0 : _c.shouldRemove) === null || _d === void 0 ? void 0 : _d.call(_c, todoDatum))) {
expired.set(todoFilePath, todoDatum);
expired.add(todoDatum);
}
else {
copyLintResult(todoDatum, unmatchedTodoData);
stable.set(todoFilePath, todoDatum);
stable.add(todoDatum);
}
}
else {
add.set(io_1.todoFilePathFor(unmatchedTodoData), unmatchedTodoData);
add.add(unmatchedTodoData);
}
}
else {
add.set(io_1.todoFilePathFor(unmatchedTodoData), unmatchedTodoData);
add.add(unmatchedTodoData);
}

@@ -114,3 +109,3 @@ maybeTodos.delete(unmatchedTodoData);

for (const matcher of [...existingTodos.values()]) {
remove = new Map([...remove, ...matcher.unmatched((_e = this.options) === null || _e === void 0 ? void 0 : _e.shouldRemove)]);
remove = new Set([...remove, ...matcher.unmatched((_e = this.options) === null || _e === void 0 ? void 0 : _e.shouldRemove)]);
}

@@ -117,0 +112,0 @@ return {

@@ -1,11 +0,15 @@

import { TodoDataV2, TodoFilePathHash } from './types';
import { TodoData, Operation } from './types';
export declare function exactMatch(todoDataToFind: TodoData, todoDatum: TodoData): boolean;
export default class TodoMatcher {
unprocessed: Set<TodoDataV2>;
unprocessed: Set<TodoData>;
constructor();
unmatched(predicate?: (todoDatum: TodoDataV2) => boolean): Map<TodoFilePathHash, TodoDataV2>;
add(todoDatum: TodoDataV2): void;
find(todoFilePathHash: TodoFilePathHash): TodoDataV2 | undefined;
exactMatch(todoDataToFind: TodoDataV2): TodoDataV2 | undefined;
fuzzyMatch(todoDataToFind: TodoDataV2): TodoDataV2 | undefined;
unmatched(predicate?: (todoDatum: TodoData) => boolean): Set<TodoData>;
add(todoDatum: TodoData): void;
remove(todoDatum: TodoData): void;
addOrRemove(operation: Operation, todoDatum: TodoData): void;
find2(todoDatum: TodoData): TodoData | undefined;
find(predicate: (value: TodoData, index?: number, obj?: TodoData[]) => unknown): TodoData | undefined;
exactMatch(todoDataToFind: TodoData): TodoData | undefined;
fuzzyMatch(todoDataToFind: TodoData): TodoData | undefined;
}
//# sourceMappingURL=todo-matcher.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const io_1 = require("./io");
const types_1 = require("./types");
const ExactMatchers = new Map([
[
types_1.TodoFileFormat.Version1,
{
match: (todoDataToFind, todoDatum) => {
return (todoDataToFind.engine === todoDatum.engine &&
todoDataToFind.ruleId === todoDatum.ruleId &&
todoDataToFind.range.start.line === todoDatum.range.start.line &&
todoDataToFind.range.start.column === todoDatum.range.start.column);
},
},
],
[
types_1.TodoFileFormat.Version2,
{
match: (todoDataToFind, todoDatum) => {
return (todoDataToFind.engine === todoDatum.engine &&
todoDataToFind.ruleId === todoDatum.ruleId &&
todoDataToFind.range.start.line === todoDatum.range.start.line &&
todoDataToFind.range.start.column === todoDatum.range.start.column &&
todoDataToFind.range.end.line === todoDatum.range.end.line &&
todoDataToFind.range.end.column === todoDatum.range.end.column &&
todoDataToFind.source === todoDatum.source);
},
},
],
]);
exports.exactMatch = void 0;
function exactMatch(todoDataToFind, todoDatum) {
return (todoDataToFind.engine === todoDatum.engine &&
todoDataToFind.ruleId === todoDatum.ruleId &&
todoDataToFind.range.start.line === todoDatum.range.start.line &&
todoDataToFind.range.start.column === todoDatum.range.start.column &&
todoDataToFind.range.end.line === todoDatum.range.end.line &&
todoDataToFind.range.end.column === todoDatum.range.end.column &&
todoDataToFind.source === todoDatum.source);
}
exports.exactMatch = exactMatch;
class TodoMatcher {

@@ -37,7 +19,3 @@ constructor() {

unmatched(predicate = () => false) {
return new Map([...this.unprocessed]
.filter((todoDatum) => predicate(todoDatum))
.map((todoDatum) => {
return [io_1.todoFilePathFor(todoDatum), todoDatum];
}));
return new Set([...this.unprocessed].filter((todoDatum) => predicate(todoDatum)));
}

@@ -47,10 +25,26 @@ add(todoDatum) {

}
find(todoFilePathHash) {
return [...this.unprocessed].find((todoDatum) => io_1.todoFileNameFor(todoDatum) === todoFilePathHash);
remove(todoDatum) {
this.unprocessed.delete(todoDatum);
}
addOrRemove(operation, todoDatum) {
if (operation === 'add' && !this.find2(todoDatum)) {
this.add(todoDatum);
}
if (operation === 'remove') {
const todoToRemove = this.find2(todoDatum);
if (todoToRemove) {
this.remove(todoToRemove);
}
}
}
find2(todoDatum) {
return [...this.unprocessed].find((unprocessedTodo) => exactMatch(unprocessedTodo, todoDatum));
}
find(predicate) {
return [...this.unprocessed].find((todoDatum) => predicate(todoDatum));
}
exactMatch(todoDataToFind) {
var _a;
let found;
for (const todoDatum of this.unprocessed) {
if ((_a = ExactMatchers.get(todoDatum.fileFormat)) === null || _a === void 0 ? void 0 : _a.match(todoDataToFind, todoDatum)) {
if (exactMatch(todoDataToFind, todoDatum)) {
found = todoDatum;

@@ -57,0 +51,0 @@ this.unprocessed.delete(todoDatum);

@@ -25,2 +25,4 @@ import { ESLint, Linter } from 'eslint';

column: number;
endLine?: number;
endColumn?: number;
source: string;

@@ -27,0 +29,0 @@ }

@@ -19,44 +19,14 @@ import { PackageJson } from 'type-fest';

*
* @deprecated This type is deprecated in favor of the more descriptive TodoFileHash.
* @example
* 42b8532cff6da75c5e5895a6f33522bf37418d0c/6e3be839
* app/settings/foo.js
*/
export declare type FilePath = string;
/**
* Represents the hashed filePath of the todos, which is a directory that contains todo files.
*
* @example
* 42b8532cff6da75c5e5895a6f33522bf37418d0c
*/
export declare type TodoFilePathHash = string;
/**
* Represents the path to the todo file.
*
* @example
* 42b8532cff6da75c5e5895a6f33522bf37418d0c/6e3be839
*/
export declare type TodoFileHash = string;
export declare type TodoBatches = {
add: Map<TodoFileHash, TodoDataV2>;
expired: Map<TodoFileHash, TodoDataV2>;
stable: Map<TodoFileHash, TodoDataV2>;
remove: Map<TodoFileHash, TodoDataV2>;
add: Set<TodoData>;
expired: Set<TodoData>;
stable: Set<TodoData>;
remove: Set<TodoData>;
};
export declare enum TodoFileFormat {
Version1 = 1,
Version2 = 2
}
export interface TodoDataV1 {
engine: 'eslint' | 'ember-template-lint';
filePath: string;
ruleId: string;
line: number;
column: number;
createdDate: number;
fileFormat: TodoFileFormat;
source?: string;
warnDate?: number;
errorDate?: number;
}
export interface TodoDataV2 {
export declare type Operation = 'add' | 'remove';
export interface TodoData {
engine: 'eslint' | 'ember-template-lint' | string;

@@ -67,3 +37,2 @@ filePath: string;

createdDate: number;
fileFormat: TodoFileFormat;
source: string;

@@ -74,4 +43,3 @@ warnDate?: number;

}
export declare type TodoData = TodoDataV1 | TodoDataV2;
export declare type TodoDates = Pick<TodoDataV2, 'createdDate' | 'errorDate' | 'warnDate'>;
export declare type TodoDates = Pick<TodoData, 'createdDate' | 'errorDate' | 'warnDate'>;
export declare type Range = {

@@ -120,4 +88,4 @@ start: {

todoConfig: TodoConfig;
shouldRemove: (todoDatum: TodoDataV2) => boolean;
shouldRemove: (todoDatum: TodoData) => boolean;
}
//# sourceMappingURL=todos.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TodoFileFormat = void 0;
var TodoFileFormat;
(function (TodoFileFormat) {
TodoFileFormat[TodoFileFormat["Version1"] = 1] = "Version1";
TodoFileFormat[TodoFileFormat["Version2"] = 2] = "Version2";
})(TodoFileFormat = exports.TodoFileFormat || (exports.TodoFileFormat = {}));
//# sourceMappingURL=todos.js.map
{
"name": "@ember-template-lint/todo-utils",
"version": "10.0.0",
"version": "11.0.0-alpha.0",
"repository": "https://github.com/ember-template-lint/ember-template-lint-todo-utils.git",

@@ -22,7 +22,9 @@ "license": "MIT",

"fs-extra": "^9.1.0",
"proper-lockfile": "^4.1.2",
"slash": "^3.0.0",
"tslib": "^2.2.0"
"tslib": "^2.3.1"
},
"devDependencies": {
"@types/fs-extra": "^9.0.11",
"@types/fs-extra": "^9.0.12",
"@types/proper-lockfile": "^4.1.2",
"@types/slash": "^3.0.0",

@@ -32,3 +34,3 @@ "@types/tmp": "^0.2.0",

"@typescript-eslint/parser": "^4.29.1",
"date-fns": "^2.22.1",
"date-fns": "^2.23.0",
"eslint": "^7.31.0",

@@ -46,3 +48,3 @@ "eslint-config-prettier": "^7.2.0",

"prettier": "^2.3.2",
"release-it": "^14.10.0",
"release-it": "^14.11.5",
"release-it-lerna-changelog": "^3.1.0",

@@ -52,3 +54,3 @@ "tmp": "^0.2.1",

"type-fest": "^2.0.0",
"typescript": "^4.3.4"
"typescript": "^4.3.5"
},

@@ -55,0 +57,0 @@ "engines": {

@@ -21,3 +21,3 @@ # @ember-template-lint/todo-utils

<dt><a href="#buildTodoDatum">buildTodoDatum(lintResult, lintMessage, todoConfig)</a> ⇒</dt>
<dd><p>Adapts a <a href="https://github.com/ember-template-lint/ember-template-lint-todo-utils/blob/master/src/types/lint.ts#L31">LintResult</a> to a <a href="https://github.com/ember-template-lint/ember-template-lint-todo-utils/blob/master/src/types/todo.ts#L61">TodoDataV2</a>. FilePaths are absolute
<dd><p>Adapts a <a href="https://github.com/ember-template-lint/ember-template-lint-todo-utils/blob/master/src/types/lint.ts#L31">LintResult</a> to a <a href="https://github.com/ember-template-lint/ember-template-lint-todo-utils/blob/master/src/types/todo.ts#L61">TodoData</a>. FilePaths are absolute
when received from a lint result, so they&#39;re converted to relative paths for stability in

@@ -92,14 +92,15 @@ serializing the contents to disc.</p>

## buildTodoDatum(lintResult, lintMessage, todoConfig) ⇒
Adapts a [LintResult](https://github.com/ember-template-lint/ember-template-lint-todo-utils/blob/master/src/types/lint.ts#L31) to a [TodoDataV2](https://github.com/ember-template-lint/ember-template-lint-todo-utils/blob/master/src/types/todo.ts#L61). FilePaths are absolute
Adapts a [LintResult](https://github.com/ember-template-lint/ember-template-lint-todo-utils/blob/master/src/types/lint.ts#L31) to a [TodoData](https://github.com/ember-template-lint/ember-template-lint-todo-utils/blob/master/src/types/todo.ts#L61). FilePaths are absolute
when received from a lint result, so they're converted to relative paths for stability in
serializing the contents to disc.
**Kind**: global function
**Returns**: - A [TodoDataV2](https://github.com/ember-template-lint/ember-template-lint-todo-utils/blob/master/src/types/todo.ts#L61) object.
**Kind**: global function
**Returns**: - A [TodoData](https://github.com/ember-template-lint/ember-template-lint-todo-utils/blob/master/src/types/todo.ts#L61) object.
| Param | Description |
| --- | --- |
| lintResult | The lint result object. |
| Param | Description |
| ----------- | ------------------------------------------------------------------- |
| lintResult | The lint result object. |
| lintMessage | A lint message object representing a specific violation for a file. |
| todoConfig | An object containing the warn or error days, in integers. |
| todoConfig | An object containing the warn or error days, in integers. |

@@ -109,9 +110,10 @@ <a name="todoStorageDirExists"></a>

## todoStorageDirExists(baseDir) ⇒
Determines if the .lint-todo storage directory exists.
**Kind**: global function
**Returns**: - true if the todo storage directory exists, otherwise false.
**Kind**: global function
**Returns**: - true if the todo storage directory exists, otherwise false.
| Param | Description |
| --- | --- |
| Param | Description |
| ------- | ------------------------------------------------------------------ |
| baseDir | The base directory that contains the .lint-todo storage directory. |

@@ -122,9 +124,10 @@

## ensureTodoStorageDir(baseDir) ⇒
Creates, or ensures the creation of, the .lint-todo directory.
**Kind**: global function
**Returns**: - The todo storage directory path.
**Kind**: global function
**Returns**: - The todo storage directory path.
| Param | Description |
| --- | --- |
| Param | Description |
| ------- | ------------------------------------------------------------------ |
| baseDir | The base directory that contains the .lint-todo storage directory. |

@@ -135,7 +138,8 @@

## getTodoStorageDirPath(baseDir) ⇒
**Kind**: global function
**Returns**: - The todo storage directory path.
| Param | Description |
| --- | --- |
**Kind**: global function
**Returns**: - The todo storage directory path.
| Param | Description |
| ------- | ------------------------------------------------------------------ |
| baseDir | The base directory that contains the .lint-todo storage directory. |

@@ -146,26 +150,30 @@

## todoFilePathFor(baseDir, todoData) ⇒
Creates a file path from the linting data. Excludes extension.
**Kind**: global function
**Returns**: - The todo file path for a [TodoDataV2](https://github.com/ember-template-lint/ember-template-lint-todo-utils/blob/master/src/types/todo.ts#L61) object.
**Kind**: global function
**Returns**: - The todo file path for a [TodoData](https://github.com/ember-template-lint/ember-template-lint-todo-utils/blob/master/src/types/todo.ts#L61) object.
| Param | Description |
| --- | --- |
| baseDir | The base directory that contains the .lint-todo storage directory. |
| todoData | The linting data for an individual violation. |
| Param | Description |
| -------- | ------------------------------------------------------------------ |
| baseDir | The base directory that contains the .lint-todo storage directory. |
| todoData | The linting data for an individual violation. |
**Example**
**Example**
```js
42b8532cff6da75c5e5895a6f33522bf37418d0c/6e3be839
```
<a name="todoDirFor"></a>
## todoDirFor(filePath) ⇒
Creates a short hash for the todo's file path.
**Kind**: global function
**Returns**: - The todo directory for a specific filepath.
**Kind**: global function
**Returns**: - The todo directory for a specific filepath.
| Param | Description |
| --- | --- |
| Param | Description |
| -------- | ----------------------------------------------------------- |
| filePath | The filePath from linting data for an individual violation. |

@@ -176,9 +184,10 @@

## todoFileNameFor(todoData) ⇒
Generates a unique filename for a todo lint data.
**Kind**: global function
**Returns**: - The todo file name for a [TodoDataV2](https://github.com/ember-template-lint/ember-template-lint-todo-utils/blob/master/src/types/todo.ts#L61) object.
**Kind**: global function
**Returns**: - The todo file name for a [TodoData](https://github.com/ember-template-lint/ember-template-lint-todo-utils/blob/master/src/types/todo.ts#L61) object.
| Param | Description |
| --- | --- |
| Param | Description |
| -------- | --------------------------------------------- |
| todoData | The linting data for an individual violation. |

@@ -189,2 +198,3 @@

## writeTodos(baseDir, maybeTodos, options) ⇒
Writes files for todo lint violations. One file is generated for each violation, using a generated

@@ -196,10 +206,10 @@ hash to identify each.

**Kind**: global function
**Returns**: - The counts of added and removed todos.
**Kind**: global function
**Returns**: - The counts of added and removed todos.
| Param | Description |
| --- | --- |
| baseDir | The base directory that contains the .lint-todo storage directory. |
| maybeTodos | The linting data, converted to TodoDataV2 format. |
| options | An object containing write options. |
| Param | Description |
| ---------- | ------------------------------------------------------------------ |
| baseDir | The base directory that contains the .lint-todo storage directory. |
| maybeTodos | The linting data, converted to TodoData format. |
| options | An object containing write options. |

@@ -209,9 +219,10 @@ <a name="readTodos"></a>

## readTodos(baseDir) ⇒
Reads all todo files in the .lint-todo directory.
**Kind**: global function
**Returns**: - A [Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) of [TodoFilePathHash](https://github.com/ember-template-lint/ember-template-lint-todo-utils/blob/master/src/types/todo.ts#L26)/[TodoMatcher](https://github.com/ember-template-lint/ember-template-lint-todo-utils/blob/master/src/todo-matcher.ts#L4).
**Kind**: global function
**Returns**: - A [Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) of [TodoFilePathHash](https://github.com/ember-template-lint/ember-template-lint-todo-utils/blob/master/src/types/todo.ts#L26)/[TodoMatcher](https://github.com/ember-template-lint/ember-template-lint-todo-utils/blob/master/src/todo-matcher.ts#L4).
| Param | Description |
| --- | --- |
| Param | Description |
| ------- | ------------------------------------------------------------------ |
| baseDir | The base directory that contains the .lint-todo storage directory. |

@@ -222,11 +233,12 @@

## readTodosForFilePath(todoStorageDir, filePath) ⇒
Reads todo files in the .lint-todo directory for a specific filePath.
**Kind**: global function
**Returns**: - A [Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) of [TodoFilePathHash](https://github.com/ember-template-lint/ember-template-lint-todo-utils/blob/master/src/types/todo.ts#L26)/[TodoMatcher](https://github.com/ember-template-lint/ember-template-lint-todo-utils/blob/master/src/todo-matcher.ts#L4).
**Kind**: global function
**Returns**: - A [Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) of [TodoFilePathHash](https://github.com/ember-template-lint/ember-template-lint-todo-utils/blob/master/src/types/todo.ts#L26)/[TodoMatcher](https://github.com/ember-template-lint/ember-template-lint-todo-utils/blob/master/src/todo-matcher.ts#L4).
| Param | Description |
| --- | --- |
| todoStorageDir | The .lint-todo storage directory. |
| filePath | The relative file path of the file to return todo items for. |
| Param | Description |
| -------------- | ------------------------------------------------------------ |
| todoStorageDir | The .lint-todo storage directory. |
| filePath | The relative file path of the file to return todo items for. |

@@ -236,9 +248,10 @@ <a name="readTodoData"></a>

## readTodoData(baseDir) ⇒
Reads todo files in the .lint-todo directory and returns Todo data in an array.
**Kind**: global function
**Returns**: An array of [TodoDataV2](https://github.com/ember-template-lint/ember-template-lint-todo-utils/blob/master/src/types/todo.ts#L61)
**Kind**: global function
**Returns**: An array of [TodoData](https://github.com/ember-template-lint/ember-template-lint-todo-utils/blob/master/src/types/todo.ts#L61)
| Param | Description |
| --- | --- |
| Param | Description |
| ------- | ------------------------------------------------------------------ |
| baseDir | The base directory that contains the .lint-todo storage directory. |

@@ -249,12 +262,13 @@

## getTodoBatches(maybeTodos, existing, options) ⇒
Gets 4 maps containing todo items to add, remove, those that are expired, or those that are stable (not to be modified).
**Kind**: global function
**Returns**: - An object of [TodoBatches](https://github.com/ember-template-lint/ember-template-lint-todo-utils/blob/master/src/types/todo.ts#L36).
**Kind**: global function
**Returns**: - An object of [TodoBatches](https://github.com/ember-template-lint/ember-template-lint-todo-utils/blob/master/src/types/todo.ts#L36).
| Param | Description |
| --- | --- |
| maybeTodos | The linting data for violations. |
| existing | Existing todo lint data. |
| options | An object containing write options. |
| Param | Description |
| ---------- | ----------------------------------- |
| maybeTodos | The linting data for violations. |
| existing | Existing todo lint data. |
| options | An object containing write options. |

@@ -264,11 +278,12 @@ <a name="applyTodoChanges"></a>

## applyTodoChanges(todoStorageDir, add, remove)
Applies todo changes, either adding or removing, based on batches from `getTodoBatches`.
**Kind**: global function
**Kind**: global function
| Param | Description |
| --- | --- |
| Param | Description |
| -------------- | --------------------------------- |
| todoStorageDir | The .lint-todo storage directory. |
| add | Batch of todos to add. |
| remove | Batch of todos to remove. |
| add | Batch of todos to add. |
| remove | Batch of todos to remove. |

@@ -278,2 +293,3 @@ <a name="getTodoConfig"></a>

## getTodoConfig(baseDir, engine, customDaysToDecay) ⇒
Gets the todo configuration.

@@ -284,12 +300,13 @@ Config values can be present in

**Kind**: global function
**Returns**: - The todo config object.
**Kind**: global function
**Returns**: - The todo config object.
| Param | Description |
| --- | --- |
| baseDir | The base directory that contains the project's package.json. |
| engine | The engine for this configuration, eg. eslint |
| customDaysToDecay | The optional custom days to decay configuration. |
| Param | Description |
| ----------------- | ------------------------------------------------------------ |
| baseDir | The base directory that contains the project's package.json. |
| engine | The engine for this configuration, eg. eslint |
| customDaysToDecay | The optional custom days to decay configuration. |
**Example**
**Example**
```json

@@ -312,32 +329,32 @@ {

A .lint-todorc.js file
**Example**
**Example**
```js
module.exports = {
"some-engine": {
"daysToDecay": {
"warn": 5,
"error": 10
'some-engine': {
daysToDecay: {
warn: 5,
error: 10,
},
"daysToDecayByRule": {
"no-bare-strings": { "warn": 10, "error": 20 }
}
}
}
daysToDecayByRule: {
'no-bare-strings': { warn: 10, error: 20 },
},
},
};
```
Environment variables (`TODO_DAYS_TO_WARN` or `TODO_DAYS_TO_ERROR`)
- Env vars override package.json config
Environment variables (`TODO_DAYS_TO_WARN` or `TODO_DAYS_TO_ERROR`) - Env vars override package.json config
Passed in directly, such as from command line options.
- Passed in options override both env vars and package.json config
Passed in directly, such as from command line options. - Passed in options override both env vars and package.json config
<a name="validateConfig"></a>
## validateConfig(baseDir) ⇒
Validates whether we have a unique config in a single location.
**Kind**: global function
**Returns**: A ConfigValidationResult that indicates whether a config is unique
**Kind**: global function
**Returns**: A ConfigValidationResult that indicates whether a config is unique
| Param | Description |
| --- | --- |
| Param | Description |
| ------- | ------------------------------------------------------------ |
| baseDir | The base directory that contains the project's package.json. |

@@ -348,10 +365,11 @@

## getSeverity(todo, today) ⇒
Returns the correct severity level based on the todo data's decay dates.
**Kind**: global function
**Returns**: Severity - the lint severity based on the evaluation of the decay dates.
**Kind**: global function
**Returns**: Severity - the lint severity based on the evaluation of the decay dates.
| Param | Description |
| --- | --- |
| todo | The todo data. |
| Param | Description |
| ----- | -------------------------------------------------------- |
| todo | The todo data. |
| today | A number representing a date (UNIX Epoch - milliseconds) |

@@ -362,10 +380,11 @@

## isExpired(date, today) ⇒
Evaluates whether a date is expired (earlier than today)
**Kind**: global function
**Returns**: true if the date is earlier than today, otherwise false
**Kind**: global function
**Returns**: true if the date is earlier than today, otherwise false
| Param | Description |
| --- | --- |
| date | The date to evaluate |
| Param | Description |
| ----- | -------------------------------------------------------- |
| date | The date to evaluate |
| today | A number representing a date (UNIX Epoch - milliseconds) |

@@ -376,10 +395,11 @@

## getDatePart(date) ⇒
Converts a date to include year, month, and day values only (time is zeroed out).
**Kind**: global function
**Returns**: Date - A date with the time zeroed out eg. '2021-01-01T08:00:00.000Z'
**Kind**: global function
**Returns**: Date - A date with the time zeroed out eg. '2021-01-01T08:00:00.000Z'
| Param | Description |
| --- | --- |
| date | The date to convert |
| Param | Description |
| ----- | ------------------- |
| date | The date to convert |

@@ -389,11 +409,12 @@ <a name="differenceInDays"></a>

## differenceInDays(startDate, endDate) ⇒
Returns the difference in days between two dates.
**Kind**: global function
**Returns**: a number representing the days between the dates
**Kind**: global function
**Returns**: a number representing the days between the dates
| Param | Description |
| --- | --- |
| Param | Description |
| --------- | -------------- |
| startDate | The start date |
| endDate | The end date |
| endDate | The end date |

@@ -403,12 +424,12 @@ <a name="format"></a>

## format(date) ⇒
Formats the date in short form, eg. 2021-01-01
**Kind**: global function
**Returns**: A string representing the formatted date
**Kind**: global function
**Returns**: A string representing the formatted date
| Param | Description |
| --- | --- |
| date | The date to format |
| Param | Description |
| ----- | ------------------ |
| date | The date to format |
<!--DOCS_END-->

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc