Skip to content
Merged
21 changes: 21 additions & 0 deletions etc/eslint/rules/stdlib.js
Original file line number Diff line number Diff line change
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 @@ -4186,6 +4186,27 @@
*/
rules[ 'stdlib/no-empty-comments' ] = 'error';

/**
* Enforce no empty lines between module-level require statements.
*
* @name no-empty-lines-between-requires
* @memberof rules
* @type {string}
* @default 'error'
*
* @example
* // Bad...
* var foo = require( 'foo' );
*
* var bar = require( 'bar' );
*
* @example
* // Good...
* var foo = require( 'foo' );
* var bar = require( 'bar' );
*/
rules[ 'stdlib/no-empty-lines-between-requires' ] = 'error';

/**
* Disallow string concatenation in error messages.
*
Expand Down
9 changes: 9 additions & 0 deletions lib/node_modules/@stdlib/_tools/eslint/rules/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,15 @@ setReadOnly( rules, 'no-dynamic-require', require( '@stdlib/_tools/eslint/rules/
*/
setReadOnly( rules, 'no-empty-comments', require( '@stdlib/_tools/eslint/rules/no-empty-comments' ) );

/**
* @name no-empty-lines-between-requires
* @memberof rules
* @readonly
* @type {Function}
* @see {@link module:@stdlib/_tools/eslint/rules/no-empty-lines-between-requires}
*/
setReadOnly( rules, 'no-empty-lines-between-requires', require( '@stdlib/_tools/eslint/rules/no-empty-lines-between-requires' ) );

/**
* @name no-error-string-concat
* @memberof rules
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
<!--

@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.

-->

# no-empty-lines-between-requires

> [ESLint rule][eslint-rules] to enforce no empty lines between module-level require statements.

<section class="intro">

</section>

<!-- /.intro -->

<section class="usage">

## Usage

```javascript
var rule = require( '@stdlib/_tools/eslint/rules/no-empty-lines-between-requires' );
```

#### rule

[ESLint rule][eslint-rules] to enforce no empty lines between module-level require statements. Section header comments (such as `// FIXTURES //`) are allowed to separate groups of require statements.

This rule only applies to top-level (module-level) require statements. Require statements inside functions or blocks are not checked.

**Bad**:

<!-- run-disable -->

<!-- eslint-disable stdlib/no-empty-lines-between-requires -->

```javascript
var tape = require( 'tape' );

var isnan = require( '@stdlib/math/base/assert/is-nan' );

var abs = require( '@stdlib/math/base/special/abs' );
```

**Good**:

<!-- run-disable -->

<!-- eslint-disable stdlib/no-empty-lines-between-requires -->

```javascript
var tape = require( 'tape' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var abs = require( '@stdlib/math/base/special/abs' );
```

**Good** (section headers separate groups):

<!-- run-disable -->

<!-- eslint-disable stdlib/no-empty-lines-between-requires, stdlib/require-file-extensions -->

```javascript
var tape = require( 'tape' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );


// FIXTURES //

var data = require( './fixtures/data.json' );
var expected = require( './fixtures/expected.json' );
```

</section>

<!-- /.usage -->

<section class="examples">

## Examples

<!-- eslint no-undef: "error" -->

```javascript
var Linter = require( 'eslint' ).Linter;
var rule = require( '@stdlib/_tools/eslint/rules/no-empty-lines-between-requires' );

var linter = new Linter();

var opts = {
'rules': {
'no-empty-lines-between-requires': 'error'
}
};
linter.defineRule( 'no-empty-lines-between-requires', rule );

var code = [
'\'use strict\';',
'',
'// MODULES //',
'',
'var tape = require( \'tape\' );',
'',
'var isnan = require( \'@stdlib/math/base/assert/is-nan\' );'
].join( '\n' );

var result = linter.verify( code, opts );
console.log( result );
/* =>
[
{
'ruleId': 'no-empty-lines-between-requires',
'severity': 2,
'message': 'Unexpected empty line between require statements.',
'line': 6,
'column': 0,
'nodeType': null,
'endLine': 7,
'endColumn': 0
}
]
*/
```

</section>

<!-- /.examples -->

<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->

<section class="related">

</section>

<!-- /.related -->

<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="links">

[eslint-rules]: https://eslint.org/docs/developer-guide/working-with-rules

</section>

<!-- /.links -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* @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';

var Linter = require( 'eslint' ).Linter;
var rule = require( './../lib' );

var linter = new Linter();

var opts = {
'rules': {
'no-empty-lines-between-requires': 'error'
}
};
linter.defineRule( 'no-empty-lines-between-requires', rule );

var code = [
'\'use strict\';',
'',
'// MODULES //',
'',
'var tape = require( \'tape\' );',
'',
'var isnan = require( \'@stdlib/math/base/assert/is-nan\' );',
'',
'',
'// TESTS //',
'',
'tape( \'test\', function() {} );'
].join( '\n' );

var result = linter.verifyAndFix( code, opts );
console.log( result );
/* =>
{
'fixed': true,
'messages': [],
'output': '\'use strict\';\n\n// MODULES //\n\nvar tape = require( \'tape\' );\nvar isnan = require( \'@stdlib/math/base/assert/is-nan\' );\n\n\n// TESTS //\n\ntape( \'test\', function() {} );'
}
*/
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* @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 rule to enforce no empty lines between module-level require statements.
*
* @module @stdlib/_tools/eslint/rules/no-empty-lines-between-requires
*
* @example
* var rule = require( '@stdlib/_tools/eslint/rules/no-empty-lines-between-requires' );
*
* console.log( rule );
*/

// MODULES //

var main = require( './main.js' );


// EXPORTS //

module.exports = main;
Loading