From 1298006a8dbf87c4ef7857122344132efe10b27a Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Wed, 19 Feb 2025 15:23:03 -0500 Subject: [PATCH 1/7] build: add lint rule enforcing empty lines between requires and code --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na --- --- .../jsdoc-example-require-spacing/README.md | 157 ++++++++++++++++ .../examples/index.js | 75 ++++++++ .../lib/index.js | 45 +++++ .../jsdoc-example-require-spacing/lib/main.js | 172 ++++++++++++++++++ .../package.json | 64 +++++++ .../test/fixtures/invalid.js | 90 +++++++++ .../test/fixtures/valid.js | 90 +++++++++ .../test/test.js | 70 +++++++ 8 files changed, 763 insertions(+) create mode 100644 lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-example-require-spacing/README.md create mode 100644 lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-example-require-spacing/examples/index.js create mode 100644 lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-example-require-spacing/lib/index.js create mode 100644 lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-example-require-spacing/lib/main.js create mode 100644 lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-example-require-spacing/package.json create mode 100644 lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-example-require-spacing/test/fixtures/invalid.js create mode 100644 lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-example-require-spacing/test/fixtures/valid.js create mode 100644 lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-example-require-spacing/test/test.js diff --git a/lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-example-require-spacing/README.md b/lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-example-require-spacing/README.md new file mode 100644 index 000000000000..83b9d6d1dfcc --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-example-require-spacing/README.md @@ -0,0 +1,157 @@ + + +# jsdoc-example-require-spacing + +> [ESLint rule][eslint-rules] to enforce empty lines between requires and code in JSDoc examples. + +
+ +
+ + + +
+ +## Usage + +```javascript +var rule = require( '@stdlib/_tools/eslint/rules/jsdoc-example-require-spacing' ); +``` + +#### rule + +[ESLint rule][eslint-rules] to enforce empty lines between requires and code in JSDoc examples. + +**Bad**: + + + +```javascript +/** +* Fréchet distribution constructor. +* +* @module @stdlib/stats/base/dists/frechet/ctor +* +* @example +* var Frechet = require( '@stdlib/stats/base/dists/frechet/ctor' ); +* var frechet = new Frechet( 1.0, 1.0, 0.5 ); +* +* var y = frechet.cdf( 0.8 ); +* // returns ~0.036 +*/ +``` + +**Good**: + +```javascript +/** +* Fréchet distribution constructor. +* +* @module @stdlib/stats/base/dists/frechet/ctor +* +* @example +* var Frechet = require( '@stdlib/stats/base/dists/frechet/ctor' ); +* +* var frechet = new Frechet( 1.0, 1.0, 0.5 ); +* +* var y = frechet.cdf( 0.8 ); +* // returns ~0.036 +*/ +``` + +
+ + + +
+ +## Examples + + + +```javascript +var Linter = require( 'eslint' ).Linter; +var rule = require( '@stdlib/_tools/eslint/rules/jsdoc-example-require-spacing' ); + +var linter = new Linter(); +var result; +var code; + +code = [ + '/**', + '* Fréchet distribution constructor.', + '*', + '* @module @stdlib/stats/base/dists/frechet/ctor', + '*', + '* @example', + '* var Frechet = require( \'@stdlib/stats/base/dists/frechet/ctor\' );', + '* var frechet = new Frechet( 1.0, 1.0, 0.5 );', + '*', + '* var y = frechet.cdf( 0.8 );', + '* // returns ~0.036', + '*/', + 'function Frechet() {}' +].join( '\n' ); + +linter.defineRule( 'jsdoc-example-require-spacing', rule ); + +result = linter.verify( code, { + 'rules': { + 'jsdoc-example-require-spacing': 'error' + } +}); +/* returns + [ + { + 'ruleId': 'jsdoc-example-require-spacing', + 'severity': 2, + 'message': 'Missing empty line between require statement and code', + 'line': 13, + 'column': 1, + 'nodeType': 'FunctionDeclaration', + 'endLine': 13, + 'endColumn': 21 + } + ] +*/ +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-example-require-spacing/examples/index.js b/lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-example-require-spacing/examples/index.js new file mode 100644 index 000000000000..7761ac91946a --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-example-require-spacing/examples/index.js @@ -0,0 +1,75 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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'; + +var Linter = require( 'eslint' ).Linter; +var rule = require( './../lib' ); + +var linter = new Linter(); + +// Valid example with empty line after require: +var valid = [ + '/**', + '* Fréchet distribution constructor.', + '*', + '* @example', + '* var Frechet = require( \'@stdlib/stats/base/dists/frechet/ctor\' );', + '*', + '* var frechet = new Frechet( 1.0, 1.0, 0.5 );', + '*', + '* var y = frechet.cdf( 0.8 );', + '* // returns ~0.036', + '*/', + 'function Frechet() {}' +].join( '\n' ); + +// Invalid example without empty line after require: +var invalid = [ + '/**', + '* Fréchet distribution constructor.', + '*', + '* @example', + '* var Frechet = require( \'@stdlib/stats/base/dists/frechet/ctor\' );', + '* var frechet = new Frechet( 1.0, 1.0, 0.5 );', + '*', + '* var y = frechet.cdf( 0.8 );', + '* // returns ~0.036', + '*/', + 'function Frechet() {}' +].join( '\n' ); + +// Register the rule: +linter.defineRule( 'jsdoc-example-require-spacing', rule ); + +// Lint the valid example: +var validResult = linter.verify( valid, { + 'rules': { + 'jsdoc-example-require-spacing': 'error' + } +}); +console.log( 'Valid example - Number of errors: %d', validResult.length ); + +// Lint the invalid example: +var invalidResult = linter.verify( invalid, { + 'rules': { + 'jsdoc-example-require-spacing': 'error' + } +}); +console.log( 'Invalid example - Number of errors: %d', invalidResult.length ); +console.log( 'Error message: %s', invalidResult[ 0 ].message ); diff --git a/lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-example-require-spacing/lib/index.js b/lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-example-require-spacing/lib/index.js new file mode 100644 index 000000000000..ef0c4f34a4d7 --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-example-require-spacing/lib/index.js @@ -0,0 +1,45 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 rule = require( './main.js' ); + + +// MAIN // + +/** +* ESLint rule to enforce empty lines between requires and code in JSDoc examples. +* +* @module @stdlib/_tools/eslint/rules/jsdoc-example-require-spacing +* +* @example +* var rule = require( '@stdlib/_tools/eslint/rules/jsdoc-example-require-spacing' ); +* +* var config = { +* 'rules': { +* 'stdlib/jsdoc-example-require-spacing': 'error' +* } +* }; +*/ + +// EXPORTS // + +module.exports = rule; diff --git a/lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-example-require-spacing/lib/main.js b/lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-example-require-spacing/lib/main.js new file mode 100644 index 000000000000..c20464fbb291 --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-example-require-spacing/lib/main.js @@ -0,0 +1,172 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 parseJSDoc = require( 'doctrine' ).parse; +var trim = require( '@stdlib/string/base/trim' ); +var isObject = require( '@stdlib/assert/is-object' ); +var isEmptyArray = require( '@stdlib/assert/is-empty-array' ); +var findJSDoc = require( '@stdlib/_tools/eslint/utils/find-jsdoc' ); + + +// VARIABLES // + +var RE_NEWLINE = /\r?\n/g; +var DOPTS = { + 'sloppy': true, + 'unwrap': true, + 'tags': [ 'example' ] +}; +var rule; + + +// MAIN // + +/** +* Rule to enforce empty lines between requires and code in JSDoc examples. +* +* @param {Object} context - ESLint context +* @returns {Object} rule object +*/ +function main( context ) { + var source = context.getSourceCode(); + + /** + * Reports the error message. + * + * @private + * @param {Object} node - node to report + */ + function report( node ) { + context.report({ + 'node': node, + 'message': 'Missing empty line between require statement and code in JSDoc example' + }); + } + + /** + * Checks if a line contains a require statement. + * + * @private + * @param {string} line - line to check + * @returns {boolean} boolean indicating if line contains a require statement + */ + function hasRequire( line ) { + return trim( line ).indexOf( 'require(' ) !== -1; + } + + /** + * Checks if a line is empty. + * + * @private + * @param {string} line - line to check + * @returns {boolean} boolean indicating if line is empty + */ + function isEmpty( line ) { + return trim( line ) === ''; + } + + /** + * Processes an example tag description. + * + * @private + * @param {string} description - example description + * @param {Object} node - node to report + */ + function processExample( description, node ) { + var nextLine; + var lines; + var i; + + lines = description.split( RE_NEWLINE ); + for ( i = 0; i < lines.length; i++ ) { + if ( hasRequire( lines[ i ] ) ) { + if ( i + 1 >= lines.length ) { + break; + } + nextLine = lines[ i+1 ]; + if ( isEmpty( nextLine ) ) { + continue; + } + + // If next line is neither empty nor another require, report the error: + if ( !hasRequire( nextLine ) ) { + report( node ); + return; + } + } + } + } + + /** + * Checks if a JSDoc comment contains examples with require statements not followed by empty lines. + * + * @private + * @param {Object} node - node to examine + */ + function validate( node ) { + var jsdoc; + var tags; + var tag; + var ast; + var j; + + jsdoc = findJSDoc( source, node ); + if ( isObject( jsdoc ) ) { + ast = parseJSDoc( jsdoc.value, DOPTS ); + tags = ast.tags; + if ( isEmptyArray( tags ) ) { + return; + } + for ( j = 0; j < tags.length; j++ ) { + tag = tags[ j ]; + if ( tag.title === 'example' && tag.description ) { + processExample( tag.description, node ); + } + } + } + } + + return { + 'FunctionDeclaration': validate, + 'VariableDeclaration': validate, + 'ExpressionStatement': validate + }; +} + + +// MAIN // + +rule = { + 'meta': { + 'type': 'suggestion', + 'docs': { + 'description': 'enforce empty lines between requires and code in JSDoc examples' + }, + 'schema': [] + }, + 'create': main +}; + + +// EXPORTS // + +module.exports = rule; diff --git a/lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-example-require-spacing/package.json b/lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-example-require-spacing/package.json new file mode 100644 index 000000000000..45024d3d2457 --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-example-require-spacing/package.json @@ -0,0 +1,64 @@ +{ + "name": "@stdlib/_tools/eslint/rules/jsdoc-example-require-spacing", + "version": "0.0.0", + "description": "ESLint rule to enforce empty lines between requires and code in JSDoc examples.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "bin": {}, + "main": "./lib", + "directories": { + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "tools", + "tool", + "eslint", + "lint", + "custom", + "rules", + "rule", + "plugin", + "jsdoc", + "example", + "require", + "spacing" + ] +} diff --git a/lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-example-require-spacing/test/fixtures/invalid.js b/lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-example-require-spacing/test/fixtures/invalid.js new file mode 100644 index 000000000000..bc1b8df8cd2b --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-example-require-spacing/test/fixtures/invalid.js @@ -0,0 +1,90 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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'; + +var invalid = []; +var test; + +test = { + 'code': [ + '/**', + '* Single require without proper spacing.', + '*', + '* @example', + '* var foo = require( \'foo\' );', + '* var x = foo();', + '*/', + 'function test1() {}' + ].join( '\n' ), + 'errors': [ + { + 'message': 'Missing empty line between require statement and code in JSDoc example', + 'type': 'FunctionDeclaration' + } + ] +}; +invalid.push( test ); + +test = { + 'code': [ + '/**', + '* Multiple requires without proper spacing.', + '*', + '* @example', + '* var foo = require( \'foo\' );', + '* var bar = require( \'bar\' );', + '* var x = foo( bar() );', + '*/', + 'function test2() {}' + ].join( '\n' ), + 'errors': [ + { + 'message': 'Missing empty line between require statement and code in JSDoc example', + 'type': 'FunctionDeclaration' + } + ] +}; +invalid.push( test ); + +test = { + 'code': [ + '/**', + '* Mixed spacing - second require without proper spacing.', + '*', + '* @example', + '* var foo = require( \'foo\' );', + '*', + '* var bar = require( \'bar\' );', + '* var x = foo( bar() );', + '*/', + 'function test4() {}' + ].join( '\n' ), + 'errors': [ + { + 'message': 'Missing empty line between require statement and code in JSDoc example', + 'type': 'FunctionDeclaration' + } + ] +}; +invalid.push( test ); + + +// EXPORTS // + +module.exports = invalid; diff --git a/lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-example-require-spacing/test/fixtures/valid.js b/lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-example-require-spacing/test/fixtures/valid.js new file mode 100644 index 000000000000..208284fdc264 --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-example-require-spacing/test/fixtures/valid.js @@ -0,0 +1,90 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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'; + +var valid = []; +var test; + +test = { + 'code': [ + '/**', + '* Single require with proper spacing.', + '*', + '* @example', + '* var foo = require( \'foo\' );', + '*', + '* var x = foo();', + '*/', + 'function test1() {}' + ].join( '\n' ) +}; +valid.push( test ); + +test = { + 'code': [ + '/**', + '* Multiple requires with proper spacing.', + '*', + '* @example', + '* var foo = require( \'foo\' );', + '*', + '* var bar = require( \'bar\' );', + '*', + '* var x = foo( bar() );', + '*/', + 'function test2() {}' + ].join( '\n' ) +}; +valid.push( test ); + +test = { + 'code': [ + '/**', + '* Example without requires.', + '*', + '* @example', + '* var x = 5;', + '* var y = x * 2;', + '*/', + 'function test3() {}' + ].join( '\n' ) +}; +valid.push( test ); + +test = { + 'code': [ + '/**', + '* Example with requires and comments.', + '*', + '* @example', + '* var foo = require( \'foo\' );', + '*', + '* // This is a comment', + '*', + '* var x = foo();', + '*/', + 'function test4() {}' + ].join( '\n' ) +}; +valid.push( test ); + + +// EXPORTS // + +module.exports = valid; diff --git a/lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-example-require-spacing/test/test.js b/lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-example-require-spacing/test/test.js new file mode 100644 index 000000000000..2fa07c24668f --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-example-require-spacing/test/test.js @@ -0,0 +1,70 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 tape = require( 'tape' ); +var RuleTester = require( 'eslint' ).RuleTester; +var rule = require( './../lib' ); + + +// FIXTURES // + +var valid = require( './fixtures/valid.js' ); +var invalid = require( './fixtures/invalid.js' ); + + +// TESTS // + +tape( 'main export is an object', function test( t ) { + t.ok( true, __filename ); + t.equal( typeof rule, 'object', 'main export is an object' ); + t.end(); +}); + +tape( 'the function positively validates JSDoc examples with proper spacing after require statements', function test( t ) { + var tester = new RuleTester(); + + try { + tester.run( 'jsdoc-example-require-spacing', rule, { + 'valid': valid, + 'invalid': [] + }); + t.pass( 'passed without errors' ); + } catch ( err ) { + t.fail( 'encountered an error: ' + err.message ); + } + t.end(); +}); + +tape( 'the function negatively validates JSDoc examples without proper spacing after require statements', function test( t ) { + var tester = new RuleTester(); + + try { + tester.run( 'jsdoc-example-require-spacing', rule, { + 'valid': [], + 'invalid': invalid + }); + t.pass( 'passed without errors' ); + } catch ( err ) { + t.fail( 'encountered an error: ' + err.message ); + } + t.end(); +}); From 2983ed733bd1ca10b8179d1a0aba2d61d51ebe2c Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Wed, 19 Feb 2025 17:48:59 -0500 Subject: [PATCH 2/7] build: enable lint rule and add directives --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: passed - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na --- --- etc/eslint/rules/stdlib.js | 45 ++++++++++++++++++- .../jsdoc-example-require-spacing/README.md | 4 +- .../@stdlib/_tools/eslint/rules/lib/index.js | 9 ++++ 3 files changed, 56 insertions(+), 2 deletions(-) diff --git a/etc/eslint/rules/stdlib.js b/etc/eslint/rules/stdlib.js index 09d3f9d7e717..cb19b00cc4a1 100644 --- a/etc/eslint/rules/stdlib.js +++ b/etc/eslint/rules/stdlib.js @@ -16,7 +16,7 @@ * limitations under the License. */ -/* eslint-disable stdlib/jsdoc-doctest-marker, stdlib/jsdoc-doctest */ +/* eslint-disable stdlib/jsdoc-doctest-marker, stdlib/jsdoc-doctest, stdlib/jsdoc-example-require-spacing */ 'use strict'; @@ -838,6 +838,49 @@ rules[ 'stdlib/jsdoc-emphasis-marker' ] = [ 'error', '_' ]; */ rules[ 'stdlib/jsdoc-empty-line-before-example' ] = 'error'; +/** +* Enforce empty lines between requires and code in JSDoc examples. +* +* @name jsdoc-example-require-spacing +* @memberof rules +* @type {string} +* @default 'error' +* +* @example +* // Bad... +* +* /** +* * Fréchet distribution constructor. +* * +* * @module @stdlib/stats/base/dists/frechet/ctor +* * +* * @example +* * var Frechet = require( '@stdlib/stats/base/dists/frechet/ctor' ); +* * var frechet = new Frechet( 1.0, 1.0, 0.5 ); +* * +* * var y = frechet.cdf( 0.8 ); +* * // returns ~0.036 +* *\/ +* +* @example +* // Good... +* +* /** +* * Fréchet distribution constructor. +* * +* * @module @stdlib/stats/base/dists/frechet/ctor +* * +* * @example +* * var Frechet = require( '@stdlib/stats/base/dists/frechet/ctor' ); +* * +* * var frechet = new Frechet( 1.0, 1.0, 0.5 ); +* * +* * var y = frechet.cdf( 0.8 ); +* * // returns ~0.036 +* *\/ +*/ +rules[ 'stdlib/jsdoc-example-require-spacing' ] = 'error'; + /** * Require `\`` be used as the fenced code marker. * diff --git a/lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-example-require-spacing/README.md b/lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-example-require-spacing/README.md index 83b9d6d1dfcc..00b50ab37889 100644 --- a/lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-example-require-spacing/README.md +++ b/lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-example-require-spacing/README.md @@ -42,7 +42,7 @@ var rule = require( '@stdlib/_tools/eslint/rules/jsdoc-example-require-spacing' **Bad**: - + ```javascript /** @@ -61,6 +61,8 @@ var rule = require( '@stdlib/_tools/eslint/rules/jsdoc-example-require-spacing' **Good**: + + ```javascript /** * Fréchet distribution constructor. diff --git a/lib/node_modules/@stdlib/_tools/eslint/rules/lib/index.js b/lib/node_modules/@stdlib/_tools/eslint/rules/lib/index.js index 8b029f004377..e4d567fa12f6 100644 --- a/lib/node_modules/@stdlib/_tools/eslint/rules/lib/index.js +++ b/lib/node_modules/@stdlib/_tools/eslint/rules/lib/index.js @@ -207,6 +207,15 @@ setReadOnly( rules, 'jsdoc-emphasis-marker', require( '@stdlib/_tools/eslint/rul */ setReadOnly( rules, 'jsdoc-empty-line-before-example', require( '@stdlib/_tools/eslint/rules/jsdoc-empty-line-before-example' ) ); +/** +* @name jsdoc-example-require-spacing +* @memberof rules +* @readonly +* @type {Function} +* @see {@link module:@stdlib/_tools/eslint/rules/jsdoc-example-require-spacing} +*/ +setReadOnly( rules, 'jsdoc-example-require-spacing', require( '@stdlib/_tools/eslint/rules/jsdoc-example-require-spacing' ) ); + /** * @name jsdoc-fenced-code-flag * @memberof rules From a324f996eb81155c7bcde4783416aad6900b8069 Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Fri, 21 Feb 2025 17:35:51 -0500 Subject: [PATCH 3/7] chore: apply suggestions from code review Co-authored-by: Athan Signed-off-by: Philipp Burckhardt --- .../eslint/rules/jsdoc-example-require-spacing/README.md | 4 ++-- .../eslint/rules/jsdoc-example-require-spacing/lib/index.js | 2 +- .../eslint/rules/jsdoc-example-require-spacing/lib/main.js | 4 ++-- .../eslint/rules/jsdoc-example-require-spacing/package.json | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-example-require-spacing/README.md b/lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-example-require-spacing/README.md index 00b50ab37889..3d9d99a0bed7 100644 --- a/lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-example-require-spacing/README.md +++ b/lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-example-require-spacing/README.md @@ -20,7 +20,7 @@ limitations under the License. # jsdoc-example-require-spacing -> [ESLint rule][eslint-rules] to enforce empty lines between requires and code in JSDoc examples. +> [ESLint rule][eslint-rules] to enforce empty lines between `require` statements and code in JSDoc examples.
@@ -38,7 +38,7 @@ var rule = require( '@stdlib/_tools/eslint/rules/jsdoc-example-require-spacing' #### rule -[ESLint rule][eslint-rules] to enforce empty lines between requires and code in JSDoc examples. +[ESLint rule][eslint-rules] to enforce empty lines between `require` statements and code in JSDoc examples. **Bad**: diff --git a/lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-example-require-spacing/lib/index.js b/lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-example-require-spacing/lib/index.js index ef0c4f34a4d7..c65d6877d487 100644 --- a/lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-example-require-spacing/lib/index.js +++ b/lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-example-require-spacing/lib/index.js @@ -26,7 +26,7 @@ var rule = require( './main.js' ); // MAIN // /** -* ESLint rule to enforce empty lines between requires and code in JSDoc examples. +* ESLint rule to enforce empty lines between `require` statements and code in JSDoc examples. * * @module @stdlib/_tools/eslint/rules/jsdoc-example-require-spacing * diff --git a/lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-example-require-spacing/lib/main.js b/lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-example-require-spacing/lib/main.js index c20464fbb291..9fae056afa84 100644 --- a/lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-example-require-spacing/lib/main.js +++ b/lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-example-require-spacing/lib/main.js @@ -41,7 +41,7 @@ var rule; // MAIN // /** -* Rule to enforce empty lines between requires and code in JSDoc examples. +* Rule to enforce empty lines between `require` statements and code in JSDoc examples. * * @param {Object} context - ESLint context * @returns {Object} rule object @@ -117,7 +117,7 @@ function main( context ) { } /** - * Checks if a JSDoc comment contains examples with require statements not followed by empty lines. + * Checks if a JSDoc comment contains examples with `require` statements which are not followed by empty lines. * * @private * @param {Object} node - node to examine diff --git a/lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-example-require-spacing/package.json b/lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-example-require-spacing/package.json index 45024d3d2457..ee740cdd67d1 100644 --- a/lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-example-require-spacing/package.json +++ b/lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-example-require-spacing/package.json @@ -1,7 +1,7 @@ { "name": "@stdlib/_tools/eslint/rules/jsdoc-example-require-spacing", "version": "0.0.0", - "description": "ESLint rule to enforce empty lines between requires and code in JSDoc examples.", + "description": "ESLint rule to enforce empty lines between `require` statements and code in JSDoc examples.", "license": "Apache-2.0", "author": { "name": "The Stdlib Authors", From 429c6606487ae1917c934f76af6994b86f75742e Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Fri, 21 Feb 2025 17:37:36 -0500 Subject: [PATCH 4/7] refactor: move functions to parent scope --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../jsdoc-example-require-spacing/lib/main.js | 47 ++++++++++--------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-example-require-spacing/lib/main.js b/lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-example-require-spacing/lib/main.js index 9fae056afa84..6eb323b55296 100644 --- a/lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-example-require-spacing/lib/main.js +++ b/lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-example-require-spacing/lib/main.js @@ -38,6 +38,31 @@ var DOPTS = { var rule; +// FUNCTIONS // + +/** +* Checks if a line contains a require statement. +* +* @private +* @param {string} line - line to check +* @returns {boolean} boolean indicating if line contains a require statement +*/ +function hasRequire( line ) { + return trim( line ).indexOf( 'require(' ) !== -1; +} + +/** +* Checks if a line is empty. +* +* @private +* @param {string} line - line to check +* @returns {boolean} boolean indicating if line is empty +*/ +function isEmpty( line ) { + return trim( line ) === ''; +} + + // MAIN // /** @@ -62,28 +87,6 @@ function main( context ) { }); } - /** - * Checks if a line contains a require statement. - * - * @private - * @param {string} line - line to check - * @returns {boolean} boolean indicating if line contains a require statement - */ - function hasRequire( line ) { - return trim( line ).indexOf( 'require(' ) !== -1; - } - - /** - * Checks if a line is empty. - * - * @private - * @param {string} line - line to check - * @returns {boolean} boolean indicating if line is empty - */ - function isEmpty( line ) { - return trim( line ) === ''; - } - /** * Processes an example tag description. * From 83162cde38651893c909cf5c21d1a482446b4cc0 Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Fri, 21 Feb 2025 17:39:41 -0500 Subject: [PATCH 5/7] refactor: use stdlib package --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na --- --- .../eslint/rules/jsdoc-example-require-spacing/lib/main.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-example-require-spacing/lib/main.js b/lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-example-require-spacing/lib/main.js index 6eb323b55296..d371e73643a5 100644 --- a/lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-example-require-spacing/lib/main.js +++ b/lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-example-require-spacing/lib/main.js @@ -22,6 +22,7 @@ var parseJSDoc = require( 'doctrine' ).parse; var trim = require( '@stdlib/string/base/trim' ); +var reEOL = require( '@stdlib/regexp/eol' ); var isObject = require( '@stdlib/assert/is-object' ); var isEmptyArray = require( '@stdlib/assert/is-empty-array' ); var findJSDoc = require( '@stdlib/_tools/eslint/utils/find-jsdoc' ); @@ -29,7 +30,6 @@ var findJSDoc = require( '@stdlib/_tools/eslint/utils/find-jsdoc' ); // VARIABLES // -var RE_NEWLINE = /\r?\n/g; var DOPTS = { 'sloppy': true, 'unwrap': true, @@ -99,7 +99,7 @@ function main( context ) { var lines; var i; - lines = description.split( RE_NEWLINE ); + lines = description.split( reEOL.REGEXP ); for ( i = 0; i < lines.length; i++ ) { if ( hasRequire( lines[ i ] ) ) { if ( i + 1 >= lines.length ) { From 3dee135c30c4265dc2e38340be484aa4d3bc3523 Mon Sep 17 00:00:00 2001 From: Athan Date: Fri, 21 Feb 2025 15:13:07 -0800 Subject: [PATCH 6/7] style: resolve lint error Signed-off-by: Athan --- etc/eslint/rules/stdlib.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/etc/eslint/rules/stdlib.js b/etc/eslint/rules/stdlib.js index cb19b00cc4a1..28be3f557c6a 100644 --- a/etc/eslint/rules/stdlib.js +++ b/etc/eslint/rules/stdlib.js @@ -2964,6 +2964,8 @@ rules[ 'stdlib/jsdoc-no-space-aligned-asterisks' ] = 'error'; */ rules[ 'stdlib/jsdoc-no-table-indentation' ] = 'error'; +/* eslint-disable stdlib/jsdoc-no-tabs */ + /** * Forbid the use of tabs. * @@ -3010,6 +3012,8 @@ rules[ 'stdlib/jsdoc-no-table-indentation' ] = 'error'; */ rules[ 'stdlib/jsdoc-no-tabs' ] = 'error'; +/* eslint-enable stdlib/jsdoc-no-tabs */ + /** * Prevent references to undefined definitions. * From 9838a27719e85ce5582af630122aa1de37080ad6 Mon Sep 17 00:00:00 2001 From: Athan Date: Fri, 21 Feb 2025 15:31:28 -0800 Subject: [PATCH 7/7] style: resolve lint error Signed-off-by: Athan --- etc/eslint/rules/stdlib.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/etc/eslint/rules/stdlib.js b/etc/eslint/rules/stdlib.js index 28be3f557c6a..ceacbd72d966 100644 --- a/etc/eslint/rules/stdlib.js +++ b/etc/eslint/rules/stdlib.js @@ -1,3 +1,5 @@ +/* eslint-disable stdlib/jsdoc-doctest-marker, stdlib/jsdoc-doctest, stdlib/jsdoc-example-require-spacing, stdlib/jsdoc-no-tabs */ + /** * @license Apache-2.0 * @@ -16,8 +18,6 @@ * limitations under the License. */ -/* eslint-disable stdlib/jsdoc-doctest-marker, stdlib/jsdoc-doctest, stdlib/jsdoc-example-require-spacing */ - 'use strict'; /** @@ -2964,8 +2964,6 @@ rules[ 'stdlib/jsdoc-no-space-aligned-asterisks' ] = 'error'; */ rules[ 'stdlib/jsdoc-no-table-indentation' ] = 'error'; -/* eslint-disable stdlib/jsdoc-no-tabs */ - /** * Forbid the use of tabs. * @@ -3012,8 +3010,6 @@ rules[ 'stdlib/jsdoc-no-table-indentation' ] = 'error'; */ rules[ 'stdlib/jsdoc-no-tabs' ] = 'error'; -/* eslint-enable stdlib/jsdoc-no-tabs */ - /** * Prevent references to undefined definitions. *