From c6bab92649a36c25b856290966e014ea43dc2691 Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Sun, 15 Mar 2026 13:05:11 -0500 Subject: [PATCH] build: switch Makefiles and pre-commit to flat config Update build tooling to use ESLint flat config (eslint.config.cjs) instead of legacy .eslintrc.* files: - Remove `ESLINT_USE_FLAT_CONFIG=false` from JS eslint.mk - Remove `--ignore-path`, `--config`, and per-target config variables from both JS and TS eslint.mk (flat config autodiscovery handles all of this via eslint.config.cjs) - Remove per-directory tsconfig.json copy mechanism from TS eslint.mk (the flat config's TS block points to the root tsconfig.json) - Remove legacy config path variables from pre-commit hook ESLint now autodiscovers eslint.config.cjs at the repo root and applies the correct rules based on file patterns (benchmarks, tests, examples, TypeScript) defined in the flat config. Ref: https://github.com/stdlib-js/metr-issue-tracker/issues/54 --- tools/git/hooks/pre-commit | 12 ++---- tools/make/lib/lint/javascript/eslint.mk | 39 +++++------------- tools/make/lib/lint/typescript/eslint.mk | 51 ++++-------------------- 3 files changed, 21 insertions(+), 81 deletions(-) diff --git a/tools/git/hooks/pre-commit b/tools/git/hooks/pre-commit index dbee4c6e1076..79c4bf95be28 100644 --- a/tools/git/hooks/pre-commit +++ b/tools/git/hooks/pre-commit @@ -60,16 +60,12 @@ lint_package_json="${root}/lib/node_modules/@stdlib/_tools/lint/pkg-json/bin/cli lint_repl_help="${root}/lib/node_modules/@stdlib/_tools/lint/repl-txt/bin/cli" # Define the path to ESLint configuration file for linting examples: -eslint_examples_conf="${root}/etc/eslint/.eslintrc.examples.js" # Define the path to ESLint configuration file for linting tests: -eslint_tests_conf="${root}/etc/eslint/.eslintrc.tests.js" # Define the path to ESLint configuration file for linting benchmarks: -eslint_benchmarks_conf="${root}/etc/eslint/.eslintrc.benchmarks.js" # Define the path to ESLint configuration file for linting TypeScript definition tests: -eslint_typescript_tests_conf="${root}/etc/eslint/.eslintrc.typescript.tests.js" # Define the path to cppcheck configuration file for linting examples: cppcheck_examples_suppressions_list="${root}/etc/cppcheck/suppressions.examples.txt" @@ -316,7 +312,7 @@ run_lint() { if [[ -z "${skip_javascript_examples}" ]]; then files=$(echo "${changed_files}" | grep '/examples/.*\.js$' | tr '\n' ' ') if [[ -n "${files}" ]]; then - make JAVASCRIPT_LINTER=eslint ESLINT_CONF="${eslint_examples_conf}" FILES="${files}" FIX=1 lint-javascript-files > /dev/null >&2 + make JAVASCRIPT_LINTER=eslint FILES="${files}" FIX=1 lint-javascript-files > /dev/null >&2 if [[ "$?" -ne 0 ]]; then task_status 'failed' echo '' >&2 @@ -335,7 +331,7 @@ run_lint() { if [[ -z "${skip_javascript_tests}" ]]; then files=$(echo "${changed_files}" | grep '/test/.*\.js$' | tr '\n' ' ') if [[ -n "${files}" ]]; then - make JAVASCRIPT_LINTER=eslint ESLINT_CONF="${eslint_tests_conf}" FILES="${files}" FIX=1 lint-javascript-files > /dev/null >&2 + make JAVASCRIPT_LINTER=eslint FILES="${files}" FIX=1 lint-javascript-files > /dev/null >&2 if [[ "$?" -ne 0 ]]; then task_status 'failed' echo '' >&2 @@ -354,7 +350,7 @@ run_lint() { if [[ -z "${skip_javascript_benchmarks}" ]]; then files=$(echo "${changed_files}" | grep '/benchmark/.*\.js$' | tr '\n' ' ') if [[ -n "${files}" ]]; then - make JAVASCRIPT_LINTER=eslint ESLINT_CONF="${eslint_benchmarks_conf}" FILES="${files}" FIX=1 lint-javascript-files > /dev/null >&2 + make JAVASCRIPT_LINTER=eslint FILES="${files}" FIX=1 lint-javascript-files > /dev/null >&2 if [[ "$?" -ne 0 ]]; then task_status 'failed' echo '' >&2 @@ -587,7 +583,7 @@ run_lint() { # Lint all collected test files... if [[ -n "${files}" ]]; then - make TYPESCRIPT_DECLARATIONS_LINTER=eslint FILES="${files}" ESLINT_TS_CONF="${eslint_typescript_tests_conf}" lint-typescript-declarations-files > /dev/null >&2 + make TYPESCRIPT_DECLARATIONS_LINTER=eslint FILES="${files}" lint-typescript-declarations-files > /dev/null >&2 if [[ "$?" -ne 0 ]]; then task_status 'failed' echo '' >&2 diff --git a/tools/make/lib/lint/javascript/eslint.mk b/tools/make/lib/lint/javascript/eslint.mk index 46f0070a4d29..49624a7a4ee4 100644 --- a/tools/make/lib/lint/javascript/eslint.mk +++ b/tools/make/lib/lint/javascript/eslint.mk @@ -29,27 +29,8 @@ # [1]: https://eslint.org/ ESLINT ?= $(BIN_DIR)/eslint -# Define the path to the ESLint configuration file: -ESLINT_CONF ?= $(CONFIG_DIR)/eslint/.eslintrc.js - -# Define the path to the ESLint configuration file for examples: -ESLINT_CONF_EXAMPLES ?= $(CONFIG_DIR)/eslint/.eslintrc.examples.js - -# Define the path to the ESLint configuration file for tests: -ESLINT_CONF_TESTS ?= $(CONFIG_DIR)/eslint/.eslintrc.tests.js - -# Define the path to the ESLint configuration file for benchmarks: -ESLINT_CONF_BENCHMARKS ?= $(CONFIG_DIR)/eslint/.eslintrc.benchmarks.js - -# Define the path to the ESLint ignore file: -ESLINT_IGNORE ?= $(ROOT_DIR)/.eslintignore - -# Force legacy config mode (eslint.config.cjs exists but Makefiles still use legacy flags): -export ESLINT_USE_FLAT_CONFIG := false - # Define the command-line options to use when invoking the ESLint executable: eslint_flags := \ - --ignore-path $(ESLINT_IGNORE) \ --report-unused-disable-directives # Define user-supplied command-line options: @@ -97,14 +78,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) $$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) $$file; then \ echo 'Linting failed.'; \ status=1; \ fi; \ @@ -138,14 +119,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) $$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) $$file; then \ echo 'Linting failed.'; \ status=1; \ fi; \ @@ -179,14 +160,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) $$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) $$file; then \ echo 'Linting failed.'; \ status=1; \ fi; \ @@ -220,14 +201,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) $$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) $$file; then \ echo 'Linting failed.'; \ status=1; \ fi; \ @@ -258,14 +239,14 @@ ifeq ($(FAIL_FAST), true) $(QUIET) for file in $(FILES); do \ echo ''; \ echo "Linting file: $$file"; \ - $(ESLINT) $(eslint_flags) --config $(ESLINT_CONF) $$file || exit 1; \ + $(ESLINT) $(eslint_flags) $$file || exit 1; \ done 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) $$file; then \ echo 'Linting failed.'; \ status=1; \ fi; \ diff --git a/tools/make/lib/lint/typescript/eslint.mk b/tools/make/lib/lint/typescript/eslint.mk index af927a65a6a5..90d53dcbc6fa 100644 --- a/tools/make/lib/lint/typescript/eslint.mk +++ b/tools/make/lib/lint/typescript/eslint.mk @@ -29,21 +29,8 @@ # [1]: https://eslint.org/ ESLINT ?= $(BIN_DIR)/eslint -# Define the path to the ESLint configuration file: -ESLINT_TS_CONF ?= $(CONFIG_DIR)/eslint/.eslintrc.typescript.js - -# Define the path to the ESLint configuration file for tests: -ESLINT_TS_CONF_TESTS ?= $(CONFIG_DIR)/eslint/.eslintrc.typescript.tests.js - -# Define the path to a TypeScript configuration file: -TS_CONFIG ?= $(CONFIG_DIR)/typescript/tsconfig.json - -# Define the path to the ESLint ignore file: -ESLINT_IGNORE ?= $(ROOT_DIR)/.eslintignore - # Define the command-line options to use when invoking the ESLint executable: -ESLINT_TS_FLAGS ?= \ - --ignore-path $(ESLINT_IGNORE) +ESLINT_TS_FLAGS ?= ifeq ($(AUTOFIX),true) ESLINT_TS_FLAGS += --fix @@ -80,21 +67,13 @@ ifeq ($(FAIL_FAST), true) $(QUIET) $(FIND_TYPESCRIPT_DECLARATIONS_CMD) | grep '^[\/]\|^[a-zA-Z]:[/\]' | while read -r file; do \ echo ''; \ echo "Linting file: $$file"; \ - DIR=`dirname $$file`; \ - LOCAL_TS_CONFIG=$$DIR/tsconfig.json; \ - $(CP) $(TS_CONFIG) $$DIR; \ - $(ESLINT) $(ESLINT_TS_FLAGS) --config $(ESLINT_TS_CONF) --parser-options=project:$$LOCAL_TS_CONFIG $$file || exit 1; \ - rm $$LOCAL_TS_CONFIG; \ + $(ESLINT) $(ESLINT_TS_FLAGS) $$file || exit 1; \ done else $(QUIET) $(FIND_TYPESCRIPT_DECLARATIONS_CMD) | grep '^[\/]\|^[a-zA-Z]:[/\]' | while read -r file; do \ echo ''; \ echo "Linting file: $$file"; \ - DIR=`dirname $$file`; \ - LOCAL_TS_CONFIG=$$DIR/tsconfig.json; \ - $(CP) $(TS_CONFIG) $$DIR; \ - $(ESLINT) $(ESLINT_TS_FLAGS) --config $(ESLINT_TS_CONF) --parser-options=project:$$LOCAL_TS_CONFIG $$file || echo 'Linting failed.'; \ - rm $$LOCAL_TS_CONFIG; \ + $(ESLINT) $(ESLINT_TS_FLAGS) $$file || echo 'Linting failed.'; \ done endif @@ -121,21 +100,13 @@ ifeq ($(FAIL_FAST), true) $(QUIET) $(FIND_TYPESCRIPT_DECLARATIONS_TESTS_CMD) | grep '^[\/]\|^[a-zA-Z]:[/\]' | while read -r file; do \ echo ''; \ echo "Linting file: $$file"; \ - DIR=`dirname $$file`; \ - LOCAL_TS_CONFIG=$$DIR/tsconfig.json; \ - $(CP) $(TS_CONFIG) $$DIR; \ - $(ESLINT) $(ESLINT_TS_FLAGS) --config $(ESLINT_TS_CONF_TESTS) --parser-options=project:$$LOCAL_TS_CONFIG $$file || exit 1; \ - rm $$LOCAL_TS_CONFIG; \ + $(ESLINT) $(ESLINT_TS_FLAGS) $$file || exit 1; \ done else $(QUIET) $(FIND_TYPESCRIPT_DECLARATIONS_TESTS_CMD) | grep '^[\/]\|^[a-zA-Z]:[/\]' | while read -r file; do \ echo ''; \ echo "Linting file: $$file"; \ - DIR=`dirname $$file`; \ - LOCAL_TS_CONFIG=$$DIR/tsconfig.json; \ - $(CP) $(TS_CONFIG) $$DIR; \ - $(ESLINT) $(ESLINT_TS_FLAGS) --config $(ESLINT_TS_CONF_TESTS) --parser-options=project:$$LOCAL_TS_CONFIG $$file || echo 'Linting failed.'; \ - rm $$LOCAL_TS_CONFIG; \ + $(ESLINT) $(ESLINT_TS_FLAGS) $$file || echo 'Linting failed.'; \ done endif @@ -160,21 +131,13 @@ ifeq ($(FAIL_FAST), true) $(QUIET) for file in $(FILES); do \ echo ''; \ echo "Linting file: $$file"; \ - DIR=`dirname $$file`; \ - LOCAL_TS_CONFIG=$$DIR/tsconfig.json; \ - $(CP) $(TS_CONFIG) $$DIR; \ - $(ESLINT) $(ESLINT_TS_FLAGS) --config $(ESLINT_TS_CONF) --parser-options=project:$$LOCAL_TS_CONFIG $$file || exit 1; \ - rm $$LOCAL_TS_CONFIG; \ + $(ESLINT) $(ESLINT_TS_FLAGS) $$file || exit 1; \ done else $(QUIET) for file in $(FILES); do \ echo ''; \ echo "Linting file: $$file"; \ - DIR=`dirname $$file`; \ - LOCAL_TS_CONFIG=$$DIR/tsconfig.json; \ - $(CP) $(TS_CONFIG) $$DIR; \ - $(ESLINT) $(ESLINT_TS_FLAGS) --config $(ESLINT_TS_CONF) --parser-options=project:$$LOCAL_TS_CONFIG $$file || echo 'Linting failed.'; \ - rm $$LOCAL_TS_CONFIG; \ + $(ESLINT) $(ESLINT_TS_FLAGS) $$file || echo 'Linting failed.'; \ done endif