diff --git a/.github/workflows/scripts/common/lint_javascript_files b/.github/workflows/scripts/common/lint_javascript_files index b05cf4af0acc..a30e7e4acce3 100755 --- a/.github/workflows/scripts/common/lint_javascript_files +++ b/.github/workflows/scripts/common/lint_javascript_files @@ -39,6 +39,13 @@ fix="${FIX:-0}" # Files to lint: files_to_lint="$*" +# Filter out non-existent files: +filter_existing_files() { + echo "$1" | tr ' ' '\n' | while read -r f; do + [ -f "$f" ] && printf '%s ' "$f" + done | sed 's/ $//' +} + # Define the path to ESLint configuration file for linting examples: eslint_examples_conf="${root}/etc/eslint/.eslintrc.examples.js" @@ -49,7 +56,7 @@ eslint_tests_conf="${root}/etc/eslint/.eslintrc.tests.js" eslint_benchmarks_conf="${root}/etc/eslint/.eslintrc.benchmarks.js" # Lint JavaScript source files: -files=$(echo "${files_to_lint}" | tr ' ' '\n' | grep '\.js$' | grep -v -e '/examples' -e '/test' -e '/benchmark' -e '^dist/' | tr '\n' ' ' | sed 's/ $//') +files=$(filter_existing_files "$(echo "${files_to_lint}" | tr ' ' '\n' | grep '\.js$' | grep -v -e '/examples' -e '/test' -e '/benchmark' -e '^dist/' | tr '\n' ' ')") # Build native addons if present: packages=$(echo "${files}" | tr ' ' '\n' | sed 's/^lib\/node_modules\///g' | sed 's/\/lib\/.*//g' | sort | uniq) @@ -64,25 +71,25 @@ if [[ -n "${files}" ]]; then fi # Lint JavaScript command-line interfaces... -file=$(echo "${files_to_lint}" | tr ' ' '\n' | grep '\.js$' | grep -E '/bin/cli$' | tr '\n' ' ' | sed 's/ $//') +file=$(filter_existing_files "$(echo "${files_to_lint}" | tr ' ' '\n' | grep '\.js$' | grep -E '/bin/cli$' | tr '\n' ' ')") if [[ -n "${file}" ]]; then make lint-javascript-files FIX="${fix}" FAST_FAIL=0 FILES="${file}" fi # Lint JavaScript example files: -files=$(echo "${files_to_lint}" | tr ' ' '\n' | grep '/examples/.*\.js$' | tr '\n' ' ' | sed 's/ $//') +files=$(filter_existing_files "$(echo "${files_to_lint}" | tr ' ' '\n' | grep '/examples/.*\.js$' | tr '\n' ' ')") if [[ -n "${files}" ]]; then make lint-javascript-files FIX="${fix}" FAST_FAIL=0 FILES="${files}" ESLINT_CONF="${eslint_examples_conf}" fi # Lint JavaScript test files: -files=$(echo "${files_to_lint}" | tr ' ' '\n' | grep '/test/.*\.js$' | tr '\n' ' ' | sed 's/ $//') +files=$(filter_existing_files "$(echo "${files_to_lint}" | tr ' ' '\n' | grep '/test/.*\.js$' | tr '\n' ' ')") if [[ -n "${files}" ]]; then make lint-javascript-files FIX="${fix}" FAST_FAIL=0 FILES="${files}" ESLINT_CONF="${eslint_tests_conf}" fi # Lint JavaScript benchmark files: -files=$(echo "${files_to_lint}" | tr ' ' '\n' | grep '/benchmark/.*\.js$' | tr '\n' ' ' | sed 's/ $//') +files=$(filter_existing_files "$(echo "${files_to_lint}" | tr ' ' '\n' | grep '/benchmark/.*\.js$' | tr '\n' ' ')") if [[ -n "${files}" ]]; then make lint-javascript-files FIX="${fix}" FAST_FAIL=0 FILES="${files}" ESLINT_CONF="${eslint_benchmarks_conf}" fi