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

@ember-template-lint/pending-utils

Package Overview
Dependencies
Maintainers
4
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

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

Comparing version 1.0.0 to 2.0.0

lib/set-utils.d.ts

9

CHANGELOG.md

@@ -0,1 +1,10 @@

## v2.0.0 (2020-10-02)
#### :boom: Breaking Change
* [#9](https://github.com/ember-template-lint/ember-template-lint-pending-utils/pull/9) Cleanup of APIs/batch generation ([@scalvert](https://github.com/scalvert))
#### Committers: 1
- Steve Calvert ([@scalvert](https://github.com/scalvert))
## v1.0.0 (2020-10-01)

@@ -2,0 +11,0 @@

2

lib/index.d.ts
export { buildPendingLintMessage, buildPendingLintMessages } from './builders';
export { ensurePendingDir, getPendingDirPath, generateFileName, generatePendingFiles, updatePendingForFile, readPendingFiles, } from './io';
export { ensurePendingDir, getPendingDirPath, generateFileName, generatePendingFiles, readPendingFiles, getPendingBatches, _getPendingMap, } from './io';
//# sourceMappingURL=index.d.ts.map

@@ -11,4 +11,5 @@ "use strict";

Object.defineProperty(exports, "generatePendingFiles", { enumerable: true, get: function () { return io_1.generatePendingFiles; } });
Object.defineProperty(exports, "updatePendingForFile", { enumerable: true, get: function () { return io_1.updatePendingForFile; } });
Object.defineProperty(exports, "readPendingFiles", { enumerable: true, get: function () { return io_1.readPendingFiles; } });
Object.defineProperty(exports, "getPendingBatches", { enumerable: true, get: function () { return io_1.getPendingBatches; } });
Object.defineProperty(exports, "_getPendingMap", { enumerable: true, get: function () { return io_1._getPendingMap; } });
//# sourceMappingURL=index.js.map

@@ -24,18 +24,20 @@ import { PendingLintMessage } from './types';

* @param pendingLintMessages The linting data for all violations.
* @param filePath? The absolute file path of the file to update violations for.
*/
export declare function generatePendingFiles(baseDir: string, pendingLintMessages: PendingLintMessage[]): Promise<string>;
export declare function generatePendingFiles(baseDir: string, pendingLintMessages: PendingLintMessage[], filePath?: string): Promise<string>;
/**
* Updates violations for a single file.
* Reads all pending files in the .lint-pending directory.
*
* @param baseDir The base directory that contains the .lint-pending storage directory.
* @param filePath The absolute file path of the file to update violations for.
* @param pendingLintMessages The linting data for all violations.
* @param filePath? The absolute file path of the file to return pending items for.
*/
export declare function updatePendingForFile(baseDir: string, filePath: string, pendingLintMessages: PendingLintMessage[]): Promise<string>;
export declare function readPendingFiles(pendingDir: string, filePath?: string): Promise<Map<string, PendingLintMessage>>;
/**
* Reads all pending files in the .lint-pending directory.
* Gets 3 maps containing pending items to add, remove, or those that are stable (not to be modified).
*
* @param baseDir The base directory that contains the .lint-pending storage directory.
* @param lintResults The linting data for all violations.
* @param existing Existing pending lint data.
*/
export declare function readPendingFiles(baseDir: string): Promise<PendingLintMessage[]>;
export declare function getPendingBatches(lintResults: Map<string, PendingLintMessage>, existing: Map<string, PendingLintMessage>): Promise<Map<string, PendingLintMessage>[]>;
export declare function _getPendingMap(pendingLintMessages: PendingLintMessage[]): Map<string, PendingLintMessage>;
//# sourceMappingURL=io.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.readPendingFiles = exports.updatePendingForFile = exports.generatePendingFiles = exports.generateFileName = exports.getPendingDirPath = exports.ensurePendingDir = void 0;
exports._getPendingMap = exports.getPendingBatches = exports.readPendingFiles = exports.generatePendingFiles = exports.generateFileName = exports.getPendingDirPath = exports.ensurePendingDir = void 0;
const crypto_1 = require("crypto");
const path_1 = require("path");
const fs_extra_1 = require("fs-extra");
const extra_set_1 = require("extra-set");
/**

@@ -42,60 +41,77 @@ * Creates, or ensures the creation of, the .lint-pending directory.

* @param pendingLintMessages The linting data for all violations.
* @param filePath? The absolute file path of the file to update violations for.
*/
async function generatePendingFiles(baseDir, pendingLintMessages) {
const path = await ensurePendingDir(baseDir);
const existingPendingItemFilenames = new Set((await fs_extra_1.readdir(path)).map((fileName) => path_1.parse(fileName).name));
await _generateFiles(baseDir, pendingLintMessages, existingPendingItemFilenames);
return path;
async function generatePendingFiles(baseDir, pendingLintMessages, filePath) {
const pendingDir = await ensurePendingDir(baseDir);
const existing = await readPendingFiles(pendingDir, filePath);
const [add, remove] = await getPendingBatches(_getPendingMap(pendingLintMessages), existing);
await _generateFiles(baseDir, add, remove);
return pendingDir;
}
exports.generatePendingFiles = generatePendingFiles;
/**
* Updates violations for a single file.
* Reads all pending files in the .lint-pending directory.
*
* @param baseDir The base directory that contains the .lint-pending storage directory.
* @param filePath The absolute file path of the file to update violations for.
* @param pendingLintMessages The linting data for all violations.
* @param filePath? The absolute file path of the file to return pending items for.
*/
async function updatePendingForFile(baseDir, filePath, pendingLintMessages) {
const path = await ensurePendingDir(baseDir);
const pendingLintFiles = await readPendingFiles(baseDir);
const existingPendingItemFilenames = new Set(pendingLintFiles
.filter((pendingFile) => pendingFile.filePath === filePath)
.map((pendingLintMessage) => generateFileName(pendingLintMessage)));
await _generateFiles(baseDir, pendingLintMessages, existingPendingItemFilenames);
return path;
async function readPendingFiles(pendingDir, filePath) {
const fileNames = await fs_extra_1.readdir(pendingDir);
const map = new Map();
for (const fileName of fileNames) {
const pendingLintMessage = await fs_extra_1.readJSON(path_1.join(pendingDir, fileName));
if (filePath && pendingLintMessage.filePath !== filePath) {
continue;
}
map.set(path_1.parse(fileName).name, pendingLintMessage);
}
return map;
}
exports.updatePendingForFile = updatePendingForFile;
exports.readPendingFiles = readPendingFiles;
/**
* Reads all pending files in the .lint-pending directory.
* Gets 3 maps containing pending items to add, remove, or those that are stable (not to be modified).
*
* @param baseDir The base directory that contains the .lint-pending storage directory.
* @param lintResults The linting data for all violations.
* @param existing Existing pending lint data.
*/
async function readPendingFiles(baseDir) {
const pendingDir = getPendingDirPath(baseDir);
const fileNames = await fs_extra_1.readdir(pendingDir);
return await Promise.all(fileNames.map(async (fileName) => {
return await fs_extra_1.readJSON(path_1.join(pendingDir, fileName));
}));
async function getPendingBatches(lintResults, existing) {
const add = new Map();
const remove = new Map();
const stable = new Map();
for (const [fileHash, pendingLintMessage] of lintResults) {
if (!existing.has(fileHash)) {
add.set(fileHash, pendingLintMessage);
}
else {
stable.set(fileHash, pendingLintMessage);
}
}
for (const [fileHash, pendingLintMessage] of existing) {
if (!lintResults.has(fileHash)) {
remove.set(fileHash, pendingLintMessage);
}
else {
stable.set(fileHash, pendingLintMessage);
}
}
return [add, remove, stable];
}
exports.readPendingFiles = readPendingFiles;
async function _generateFiles(baseDir, pendingLintMessages, existingPendingItemFilenames) {
exports.getPendingBatches = getPendingBatches;
async function _generateFiles(baseDir, add, remove) {
const path = getPendingDirPath(baseDir);
const pendingLintMessagesMap = pendingLintMessages.reduce((map, currentLintMessage) => {
const fileName = generateFileName(currentLintMessage);
map.set(fileName, currentLintMessage);
return map;
}, new Map());
const pendingFileNamesToWrite = extra_set_1.difference(new Set(pendingLintMessagesMap.keys()), existingPendingItemFilenames);
const pendingFileNamesToDelete = extra_set_1.difference(existingPendingItemFilenames, new Set(pendingLintMessagesMap.keys()));
for (const fileName of pendingFileNamesToWrite) {
const pendingLintMessage = pendingLintMessagesMap.get(fileName);
if (pendingLintMessage) {
// eslint-disable-next-line unicorn/no-null
await fs_extra_1.writeFile(path_1.join(path, `${fileName}.json`), JSON.stringify(pendingLintMessage, null, 2));
}
for (const [fileHash, pendingLintMessage] of add) {
// eslint-disable-next-line unicorn/no-null
await fs_extra_1.writeFile(path_1.join(path, `${fileHash}.json`), JSON.stringify(pendingLintMessage, null, 2));
}
for (const fileName of pendingFileNamesToDelete) {
await fs_extra_1.unlink(path_1.join(path, `${fileName}.json`));
for (const [fileHash] of remove) {
await fs_extra_1.unlink(path_1.join(path, `${fileHash}.json`));
}
}
function _getPendingMap(pendingLintMessages) {
return new Map(pendingLintMessages.map((currentLintMessage) => {
const fileName = generateFileName(currentLintMessage);
return [fileName, currentLintMessage];
}));
}
exports._getPendingMap = _getPendingMap;
//# sourceMappingURL=io.js.map
{
"name": "@ember-template-lint/pending-utils",
"version": "1.0.0",
"version": "2.0.0",
"repository": "https://github.com/ember-template-lint/ember-template-lint-pending-utils.git",

@@ -18,3 +18,2 @@ "license": "MIT",

"dependencies": {
"extra-set": "^2.2.4",
"fs-extra": "^9.0.1"

@@ -21,0 +20,0 @@ },

@@ -22,3 +22,3 @@ # @ember-template-lint/pending-utils

</dd>
<dt><a href="#generatePendingFiles">generatePendingFiles(baseDir, pendingLintMessages)</a></dt>
<dt><a href="#generatePendingFiles">generatePendingFiles(baseDir, pendingLintMessages, filePath?)</a></dt>
<dd><p>Generates files for pending lint violations. One file is generated for each violation, using a generated

@@ -29,8 +29,8 @@ hash to identify each.</p>

</dd>
<dt><a href="#updatePendingForFile">updatePendingForFile(baseDir, filePath, pendingLintMessages)</a></dt>
<dd><p>Updates violations for a single file.</p>
</dd>
<dt><a href="#readPendingFiles">readPendingFiles(baseDir)</a></dt>
<dt><a href="#readPendingFiles">readPendingFiles(baseDir, filePath?)</a></dt>
<dd><p>Reads all pending files in the .lint-pending directory.</p>
</dd>
<dt><a href="#getPendingBatches">getPendingBatches(lintResults, existing)</a></dt>
<dd><p>Gets 3 maps containing pending items to add, remove, or those that are stable (not to be modified).</p>
</dd>
</dl>

@@ -85,3 +85,3 @@

## generatePendingFiles(baseDir, pendingLintMessages)
## generatePendingFiles(baseDir, pendingLintMessages, filePath?)

@@ -100,27 +100,28 @@ Generates files for pending lint violations. One file is generated for each violation, using a generated

| pendingLintMessages | The linting data for all violations. |
| filePath? | The absolute file path of the file to update violations for. |
<a name="updatePendingForFile"></a>
<a name="readPendingFiles"></a>
## updatePendingForFile(baseDir, filePath, pendingLintMessages)
## readPendingFiles(baseDir, filePath?)
Updates violations for a single file.
Reads all pending files in the .lint-pending directory.
**Kind**: global function
| Param | Description |
| ------------------- | --------------------------------------------------------------------- |
| baseDir | The base directory that contains the .lint-pending storage directory. |
| filePath | The absolute file path of the file to update violations for. |
| pendingLintMessages | The linting data for all violations. |
| Param | Description |
| --------- | --------------------------------------------------------------------- |
| baseDir | The base directory that contains the .lint-pending storage directory. |
| filePath? | The absolute file path of the file to return pending items for. |
<a name="readPendingFiles"></a>
<a name="getPendingBatches"></a>
## readPendingFiles(baseDir)
## getPendingBatches(lintResults, existing)
Reads all pending files in the .lint-pending directory.
Gets 3 maps containing pending items to add, remove, or those that are stable (not to be modified).
**Kind**: global function
| Param | Description |
| ------- | --------------------------------------------------------------------- |
| baseDir | The base directory that contains the .lint-pending storage directory. |
| Param | Description |
| ----------- | ------------------------------------ |
| lintResults | The linting data for all violations. |
| existing | Existing pending lint data. |

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