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
104 changes: 104 additions & 0 deletions eslint.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,15 @@ 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 pluginJsonc = require( 'eslint-plugin-jsonc' );
var jsoncParser = require( 'jsonc-eslint-parser' );
var pluginYml = require( 'eslint-plugin-yml' );
var yamlParser = require( 'yaml-eslint-parser' );
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 jsonRules = require( './etc/eslint/rules/json.js' );
var yamlRules = require( './etc/eslint/rules/yaml.js' );


// VARIABLES //
Expand Down Expand Up @@ -101,6 +107,8 @@ module.exports = [
'**/reports/',
'dist/',
'.git*',
'!.github/',
'!.codecov.yml',

// ESLint ignores **/node_modules/ by default. stdlib source
// lives in lib/node_modules/, so un-ignore it:
Expand Down Expand Up @@ -217,5 +225,101 @@ module.exports = [
'rules': {
'jsdoc/require-jsdoc': 'off'
}
},

// Base JSON:
{
'files': [ '**/*.json' ],
'languageOptions': {
'parser': jsoncParser
},
'plugins': {
'jsonc': pluginJsonc
},
'rules': jsonRules
},

// cli_opts.json override (tab-indented per .editorconfig):
{
'files': [ '**/cli_opts.json' ],
'rules': {
'jsonc/indent': [ 'error', 'tab' ]
}
},

// package.json key ordering:
{
'files': [ '**/package.json' ],
'rules': {
'jsonc/sort-keys': [ 'error', {
'pathPattern': '^$',
'order': [
'name',
'private',
'version',
'description',
'license',
'licenses',
'author',
'maintainers',
'contributors',
'funding',
'bin',
'main',
'exports',
'browser',
'unpkg',
'gypfile',
'directories',
'types',
'scripts',
'homepage',
'repository',
'repositories',
'bugs',
'dependencies',
'optionalDependencies',
'devDependencies',
'engines',
'os',
'keywords',
'__stdlib__'
]
}]
}
},

// Base YAML:
{
'files': [ '**/*.yml' ],
'languageOptions': {
'parser': yamlParser
},
'plugins': {
'yml': pluginYml,
'stdlib': stdlibPlugin
},
'rules': {
...yamlRules,
'stdlib/yaml-license-header': 'error'
}
},

// GitHub Actions workflow key ordering:
{
'files': [ '.github/workflows/*.yml' ],
'rules': {
'yml/sort-keys': [ 'error', {
'pathPattern': '^$',
'order': [
'name',
'on',
'concurrency',
'permissions',
'env',
'jobs'
]
}]
}
}
];
121 changes: 121 additions & 0 deletions etc/eslint/rules/json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/**
* @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';

/**
* ESLint rules for JSON files.
*
* @namespace rules
*/
var rules = {};

/**
* Enforce 2-space indentation per `.editorconfig`.
*
* @name jsonc/indent
* @memberof rules
* @type {Array}
*/
rules[ 'jsonc/indent' ] = [ 'error', 2 ];

/**
* Disallow comments in JSON files.
*
* @name jsonc/no-comments
* @memberof rules
* @type {string}
*/
rules[ 'jsonc/no-comments' ] = 'error';

/**
* Disallow trailing commas.
*
* @name jsonc/comma-dangle
* @memberof rules
* @type {Array}
*/
rules[ 'jsonc/comma-dangle' ] = [ 'error', 'never' ];

/**
* Disallow duplicate keys.
*
* @name jsonc/no-dupe-keys
* @memberof rules
* @type {string}
*/
rules[ 'jsonc/no-dupe-keys' ] = 'error';

/**
* Disallow floating decimals (e.g., `.5` or `1.`).
*
* @name jsonc/no-floating-decimal
* @memberof rules
* @type {string}
*/
rules[ 'jsonc/no-floating-decimal' ] = 'error';

/**
* Disallow irregular whitespace characters.
*
* @name jsonc/no-irregular-whitespace
* @memberof rules
* @type {string}
*/
rules[ 'jsonc/no-irregular-whitespace' ] = 'error';

/**
* Disallow multi-line strings.
*
* @name jsonc/no-multi-str
* @memberof rules
* @type {string}
*/
rules[ 'jsonc/no-multi-str' ] = 'error';

/**
* Disallow octal literals.
*
* @name jsonc/no-octal
* @memberof rules
* @type {string}
*/
rules[ 'jsonc/no-octal' ] = 'error';

/**
* Disallow useless escape characters.
*
* @name jsonc/no-useless-escape
* @memberof rules
* @type {string}
*/
rules[ 'jsonc/no-useless-escape' ] = 'error';

/**
* Enforce valid JSON number literals.
*
* @name jsonc/valid-json-number
* @memberof rules
* @type {string}
*/
rules[ 'jsonc/valid-json-number' ] = 'error';


// EXPORTS //

module.exports = rules;
144 changes: 144 additions & 0 deletions etc/eslint/rules/yaml.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
/**
* @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';

/**
* ESLint rules for YAML files.
*
* @namespace rules
*/
var rules = {};

/**
* Enforce 2-space indentation per `.editorconfig`.
*
* @name yml/indent
* @memberof rules
* @type {Array}
*/
rules[ 'yml/indent' ] = [ 'error', 2 ];

/**
* Disallow empty YAML documents.
*
* @name yml/no-empty-document
* @memberof rules
* @type {string}
*/
rules[ 'yml/no-empty-document' ] = 'error';

/**
* Disallow empty keys.
*
* @name yml/no-empty-key
* @memberof rules
* @type {string}
*/
rules[ 'yml/no-empty-key' ] = 'error';

/**
* Disallow empty mapping values.
*
* @name yml/no-empty-mapping-value
* @memberof rules
* @type {string}
*/
rules[ 'yml/no-empty-mapping-value' ] = 'error';

/**
* Disallow empty sequence entries.
*
* @name yml/no-empty-sequence-entry
* @memberof rules
* @type {string}
*/
rules[ 'yml/no-empty-sequence-entry' ] = 'error';

/**
* Disallow irregular whitespace characters.
*
* @name yml/no-irregular-whitespace
* @memberof rules
* @type {string}
*/
rules[ 'yml/no-irregular-whitespace' ] = 'error';

/**
* Disallow tab indentation.
*
* @name yml/no-tab-indent
* @memberof rules
* @type {string}
*/
rules[ 'yml/no-tab-indent' ] = 'error';

/**
* Require string keys.
*
* @name yml/require-string-key
* @memberof rules
* @type {string}
*/
rules[ 'yml/require-string-key' ] = 'error';

/**
* Enforce block-style mappings.
*
* @name yml/block-mapping
* @memberof rules
* @type {string}
*/
rules[ 'yml/block-mapping' ] = 'error';

/**
* Enforce block-style sequences.
*
* @name yml/block-sequence
* @memberof rules
* @type {string}
*/
rules[ 'yml/block-sequence' ] = 'error';

/**
* Disallow multiple consecutive empty lines.
*
* @name yml/no-multiple-empty-lines
* @memberof rules
* @type {Array}
*/
rules[ 'yml/no-multiple-empty-lines' ] = [ 'error', {
'max': 1
}];

/**
* Prefer single quotes (warn first to assess impact on `${{ }}` expressions).
*
* @name yml/quotes
* @memberof rules
* @type {Array}
*/
rules[ 'yml/quotes' ] = [ 'warn', {
'prefer': 'single',
'avoidEscape': true
}];


// EXPORTS //

module.exports = rules;
Loading
Loading