UNPKG

@lint-todo/utils

Version:

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

73 lines 2.6 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); 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 { constructor() { this.unprocessed = new Set(); } unmatched(predicate = () => false) { return new Set([...this.unprocessed].filter((todoDatum) => predicate(todoDatum))); } add(todoDatum) { this.unprocessed.add(todoDatum); } 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) { let found; for (const todoDatum of this.unprocessed) { if (exactMatch(todoDataToFind, todoDatum)) { found = todoDatum; this.unprocessed.delete(todoDatum); break; } } return found; } fuzzyMatch(todoDataToFind) { let found; for (const todoDatum of this.unprocessed) { const hasSource = todoDataToFind.source && todoDatum.source; const sourceMatches = todoDataToFind.source === todoDatum.source; if (todoDataToFind.engine === todoDatum.engine && todoDataToFind.ruleId === todoDatum.ruleId && hasSource && sourceMatches) { found = todoDatum; this.unprocessed.delete(todoDatum); break; } } return found; } } exports.default = TodoMatcher; //# sourceMappingURL=todo-matcher.js.map