Skip to content

Commit 0c772d5

Browse files
committed
feat: disallow loading lib and package.json in no-internal-require lint rule
--- 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 510d9ae commit 0c772d5

File tree

2 files changed

+36
-1
lines changed
  • lib/node_modules/@stdlib/_tools/eslint/rules/no-internal-require

2 files changed

+36
-1
lines changed

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

Lines changed: 6 additions & 1 deletion
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 contains = require( '@stdlib/assert/contains' );
2526
var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
2627

@@ -66,7 +67,11 @@ function main( context ) {
6667
if (
6768
isString( requirePath ) &&
6869
startsWith( requirePath, '@stdlib' ) &&
69-
contains( requirePath, '/lib/' )
70+
(
71+
contains( requirePath, '/lib/' ) ||
72+
endsWith( requirePath, 'lib' ) ||
73+
endsWith( requirePath, '/package.json' )
74+
)
7075
) {
7176
report( node );
7277
}

lib/node_modules/@stdlib/_tools/eslint/rules/no-internal-require/test/fixtures/invalid.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,21 @@ test = {
3636
};
3737
invalid.push( test );
3838

39+
test = {
40+
'code': [
41+
'// MODULES //',
42+
'',
43+
'var betainc = require( \'@stdlib/math/base/special/betainc/lib\' );'
44+
].join( '\n' ),
45+
'errors': [
46+
{
47+
'message': 'require() call contains a path which loads a module internal to a stdlib package, and, thus, should be considered private',
48+
'type': 'CallExpression'
49+
}
50+
]
51+
};
52+
invalid.push( test );
53+
3954
test = {
4055
'code': [
4156
'// MODULES //',
@@ -52,6 +67,21 @@ test = {
5267
};
5368
invalid.push( test );
5469

70+
test = {
71+
'code': [
72+
'// MODULES //',
73+
'',
74+
'var pkg = require( \'@stdlib/math/base/special/betainc/package.json\' );'
75+
].join( '\n' ),
76+
'errors': [
77+
{
78+
'message': 'require() call contains a path which loads a module internal to a stdlib package, and, thus, should be considered private',
79+
'type': 'CallExpression'
80+
}
81+
]
82+
};
83+
invalid.push( test );
84+
5585

5686
// EXPORTS //
5787

0 commit comments

Comments
 (0)