Skip to content

Commit 372622f

Browse files
committed
build: ensure dir is initialized before checking relative paths
--- 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: 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 ---
1 parent 3fb383b commit 372622f

File tree

2 files changed

+19
-2
lines changed
  • lib/node_modules/@stdlib/_tools/eslint/rules/require-file-extensions

2 files changed

+19
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ function main( context ) {
112112
if ( node.callee.name === 'require' ) {
113113
requirePath = node.arguments[ 0 ].value;
114114
if ( isString( requirePath ) ) {
115+
filename = context.getFilename();
116+
dir = dirname( filename );
115117
if ( startsWith( requirePath, '.' ) ) {
116118
requirePath = path.resolve( dir, requirePath );
117119
}
@@ -128,8 +130,6 @@ function main( context ) {
128130
}
129131
}
130132
}
131-
filename = context.getFilename();
132-
dir = dirname( filename );
133133
resolved = tryResolve( requirePath, dir );
134134
parts = path.parse( requirePath );
135135

lib/node_modules/@stdlib/_tools/eslint/rules/require-file-extensions/test/fixtures/valid.js

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

2323
var resolve = require( 'path' ).resolve;
24+
var join = require( 'path' ).join;
25+
var rootDir = require( '@stdlib/_tools/utils/root-dir' );
26+
27+
28+
// VARIABLES //
29+
30+
var ROOT_DIR = rootDir();
2431

2532

2633
// MAIN //
@@ -106,6 +113,16 @@ test = {
106113
};
107114
valid.push( test );
108115

116+
test = {
117+
'code': [
118+
'// MODULES //',
119+
'',
120+
'var main = require( \'./main.js\' );'
121+
].join( '\n' ),
122+
'filename': join( ROOT_DIR, 'lib/index.js' )
123+
};
124+
valid.push( test );
125+
109126

110127
// EXPORTS //
111128

0 commit comments

Comments
 (0)