-
-
Notifications
You must be signed in to change notification settings - Fork 885
build: add tsdoc-doctest
ESLint rule
#8039
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?
Conversation
tsdoc-doctest
ESLint ruletsdoc-doctest
ESLint rule
15a3eab
to
f723627
Compare
lib/node_modules/@stdlib/_tools/eslint/rules/tsdoc-doctest/test/fixtures/invalid.js
Outdated
Show resolved
Hide resolved
lib/node_modules/@stdlib/_tools/eslint/rules/tsdoc-doctest/test/fixtures/unvalidated.js
Outdated
Show resolved
Hide resolved
lib/node_modules/@stdlib/_tools/eslint/rules/tsdoc-doctest/test/fixtures/unvalidated.js
Outdated
Show resolved
Hide resolved
lib/node_modules/@stdlib/_tools/eslint/rules/tsdoc-doctest/test/fixtures/valid.js
Outdated
Show resolved
Hide resolved
lib/node_modules/@stdlib/_tools/eslint/rules/tsdoc-doctest/test/fixtures/valid.js
Outdated
Show resolved
Hide resolved
lib/node_modules/@stdlib/_tools/eslint/rules/tsdoc-doctest/test/fixtures/valid.js
Outdated
Show resolved
Hide resolved
lib/node_modules/@stdlib/_tools/eslint/rules/tsdoc-doctest/README.md
Outdated
Show resolved
Hide resolved
lib/node_modules/@stdlib/_tools/eslint/rules/tsdoc-doctest/README.md
Outdated
Show resolved
Hide resolved
lib/node_modules/@stdlib/_tools/eslint/rules/tsdoc-doctest/README.md
Outdated
Show resolved
Hide resolved
lib/node_modules/@stdlib/_tools/eslint/rules/tsdoc-doctest/lib/add_package_to_scope.js
Outdated
Show resolved
Hide resolved
lib/node_modules/@stdlib/_tools/eslint/rules/tsdoc-doctest/lib/add_package_to_scope.js
Outdated
Show resolved
Hide resolved
lib/node_modules/@stdlib/_tools/eslint/rules/tsdoc-doctest/lib/main.js
Outdated
Show resolved
Hide resolved
lib/node_modules/@stdlib/_tools/eslint/rules/tsdoc-doctest/lib/main.js
Outdated
Show resolved
Hide resolved
lib/node_modules/@stdlib/_tools/eslint/rules/tsdoc-doctest/lib/main.js
Outdated
Show resolved
Hide resolved
lib/node_modules/@stdlib/_tools/eslint/rules/tsdoc-doctest/lib/main.js
Outdated
Show resolved
Hide resolved
lib/node_modules/@stdlib/_tools/eslint/rules/tsdoc-doctest/lib/main.js
Outdated
Show resolved
Hide resolved
lib/node_modules/@stdlib/_tools/eslint/rules/tsdoc-doctest/lib/main.js
Outdated
Show resolved
Hide resolved
lib/node_modules/@stdlib/_tools/eslint/rules/tsdoc-doctest/lib/main.js
Outdated
Show resolved
Hide resolved
lib/node_modules/@stdlib/_tools/eslint/rules/tsdoc-doctest/lib/main.js
Outdated
Show resolved
Hide resolved
lib/node_modules/@stdlib/_tools/eslint/rules/tsdoc-doctest/lib/main.js
Outdated
Show resolved
Hide resolved
|
||
last = 0; | ||
RE_ANNOTATION.lastIndex = 0; | ||
try { |
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.
I am not sure why we are enclosing the entirety of the code logic in a try
block. This is obviously not best practice. I see that the same thing was done in jsdoc-doctest
; that should also be cleaned up. Otherwise, we are swallowing programmer errors.
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.
@Planeshifter You marked this as resolved, but didn't make any changes.
lib/node_modules/@stdlib/_tools/eslint/rules/tsdoc-doctest/lib/main.js
Outdated
Show resolved
Hide resolved
lib/node_modules/@stdlib/_tools/eslint/rules/tsdoc-doctest/lib/main.js
Outdated
Show resolved
Hide resolved
Signed-off-by: Athan <kgryte@gmail.com>
lib/node_modules/@stdlib/_tools/eslint/rules/tsdoc-declarations-doctest/README.md
Outdated
Show resolved
Hide resolved
Signed-off-by: Athan <kgryte@gmail.com>
lib/node_modules/@stdlib/_tools/eslint/rules/tsdoc-declarations-doctest/README.md
Outdated
Show resolved
Hide resolved
Signed-off-by: Athan <kgryte@gmail.com>
Signed-off-by: Athan <kgryte@gmail.com>
lib/node_modules/@stdlib/_tools/eslint/rules/tsdoc-declarations-doctest/README.md
Outdated
Show resolved
Hide resolved
Signed-off-by: Athan <kgryte@gmail.com>
lib/node_modules/@stdlib/_tools/eslint/rules/tsdoc-declarations-doctest/README.md
Outdated
Show resolved
Hide resolved
Signed-off-by: Athan <kgryte@gmail.com>
Signed-off-by: Athan <kgryte@gmail.com>
...e_modules/@stdlib/_tools/eslint/rules/tsdoc-declarations-doctest/lib/add_package_to_scope.js
Outdated
Show resolved
Hide resolved
Signed-off-by: Athan <kgryte@gmail.com>
if ( pkgType === 'object' && pkg !== null ) { | ||
namespaceMatch = sourceText.match( RE_DECLARE_VAR_INTERFACE ); | ||
if ( namespaceMatch ) { | ||
scope[ namespaceMatch[1] ] = pkg; |
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.
@Planeshifter You fall-through here. Is that intended?
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.
If so, it would be good to document that the fall-through is intended.
|
||
var vm = require( 'vm' ); | ||
var resolve = require( 'path' ).resolve; | ||
var readFileSync = require( 'fs' ).readFileSync; // eslint-disable-line node/no-sync |
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.
@Planeshifter We should be using @stdlib/fs/read-file
.sync.
if ( lineCountCache[ str ] ) { | ||
return lineCountCache[ str ]; | ||
} | ||
lines = str.split( reEOL() ); |
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.
@Planeshifter You don't need to create a new EOL regexp here. Use .REGEXP
from the respective package.
function countLines( str ) { | ||
var lines; | ||
|
||
// Use cached result if available |
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.
// Use cached result if available |
What if the line count in the cache is 0
?
lib/node_modules/@stdlib/_tools/eslint/rules/tsdoc-declarations-doctest/lib/main.js
Outdated
Show resolved
Hide resolved
lib/node_modules/@stdlib/_tools/eslint/rules/tsdoc-declarations-doctest/lib/main.js
Outdated
Show resolved
Hide resolved
|
||
// Read and parse package.json: | ||
try { | ||
pkgJSON = JSON.parse( readFileSync( pkgPath, 'utf8' ) ); |
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.
@Planeshifter Use @stdlib/utils/parse-json
. Then handle with
json = parseJSON(...);
if ( json instanceof Error ) {
debug( .... );
return null;
}
But also, more generally here, you can use @stdlib/fs/read-json
which combines both reading and parsing.
mainPath = pkgJSON.main || './lib'; | ||
pkgDir = dirname( pkgPath ); | ||
return resolve( pkgDir, mainPath ); |
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.
mainPath = pkgJSON.main || './lib'; | |
pkgDir = dirname( pkgPath ); | |
return resolve( pkgDir, mainPath ); | |
return resolve( dirname( pkgPath ), pkgJSON.main || './lib' ); |
The intermediate variables are not particularly useful here.
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.
What if pkgJSON.main
is the empty string? In that case, main would default to index.js
. Here, you default to ./lib
which I don't think would be correct.
lib/node_modules/@stdlib/_tools/eslint/rules/tsdoc-declarations-doctest/lib/main.js
Outdated
Show resolved
Hide resolved
Signed-off-by: Athan <kgryte@gmail.com>
Signed-off-by: Athan <kgryte@gmail.com>
Signed-off-by: Athan <kgryte@gmail.com>
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.
Only a few comments remain wrt the main implementation.
Description
This pull request:
tsdoc-doctest
ESLint rule for for linting return annotations in TSDoc example code inside of TypeScript declaration files.Related Issues
This pull request:
Questions
No.
Other
No.
Checklist
@stdlib-js/reviewers