-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
build: add ESLint rule to enforce no empty lines between module-level require statements #9488
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
d4f153a
build: add ESLint rule to enforce no empty lines between module-level…
Planeshifter 1457ef5
fix: add column check to `isSectionHeader` and expand test coverage
Planeshifter 6fa3fec
chore: update copyright years
stdlib-bot 35d7138
Apply suggestions from code review
kgryte 1a3cc8e
docs: update example
kgryte b6ac765
docs: remove comment
kgryte 217da79
chore: remove field
kgryte 51fc782
chore: clean-up
kgryte bc27ed2
docs: update comments
kgryte 4be5a25
docs: update comments
kgryte 1167310
docs: update comments
kgryte 62cb2c5
chore: move declaration
kgryte 8323128
chore: move declaration
kgryte File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
161 changes: 161 additions & 0 deletions
161
...e_modules/@stdlib/_tools/eslint/rules/no-empty-lines-between-requires/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,161 @@ | ||
| <!-- | ||
|
|
||
| @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 result; | ||
| var code; | ||
|
|
||
| var opts = { | ||
| 'rules': { | ||
| 'no-empty-lines-between-requires': 'error' | ||
| } | ||
| }; | ||
| linter.defineRule( 'no-empty-lines-between-requires', rule ); | ||
|
|
||
| code = [ | ||
| '\'use strict\';', | ||
| '', | ||
| '// MODULES //', | ||
| '', | ||
| 'var tape = require( \'tape\' );', | ||
| '', | ||
| 'var isnan = require( \'@stdlib/math/base/assert/is-nan\' );' | ||
| ].join( '\n' ); | ||
|
|
||
| result = linter.verify( code, opts ); | ||
kgryte marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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 --> | ||
58 changes: 58 additions & 0 deletions
58
...ode_modules/@stdlib/_tools/eslint/rules/no-empty-lines-between-requires/examples/index.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| /** | ||
| * @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 result; | ||
| var code; | ||
|
|
||
| var opts = { | ||
| 'rules': { | ||
| 'no-empty-lines-between-requires': 'error' | ||
| } | ||
| }; | ||
| linter.defineRule( 'no-empty-lines-between-requires', rule ); | ||
|
|
||
| code = [ | ||
| '\'use strict\';', | ||
| '', | ||
| '// MODULES //', | ||
| '', | ||
| 'var tape = require( \'tape\' );', | ||
| '', | ||
| 'var isnan = require( \'@stdlib/math/base/assert/is-nan\' );', | ||
| '', | ||
| '', | ||
| '// TESTS //', | ||
| '', | ||
| 'tape( \'test\', function() {} );' | ||
| ].join( '\n' ); | ||
|
|
||
| result = linter.verifyAndFix( code, opts ); | ||
kgryte marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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() {} );' | ||
| } | ||
| */ | ||
39 changes: 39 additions & 0 deletions
39
lib/node_modules/@stdlib/_tools/eslint/rules/no-empty-lines-between-requires/lib/index.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.