Repository navigation
feat: enforce primary header filenames #15369
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
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,7 +20,7 @@ | |
|
|
||
| // MODULES // | ||
|
|
||
| var basename = require( 'path' ).basename; // TODO: use stdlib module | ||
| var objectKeys = require( '@stdlib/utils/keys' ); | ||
| var extname = require( '@stdlib/utils/extname' ); | ||
| var hasOwnProp = require( '@stdlib/assert/has-own-property' ); | ||
|
|
@@ -39,21 +39,50 @@ | |
| * @returns {(ObjectArray|EmptyArray)} array of lint errors | ||
| */ | ||
| function lint( arr ) { | ||
| var packageNames; | ||
| var packagePath; | ||
| var expected; | ||
| var packages; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The variable declarations should be ordered by length in decreasing order. Please rearrange them accordingly.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the review! |
||
| var headers; | ||
| var include; | ||
| var fnames; | ||
| var fname; | ||
| var list; | ||
| var exts; | ||
| var name; | ||
| var list; | ||
| var ext; | ||
| var tmp; | ||
| var out; | ||
| var pkg; | ||
| var i; | ||
| var j; | ||
| var k; | ||
|
|
||
| headers = {}; | ||
| packages = {}; | ||
| out = []; | ||
| for ( i = 0; i < arr.length; i++ ) { | ||
| name = arr[ i ].replace( /\\/g, '/' ); | ||
| if ( name.indexOf( '/include/' ) !== -1 ) { | ||
| include = name.substring( 0, name.indexOf( '/include/' )+9 ); | ||
| pkg = basename( include.substring( 0, include.length-9 ) ); | ||
| if ( pkg !== '.' && pkg !== '..' && !/^[A-Za-z]:\//.test( name ) ) { | ||
| expected = pkg.replace( /-/g, '_' )+'.h'; | ||
| if ( include.indexOf( '/@stdlib/' ) !== -1 ) { | ||
| packagePath = include.substring( include.indexOf( '/@stdlib/' )+9, include.length-9 ); | ||
| expected = 'stdlib/'+packagePath.slice( 0, -pkg.length )+pkg.replace( /-/g, '_' )+'.h'; | ||
| } | ||
| if ( !packages[ include ] ) { | ||
| packages[ include ] = { | ||
| 'path': include+expected, | ||
| 'found': false | ||
| }; | ||
| } | ||
| if ( name === packages[ include ].path || name === packages[ include ].path.replace( /\\.h$/, '.hpp' ) ) { | ||
| packages[ include ].found = true; | ||
| } | ||
| } | ||
| } | ||
| fname = basename( arr[ i ] ); | ||
| ext = extname( fname ); | ||
| fname = fname.substring( 0, fname.length-ext.length ); | ||
|
|
@@ -81,6 +110,16 @@ | |
| headers[ ext ][ fname ] = [ arr[ i ] ]; | ||
| } | ||
| } | ||
| // Ensure every package has a primary header file... | ||
| packageNames = objectKeys( packages ); | ||
| for ( i = 0; i < packageNames.length; i++ ) { | ||
| if ( !packages[ packageNames[ i ] ].found ) { | ||
| out.push({ | ||
| 'name': packages[ packageNames[ i ] ].path, | ||
| 'error': 'missing primary header file.' | ||
| }); | ||
| } | ||
| } | ||
| // For every basename found multiple times, log a lint error... | ||
| exts = objectKeys( headers ); | ||
| for ( i = 0; i < exts.length; i++ ) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.