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

![CI Build](https://github.com/ember-template-lint/ember-template-lint-todo-utils/workflows/CI%20Build/badge.svg) [![npm version](https://badge.fury.io/js/%40ember-template-lint%2Ftodo-utils.svg)](https://badge.fury.io/js/%40ember-template-lint%2Ftodo-uti

  • 10.0.0-beta.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
17K
increased by9.24%
Maintainers
4
Weekly downloads
 
Created
Source

@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

buildTodoData(baseDir, lintResults, todoConfig)

Adapts a list of LintResult to a map of TodoFileHash, TodoData.

buildTodoDatum(lintResult, lintMessage, todoConfig)

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

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 4 maps containing todo items to add, remove, those that are expired, 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.

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

buildTodoData(baseDir, lintResults, todoConfig) ⇒

Adapts a list of LintResult to a map of TodoFileHash, TodoData.

Kind: global function
Returns: - A Promise resolving to a Set of TodoData.

ParamDescription
baseDirThe base directory that contains the .lint-todo storage directory.
lintResultsA list of LintResult objects to convert to TodoData objects.
todoConfigAn object containing the warn or error days, in integers.

buildTodoDatum(lintResult, lintMessage, todoConfig) ⇒

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.

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.

todoStorageDirExists(baseDir) ⇒

Determines if the .lint-todo storage directory exists.

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

ParamDescription
baseDirThe 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.

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

getTodoStorageDirPath(baseDir) ⇒

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

ParamDescription
baseDirThe 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.

ParamDescription
baseDirThe base directory that contains the .lint-todo storage directory.
todoDataThe 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.

ParamDescription
filePathThe 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.

ParamDescription
todoDataThe linting data for an individual violation.

writeTodos(baseDir, lintResults, 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.
lintResultsThe raw linting data.
optionsAn object containing write options.

readTodos(baseDir) ⇒

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

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

ParamDescription
baseDirThe 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 Map of TodoFilePathHash/TodoMatcher.

ParamDescription
todoStorageDirThe .lint-todo storage directory.
filePathThe relative file path of the file to return todo items for.

getTodoBatches(lintResults, existing) ⇒

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: - A Map of TodoFileHash/TodoData.

ParamDescription
lintResultsThe linting data for all violations.
existingExisting todo lint data.

applyTodoChanges(todoStorageDir, add, remove)

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

Kind: global function

ParamDescription
todoStorageDirThe .lint-todo storage directory.
addBatch of todos to add.
removeBatch of todos to remove.

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

FAQs

Package last updated on 23 Jul 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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