Skip to content

Commit 63af7d2

Browse files
committed
chore: move function to module scope and use built-ins
--- 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: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent f92602c commit 63af7d2

File tree

1 file changed

+18
-17
lines changed
  • lib/node_modules/@stdlib/_tools/eslint/rules/require-order/lib

1 file changed

+18
-17
lines changed

lib/node_modules/@stdlib/_tools/eslint/rules/require-order/lib/main.js

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
// MODULES //
2222

2323
var startsWith = require( '@stdlib/string/starts-with' );
24+
var endsWith = require( '@stdlib/string/ends-with' );
2425
var hasOwnProp = require( '@stdlib/assert/has-own-property' );
2526
var isNodeBuiltin = require( '@stdlib/assert/is-node-builtin' );
2627
var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
@@ -99,6 +100,21 @@ function rank( order, regexps, name ) {
99100
return indexOf( order, type );
100101
}
101102

103+
/**
104+
* Sorts `require` statements based on their ranks.
105+
*
106+
* @private
107+
* @param {Object} a - first require statement
108+
* @param {Object} b - second require statement
109+
* @returns {number} number indicating sort order
110+
*/
111+
function sortRequires( a, b ) {
112+
if ( a.rank < b.rank ) {
113+
return -1;
114+
}
115+
return 1;
116+
}
117+
102118
/**
103119
* Rule for validating `require()` calls follow a specified order.
104120
*
@@ -125,21 +141,6 @@ function main( context ) {
125141
}
126142
}
127143

128-
/**
129-
* Sorts `require` statements based on their ranks.
130-
*
131-
* @private
132-
* @param {Object} a - first require statement
133-
* @param {Object} b - second require statement
134-
* @returns {number} number indicating sort order
135-
*/
136-
function sortRequires( a, b ) {
137-
if ( a.rank < b.rank ) {
138-
return -1;
139-
}
140-
return 1;
141-
}
142-
143144
/**
144145
* Fixes the lint error by reordering the require statements.
145146
*
@@ -181,10 +182,10 @@ function main( context ) {
181182
// Build the replacement text:
182183
for ( i = 0; i < requireDeclarations.length; i++ ) {
183184
txt = requireDeclarations[ i ].text;
184-
if ( !txt.startsWith( 'var' ) ) {
185+
if ( !startsWith( txt, 'var' ) ) {
185186
txt = 'var '+txt;
186187
}
187-
if ( !txt.endsWith( ';' ) ) {
188+
if ( !endsWith( txt, ';' ) ) {
188189
txt += ';';
189190
}
190191
replacingText += txt;

0 commit comments

Comments
 (0)