@ember-template-lint/todo-utils
A collection of utilities to generate and store lint item metadata.
Those utilities are:
Functions
- buildTodoData(baseDir, lintResults, daysToDecay) ⇒
Adapts a list of LintResult to a map of FilePath, TodoData.
- _buildTodoDatum(lintResult, lintMessage, daysToDecay) ⇒
Adapts an 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.
- todoStorageDirExists(baseDir) ⇒
Determines if the .lint-todo storage directory exists.
- ensureTodoStorageDir(baseDir) ⇒
Creates, or ensures the creation of, the .lint-todo directory.
- getTodoStorageDirPath(baseDir) ⇒
- todoFilePathFor(baseDir, todoData) ⇒
Creates a file path from the linting data. Excludes extension.
- todoDirFor(filePath) ⇒
Creates a short hash for the todo's file path.
- todoFileNameFor(todoData) ⇒
Generates a unique filename for a todo lint data.
- writeTodos(baseDir, lintResults, filePath, daysToDecay) ⇒
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) ⇒
Reads all todo files in the .lint-todo directory.
- readTodosForFilePath(todoStorageDir, filePath) ⇒
Reads todo files in the .lint-todo directory for a specific filePath.
- getTodoBatches(lintResults, existing) ⇒
Gets 3 maps containing todo items to add, remove, or those that are stable (not to be modified).
- applyTodoChanges(todoStorageDir, add, remove)
Applies todo changes, either adding or removing, based on batches from getTodoBatches
.
buildTodoData(baseDir, lintResults, daysToDecay) ⇒
Adapts a list of LintResult to a map of FilePath, TodoData.
Kind: global function
Returns: - A Promise resolving to a Map of FilePath/TodoData.
Param | Description |
---|
baseDir | The base directory that contains the .lint-todo storage directory. |
lintResults | A list of LintResult objects to convert to TodoData objects. |
daysToDecay | An object containing the warn or error days, in integers. |
_buildTodoDatum(lintResult, lintMessage, daysToDecay) ⇒
Adapts an 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.
Param | Description |
---|
lintResult | The lint result object. |
lintMessage | A lint message object representing a specific violation for a file. |
daysToDecay | An object containing the warn or error days, in integers. |
todoStorageDirExists(baseDir) ⇒
Determines if the .lint-todo storage directory exists.
Kind: global function
Returns: - true if the todo storage directory exists, otherwise false.
Param | Description |
---|
baseDir | The base directory that contains the .lint-todo storage directory. |
ensureTodoStorageDir(baseDir) ⇒
Creates, or ensures the creation of, the .lint-todo directory.
Kind: global function
Returns: - The todo storage directory path.
Param | Description |
---|
baseDir | The base directory that contains the .lint-todo storage directory. |
getTodoStorageDirPath(baseDir) ⇒
Kind: global function
Returns: - The todo storage directory path.
Param | Description |
---|
baseDir | The base directory that contains the .lint-todo storage directory. |
todoFilePathFor(baseDir, todoData) ⇒
Creates a file path from the linting data. Excludes extension.
Kind: global function
Returns: - The todo file path for a TodoData object.
Param | Description |
---|
baseDir | The base directory that contains the .lint-todo storage directory. |
todoData | The linting data for an individual violation. |
Example
42b8532cff6da75c5e5895a6f33522bf37418d0c/6e3be839
todoDirFor(filePath) ⇒
Creates a short hash for the todo's file path.
Kind: global function
Returns: - The todo directory for a specific filepath.
Param | Description |
---|
filePath | The filePath from linting data for an individual violation. |
todoFileNameFor(todoData) ⇒
Generates a unique filename for a todo lint data.
Kind: global function
Returns: - The todo file name for a TodoData object.
Param | Description |
---|
todoData | The linting data for an individual violation. |
writeTodos(baseDir, lintResults, filePath, daysToDecay) ⇒
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 todo storage directory path.
Param | Description |
---|
baseDir | The base directory that contains the .lint-todo storage directory. |
lintResults | The raw linting data. |
filePath | The relative file path of the file to update violations for. |
daysToDecay | An object containing the warn or error days, in integers. |
readTodos(baseDir) ⇒
Reads all todo files in the .lint-todo directory.
Kind: global function
Returns: - A Promise resolving to a Map of FilePath/TodoData.
Param | Description |
---|
baseDir | The base directory that contains the .lint-todo storage directory. |
readTodosForFilePath(todoStorageDir, filePath) ⇒
Reads todo files in the .lint-todo directory for a specific filePath.
Kind: global function
Returns: - A Promise resolving to a Map of FilePath/TodoData.
Param | Description |
---|
todoStorageDir | The .lint-todo storage directory. |
filePath | The relative file path of the file to return todo items for. |
getTodoBatches(lintResults, existing) ⇒
Gets 3 maps containing todo items to add, remove, or those that are stable (not to be modified).
Kind: global function
Returns: - A Promise resolving to a Map of FilePath/TodoData.
Param | Description |
---|
lintResults | The linting data for all violations. |
existing | Existing todo lint data. |
applyTodoChanges(todoStorageDir, add, remove)
Applies todo changes, either adding or removing, based on batches from getTodoBatches
.
Kind: global function
Param | Description |
---|
todoStorageDir | The .lint-todo storage directory. |
add | Batch of todos to add. |
remove | Batch of todos to remove. |