@ember-template-lint/todo-utils

中文文档
11.0.0发布于 2021/12/03MITTypeScriptCommonJS近 30 天下载 6.3万
原始使用文档
文档目录25 节
  1. Functions
  2. buildTodoDatum(lintResult, lintMessage, todoConfig) ⇒
  3. todoStorageFileExists(baseDir) ⇒
  4. ensureTodoStorageFile(baseDir) ⇒
  5. getTodoStorageFilePath(baseDir) ⇒
  6. hasConflicts(todoContents) ⇒
  7. resolveConflicts(operations) ⇒
  8. readTodoStorageFile(todoStorageFilePath) ⇒
  9. writeTodoStorageFile(todoStorageFilePath, operations)
  10. writeTodos(baseDir, maybeTodos, options) ⇒
  11. readTodos(baseDir, shouldLock) ⇒
  12. readTodosForFilePath(todoStorageDir, filePath, shouldLock) ⇒
  13. readTodoData(baseDir) ⇒
  14. getTodoBatches(maybeTodos, existing, options) ⇒
  15. applyTodoChanges(baseDir, add, remove, shouldLock)
  16. ADD_OPERATIONS_ONLY(operation) ⇒
  17. EXCLUDE_EXPIRED(operation) ⇒
  18. compactTodoStorageFile(baseDir, compactStrategy) ⇒
  19. getTodoConfig(baseDir, engine, customDaysToDecay) ⇒
  20. validateConfig(baseDir) ⇒
  21. getSeverity(todo, today) ⇒
  22. isExpired(date, today) ⇒
  23. getDatePart(date) ⇒
  24. differenceInDays(startDate, endDate) ⇒
  25. format(date) ⇒

@ember-template-lint/todo-utils

CI Build npm version License Dependabot Volta Managed TypeScript Code Style: prettier

A collection of utilities to generate and store lint item metadata.

Those utilities are:

Functions

buildTodoDatum(lintResult, lintMessage, todoConfig) ⇒

Adapts a LintResult to a TodoData. FilePaths are absolute when received from a lint result, so they're converted to relative paths for stability in serializing the contents to disc.

todoStorageFileExists(baseDir) ⇒

Determines if the .lint-todo storage file exists.

ensureTodoStorageFile(baseDir) ⇒

Creates, or ensures the creation of, the .lint-todo file.

getTodoStorageFilePath(baseDir) ⇒
hasConflicts(todoContents) ⇒

Determines if the .lint-todo storage file has conflicts.

resolveConflicts(operations) ⇒

Resolves git conflicts in todo operations by removing any lines that match conflict markers.

readTodoStorageFile(todoStorageFilePath) ⇒

Reads the .lint-todo storage file.

writeTodoStorageFile(todoStorageFilePath, operations)

Writes the operations to the .lint-todo storage file to the path provided by todoStorageFilePath.

writeTodos(baseDir, maybeTodos, options) ⇒

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.

readTodos(baseDir, shouldLock) ⇒

Reads all todo files in the .lint-todo directory.

readTodosForFilePath(todoStorageDir, filePath, shouldLock) ⇒

Reads todo files in the .lint-todo directory for a specific filePath.

readTodoData(baseDir) ⇒

Reads todo files in the .lint-todo directory and returns Todo data in an array.

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).

applyTodoChanges(baseDir, add, remove, shouldLock)

Applies todo changes, either adding or removing, based on batches from getTodoBatches.

ADD_OPERATIONS_ONLY(operation) ⇒

Compact strategy to leave only add operations in the todo storage file.

EXCLUDE_EXPIRED(operation) ⇒

Compact strategy to remove all expired operations from the todo storage file.

compactTodoStorageFile(baseDir, compactStrategy) ⇒

Compacts the .lint-todo storage file based on the compact strategy.

getTodoConfig(baseDir, engine, customDaysToDecay) ⇒

Gets the todo configuration. Config values can be present in

The package.json

validateConfig(baseDir) ⇒

Validates whether we have a unique config in a single location.

getSeverity(todo, today) ⇒

Returns the correct severity level based on the todo data's decay dates.

isExpired(date, today) ⇒

Evaluates whether a date is expired (earlier than today)

getDatePart(date) ⇒

Converts a date to include year, month, and day values only (time is zeroed out).

differenceInDays(startDate, endDate) ⇒

Returns the difference in days between two dates.

format(date) ⇒

Formats the date in short form, eg. 2021-01-01

buildTodoDatum(lintResult, lintMessage, todoConfig) ⇒

Adapts a LintResult to a TodoData. 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 TodoData object.

ParamDescription
lintResultThe lint result object.
lintMessageA lint message object representing a specific violation for a file.
todoConfigAn object containing the warn or error days, in integers.

todoStorageFileExists(baseDir) ⇒

Determines if the .lint-todo storage file exists.

Kind: global function
Returns: - true if the todo storage file exists, otherwise false.

ParamDescription
baseDirThe base directory that contains the .lint-todo storage file.

ensureTodoStorageFile(baseDir) ⇒

Creates, or ensures the creation of, the .lint-todo file.

Kind: global function
Returns: - The todo storage file path.

ParamDescription
baseDirThe base directory that contains the .lint-todo storage file.

getTodoStorageFilePath(baseDir) ⇒

Kind: global function
Returns: - The todo storage file path.

ParamDescription
baseDirThe base directory that contains the .lint-todo storage file.

hasConflicts(todoContents) ⇒

Determines if the .lint-todo storage file has conflicts.

Kind: global function
Returns: true if the file has conflicts, otherwise false.

ParamDescription
todoContentsThe unparsed contents of the .lint-todo file.

resolveConflicts(operations) ⇒

Resolves git conflicts in todo operations by removing any lines that match conflict markers.

Kind: global function
Returns: An array of string operations excluding any operations that were identified as git conflict lines.

ParamDescription
operationsAn array of string operations that are used to recreate todos.

readTodoStorageFile(todoStorageFilePath) ⇒

Reads the .lint-todo storage file.

Kind: global function
Returns: A array of todo operations.

ParamDescription
todoStorageFilePathThe .lint-todo storage file path.

writeTodoStorageFile(todoStorageFilePath, operations)

Writes the operations to the .lint-todo storage file to the path provided by todoStorageFilePath.

Kind: global function

ParamDescription
todoStorageFilePathThe .lint-todo storage file path.
operationsAn array of string operations that are used to recreate todos.

writeTodos(baseDir, maybeTodos, options) ⇒

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.

Kind: global function
Returns: - The counts of added and removed todos.

ParamDescription
baseDirThe base directory that contains the .lint-todo storage directory.
maybeTodosThe linting data, converted to TodoData format.
optionsAn object containing write options.

readTodos(baseDir, shouldLock) ⇒

Reads all todo files in the .lint-todo directory.

Kind: global function
Returns: - A Map of FilePath/TodoMatcher.

ParamDefaultDescription
baseDirThe base directory that contains the .lint-todo storage directory.
shouldLocktrueTrue if the .lint-todo storage file should be locked, otherwise false. Default: true.

readTodosForFilePath(todoStorageDir, filePath, shouldLock) ⇒

Reads todo files in the .lint-todo directory for a specific filePath.

Kind: global function
Returns: - A Map of FilePath/TodoMatcher.

ParamDescription
todoStorageDirThe .lint-todo storage directory.
filePathThe relative file path of the file to return todo items for.
shouldLockTrue if the .lint-todo storage file should be locked, otherwise false. Default: true.

readTodoData(baseDir) ⇒

Reads todo files in the .lint-todo directory and returns Todo data in an array.

Kind: global function
Returns: An array of TodoData

ParamDescription
baseDirThe base directory that contains the .lint-todo storage directory.

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.

ParamDescription
maybeTodosThe linting data for violations.
existingExisting todo lint data.
optionsAn object containing write options.

applyTodoChanges(baseDir, add, remove, shouldLock)

Applies todo changes, either adding or removing, based on batches from getTodoBatches.

Kind: global function

ParamDefaultDescription
baseDirThe base directory that contains the .lint-todo storage directory.
addBatch of todos to add.
removeBatch of todos to remove.
shouldLocktrueTrue if the .lint-todo storage file should be locked, otherwise false. Default: true.

ADD_OPERATIONS_ONLY(operation) ⇒

Compact strategy to leave only add operations in the todo storage file.

Kind: global function
Returns: True if the line matches an add operation, otherwise false.

ParamDescription
operationThe single line operation read from the todo storage file.

EXCLUDE_EXPIRED(operation) ⇒

Compact strategy to remove all expired operations from the todo storage file.

Kind: global function
Returns: True if the operation is not expired, otherwise false.

ParamDescription
operationThe single line operation read from the todo storage file.

compactTodoStorageFile(baseDir, compactStrategy) ⇒

Compacts the .lint-todo storage file based on the compact strategy.

Kind: global function
Returns: The count of compacted todos.

ParamDescription
baseDirThe base directory that contains the .lint-todo storage directory.
compactStrategyThe strategy to use when compacting the storage file. Default: ADD_OPERATIONS_ONLY

getTodoConfig(baseDir, engine, customDaysToDecay) ⇒

Gets the todo configuration. Config values can be present in

The package.json

Kind: global function
Returns: - The todo config object.

ParamDescription
baseDirThe base directory that contains the project's package.json.
engineThe engine for this configuration, eg. eslint
customDaysToDecayThe optional custom days to decay configuration.

Example

{
  "lintTodo": {
    "some-engine": {
      "daysToDecay": {
        "warn": 5,
        "error": 10
      },
      "daysToDecayByRule": {
        "no-bare-strings": { "warn": 10, "error": 20 }
      }
    }
  }
}

A .lint-todorc.js file Example

module.exports = {
  "some-engine": {
    "daysToDecay": {
      "warn": 5,
      "error": 10
    },
    "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

Passed in directly, such as from command line options. - Passed in options override both env vars and package.json config

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

ParamDescription
baseDirThe base directory that contains the project's package.json.

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.

ParamDescription
todoThe todo data.
todayA number representing a date (UNIX Epoch - milliseconds)

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

ParamDescription
dateThe date to evaluate
todayA number representing a date (UNIX Epoch - milliseconds)

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'

ParamDescription
dateThe date to convert

differenceInDays(startDate, endDate) ⇒

Returns the difference in days between two dates.

Kind: global function
Returns: a number representing the days between the dates

ParamDescription
startDateThe start date
endDateThe end date

format(date) ⇒

Formats the date in short form, eg. 2021-01-01

Kind: global function
Returns: A string representing the formatted date

ParamDescription
dateThe date to format

版本与发布记录

@ember-template-lint/todo-utils 共发布 37 个版本,首次发布于 2020/10/16;过去 12 个月发布了 0 个版本。

版本发布日期距今
11.0.0latest2021/12/034 年前
11.0.0-beta.1beta2021/12/034 年前
11.0.0-beta.02021/12/024 年前
11.0.0-alpha.0alpha2021/11/304 年前
10.0.02021/08/155 年前
10.0.0-beta.52021/08/135 年前

关于 @ember-template-lint/todo-utils 的常见问题

@ember-template-lint/todo-utils 是什么?

[](https://badge.fury.io/js/%40ember-template-lint%2Ftodo-uti

如何安装 @ember-template-lint/todo-utils?

在项目目录运行 npm install @ember-template-lint/todo-utils,或使用 pnpm add / yarn add / bun add。

@ember-template-lint/todo-utils 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@ember-template-lint/todo-utils 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@ember-template-lint/todo-utils 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js 12.* || >= 14。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@ember-template-lint/todo-utils 可以商用吗?

@ember-template-lint/todo-utils 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@ember-template-lint/todo-utils 的下载量有多少?

根据 npm 官方下载统计,@ember-template-lint/todo-utils 在 2026/10/14 – 2026/11/12 这 30 天内被下载 63,172 次,日均约 2,106 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@ember-template-lint/todo-utils 还在维护吗?

最新版本 11.0.0 发布于 2021/12/03(4 年前);至今共发布 37 个版本,其中过去 12 个月发布了 0 个;首次发布于 2020/10/16。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。