fisrt commit
This commit is contained in:
24
node_modules/prettier-linter-helpers/LICENSE.md
generated
vendored
Normal file
24
node_modules/prettier-linter-helpers/LICENSE.md
generated
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
# The MIT License (MIT)
|
||||
|
||||
Copyright © 2017 Andres Suarez and Teddy Katz
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation
|
||||
files (the “Software”), to deal in the Software without
|
||||
restriction, including without limitation the rights to use,
|
||||
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the
|
||||
Software is furnished to do so, subject to the following
|
||||
conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
||||
14
node_modules/prettier-linter-helpers/README.md
generated
vendored
Normal file
14
node_modules/prettier-linter-helpers/README.md
generated
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
# prettier-linter-helpers
|
||||
|
||||
Helper functions for exposing prettier changes within linting tools.
|
||||
|
||||
This package contains:
|
||||
|
||||
- `showInvisibles(string)` - Replace invisible characters with ones you can see for
|
||||
for easier diffing.
|
||||
- `generateDifferences(source, prettierSource)` - Generate an array of
|
||||
differences between two strings.
|
||||
|
||||
## Inspiration
|
||||
|
||||
This code was extracted from [eslint-plugin-prettier v2.7.0](https://github.com/prettier/eslint-plugin-prettier/blob/9fac6b4039c1983b83073fa7af7864f0d7e1f2d3/eslint-plugin-prettier.js#L85-L215)
|
||||
41
node_modules/prettier-linter-helpers/index.d.ts
generated
vendored
Normal file
41
node_modules/prettier-linter-helpers/index.d.ts
generated
vendored
Normal file
@ -0,0 +1,41 @@
|
||||
/**
|
||||
* Converts invisible characters to a commonly recognizable visible form.
|
||||
* @param {string} str - The string with invisibles to convert.
|
||||
* @returns {string} The converted string.
|
||||
*/
|
||||
export function showInvisibles(str: string): string;
|
||||
|
||||
export type Difference =
|
||||
| {
|
||||
operation: 'insert';
|
||||
insertText: string;
|
||||
offset: number;
|
||||
}
|
||||
| {
|
||||
operation: 'delete';
|
||||
deleteText: string;
|
||||
offset: number;
|
||||
}
|
||||
| {
|
||||
operation: 'replace';
|
||||
insertText: string;
|
||||
deleteText: string;
|
||||
offset: number;
|
||||
};
|
||||
|
||||
/**
|
||||
* Generate results for differences between source code and formatted version.
|
||||
*
|
||||
* @param {string} source - The original source.
|
||||
* @param {string} prettierSource - The Prettier formatted source.
|
||||
* @returns {Difference[]} - An array containing { operation, offset, insertText, deleteText }
|
||||
*/
|
||||
export function generateDifferences(
|
||||
source: string,
|
||||
prettierSource: string
|
||||
): Difference[];
|
||||
export namespace generateDifferences {
|
||||
let INSERT: 'insert';
|
||||
let DELETE: 'delete';
|
||||
let REPLACE: 'replace';
|
||||
}
|
||||
152
node_modules/prettier-linter-helpers/index.js
generated
vendored
Normal file
152
node_modules/prettier-linter-helpers/index.js
generated
vendored
Normal file
@ -0,0 +1,152 @@
|
||||
// @ts-check
|
||||
|
||||
const diff = require('fast-diff');
|
||||
|
||||
const LINE_ENDING_RE = /\r\n|[\r\n\u2028\u2029]/;
|
||||
|
||||
/**
|
||||
* Converts invisible characters to a commonly recognizable visible form.
|
||||
* @param {string} str - The string with invisibles to convert.
|
||||
* @returns {string} The converted string.
|
||||
*/
|
||||
function showInvisibles(str) {
|
||||
let ret = '';
|
||||
for (let i = 0; i < str.length; i++) {
|
||||
switch (str[i]) {
|
||||
case ' ':
|
||||
ret += '·'; // Middle Dot, \u00B7
|
||||
break;
|
||||
case '\n':
|
||||
ret += '⏎'; // Return Symbol, \u23ce
|
||||
break;
|
||||
case '\t':
|
||||
ret += '↹'; // Left Arrow To Bar Over Right Arrow To Bar, \u21b9
|
||||
break;
|
||||
case '\r':
|
||||
ret += '␍'; // Carriage Return Symbol, \u240D
|
||||
break;
|
||||
default:
|
||||
ret += str[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/** @typedef {({operation: 'insert'; insertText: string; offset: number;} | {operation: 'delete'; deleteText: string; offset: number;} | {operation: 'replace'; insertText: string; deleteText: string; offset: number;})} Difference */
|
||||
|
||||
/**
|
||||
* Generate results for differences between source code and formatted version.
|
||||
*
|
||||
* @param {string} source - The original source.
|
||||
* @param {string} prettierSource - The Prettier formatted source.
|
||||
* @returns {Difference[]} - An array containing { operation, offset, insertText, deleteText }
|
||||
*/
|
||||
function generateDifferences(source, prettierSource) {
|
||||
// fast-diff returns the differences between two texts as a series of
|
||||
// INSERT, DELETE or EQUAL operations. The results occur only in these
|
||||
// sequences:
|
||||
// /-> INSERT -> EQUAL
|
||||
// EQUAL | /-> EQUAL
|
||||
// \-> DELETE |
|
||||
// \-> INSERT -> EQUAL
|
||||
// Instead of reporting issues at each INSERT or DELETE, certain sequences
|
||||
// are batched together and are reported as a friendlier "replace" operation:
|
||||
// - A DELETE immediately followed by an INSERT.
|
||||
// - Any number of INSERTs and DELETEs where the joining EQUAL of one's end
|
||||
// and another's beginning does not have line endings (i.e. issues that occur
|
||||
// on contiguous lines).
|
||||
|
||||
const results = diff(source, prettierSource);
|
||||
|
||||
/** @type {Difference[]} */
|
||||
const differences = [];
|
||||
|
||||
/** @type {typeof results} */
|
||||
const batch = [];
|
||||
let offset = 0; // NOTE: INSERT never advances the offset.
|
||||
while (results.length) {
|
||||
const result = /** @type {typeof results[number]} */ (results.shift());
|
||||
const op = result[0];
|
||||
const text = result[1];
|
||||
switch (op) {
|
||||
case diff.INSERT:
|
||||
case diff.DELETE:
|
||||
batch.push(result);
|
||||
break;
|
||||
case diff.EQUAL:
|
||||
if (results.length) {
|
||||
if (batch.length) {
|
||||
if (LINE_ENDING_RE.test(text)) {
|
||||
flush();
|
||||
offset += text.length;
|
||||
} else {
|
||||
batch.push(result);
|
||||
}
|
||||
} else {
|
||||
offset += text.length;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new Error(`Unexpected fast-diff operation "${op}"`);
|
||||
}
|
||||
if (batch.length && !results.length) {
|
||||
flush();
|
||||
}
|
||||
}
|
||||
|
||||
return differences;
|
||||
|
||||
function flush() {
|
||||
let aheadDeleteText = '';
|
||||
let aheadInsertText = '';
|
||||
while (batch.length) {
|
||||
const next = /** @type {typeof batch[number]} */ (batch.shift());
|
||||
const op = next[0];
|
||||
const text = next[1];
|
||||
switch (op) {
|
||||
case diff.INSERT:
|
||||
aheadInsertText += text;
|
||||
break;
|
||||
case diff.DELETE:
|
||||
aheadDeleteText += text;
|
||||
break;
|
||||
case diff.EQUAL:
|
||||
aheadDeleteText += text;
|
||||
aheadInsertText += text;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (aheadDeleteText && aheadInsertText) {
|
||||
differences.push({
|
||||
offset,
|
||||
operation: generateDifferences.REPLACE,
|
||||
insertText: aheadInsertText,
|
||||
deleteText: aheadDeleteText,
|
||||
});
|
||||
} else if (!aheadDeleteText && aheadInsertText) {
|
||||
differences.push({
|
||||
offset,
|
||||
operation: generateDifferences.INSERT,
|
||||
insertText: aheadInsertText,
|
||||
});
|
||||
} else if (aheadDeleteText && !aheadInsertText) {
|
||||
differences.push({
|
||||
offset,
|
||||
operation: generateDifferences.DELETE,
|
||||
deleteText: aheadDeleteText,
|
||||
});
|
||||
}
|
||||
offset += aheadDeleteText.length;
|
||||
}
|
||||
}
|
||||
|
||||
generateDifferences.INSERT = /** @type {const} */ ('insert');
|
||||
generateDifferences.DELETE = /** @type {const} */ ('delete');
|
||||
generateDifferences.REPLACE = /** @type {const} */ ('replace');
|
||||
|
||||
module.exports = {
|
||||
showInvisibles,
|
||||
generateDifferences,
|
||||
};
|
||||
43
node_modules/prettier-linter-helpers/package.json
generated
vendored
Normal file
43
node_modules/prettier-linter-helpers/package.json
generated
vendored
Normal file
@ -0,0 +1,43 @@
|
||||
{
|
||||
"name": "prettier-linter-helpers",
|
||||
"version": "1.0.1",
|
||||
"description": "Utilities to help expose prettier output in linting tools",
|
||||
"contributors": [
|
||||
"Ben Scott",
|
||||
"Teddy Katz"
|
||||
],
|
||||
"main": "index.js",
|
||||
"types": "index.d.ts",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/prettier/prettier-linter-helpers.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/prettier/prettier-linter-helpers/issues"
|
||||
},
|
||||
"homepage": "https://github.com/prettier/prettier-linter-helpers#readme",
|
||||
"files": [
|
||||
"index.js",
|
||||
"index.d.ts"
|
||||
],
|
||||
"dependencies": {
|
||||
"fast-diff": "^1.1.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/js": "^9.39.2",
|
||||
"eslint": "^9.39.2",
|
||||
"eslint-config-prettier": "^10.1.8",
|
||||
"eslint-plugin-n": "^17.23.1 ",
|
||||
"eslint-plugin-prettier": "^5.5.4",
|
||||
"prettier": "^3.7.4"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6.0.0"
|
||||
},
|
||||
"scripts": {
|
||||
"lint": "eslint . && prettier . --check",
|
||||
"test": "node --test test/*.test.js",
|
||||
"format": "eslint . --fix && prettier '**/*.{js,json,md,yml}' --write"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user