diff --git a/src/cli/format.mjs b/src/cli/format.mjs index 1ccd14edb..1a39f3f53 100644 --- a/src/cli/format.mjs +++ b/src/cli/format.mjs @@ -1,5 +1,5 @@ import _format from "../main/format.mjs"; -import validateFileExistence from "./utl/validate-file-existence.mjs"; +import assertFileExistence from "./utl/assert-file-existence.mjs"; import normalizeOptions from "./normalize-cli-options.mjs"; import { getInStream, write } from "./utl/io.mjs"; @@ -13,7 +13,7 @@ export default async function format(pResultFile, pOptions) { const lOptions = await normalizeOptions(pOptions); if (pResultFile !== "-") { - validateFileExistence(pResultFile); + assertFileExistence(pResultFile); } return new Promise((pResolve, pReject) => { @@ -29,13 +29,13 @@ export default async function format(pResultFile, pOptions) { /* c8 ignore start */ (pError) => { pReject(pError); - } + }, /* c8 ignore stop */ ) .on("end", async () => { const lReportingResult = await _format( JSON.parse(lInputAsString), - lOptions + lOptions, ); write(lOptions.outputTo, lReportingResult.output); diff --git a/src/cli/index.mjs b/src/cli/index.mjs index 45952b6d8..7ed9de2a3 100644 --- a/src/cli/index.mjs +++ b/src/cli/index.mjs @@ -8,7 +8,7 @@ import chalk from "chalk"; import cruise from "../main/cruise.mjs"; import { INFO, bus } from "../utl/bus.mjs"; -import validateFileExistence from "./utl/validate-file-existence.mjs"; +import assertFileExistence from "./utl/assert-file-existence.mjs"; import normalizeCliOptions from "./normalize-cli-options.mjs"; import { write } from "./utl/io.mjs"; import setUpCliFeedbackListener from "./listeners/cli-feedback.mjs"; @@ -27,7 +27,7 @@ async function extractResolveOptions(pCruiseOptions) { lResolveOptions = await extractWebpackResolveConfig( lWebPackConfigFileName, pCruiseOptions?.ruleSet?.options?.webpackConfig?.env ?? null, - pCruiseOptions?.ruleSet?.options?.webpackConfig?.arguments ?? null + pCruiseOptions?.ruleSet?.options?.webpackConfig?.arguments ?? null, ); } return lResolveOptions; @@ -39,7 +39,7 @@ async function addKnownViolations(pCruiseOptions) { "../config-utl/extract-known-violations.mjs" ); const lKnownViolations = await extractKnownViolations( - pCruiseOptions.knownViolationsFile + pCruiseOptions.knownViolationsFile, ); // Check against json schema is already done in src/main/options/validate @@ -95,14 +95,14 @@ function setUpListener(pCruiseOptions) { if (Boolean(lListenerFunction)) { lListenerFunction( bus, - pCruiseOptions?.ruleSet?.options?.progress?.maximumLevel ?? INFO + pCruiseOptions?.ruleSet?.options?.progress?.maximumLevel ?? INFO, ); } } async function runCruise(pFileDirectoryArray, pCruiseOptions) { const lCruiseOptions = await addKnownViolations( - await normalizeCliOptions(pCruiseOptions) + await normalizeCliOptions(pCruiseOptions), ); pFileDirectoryArray @@ -110,9 +110,9 @@ async function runCruise(pFileDirectoryArray, pCruiseOptions) { .map((pFileOrDirectory) => lCruiseOptions?.ruleSet?.options?.baseDir ? join(lCruiseOptions.ruleSet.options.baseDir, pFileOrDirectory) - : pFileOrDirectory + : pFileOrDirectory, ) - .forEach(validateFileExistence); + .forEach(assertFileExistence); setUpListener(lCruiseOptions); @@ -126,7 +126,7 @@ async function runCruise(pFileDirectoryArray, pCruiseOptions) { pFileDirectoryArray, lCruiseOptions, lResolveOptions, - { tsConfig, babelConfig } + { tsConfig, babelConfig }, ); bus.progress("cli: writing results", { complete: 1 }); @@ -151,14 +151,14 @@ export default async function executeCli(pFileDirectoryArray, pCruiseOptions) { if (isInstalledGlobally) { process.stderr.write( `\n ${chalk.yellow( - "WARNING" + "WARNING", )}: You're running a globally installed dependency-cruiser.\n\n` + ` We recommend to ${chalk.bold.italic.underline( - "install and run it as a local devDependency" + "install and run it as a local devDependency", )} in\n` + ` your project instead. There it has your project's environment and\n` + ` transpilers at its disposal. That will ensure it can find e.g.\n` + - ` TypeScript, Vue or Svelte modules and dependencies.\n\n` + ` TypeScript, Vue or Svelte modules and dependencies.\n\n`, ); } /* c8 ignore stop */ diff --git a/src/cli/utl/validate-file-existence.mjs b/src/cli/utl/assert-file-existence.mjs similarity index 74% rename from src/cli/utl/validate-file-existence.mjs rename to src/cli/utl/assert-file-existence.mjs index 7cd34e198..5a8103f41 100644 --- a/src/cli/utl/validate-file-existence.mjs +++ b/src/cli/utl/assert-file-existence.mjs @@ -1,11 +1,11 @@ import { accessSync, R_OK } from "node:fs"; -export default function validateFileExistence(pDirectoryOrFile) { +export default function assertFileExistence(pDirectoryOrFile) { try { accessSync(pDirectoryOrFile, R_OK); } catch (pError) { throw new Error( - `Can't open '${pDirectoryOrFile}' for reading. Does it exist?\n` + `Can't open '${pDirectoryOrFile}' for reading. Does it exist?\n`, ); } } diff --git a/test/cli/asserthelpers.utl.mjs b/test/cli/asserthelpers.utl.mjs index 5eebbdfec..dac8de7a3 100644 --- a/test/cli/asserthelpers.utl.mjs +++ b/test/cli/asserthelpers.utl.mjs @@ -1,10 +1,10 @@ import { readFileSync } from "node:fs"; -import { deepEqual } from "node:assert/strict"; +import { deepEqual, equal } from "node:assert/strict"; import normalizeNewline from "normalize-newline"; import normBaseDirectory from "../main/norm-base-directory.utl.mjs"; export function assertFileEqual(pActualFileName, pExpectedFileName) { - deepEqual( + equal( normalizeNewline(readFileSync(pActualFileName, { encoding: "utf8" })), normalizeNewline(readFileSync(pExpectedFileName, { encoding: "utf8" })), ); diff --git a/test/cli/utl/validate-file-existence.spec.mjs b/test/cli/utl/assert-file-existence.spec.mjs similarity index 87% rename from test/cli/utl/validate-file-existence.spec.mjs rename to test/cli/utl/assert-file-existence.spec.mjs index 860c753af..239cdd007 100644 --- a/test/cli/utl/validate-file-existence.spec.mjs +++ b/test/cli/utl/assert-file-existence.spec.mjs @@ -1,5 +1,5 @@ import { doesNotThrow, throws } from "node:assert/strict"; -import validateFileExistence from "../../../src/cli/utl/validate-file-existence.mjs"; +import validateFileExistence from "../../../src/cli/utl/assert-file-existence.mjs"; describe("[U] cli/utl/validateFileExistence", () => { it("throws when the file or dir passed does not exists", () => {