From 70f8eaa661ca9ac9cf90249a46bd9e05e23162f7 Mon Sep 17 00:00:00 2001 From: Nick Sheck Date: Tue, 8 Oct 2024 13:25:22 -0700 Subject: [PATCH] Bail out early if no relevant files In a run where there are no relevant files, ESLint v6 was failing because the list passed in was empty. It was rendering the help listing instead of returning JSON that could be parsed. --- dist/index.js | 4 ++++ src/index.ts | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/dist/index.js b/dist/index.js index 53c2b57..5fd4316 100644 --- a/dist/index.js +++ b/dist/index.js @@ -26367,6 +26367,10 @@ async function run() { core.debug(`Extensions: ${extensions}`); let changedFilesMatchingExtensions = changedFiles.filter((file) => extensions.some((ext) => file.endsWith(ext))); core.debug(`Changed files matching extensions: ${changedFilesMatchingExtensions}`); + // Bail out early if the file list is empty (older ESLint versions will + // complain if the list is empty) + if (changedFilesMatchingExtensions.length === 0) + return; let { stdout: eslintOut, exitCode } = await (0, exec_1.getExecOutput)("npx eslint --format=json", changedFilesMatchingExtensions, // Eslint will return exit code 1 if it finds linting problems, but that is // expected and we don't want to stop execution because of it. diff --git a/src/index.ts b/src/index.ts index 1f742b5..fdee099 100644 --- a/src/index.ts +++ b/src/index.ts @@ -43,6 +43,10 @@ async function run() { `Changed files matching extensions: ${changedFilesMatchingExtensions}`, ) + // Bail out early if the file list is empty (older ESLint versions will + // complain if the list is empty) + if (changedFilesMatchingExtensions.length === 0) return + let { stdout: eslintOut, exitCode } = await getExecOutput( "npx eslint --format=json", changedFilesMatchingExtensions,