From 9905dd4c756617ff0831e1a8731bf6ab93f62529 Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Sun, 2 Mar 2025 17:12:47 -0500 Subject: [PATCH 1/2] build: add error log variable to store errors in file --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na --- --- .github/workflows/lint_random_files.yml | 10 +++++----- tools/make/lib/lint/javascript/eslint.mk | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/.github/workflows/lint_random_files.yml b/.github/workflows/lint_random_files.yml index 692cb3d8a65e..3cbc98e64bdc 100644 --- a/.github/workflows/lint_random_files.yml +++ b/.github/workflows/lint_random_files.yml @@ -335,31 +335,31 @@ jobs: done if [[ -n "${files}" ]]; then - make lint-javascript-files FIX="${FIX}" FAST_FAIL=0 FILES="${files}" 2>&1 | tee -a "$ERR_FILE" + make lint-javascript-files FIX="${FIX}" FAST_FAIL=0 FILES="${files}" ESLINT_ERROR_LOG="$ERR_FILE" fi # Lint JavaScript command-line interfaces... file=$(echo "${{ steps.random-files.outputs.files }}" | 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}" 2>&1 | tee -a "$ERR_FILE" + make lint-javascript-files FIX="${FIX}" FAST_FAIL=0 FILES="${file}" ESLINT_ERROR_LOG="$ERR_FILE" fi # Lint JavaScript example files: files=$(echo "${{ steps.random-files.outputs.files }}" | 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}" 2>&1 | tee -a "$ERR_FILE" + make lint-javascript-files FIX="${FIX}" FAST_FAIL=0 FILES="${files}" ESLINT_CONF="${eslint_examples_conf}" ESLINT_ERROR_LOG="$ERR_FILE" fi # Lint JavaScript test files: files=$(echo "${{ steps.random-files.outputs.files }}" | 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}" 2>&1 | tee -a "$ERR_FILE" + make lint-javascript-files FIX="${FIX}" FAST_FAIL=0 FILES="${files}" ESLINT_CONF="${eslint_tests_conf}" ESLINT_ERROR_LOG="$ERR_FILE" fi # Lint JavaScript benchmark files: files=$(echo "${{ steps.random-files.outputs.files }}" | 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}" 2>&1 | tee -a "$ERR_FILE" + make lint-javascript-files FIX="${FIX}" FAST_FAIL=0 FILES="${files}" ESLINT_CONF="${eslint_benchmarks_conf}" ESLINT_ERROR_LOG="$ERR_FILE" fi # Create sub-issue for JavaScript lint failures: diff --git a/tools/make/lib/lint/javascript/eslint.mk b/tools/make/lib/lint/javascript/eslint.mk index 2d193bdc6421..356e0b619f61 100644 --- a/tools/make/lib/lint/javascript/eslint.mk +++ b/tools/make/lib/lint/javascript/eslint.mk @@ -44,6 +44,9 @@ ESLINT_CONF_BENCHMARKS ?= $(CONFIG_DIR)/eslint/.eslintrc.benchmarks.js # Define the path to the ESLint ignore file: ESLINT_IGNORE ?= $(ROOT_DIR)/.eslintignore +# Define optional path for storing lint failure reports: +ESLINT_ERROR_LOG ?= + # Define the command-line options to use when invoking the ESLint executable: ESLINT_FLAGS ?= \ --ignore-path $(ESLINT_IGNORE) \ @@ -251,6 +254,18 @@ ifeq ($(FAIL_FAST), true) echo "Linting file: $$file"; \ $(ESLINT) $(ESLINT_FLAGS) --config $(ESLINT_CONF) $$file || exit 1; \ done +else ifneq ($(ESLINT_ERROR_LOG),) + $(QUIET) status=0; \ + for file in $(FILES); do \ + echo ''; \ + echo "Linting file: $$file"; \ + if ! $(ESLINT) $(ESLINT_FLAGS) --config $(ESLINT_CONF) $$file; then \ + echo 'Linting failed.'; \ + $(ESLINT) $(ESLINT_FLAGS) --quiet --config $(ESLINT_CONF) $$file >> $(ESLINT_ERROR_LOG); \ + status=1; \ + fi; \ + done; \ + exit $$status; else $(QUIET) status=0; \ for file in $(FILES); do \ From ed6a9d16985018abbee6a5238b40edbec2ee743f Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Fri, 25 Apr 2025 15:42:09 -0400 Subject: [PATCH 2/2] chore: address PR feedback --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .github/workflows/lint_random_files.yml | 44 +++++++++++++++++---- tools/make/lib/lint/javascript/eslint.mk | 50 ++++++++++-------------- 2 files changed, 56 insertions(+), 38 deletions(-) diff --git a/.github/workflows/lint_random_files.yml b/.github/workflows/lint_random_files.yml index 3cbc98e64bdc..1d445b1c9060 100644 --- a/.github/workflows/lint_random_files.yml +++ b/.github/workflows/lint_random_files.yml @@ -320,9 +320,30 @@ jobs: fi # Combined error file: - ERR_FILE="lint_javascript_errors.txt" + ERR_FILE="$GITHUB_WORKSPACE/lint_javascript_errors.txt" > "$ERR_FILE" # Initialize a clean file + # Initialize error flag: + error_occurred=0 + + run_make_lint() { + local files_to_lint="$1" + local make_args="$2" + local eslint_conf_arg="$3" + local error_log_file="$4" + + local make_cmd="make lint-javascript-files FIX=${FIX} FAST_FAIL=0 FILES=\"${files_to_lint}\" ${make_args} ${eslint_conf_arg}" + + echo "Running: ${make_cmd}" + if ! eval "${make_cmd}"; then + echo "Initial linting failed. Retrying with --quiet and logging errors..." + + # Run again with --quiet flag and log output: + eval "${make_cmd} ESLINT_FLAGS='--quiet'" >> "${error_log_file}" 2>&1 + error_occurred=1 + fi + } + # Lint JavaScript source files: files=$(echo "${{ steps.random-files.outputs.files }}" | tr ',' '\n' | grep '\.js$' | grep -v -e '/examples' -e '/test' -e '/benchmark' -e '^dist/' | tr '\n' ' ') @@ -335,31 +356,38 @@ jobs: done if [[ -n "${files}" ]]; then - make lint-javascript-files FIX="${FIX}" FAST_FAIL=0 FILES="${files}" ESLINT_ERROR_LOG="$ERR_FILE" + run_make_lint "${files}" "" "" "${ERR_FILE}" fi - # Lint JavaScript command-line interfaces... + # Lint JavaScript command-line interfaces: file=$(echo "${{ steps.random-files.outputs.files }}" | 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}" ESLINT_ERROR_LOG="$ERR_FILE" + run_make_lint "${file}" "" "" "${ERR_FILE}" fi # Lint JavaScript example files: files=$(echo "${{ steps.random-files.outputs.files }}" | 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}" ESLINT_ERROR_LOG="$ERR_FILE" + run_make_lint "${files}" "" "ESLINT_CONF=\"${eslint_examples_conf}\"" "${ERR_FILE}" fi # Lint JavaScript test files: files=$(echo "${{ steps.random-files.outputs.files }}" | 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}" ESLINT_ERROR_LOG="$ERR_FILE" + run_make_lint "${files}" "" "ESLINT_CONF=\"${eslint_tests_conf}\"" "${ERR_FILE}" fi # Lint JavaScript benchmark files: files=$(echo "${{ steps.random-files.outputs.files }}" | 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}" ESLINT_ERROR_LOG="$ERR_FILE" + run_make_lint "${files}" "" "ESLINT_CONF=\"${eslint_benchmarks_conf}\"" "${ERR_FILE}" + fi + + # Check if any errors occurred during linting: + if [[ "$error_occurred" -eq 1 ]]; then + echo "JavaScript linting errors occurred. See details below or in the artifact." + cat "$ERR_FILE" # Print errors to the workflow log + exit 1 fi # Create sub-issue for JavaScript lint failures: @@ -392,7 +420,7 @@ jobs: "5377" \ "Good First Issue" - rm "$BODY_FILE" + rm "$BODY_FILE" "$ERR_FILE" # Lint Python files: - name: 'Lint Python files' diff --git a/tools/make/lib/lint/javascript/eslint.mk b/tools/make/lib/lint/javascript/eslint.mk index 356e0b619f61..e148cbf346dd 100644 --- a/tools/make/lib/lint/javascript/eslint.mk +++ b/tools/make/lib/lint/javascript/eslint.mk @@ -44,27 +44,30 @@ ESLINT_CONF_BENCHMARKS ?= $(CONFIG_DIR)/eslint/.eslintrc.benchmarks.js # Define the path to the ESLint ignore file: ESLINT_IGNORE ?= $(ROOT_DIR)/.eslintignore -# Define optional path for storing lint failure reports: -ESLINT_ERROR_LOG ?= - # Define the command-line options to use when invoking the ESLint executable: -ESLINT_FLAGS ?= \ +eslint_flags := \ --ignore-path $(ESLINT_IGNORE) \ --report-unused-disable-directives +# Define user-supplied command-line options: +ESLINT_FLAGS ?= + ifeq ($(AUTOFIX),true) - ESLINT_FLAGS += --fix + eslint_flags += --fix endif FIX_TYPE ?= ifneq ($(FIX_TYPE),) - ESLINT_FLAGS += --fix-type $(FIX_TYPE) + eslint_flags += --fix-type $(FIX_TYPE) else ifeq ($(AUTOFIX),true) - ESLINT_FLAGS += --fix-type problem,layout,directive + eslint_flags += --fix-type problem,layout,directive endif endif +# Append user-supplied command-line options: +eslint_flags += ESLINT_FLAGS + # RULES # #/ @@ -91,14 +94,14 @@ ifeq ($(FAIL_FAST), true) $(QUIET) $(FIND_SOURCES_CMD) | grep '^[\/]\|^[a-zA-Z]:[/\]' | while read -r file; do \ echo ''; \ echo "Linting file: $$file"; \ - $(ESLINT) $(ESLINT_FLAGS) --config $(ESLINT_CONF) $$file || exit 1; \ + $(ESLINT) $(eslint_flags) --config $(ESLINT_CONF) $$file || exit 1; \ done else $(QUIET) status=0; \ $(FIND_SOURCES_CMD) | grep '^[\/]\|^[a-zA-Z]:[/\]' | while read -r file; do \ echo ''; \ echo "Linting file: $$file"; \ - if ! $(ESLINT) $(ESLINT_FLAGS) --config $(ESLINT_CONF) $$file; then \ + if ! $(ESLINT) $(eslint_flags) --config $(ESLINT_CONF) $$file; then \ echo 'Linting failed.'; \ status=1; \ fi; \ @@ -132,14 +135,14 @@ ifeq ($(FAIL_FAST), true) $(QUIET) $(FIND_TESTS_CMD) | grep '^[\/]\|^[a-zA-Z]:[/\]' | while read -r file; do \ echo ''; \ echo "Linting file: $$file"; \ - $(ESLINT) $(ESLINT_FLAGS) --config $(ESLINT_CONF_TESTS) $$file || exit 1; \ + $(ESLINT) $(eslint_flags) --config $(ESLINT_CONF_TESTS) $$file || exit 1; \ done else $(QUIET) status=0; \ $(FIND_TESTS_CMD) | grep '^[\/]\|^[a-zA-Z]:[/\]' | while read -r file; do \ echo ''; \ echo "Linting file: $$file"; \ - if ! $(ESLINT) $(ESLINT_FLAGS) --config $(ESLINT_CONF_TESTS) $$file; then \ + if ! $(ESLINT) $(eslint_flags) --config $(ESLINT_CONF_TESTS) $$file; then \ echo 'Linting failed.'; \ status=1; \ fi; \ @@ -173,14 +176,14 @@ ifeq ($(FAIL_FAST), true) $(QUIET) $(FIND_EXAMPLES_CMD) | grep '^[\/]\|^[a-zA-Z]:[/\]' | while read -r file; do \ echo ''; \ echo "Linting file: $$file"; \ - $(ESLINT) $(ESLINT_FLAGS) --config $(ESLINT_CONF_EXAMPLES) $$file || exit 1; \ + $(ESLINT) $(eslint_flags) --config $(ESLINT_CONF_EXAMPLES) $$file || exit 1; \ done else $(QUIET) status=0; \ $(FIND_EXAMPLES_CMD) | grep '^[\/]\|^[a-zA-Z]:[/\]' | while read -r file; do \ echo ''; \ echo "Linting file: $$file"; \ - if ! $(ESLINT) $(ESLINT_FLAGS) --config $(ESLINT_CONF_EXAMPLES) $$file; then \ + if ! $(ESLINT) $(eslint_flags) --config $(ESLINT_CONF_EXAMPLES) $$file; then \ echo 'Linting failed.'; \ status=1; \ fi; \ @@ -214,14 +217,14 @@ ifeq ($(FAIL_FAST), true) $(QUIET) $(FIND_BENCHMARKS_CMD) | grep '^[\/]\|^[a-zA-Z]:[/\]' | while read -r file; do \ echo ''; \ echo "Linting file: $$file"; \ - $(ESLINT) $(ESLINT_FLAGS) --config $(ESLINT_CONF_BENCHMARKS) $$file || exit 1; \ + $(ESLINT) $(eslint_flags) --config $(ESLINT_CONF_BENCHMARKS) $$file || exit 1; \ done else $(QUIET) status=0; \ $(FIND_BENCHMARKS_CMD) | grep '^[\/]\|^[a-zA-Z]:[/\]' | while read -r file; do \ echo ''; \ echo "Linting file: $$file"; \ - if ! $(ESLINT) $(ESLINT_FLAGS) --config $(ESLINT_CONF_BENCHMARKS) $$file; then \ + if ! $(ESLINT) $(eslint_flags) --config $(ESLINT_CONF_BENCHMARKS) $$file; then \ echo 'Linting failed.'; \ status=1; \ fi; \ @@ -252,26 +255,13 @@ ifeq ($(FAIL_FAST), true) $(QUIET) for file in $(FILES); do \ echo ''; \ echo "Linting file: $$file"; \ - $(ESLINT) $(ESLINT_FLAGS) --config $(ESLINT_CONF) $$file || exit 1; \ - done -else ifneq ($(ESLINT_ERROR_LOG),) - $(QUIET) status=0; \ - for file in $(FILES); do \ - echo ''; \ - echo "Linting file: $$file"; \ - if ! $(ESLINT) $(ESLINT_FLAGS) --config $(ESLINT_CONF) $$file; then \ - echo 'Linting failed.'; \ - $(ESLINT) $(ESLINT_FLAGS) --quiet --config $(ESLINT_CONF) $$file >> $(ESLINT_ERROR_LOG); \ - status=1; \ - fi; \ - done; \ - exit $$status; + $(ESLINT) $(eslint_flags) --config $(ESLINT_CONF) $$file || exit 1; \ else $(QUIET) status=0; \ for file in $(FILES); do \ echo ''; \ echo "Linting file: $$file"; \ - if ! $(ESLINT) $(ESLINT_FLAGS) --config $(ESLINT_CONF) $$file; then \ + if ! $(ESLINT) $(eslint_flags) --config $(ESLINT_CONF) $$file; then \ echo 'Linting failed.'; \ status=1; \ fi; \