From 47afeab6d38eed7cd155e7ff2f06526f2eff8d5e Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Sun, 15 Mar 2026 09:27:17 -0500 Subject: [PATCH 1/2] build: add `eslint.config.cjs` for JavaScript targets on ESLint v8 Add flat config alongside the legacy `.eslintrc.*` configuration: - Create `eslint.config.cjs` with base JS config, override blocks for benchmarks, examples, tests, and REPL namespace files - Inline stdlib rules as a runtime plugin object via `lib/node_modules/@stdlib/_tools/eslint/rules/scripts/plugin.js` - Reuse existing rule definitions from `etc/eslint/rules/` - Separate non-clonable rule options (remark plugin instances) from the main rules object to work around `structuredClone` limitations in ESLint's flat config internals - Add `globals` package for flat config environment definitions - Legacy `.eslintrc.*` files remain in place as the default workflow Usage (requires ESLint v8 with flat config enabled): ESLINT_USE_FLAT_CONFIG=true npx eslint -c eslint.config.cjs Note: files under `lib/node_modules/` are hard-ignored by ESLint v8 flat config. Full `lib/` linting via flat config requires ESLint v9, which allows `!**/node_modules/` ignore overrides. Ref: https://github.com/stdlib-js/metr-issue-tracker/issues/54 --- eslint.config.cjs | 162 ++++++++++++++++++++++++++++++++++++++++++++++ package.json | 1 + 2 files changed, 163 insertions(+) create mode 100644 eslint.config.cjs diff --git a/eslint.config.cjs b/eslint.config.cjs new file mode 100644 index 000000000000..4413515aa7a0 --- /dev/null +++ b/eslint.config.cjs @@ -0,0 +1,162 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var globals = require( 'globals' ); +var pluginN = require( 'eslint-plugin-n' ); +var pluginCspell = require( '@cspell/eslint-plugin' ); +var pluginJsdoc = require( 'eslint-plugin-jsdoc' ); +var stdlibPlugin = require( './lib/node_modules/@stdlib/_tools/eslint/rules/scripts/plugin.js' ); +var allRules = require( './etc/eslint/rules' ); +var overrides = require( './etc/eslint/overrides' ); + + +// VARIABLES // + +var restrictedSyntaxConfig = overrides[ 1 ].rules[ 'no-restricted-syntax' ]; +var nonClonableRules = {}; +var rules = {}; +var val; +var key; +var i; + + +// FUNCTIONS // + +/** +* Tests whether a value can be structured-cloned. +* +* @private +* @param {*} value - value to test +* @returns {boolean} boolean indicating whether the value is clonable +*/ +function isClonable( value ) { + try { + // eslint-disable-next-line n/no-unsupported-features/es-builtins + if ( typeof structuredClone === 'function' ) { + structuredClone( value ); + } + return true; + } catch ( e ) { + return false; + } +} + + +// MAIN // + +// Separate rules that contain non-clonable values (e.g., remark plugin +// instances) because ESLint flat config internally clones config objects: +for ( key in allRules ) { + val = allRules[ key ]; + if ( isClonable( val ) ) { + rules[ key ] = val; + } else { + nonClonableRules[ key ] = val; + } +} + +module.exports = [ + // Global ignores: + { + 'ignores': [ + '**/build/', + '**/reports/', + 'dist/', + '.git*' + ] + }, + + // Base JavaScript config: + { + 'files': [ '**/*.js' ], + 'languageOptions': { + 'ecmaVersion': 6, + 'sourceType': 'script', + 'globals': { + ...globals.browser, + ...globals.node, + ...globals.commonjs, + ...globals.worker + } + }, + 'plugins': { + 'n': pluginN, + 'jsdoc': pluginJsdoc, + '@cspell': pluginCspell, + 'stdlib': stdlibPlugin + }, + 'rules': rules + }, + + // REPL namespace files: + { + 'files': [ '**/lib/node_modules/@stdlib/**/lib/[a-z].js' ], + 'rules': { + 'stdlib/repl-namespace-order': 'error' + } + }, + + // Benchmarks: + { + 'files': [ '**/benchmark/**/*.js' ], + 'rules': { + 'no-new-wrappers': 'warn', + 'max-lines': [ 'warn', { + 'max': 1000, + 'skipBlankLines': true, + 'skipComments': true + }], + 'jsdoc/require-jsdoc': 'off', + 'no-restricted-syntax': restrictedSyntaxConfig + } + }, + + // Examples: + { + 'files': [ '**/examples/**/*.js' ], + 'rules': { + 'no-console': 'off', + 'vars-on-top': 'off', + 'jsdoc/require-jsdoc': 'off', + 'stdlib/jsdoc-private-annotation': 'off', + 'stdlib/require-order': 'off', + 'stdlib/require-file-extensions': 'off', + 'no-restricted-syntax': restrictedSyntaxConfig + } + }, + + // Tests: + { + 'files': [ '**/test/**/*.js' ], + 'rules': { + 'no-empty-function': 'off', + 'jsdoc/require-jsdoc': 'off', + 'no-undefined': 'off', + 'max-lines': [ 'warn', { + 'max': 1000, + 'skipBlankLines': true, + 'skipComments': true + }], + 'no-restricted-syntax': restrictedSyntaxConfig + } + } +]; diff --git a/package.json b/package.json index 35dfeafe6c9d..a97d6981985a 100644 --- a/package.json +++ b/package.json @@ -145,6 +145,7 @@ "eslint-plugin-expect-type": "^0.2.3", "eslint-plugin-import": "^2.29.0", "eslint-plugin-jsdoc": "^46.8.2", + "globals": "^16.1.0", "exorcist": "^2.0.0", "factor-bundle": "^2.5.0", "gh-pages": "git+https://github.com/Planeshifter/gh-pages.git#main", From c3c02ecc4ac99b3af13c7a823cbccb102740b0c9 Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Sun, 15 Mar 2026 11:29:06 -0500 Subject: [PATCH 2/2] build: add TypeScript blocks to `eslint.config.cjs` Add TypeScript-specific flat config blocks for `**/*.d.ts` and `**/test/**/*.ts` files: - Configure `@typescript-eslint/parser` with `parserOptions.project` pointing to the root `tsconfig.json` - Register `@typescript-eslint`, `@stylistic/ts`, `jsdoc`, `import`, `expect-type`, and `stdlib` plugins - Reuse the existing TypeScript rules from `etc/eslint/rules/typescript.js` - Disable `jsdoc/require-jsdoc` for TypeScript test files Ref: https://github.com/stdlib-js/metr-issue-tracker/issues/54 --- eslint.config.cjs | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/eslint.config.cjs b/eslint.config.cjs index 4413515aa7a0..afe715d2d4a2 100644 --- a/eslint.config.cjs +++ b/eslint.config.cjs @@ -20,12 +20,19 @@ // MODULES // +var path = require( 'path' ); var globals = require( 'globals' ); +var tsParser = require( '@typescript-eslint/parser' ); +var tsPlugin = require( '@typescript-eslint/eslint-plugin' ); +var stylisticTs = require( '@stylistic/eslint-plugin-ts' ); var pluginN = require( 'eslint-plugin-n' ); var pluginCspell = require( '@cspell/eslint-plugin' ); var pluginJsdoc = require( 'eslint-plugin-jsdoc' ); +var pluginImport = require( 'eslint-plugin-import' ); +var pluginExpectType = require( 'eslint-plugin-expect-type' ); var stdlibPlugin = require( './lib/node_modules/@stdlib/_tools/eslint/rules/scripts/plugin.js' ); var allRules = require( './etc/eslint/rules' ); +var tsRules = require( './etc/eslint/rules/typescript.js' ); var overrides = require( './etc/eslint/overrides' ); @@ -158,5 +165,38 @@ module.exports = [ }], 'no-restricted-syntax': restrictedSyntaxConfig } + }, + + // TypeScript declarations: + { + 'files': [ '**/*.d.ts' ], + 'languageOptions': { + 'parser': tsParser, + 'sourceType': 'module', + 'parserOptions': { + 'project': path.join( __dirname, 'tsconfig.json' ) + }, + 'globals': { + ...globals.browser, + ...globals.node + } + }, + 'plugins': { + '@typescript-eslint': tsPlugin, + '@stylistic/ts': stylisticTs, + 'jsdoc': pluginJsdoc, + 'import': pluginImport, + 'expect-type': pluginExpectType, + 'stdlib': stdlibPlugin + }, + 'rules': tsRules + }, + + // TypeScript test files: + { + 'files': [ '**/test/**/*.ts' ], + 'rules': { + 'jsdoc/require-jsdoc': 'off' + } } ];