From e369754a97c3efefdd3bc79773fd6fc2fe1fa251 Mon Sep 17 00:00:00 2001 From: HILAYTRIVEDI <52625748+HILAYTRIVEDI@users.noreply.github.com> Date: Wed, 28 Oct 2026 14:56:50 +0530 Subject: [PATCH] fix(ci): pass only existing scripts to ESLint and existing stylesheets to Stylelint ci-detect-changes lists deleted files in js-files and css-files. ESLint exits 2 with "No files matching the pattern" for each deleted script, so any PR that deletes a JS file failed lint-js. Mirror the ci-lint-php fix: lint changed scripts that still exist file by file, and run lint-command over the whole project when the list holds anything else (package.json, package-lock.json) or only deleted scripts. Stylelint gets the same existence filter. --- .github/workflows/ci-lint-css.yml | 5 ++++- .github/workflows/ci-lint-js.yml | 13 ++++++++++--- CHANGELOG.md | 2 ++ 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci-lint-css.yml b/.github/workflows/ci-lint-css.yml index 24e7325..992b842 100644 --- a/.github/workflows/ci-lint-css.yml +++ b/.github/workflows/ci-lint-css.yml @@ -54,7 +54,10 @@ jobs: # css-files also lists package.json and package-lock.json, so a dependency # change re-runs this job. Stylelint cannot parse them, and a dependency # change can affect every stylesheet, so lint the whole project then. - stylesheets=$(printf '%s\n' "$CHANGED_FILES" | grep -E '\.s?css$' || true) + # It can also name stylesheets the change deleted; Stylelint only gets files + # that still exist. + stylesheets=$(printf '%s\n' "$CHANGED_FILES" | grep -E '\.s?css$' \ + | while IFS= read -r file; do [ ! -f "$file" ] || printf '%s\n' "$file"; done || true) others=$(printf '%s\n' "$CHANGED_FILES" | grep -vE '^$|\.s?css$' || true) if [ -n "$stylesheets" ] && [ -z "$others" ]; then printf '%s\n' "$stylesheets" | xargs -d '\n' --no-run-if-empty npx --no-install stylelint -- diff --git a/.github/workflows/ci-lint-js.yml b/.github/workflows/ci-lint-js.yml index 1263486..62dbc2b 100644 --- a/.github/workflows/ci-lint-js.yml +++ b/.github/workflows/ci-lint-js.yml @@ -12,7 +12,7 @@ on: type: string default: "npm run lint:js" changed-files: - description: "Newline-separated list of JS files to lint. Empty = run lint-command over the whole project." + description: "Newline-separated changed files (ci-detect-changes' js-files). Scripts that still exist are linted file by file; if the list is empty, holds only deleted scripts, or holds anything else (package.json, package-lock.json), lint-command runs over the whole project." type: string default: "" validate-package-json: @@ -59,8 +59,15 @@ jobs: CHANGED_FILES: ${{ inputs.changed-files }} LINT_COMMAND: ${{ inputs.lint-command }} run: | - if [ -n "$CHANGED_FILES" ]; then - printf '%s\n' "$CHANGED_FILES" | xargs -d '\n' --no-run-if-empty npx --no-install eslint -- + # js-files can name scripts the change deleted, and ESLint exits 2 with + # "No files matching the pattern" for each one. It also lists package.json + # and package-lock.json, so a dependency change re-runs this job; a + # dependency change can affect every script, so lint the whole project then. + scripts=$(printf '%s\n' "$CHANGED_FILES" | grep -E '\.[cm]?[jt]sx?$' \ + | while IFS= read -r file; do [ ! -f "$file" ] || printf '%s\n' "$file"; done || true) + others=$(printf '%s\n' "$CHANGED_FILES" | grep -vE '^$|\.[cm]?[jt]sx?$' || true) + if [ -n "$scripts" ] && [ -z "$others" ]; then + printf '%s\n' "$scripts" | xargs -d '\n' --no-run-if-empty npx --no-install eslint -- else bash -eo pipefail -c "$LINT_COMMAND" fi diff --git a/CHANGELOG.md b/CHANGELOG.md index 2459d93..80b202f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). ### Fixed - `ci-lint-css.yml` no longer passes `package.json` and `package-lock.json` to Stylelint. `ci-detect-changes` lists them in `css-files` so that a dependency change re-runs the job, and Stylelint failed on them with `CssSyntaxError`. When `changed-files` holds anything other than stylesheets, or is empty, the job now runs `lint-command` over the whole project. +- `ci-lint-js.yml` no longer passes deleted files or non-script files to ESLint. A change that deletes scripts lists them in `js-files`, and ESLint failed with `No files matching the pattern`; `package.json` and `package-lock.json` are listed there too. Changed scripts that still exist are linted file by file; if the list holds anything else, or only deleted scripts, `lint-command` runs over the whole project. +- `ci-lint-css.yml` no longer passes deleted stylesheets to Stylelint. - `ci-lint-php.yml` no longer passes deleted files or non-PHP files to PHPCS. `ci-detect-changes` lists `composer.json`, `composer.lock` and the PHPStan config in `php-files`, and a change that deletes PHP files lists them too, so PHPCS failed with `does not exist` or `Start tag expected`. Changed PHP files that still exist are linted file by file; if the list holds anything else, PHPCS lints the whole project. ## v1.0.0 - 2026-08-10