]> git.proxmox.com Git - pve-eslint.git/blob - eslint/tests/_utils/index.js
0431e3aced4afd3369cda54ac6cf6ab3c4f8c0c4
[pve-eslint.git] / eslint / tests / _utils / index.js
1 "use strict";
2
3 const {
4 defineInMemoryFs,
5 defineConfigArrayFactoryWithInMemoryFileSystem,
6 defineCascadingConfigArrayFactoryWithInMemoryFileSystem,
7 defineFileEnumeratorWithInMemoryFileSystem,
8 defineCLIEngineWithInMemoryFileSystem,
9 defineESLintWithInMemoryFileSystem
10 } = require("./in-memory-fs");
11
12
13 /**
14 * Prevents leading spaces in a multiline template literal from appearing in the resulting string
15 * @param {string[]} strings The strings in the template literal
16 * @param {any[]} values The interpolation values in the template literal.
17 * @returns {string} The template literal, with spaces removed from all lines
18 */
19 function unIndent(strings, ...values) {
20 const text = strings
21 .map((s, i) => (i === 0 ? s : values[i - 1] + s))
22 .join("");
23 const lines = text.replace(/^\n/u, "").replace(/\n\s*$/u, "").split("\n");
24 const lineIndents = lines.filter(line => line.trim()).map(line => line.match(/ */u)[0].length);
25 const minLineIndent = Math.min(...lineIndents);
26
27 return lines.map(line => line.slice(minLineIndent)).join("\n");
28 }
29
30
31 module.exports = {
32 unIndent,
33 defineInMemoryFs,
34 defineConfigArrayFactoryWithInMemoryFileSystem,
35 defineCascadingConfigArrayFactoryWithInMemoryFileSystem,
36 defineFileEnumeratorWithInMemoryFileSystem,
37 defineCLIEngineWithInMemoryFileSystem,
38 defineESLintWithInMemoryFileSystem
39 };