mirror of
https://github.com/hanzoai/eslint.git
synced 2026-10-30 19:38:10 +00:00
* chore: remove formatting-related lint rules internally * chore: formatted files with Prettier via trunk fmt * rm .prettierrc.json * chore: correct comment directives and formatting * Apply introduced fmt changes post-merge * Also disable MD010 and MD030 in preparation for 19355 * Also disable MD013 in preparation for 19355 * Updated tools/update-rule-type-headers.js to print tabs * Fix introduced issues from the main merge * Manually format conf/*.json * Switch conf/*.json files back to two spaces, per prettier config * chore: empty commit to hopefully unblock GitHub
70 lines
2.2 KiB
JavaScript
70 lines
2.2 KiB
JavaScript
/**
|
|
* @fileoverview Utilities used in tests
|
|
*/
|
|
|
|
"use strict";
|
|
|
|
//-----------------------------------------------------------------------------
|
|
// Requirements
|
|
//-----------------------------------------------------------------------------
|
|
|
|
const { createTeardown, addFile } = require("fs-teardown");
|
|
|
|
//-----------------------------------------------------------------------------
|
|
// Helpers
|
|
//-----------------------------------------------------------------------------
|
|
|
|
/**
|
|
* Prevents leading spaces in a multiline template literal from appearing in the resulting string
|
|
* @param {string[]} strings The strings in the template literal
|
|
* @param {any[]} values The interpolation values in the template literal.
|
|
* @returns {string} The template literal, with spaces removed from all lines
|
|
*/
|
|
function unIndent(strings, ...values) {
|
|
const text = strings
|
|
.map((s, i) => (i === 0 ? s : values[i - 1] + s))
|
|
.join("");
|
|
const lines = text
|
|
.replace(/^\n/u, "")
|
|
.replace(/\n\s*$/u, "")
|
|
.split("\n");
|
|
const lineIndents = lines
|
|
.filter(line => line.trim())
|
|
.map(line => line.match(/ */u)[0].length);
|
|
const minLineIndent = Math.min(...lineIndents);
|
|
|
|
return lines.map(line => line.slice(minLineIndent)).join("\n");
|
|
}
|
|
|
|
/**
|
|
* @typedef {Pick<ReturnType<typeof createTeardown>, "getPath" | "cleanup" | "prepare">} Teardown
|
|
*/
|
|
|
|
/**
|
|
* Creates a new filesystem volume at the given location with the given files.
|
|
* @param {Object} desc A description of the filesystem volume to create.
|
|
* @param {string} desc.cwd The current working directory ESLint is using.
|
|
* @param {Record<string, string>} desc.files A map of filename to file contents to create.
|
|
* @returns {Teardown} An object with prepare(), cleanup(), and getPath()
|
|
* methods.
|
|
*/
|
|
function createCustomTeardown({ cwd, files }) {
|
|
const { prepare, cleanup, getPath } = createTeardown(
|
|
cwd,
|
|
...Object.keys(files).map(filename =>
|
|
addFile(filename, files[filename]),
|
|
),
|
|
);
|
|
|
|
return { prepare, cleanup, getPath };
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
// Exports
|
|
//-----------------------------------------------------------------------------
|
|
|
|
module.exports = {
|
|
unIndent,
|
|
createCustomTeardown,
|
|
};
|