2 * @fileoverview Utilities used in tests
7 //-----------------------------------------------------------------------------
9 //-----------------------------------------------------------------------------
13 defineConfigArrayFactoryWithInMemoryFileSystem
,
14 defineCascadingConfigArrayFactoryWithInMemoryFileSystem
,
15 defineFileEnumeratorWithInMemoryFileSystem
,
16 defineCLIEngineWithInMemoryFileSystem
,
17 defineESLintWithInMemoryFileSystem
18 } = require("./in-memory-fs");
20 const { createTeardown
, addFile
} = require("fs-teardown");
22 //-----------------------------------------------------------------------------
24 //-----------------------------------------------------------------------------
27 * Prevents leading spaces in a multiline template literal from appearing in the resulting string
28 * @param {string[]} strings The strings in the template literal
29 * @param {any[]} values The interpolation values in the template literal.
30 * @returns {string} The template literal, with spaces removed from all lines
32 function unIndent(strings
, ...values
) {
34 .map((s
, i
) => (i
=== 0 ? s
: values
[i
- 1] + s
))
36 const lines
= text
.replace(/^\n/u, "").replace(/\n\s*$/u, "").split("\n");
37 const lineIndents
= lines
.filter(line
=> line
.trim()).map(line
=> line
.match(/ */u
)[0].length
);
38 const minLineIndent
= Math
.min(...lineIndents
);
40 return lines
.map(line
=> line
.slice(minLineIndent
)).join("\n");
44 * Creates a new filesystem volume at the given location with the given files.
45 * @param {Object} desc A description of the filesystem volume to create.
46 * @param {string} desc.cwd The current working directory ESLint is using.
47 * @param {Object} desc.files A map of filename to file contents to create.
48 * @returns {Teardown} An object with prepare(), cleanup(), and getPath()
51 function createCustomTeardown({ cwd
, files
}) {
52 const { prepare
, cleanup
, getPath
} = createTeardown(
54 ...Object
.keys(files
).map(filename
=> addFile(filename
, files
[filename
]))
57 return { prepare
, cleanup
, getPath
};
60 //-----------------------------------------------------------------------------
62 //-----------------------------------------------------------------------------
67 defineConfigArrayFactoryWithInMemoryFileSystem
,
68 defineCascadingConfigArrayFactoryWithInMemoryFileSystem
,
69 defineFileEnumeratorWithInMemoryFileSystem
,
70 defineCLIEngineWithInMemoryFileSystem
,
71 defineESLintWithInMemoryFileSystem
,