Skip to content

Commit c3dab8a

Browse files
committed
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: stdlib-js/metr-issue-tracker#54
1 parent 85dcf2f commit c3dab8a

File tree

3 files changed

+21
-81
lines changed

3 files changed

+21
-81
lines changed

tools/git/hooks/pre-commit

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,12 @@ lint_package_json="${root}/lib/node_modules/@stdlib/_tools/lint/pkg-json/bin/cli
6060
lint_repl_help="${root}/lib/node_modules/@stdlib/_tools/lint/repl-txt/bin/cli"
6161

6262
# Define the path to ESLint configuration file for linting examples:
63-
eslint_examples_conf="${root}/etc/eslint/.eslintrc.examples.js"
6463

6564
# Define the path to ESLint configuration file for linting tests:
66-
eslint_tests_conf="${root}/etc/eslint/.eslintrc.tests.js"
6765

6866
# Define the path to ESLint configuration file for linting benchmarks:
69-
eslint_benchmarks_conf="${root}/etc/eslint/.eslintrc.benchmarks.js"
7067

7168
# Define the path to ESLint configuration file for linting TypeScript definition tests:
72-
eslint_typescript_tests_conf="${root}/etc/eslint/.eslintrc.typescript.tests.js"
7369

7470
# Define the path to cppcheck configuration file for linting examples:
7571
cppcheck_examples_suppressions_list="${root}/etc/cppcheck/suppressions.examples.txt"
@@ -316,7 +312,7 @@ run_lint() {
316312
if [[ -z "${skip_javascript_examples}" ]]; then
317313
files=$(echo "${changed_files}" | grep '/examples/.*\.js$' | tr '\n' ' ')
318314
if [[ -n "${files}" ]]; then
319-
make JAVASCRIPT_LINTER=eslint ESLINT_CONF="${eslint_examples_conf}" FILES="${files}" FIX=1 lint-javascript-files > /dev/null >&2
315+
make JAVASCRIPT_LINTER=eslint FILES="${files}" FIX=1 lint-javascript-files > /dev/null >&2
320316
if [[ "$?" -ne 0 ]]; then
321317
task_status 'failed'
322318
echo '' >&2
@@ -335,7 +331,7 @@ run_lint() {
335331
if [[ -z "${skip_javascript_tests}" ]]; then
336332
files=$(echo "${changed_files}" | grep '/test/.*\.js$' | tr '\n' ' ')
337333
if [[ -n "${files}" ]]; then
338-
make JAVASCRIPT_LINTER=eslint ESLINT_CONF="${eslint_tests_conf}" FILES="${files}" FIX=1 lint-javascript-files > /dev/null >&2
334+
make JAVASCRIPT_LINTER=eslint FILES="${files}" FIX=1 lint-javascript-files > /dev/null >&2
339335
if [[ "$?" -ne 0 ]]; then
340336
task_status 'failed'
341337
echo '' >&2
@@ -354,7 +350,7 @@ run_lint() {
354350
if [[ -z "${skip_javascript_benchmarks}" ]]; then
355351
files=$(echo "${changed_files}" | grep '/benchmark/.*\.js$' | tr '\n' ' ')
356352
if [[ -n "${files}" ]]; then
357-
make JAVASCRIPT_LINTER=eslint ESLINT_CONF="${eslint_benchmarks_conf}" FILES="${files}" FIX=1 lint-javascript-files > /dev/null >&2
353+
make JAVASCRIPT_LINTER=eslint FILES="${files}" FIX=1 lint-javascript-files > /dev/null >&2
358354
if [[ "$?" -ne 0 ]]; then
359355
task_status 'failed'
360356
echo '' >&2
@@ -587,7 +583,7 @@ run_lint() {
587583

588584
# Lint all collected test files...
589585
if [[ -n "${files}" ]]; then
590-
make TYPESCRIPT_DECLARATIONS_LINTER=eslint FILES="${files}" ESLINT_TS_CONF="${eslint_typescript_tests_conf}" lint-typescript-declarations-files > /dev/null >&2
586+
make TYPESCRIPT_DECLARATIONS_LINTER=eslint FILES="${files}" lint-typescript-declarations-files > /dev/null >&2
591587
if [[ "$?" -ne 0 ]]; then
592588
task_status 'failed'
593589
echo '' >&2

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

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -29,27 +29,8 @@
2929
# [1]: https://eslint.org/
3030
ESLINT ?= $(BIN_DIR)/eslint
3131

32-
# Define the path to the ESLint configuration file:
33-
ESLINT_CONF ?= $(CONFIG_DIR)/eslint/.eslintrc.js
34-
35-
# Define the path to the ESLint configuration file for examples:
36-
ESLINT_CONF_EXAMPLES ?= $(CONFIG_DIR)/eslint/.eslintrc.examples.js
37-
38-
# Define the path to the ESLint configuration file for tests:
39-
ESLINT_CONF_TESTS ?= $(CONFIG_DIR)/eslint/.eslintrc.tests.js
40-
41-
# Define the path to the ESLint configuration file for benchmarks:
42-
ESLINT_CONF_BENCHMARKS ?= $(CONFIG_DIR)/eslint/.eslintrc.benchmarks.js
43-
44-
# Define the path to the ESLint ignore file:
45-
ESLINT_IGNORE ?= $(ROOT_DIR)/.eslintignore
46-
47-
# Force legacy config mode (eslint.config.cjs exists but Makefiles still use legacy flags):
48-
export ESLINT_USE_FLAT_CONFIG := false
49-
5032
# Define the command-line options to use when invoking the ESLint executable:
5133
eslint_flags := \
52-
--ignore-path $(ESLINT_IGNORE) \
5334
--report-unused-disable-directives
5435

5536
# Define user-supplied command-line options:
@@ -97,14 +78,14 @@ ifeq ($(FAIL_FAST), true)
9778
$(QUIET) $(FIND_SOURCES_CMD) | grep '^[\/]\|^[a-zA-Z]:[/\]' | while read -r file; do \
9879
echo ''; \
9980
echo "Linting file: $$file"; \
100-
$(ESLINT) $(eslint_flags) --config $(ESLINT_CONF) $$file || exit 1; \
81+
$(ESLINT) $(eslint_flags) $$file || exit 1; \
10182
done
10283
else
10384
$(QUIET) status=0; \
10485
$(FIND_SOURCES_CMD) | grep '^[\/]\|^[a-zA-Z]:[/\]' | while read -r file; do \
10586
echo ''; \
10687
echo "Linting file: $$file"; \
107-
if ! $(ESLINT) $(eslint_flags) --config $(ESLINT_CONF) $$file; then \
88+
if ! $(ESLINT) $(eslint_flags) $$file; then \
10889
echo 'Linting failed.'; \
10990
status=1; \
11091
fi; \
@@ -138,14 +119,14 @@ ifeq ($(FAIL_FAST), true)
138119
$(QUIET) $(FIND_TESTS_CMD) | grep '^[\/]\|^[a-zA-Z]:[/\]' | while read -r file; do \
139120
echo ''; \
140121
echo "Linting file: $$file"; \
141-
$(ESLINT) $(eslint_flags) --config $(ESLINT_CONF_TESTS) $$file || exit 1; \
122+
$(ESLINT) $(eslint_flags) $$file || exit 1; \
142123
done
143124
else
144125
$(QUIET) status=0; \
145126
$(FIND_TESTS_CMD) | grep '^[\/]\|^[a-zA-Z]:[/\]' | while read -r file; do \
146127
echo ''; \
147128
echo "Linting file: $$file"; \
148-
if ! $(ESLINT) $(eslint_flags) --config $(ESLINT_CONF_TESTS) $$file; then \
129+
if ! $(ESLINT) $(eslint_flags) $$file; then \
149130
echo 'Linting failed.'; \
150131
status=1; \
151132
fi; \
@@ -179,14 +160,14 @@ ifeq ($(FAIL_FAST), true)
179160
$(QUIET) $(FIND_EXAMPLES_CMD) | grep '^[\/]\|^[a-zA-Z]:[/\]' | while read -r file; do \
180161
echo ''; \
181162
echo "Linting file: $$file"; \
182-
$(ESLINT) $(eslint_flags) --config $(ESLINT_CONF_EXAMPLES) $$file || exit 1; \
163+
$(ESLINT) $(eslint_flags) $$file || exit 1; \
183164
done
184165
else
185166
$(QUIET) status=0; \
186167
$(FIND_EXAMPLES_CMD) | grep '^[\/]\|^[a-zA-Z]:[/\]' | while read -r file; do \
187168
echo ''; \
188169
echo "Linting file: $$file"; \
189-
if ! $(ESLINT) $(eslint_flags) --config $(ESLINT_CONF_EXAMPLES) $$file; then \
170+
if ! $(ESLINT) $(eslint_flags) $$file; then \
190171
echo 'Linting failed.'; \
191172
status=1; \
192173
fi; \
@@ -220,14 +201,14 @@ ifeq ($(FAIL_FAST), true)
220201
$(QUIET) $(FIND_BENCHMARKS_CMD) | grep '^[\/]\|^[a-zA-Z]:[/\]' | while read -r file; do \
221202
echo ''; \
222203
echo "Linting file: $$file"; \
223-
$(ESLINT) $(eslint_flags) --config $(ESLINT_CONF_BENCHMARKS) $$file || exit 1; \
204+
$(ESLINT) $(eslint_flags) $$file || exit 1; \
224205
done
225206
else
226207
$(QUIET) status=0; \
227208
$(FIND_BENCHMARKS_CMD) | grep '^[\/]\|^[a-zA-Z]:[/\]' | while read -r file; do \
228209
echo ''; \
229210
echo "Linting file: $$file"; \
230-
if ! $(ESLINT) $(eslint_flags) --config $(ESLINT_CONF_BENCHMARKS) $$file; then \
211+
if ! $(ESLINT) $(eslint_flags) $$file; then \
231212
echo 'Linting failed.'; \
232213
status=1; \
233214
fi; \
@@ -258,14 +239,14 @@ ifeq ($(FAIL_FAST), true)
258239
$(QUIET) for file in $(FILES); do \
259240
echo ''; \
260241
echo "Linting file: $$file"; \
261-
$(ESLINT) $(eslint_flags) --config $(ESLINT_CONF) $$file || exit 1; \
242+
$(ESLINT) $(eslint_flags) $$file || exit 1; \
262243
done
263244
else
264245
$(QUIET) status=0; \
265246
for file in $(FILES); do \
266247
echo ''; \
267248
echo "Linting file: $$file"; \
268-
if ! $(ESLINT) $(eslint_flags) --config $(ESLINT_CONF) $$file; then \
249+
if ! $(ESLINT) $(eslint_flags) $$file; then \
269250
echo 'Linting failed.'; \
270251
status=1; \
271252
fi; \

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

Lines changed: 7 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,8 @@
2929
# [1]: https://eslint.org/
3030
ESLINT ?= $(BIN_DIR)/eslint
3131

32-
# Define the path to the ESLint configuration file:
33-
ESLINT_TS_CONF ?= $(CONFIG_DIR)/eslint/.eslintrc.typescript.js
34-
35-
# Define the path to the ESLint configuration file for tests:
36-
ESLINT_TS_CONF_TESTS ?= $(CONFIG_DIR)/eslint/.eslintrc.typescript.tests.js
37-
38-
# Define the path to a TypeScript configuration file:
39-
TS_CONFIG ?= $(CONFIG_DIR)/typescript/tsconfig.json
40-
41-
# Define the path to the ESLint ignore file:
42-
ESLINT_IGNORE ?= $(ROOT_DIR)/.eslintignore
43-
4432
# Define the command-line options to use when invoking the ESLint executable:
45-
ESLINT_TS_FLAGS ?= \
46-
--ignore-path $(ESLINT_IGNORE)
33+
ESLINT_TS_FLAGS ?=
4734

4835
ifeq ($(AUTOFIX),true)
4936
ESLINT_TS_FLAGS += --fix
@@ -80,21 +67,13 @@ ifeq ($(FAIL_FAST), true)
8067
$(QUIET) $(FIND_TYPESCRIPT_DECLARATIONS_CMD) | grep '^[\/]\|^[a-zA-Z]:[/\]' | while read -r file; do \
8168
echo ''; \
8269
echo "Linting file: $$file"; \
83-
DIR=`dirname $$file`; \
84-
LOCAL_TS_CONFIG=$$DIR/tsconfig.json; \
85-
$(CP) $(TS_CONFIG) $$DIR; \
86-
$(ESLINT) $(ESLINT_TS_FLAGS) --config $(ESLINT_TS_CONF) --parser-options=project:$$LOCAL_TS_CONFIG $$file || exit 1; \
87-
rm $$LOCAL_TS_CONFIG; \
70+
$(ESLINT) $(ESLINT_TS_FLAGS) $$file || exit 1; \
8871
done
8972
else
9073
$(QUIET) $(FIND_TYPESCRIPT_DECLARATIONS_CMD) | grep '^[\/]\|^[a-zA-Z]:[/\]' | while read -r file; do \
9174
echo ''; \
9275
echo "Linting file: $$file"; \
93-
DIR=`dirname $$file`; \
94-
LOCAL_TS_CONFIG=$$DIR/tsconfig.json; \
95-
$(CP) $(TS_CONFIG) $$DIR; \
96-
$(ESLINT) $(ESLINT_TS_FLAGS) --config $(ESLINT_TS_CONF) --parser-options=project:$$LOCAL_TS_CONFIG $$file || echo 'Linting failed.'; \
97-
rm $$LOCAL_TS_CONFIG; \
76+
$(ESLINT) $(ESLINT_TS_FLAGS) $$file || echo 'Linting failed.'; \
9877
done
9978
endif
10079

@@ -121,21 +100,13 @@ ifeq ($(FAIL_FAST), true)
121100
$(QUIET) $(FIND_TYPESCRIPT_DECLARATIONS_TESTS_CMD) | grep '^[\/]\|^[a-zA-Z]:[/\]' | while read -r file; do \
122101
echo ''; \
123102
echo "Linting file: $$file"; \
124-
DIR=`dirname $$file`; \
125-
LOCAL_TS_CONFIG=$$DIR/tsconfig.json; \
126-
$(CP) $(TS_CONFIG) $$DIR; \
127-
$(ESLINT) $(ESLINT_TS_FLAGS) --config $(ESLINT_TS_CONF_TESTS) --parser-options=project:$$LOCAL_TS_CONFIG $$file || exit 1; \
128-
rm $$LOCAL_TS_CONFIG; \
103+
$(ESLINT) $(ESLINT_TS_FLAGS) $$file || exit 1; \
129104
done
130105
else
131106
$(QUIET) $(FIND_TYPESCRIPT_DECLARATIONS_TESTS_CMD) | grep '^[\/]\|^[a-zA-Z]:[/\]' | while read -r file; do \
132107
echo ''; \
133108
echo "Linting file: $$file"; \
134-
DIR=`dirname $$file`; \
135-
LOCAL_TS_CONFIG=$$DIR/tsconfig.json; \
136-
$(CP) $(TS_CONFIG) $$DIR; \
137-
$(ESLINT) $(ESLINT_TS_FLAGS) --config $(ESLINT_TS_CONF_TESTS) --parser-options=project:$$LOCAL_TS_CONFIG $$file || echo 'Linting failed.'; \
138-
rm $$LOCAL_TS_CONFIG; \
109+
$(ESLINT) $(ESLINT_TS_FLAGS) $$file || echo 'Linting failed.'; \
139110
done
140111
endif
141112

@@ -160,21 +131,13 @@ ifeq ($(FAIL_FAST), true)
160131
$(QUIET) for file in $(FILES); do \
161132
echo ''; \
162133
echo "Linting file: $$file"; \
163-
DIR=`dirname $$file`; \
164-
LOCAL_TS_CONFIG=$$DIR/tsconfig.json; \
165-
$(CP) $(TS_CONFIG) $$DIR; \
166-
$(ESLINT) $(ESLINT_TS_FLAGS) --config $(ESLINT_TS_CONF) --parser-options=project:$$LOCAL_TS_CONFIG $$file || exit 1; \
167-
rm $$LOCAL_TS_CONFIG; \
134+
$(ESLINT) $(ESLINT_TS_FLAGS) $$file || exit 1; \
168135
done
169136
else
170137
$(QUIET) for file in $(FILES); do \
171138
echo ''; \
172139
echo "Linting file: $$file"; \
173-
DIR=`dirname $$file`; \
174-
LOCAL_TS_CONFIG=$$DIR/tsconfig.json; \
175-
$(CP) $(TS_CONFIG) $$DIR; \
176-
$(ESLINT) $(ESLINT_TS_FLAGS) --config $(ESLINT_TS_CONF) --parser-options=project:$$LOCAL_TS_CONFIG $$file || echo 'Linting failed.'; \
177-
rm $$LOCAL_TS_CONFIG; \
140+
$(ESLINT) $(ESLINT_TS_FLAGS) $$file || echo 'Linting failed.'; \
178141
done
179142
endif
180143

0 commit comments

Comments
 (0)