Skip to content

Commit ed6a9d1

Browse files
committed
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 ---
1 parent 9905dd4 commit ed6a9d1

File tree

2 files changed

+56
-38
lines changed

2 files changed

+56
-38
lines changed

.github/workflows/lint_random_files.yml

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -320,9 +320,30 @@ jobs:
320320
fi
321321
322322
# Combined error file:
323-
ERR_FILE="lint_javascript_errors.txt"
323+
ERR_FILE="$GITHUB_WORKSPACE/lint_javascript_errors.txt"
324324
> "$ERR_FILE" # Initialize a clean file
325325
326+
# Initialize error flag:
327+
error_occurred=0
328+
329+
run_make_lint() {
330+
local files_to_lint="$1"
331+
local make_args="$2"
332+
local eslint_conf_arg="$3"
333+
local error_log_file="$4"
334+
335+
local make_cmd="make lint-javascript-files FIX=${FIX} FAST_FAIL=0 FILES=\"${files_to_lint}\" ${make_args} ${eslint_conf_arg}"
336+
337+
echo "Running: ${make_cmd}"
338+
if ! eval "${make_cmd}"; then
339+
echo "Initial linting failed. Retrying with --quiet and logging errors..."
340+
341+
# Run again with --quiet flag and log output:
342+
eval "${make_cmd} ESLINT_FLAGS='--quiet'" >> "${error_log_file}" 2>&1
343+
error_occurred=1
344+
fi
345+
}
346+
326347
# Lint JavaScript source files:
327348
files=$(echo "${{ steps.random-files.outputs.files }}" | tr ',' '\n' | grep '\.js$' | grep -v -e '/examples' -e '/test' -e '/benchmark' -e '^dist/' | tr '\n' ' ')
328349
@@ -335,31 +356,38 @@ jobs:
335356
done
336357
337358
if [[ -n "${files}" ]]; then
338-
make lint-javascript-files FIX="${FIX}" FAST_FAIL=0 FILES="${files}" ESLINT_ERROR_LOG="$ERR_FILE"
359+
run_make_lint "${files}" "" "" "${ERR_FILE}"
339360
fi
340361
341-
# Lint JavaScript command-line interfaces...
362+
# Lint JavaScript command-line interfaces:
342363
file=$(echo "${{ steps.random-files.outputs.files }}" | tr ',' '\n' | grep '\.js$' | grep -E '/bin/cli$' | tr '\n' ' ')
343364
if [[ -n "${file}" ]]; then
344-
make lint-javascript-files FIX="${FIX}" FAST_FAIL=0 FILES="${file}" ESLINT_ERROR_LOG="$ERR_FILE"
365+
run_make_lint "${file}" "" "" "${ERR_FILE}"
345366
fi
346367
347368
# Lint JavaScript example files:
348369
files=$(echo "${{ steps.random-files.outputs.files }}" | tr ',' '\n' | grep '/examples/.*\.js$' | tr '\n' ' ')
349370
if [[ -n "${files}" ]]; then
350-
make lint-javascript-files FIX="${FIX}" FAST_FAIL=0 FILES="${files}" ESLINT_CONF="${eslint_examples_conf}" ESLINT_ERROR_LOG="$ERR_FILE"
371+
run_make_lint "${files}" "" "ESLINT_CONF=\"${eslint_examples_conf}\"" "${ERR_FILE}"
351372
fi
352373
353374
# Lint JavaScript test files:
354375
files=$(echo "${{ steps.random-files.outputs.files }}" | tr ',' '\n' | grep '/test/.*\.js$' | tr '\n' ' ')
355376
if [[ -n "${files}" ]]; then
356-
make lint-javascript-files FIX="${FIX}" FAST_FAIL=0 FILES="${files}" ESLINT_CONF="${eslint_tests_conf}" ESLINT_ERROR_LOG="$ERR_FILE"
377+
run_make_lint "${files}" "" "ESLINT_CONF=\"${eslint_tests_conf}\"" "${ERR_FILE}"
357378
fi
358379
359380
# Lint JavaScript benchmark files:
360381
files=$(echo "${{ steps.random-files.outputs.files }}" | tr ',' '\n' | grep '/benchmark/.*\.js$' | tr '\n' ' ')
361382
if [[ -n "${files}" ]]; then
362-
make lint-javascript-files FIX="${FIX}" FAST_FAIL=0 FILES="${files}" ESLINT_CONF="${eslint_benchmarks_conf}" ESLINT_ERROR_LOG="$ERR_FILE"
383+
run_make_lint "${files}" "" "ESLINT_CONF=\"${eslint_benchmarks_conf}\"" "${ERR_FILE}"
384+
fi
385+
386+
# Check if any errors occurred during linting:
387+
if [[ "$error_occurred" -eq 1 ]]; then
388+
echo "JavaScript linting errors occurred. See details below or in the artifact."
389+
cat "$ERR_FILE" # Print errors to the workflow log
390+
exit 1
363391
fi
364392
365393
# Create sub-issue for JavaScript lint failures:
@@ -392,7 +420,7 @@ jobs:
392420
"5377" \
393421
"Good First Issue"
394422
395-
rm "$BODY_FILE"
423+
rm "$BODY_FILE" "$ERR_FILE"
396424
397425
# Lint Python files:
398426
- name: 'Lint Python files'

tools/make/lib/lint/javascript/eslint.mk

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -44,27 +44,30 @@ ESLINT_CONF_BENCHMARKS ?= $(CONFIG_DIR)/eslint/.eslintrc.benchmarks.js
4444
# Define the path to the ESLint ignore file:
4545
ESLINT_IGNORE ?= $(ROOT_DIR)/.eslintignore
4646

47-
# Define optional path for storing lint failure reports:
48-
ESLINT_ERROR_LOG ?=
49-
5047
# Define the command-line options to use when invoking the ESLint executable:
51-
ESLINT_FLAGS ?= \
48+
eslint_flags := \
5249
--ignore-path $(ESLINT_IGNORE) \
5350
--report-unused-disable-directives
5451

52+
# Define user-supplied command-line options:
53+
ESLINT_FLAGS ?=
54+
5555
ifeq ($(AUTOFIX),true)
56-
ESLINT_FLAGS += --fix
56+
eslint_flags += --fix
5757
endif
5858

5959
FIX_TYPE ?=
6060
ifneq ($(FIX_TYPE),)
61-
ESLINT_FLAGS += --fix-type $(FIX_TYPE)
61+
eslint_flags += --fix-type $(FIX_TYPE)
6262
else
6363
ifeq ($(AUTOFIX),true)
64-
ESLINT_FLAGS += --fix-type problem,layout,directive
64+
eslint_flags += --fix-type problem,layout,directive
6565
endif
6666
endif
6767

68+
# Append user-supplied command-line options:
69+
eslint_flags += ESLINT_FLAGS
70+
6871
# RULES #
6972

7073
#/
@@ -91,14 +94,14 @@ ifeq ($(FAIL_FAST), true)
9194
$(QUIET) $(FIND_SOURCES_CMD) | grep '^[\/]\|^[a-zA-Z]:[/\]' | while read -r file; do \
9295
echo ''; \
9396
echo "Linting file: $$file"; \
94-
$(ESLINT) $(ESLINT_FLAGS) --config $(ESLINT_CONF) $$file || exit 1; \
97+
$(ESLINT) $(eslint_flags) --config $(ESLINT_CONF) $$file || exit 1; \
9598
done
9699
else
97100
$(QUIET) status=0; \
98101
$(FIND_SOURCES_CMD) | grep '^[\/]\|^[a-zA-Z]:[/\]' | while read -r file; do \
99102
echo ''; \
100103
echo "Linting file: $$file"; \
101-
if ! $(ESLINT) $(ESLINT_FLAGS) --config $(ESLINT_CONF) $$file; then \
104+
if ! $(ESLINT) $(eslint_flags) --config $(ESLINT_CONF) $$file; then \
102105
echo 'Linting failed.'; \
103106
status=1; \
104107
fi; \
@@ -132,14 +135,14 @@ ifeq ($(FAIL_FAST), true)
132135
$(QUIET) $(FIND_TESTS_CMD) | grep '^[\/]\|^[a-zA-Z]:[/\]' | while read -r file; do \
133136
echo ''; \
134137
echo "Linting file: $$file"; \
135-
$(ESLINT) $(ESLINT_FLAGS) --config $(ESLINT_CONF_TESTS) $$file || exit 1; \
138+
$(ESLINT) $(eslint_flags) --config $(ESLINT_CONF_TESTS) $$file || exit 1; \
136139
done
137140
else
138141
$(QUIET) status=0; \
139142
$(FIND_TESTS_CMD) | grep '^[\/]\|^[a-zA-Z]:[/\]' | while read -r file; do \
140143
echo ''; \
141144
echo "Linting file: $$file"; \
142-
if ! $(ESLINT) $(ESLINT_FLAGS) --config $(ESLINT_CONF_TESTS) $$file; then \
145+
if ! $(ESLINT) $(eslint_flags) --config $(ESLINT_CONF_TESTS) $$file; then \
143146
echo 'Linting failed.'; \
144147
status=1; \
145148
fi; \
@@ -173,14 +176,14 @@ ifeq ($(FAIL_FAST), true)
173176
$(QUIET) $(FIND_EXAMPLES_CMD) | grep '^[\/]\|^[a-zA-Z]:[/\]' | while read -r file; do \
174177
echo ''; \
175178
echo "Linting file: $$file"; \
176-
$(ESLINT) $(ESLINT_FLAGS) --config $(ESLINT_CONF_EXAMPLES) $$file || exit 1; \
179+
$(ESLINT) $(eslint_flags) --config $(ESLINT_CONF_EXAMPLES) $$file || exit 1; \
177180
done
178181
else
179182
$(QUIET) status=0; \
180183
$(FIND_EXAMPLES_CMD) | grep '^[\/]\|^[a-zA-Z]:[/\]' | while read -r file; do \
181184
echo ''; \
182185
echo "Linting file: $$file"; \
183-
if ! $(ESLINT) $(ESLINT_FLAGS) --config $(ESLINT_CONF_EXAMPLES) $$file; then \
186+
if ! $(ESLINT) $(eslint_flags) --config $(ESLINT_CONF_EXAMPLES) $$file; then \
184187
echo 'Linting failed.'; \
185188
status=1; \
186189
fi; \
@@ -214,14 +217,14 @@ ifeq ($(FAIL_FAST), true)
214217
$(QUIET) $(FIND_BENCHMARKS_CMD) | grep '^[\/]\|^[a-zA-Z]:[/\]' | while read -r file; do \
215218
echo ''; \
216219
echo "Linting file: $$file"; \
217-
$(ESLINT) $(ESLINT_FLAGS) --config $(ESLINT_CONF_BENCHMARKS) $$file || exit 1; \
220+
$(ESLINT) $(eslint_flags) --config $(ESLINT_CONF_BENCHMARKS) $$file || exit 1; \
218221
done
219222
else
220223
$(QUIET) status=0; \
221224
$(FIND_BENCHMARKS_CMD) | grep '^[\/]\|^[a-zA-Z]:[/\]' | while read -r file; do \
222225
echo ''; \
223226
echo "Linting file: $$file"; \
224-
if ! $(ESLINT) $(ESLINT_FLAGS) --config $(ESLINT_CONF_BENCHMARKS) $$file; then \
227+
if ! $(ESLINT) $(eslint_flags) --config $(ESLINT_CONF_BENCHMARKS) $$file; then \
225228
echo 'Linting failed.'; \
226229
status=1; \
227230
fi; \
@@ -252,26 +255,13 @@ ifeq ($(FAIL_FAST), true)
252255
$(QUIET) for file in $(FILES); do \
253256
echo ''; \
254257
echo "Linting file: $$file"; \
255-
$(ESLINT) $(ESLINT_FLAGS) --config $(ESLINT_CONF) $$file || exit 1; \
256-
done
257-
else ifneq ($(ESLINT_ERROR_LOG),)
258-
$(QUIET) status=0; \
259-
for file in $(FILES); do \
260-
echo ''; \
261-
echo "Linting file: $$file"; \
262-
if ! $(ESLINT) $(ESLINT_FLAGS) --config $(ESLINT_CONF) $$file; then \
263-
echo 'Linting failed.'; \
264-
$(ESLINT) $(ESLINT_FLAGS) --quiet --config $(ESLINT_CONF) $$file >> $(ESLINT_ERROR_LOG); \
265-
status=1; \
266-
fi; \
267-
done; \
268-
exit $$status;
258+
$(ESLINT) $(eslint_flags) --config $(ESLINT_CONF) $$file || exit 1; \
269259
else
270260
$(QUIET) status=0; \
271261
for file in $(FILES); do \
272262
echo ''; \
273263
echo "Linting file: $$file"; \
274-
if ! $(ESLINT) $(ESLINT_FLAGS) --config $(ESLINT_CONF) $$file; then \
264+
if ! $(ESLINT) $(eslint_flags) --config $(ESLINT_CONF) $$file; then \
275265
echo 'Linting failed.'; \
276266
status=1; \
277267
fi; \

0 commit comments

Comments
 (0)