Skip to content
Merged
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
131 changes: 131 additions & 0 deletions eslint.flat.config.js
Comment thread
Planeshifter marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/**
* @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.
*/

/* eslint-disable n/no-unpublished-require */

'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 assign = require( './lib/node_modules/@stdlib/object/assign' );
var stdlibPlugin = require( './lib/node_modules/@stdlib/_tools/eslint/rules/scripts/plugin.js' );
var restrictedSyntaxConfig = require( './etc/eslint/overrides/restricted_syntax.js' );
var rules = require( './etc/eslint/rules' );


// VARIABLES //

var globalVars;
var config;


// MAIN //

globalVars = assign( {}, globals.browser, globals.node );
globalVars = assign( globalVars, globals.commonjs, globals.worker );

config = [
// Global ignores:
{
'ignores': [
'**/build/',
'**/reports/',
'dist/',
'.git*'
]
},

// Base JavaScript config:
{
'files': [ '**/*.js' ],
'languageOptions': {
'ecmaVersion': 6,
'sourceType': 'script',
'globals': globalVars
},
'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
}
}
];


// EXPORTS //

module.exports = config;
43 changes: 1 addition & 42 deletions etc/eslint/overrides/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,48 +21,7 @@
// MODULES //

var resolve = require( 'path' ).resolve;


// VARIABLES //

var restrictedSyntaxConfig = [ 'error',
'ArrowFunctionExpression',
'ClassBody',
'ClassDeclaration',
'ClassExpression',
'DebuggerStatement',
'ExperimentalRestProperty',
'ExperimentalSpreadProperty',

// 'FunctionExpression',
'LabeledStatement',
'RestElement',
'SpreadElement',
'TaggedTemplateExpression',
'TemplateElement',
'TemplateLiteral',
'WithStatement',
'YieldExpression',
'JSXIdentifier',
'JSXNamespacedName',
'JSXMemberExpression',
'JSXEmptyExpression',
'JSXExpressionContainer',
'JSXElement',
'JSXClosingElement',
'JSXOpeningElement',
'JSXAttribute',
'JSXSpreadAttribute',
'JSXText',
'ExportDefaultDeclaration',
'ExportNamedDeclaration',
'ExportAllDeclaration',
'ExportSpecifier',
'ImportDeclaration',
'ImportSpecifier',
'ImportDefaultSpecifier',
'ImportNamespaceSpecifier'
];
var restrictedSyntaxConfig = require( './restricted_syntax.js' );


// MAIN //
Expand Down
65 changes: 65 additions & 0 deletions etc/eslint/overrides/restricted_syntax.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/**
* @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';

// MAIN //

var rule = [ 'error',
'ArrowFunctionExpression',
'ClassBody',
'ClassDeclaration',
'ClassExpression',
'DebuggerStatement',
'ExperimentalRestProperty',
'ExperimentalSpreadProperty',

// 'FunctionExpression',
'LabeledStatement',
'RestElement',
'SpreadElement',
'TaggedTemplateExpression',
'TemplateElement',
'TemplateLiteral',
'WithStatement',
'YieldExpression',
'JSXIdentifier',
'JSXNamespacedName',
'JSXMemberExpression',
'JSXEmptyExpression',
'JSXExpressionContainer',
'JSXElement',
'JSXClosingElement',
'JSXOpeningElement',
'JSXAttribute',
'JSXSpreadAttribute',
'JSXText',
'ExportDefaultDeclaration',
'ExportNamedDeclaration',
'ExportAllDeclaration',
'ExportSpecifier',
'ImportDeclaration',
'ImportSpecifier',
'ImportDefaultSpecifier',
'ImportNamespaceSpecifier'
];


// EXPORTS //

module.exports = rule;
4 changes: 2 additions & 2 deletions etc/eslint/rules/stdlib.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable stdlib/jsdoc-doctest-marker, stdlib/jsdoc-doctest, stdlib/jsdoc-example-require-spacing, stdlib/jsdoc-no-tabs */
/* eslint-disable stdlib/jsdoc-doctest-marker, stdlib/jsdoc-example-require-spacing, stdlib/jsdoc-no-tabs */

/**
* @license Apache-2.0
Expand Down Expand Up @@ -879,7 +879,7 @@
* // Bad...
*
* /**
* * Fréchet distribution constructor.

Check warning on line 882 in etc/eslint/rules/stdlib.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unknown word: "échet"
* *
* * @module @stdlib/stats/base/dists/frechet/ctor
* *
Expand All @@ -895,7 +895,7 @@
* // Good...
*
* /**
* * Fréchet distribution constructor.

Check warning on line 898 in etc/eslint/rules/stdlib.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unknown word: "échet"
* *
* * @module @stdlib/stats/base/dists/frechet/ctor
* *
Expand Down Expand Up @@ -1720,7 +1720,7 @@
*/
rules[ 'stdlib/jsdoc-markdown-remark' ] = [ 'error',
{
'config': require( './../../remark/.remarkrc.jsdoc.js' )
'configPath': require.resolve( './../../remark/.remarkrc.jsdoc.js' )
}
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,16 @@ function beep() {

<!-- /.usage -->

<section class="notes">

## Notes

- To keep rule options serializable (e.g., when using an ESLint flat config), set the `configPath` option to an absolute path for a CommonJS module which exports a remark configuration.

</section>

<!-- /.notes -->

<section class="examples">

## Examples
Expand All @@ -97,12 +107,9 @@ var noDuplicateHeadings = require( 'remark-lint-no-duplicate-headings' );
var rule = require( '@stdlib/_tools/eslint/rules/jsdoc-markdown-remark' );

var linter = new Linter();
var config;
var result;
var code;

// Generate our source code containing a single lint error (a duplicate heading):
code = [
var code = [
'/**',
'* Beep boop.',
'*',
Expand Down Expand Up @@ -150,7 +157,7 @@ code = [
].join( '\n' );

// Create a remark configuration:
config = {
var config = {
'plugins': [
[ remarkLint ],
[ noDuplicateHeadings, [ 'error' ] ]
Expand All @@ -161,7 +168,7 @@ config = {
linter.defineRule( 'jsdoc-markdown-remark', rule );

// Lint the code:
result = linter.verify( code, {
var result = linter.verify( code, {
'rules': {
'jsdoc-markdown-remark': [ 'error', {
'config': config
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,19 @@ var rule;
*/
function main( context ) {
var options;
var config;
var source;
var lint;
var opts;

options = context.options[ 0 ];
opts = {};
if ( hasOwnProp( options, 'config' ) ) {
opts.config = options.config;
if ( hasOwnProp( options, 'configPath' ) ) {
config = require( options.configPath ); // eslint-disable-line stdlib/no-dynamic-require
} else if ( hasOwnProp( options, 'config' ) ) {
config = options.config;
} else {
opts.config = {};
config = {};
}
lint = remark().use( opts.config ).processSync;
lint = remark().use( config ).processSync;
source = context.sourceCode;

return {
Expand Down Expand Up @@ -151,6 +152,9 @@ rule = {
'properties': {
'config': {
'type': 'object'
},
'configPath': {
'type': 'string'
}
},
'additionalProperties': false
Expand Down
Loading
Loading