Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
202 changes: 202 additions & 0 deletions eslint.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
/**
* @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 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' );


// 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
}
},

// 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'
}
}
];
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down