-
-
Notifications
You must be signed in to change notification settings - Fork 881
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
… in TSDoc examples --- 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
--- 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
tsdoc-doctest
ESLint ruletsdoc-doctest
ESLint rule
15a3eab
to
f723627
Compare
--- 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: passed - 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 ---
Signed-off-by: Athan <kgryte@gmail.com>
lib/node_modules/@stdlib/_tools/eslint/rules/tsdoc-doctest/test/fixtures/invalid.js
Show resolved
Hide resolved
lib/node_modules/@stdlib/_tools/eslint/rules/tsdoc-doctest/test/fixtures/unvalidated.js
Show resolved
Hide resolved
lib/node_modules/@stdlib/_tools/eslint/rules/tsdoc-doctest/test/fixtures/unvalidated.js
Show resolved
Hide resolved
lib/node_modules/@stdlib/_tools/eslint/rules/tsdoc-doctest/test/fixtures/valid.js
Show resolved
Hide resolved
lib/node_modules/@stdlib/_tools/eslint/rules/tsdoc-doctest/test/fixtures/valid.js
Show resolved
Hide resolved
lib/node_modules/@stdlib/_tools/eslint/rules/tsdoc-doctest/test/fixtures/valid.js
Show resolved
Hide resolved
lib/node_modules/@stdlib/_tools/eslint/rules/tsdoc-doctest/README.md
Outdated
Show resolved
Hide resolved
- The corresponding JavaScript package must be loadable via `require('@stdlib/<package>')` | ||
- The rule skips validation if the package cannot be loaded. | ||
- Examples are executed in a sandboxed VM context with limited globals. | ||
- The rule validates assignment-form examples (e.g., `var x = fn(...);` followed by an annotation). It does not validate console output or expression-only forms using `// =>`. |
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.
Why this limitation?
lib/node_modules/@stdlib/_tools/eslint/rules/tsdoc-doctest/lib/add_package_to_scope.js
Show resolved
Hide resolved
var funcMatch; | ||
|
||
if ( typeof pkg === 'function' ) { | ||
// Try to match declare function pattern (handles generics with <): |
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.
Similar to L60, it would be nice to include an example in each of the comments (L50, L54, etc) which demonstrate what pattern we are attempting to match.
var key; | ||
|
||
escapedValue = escapeRegex( value ); | ||
key = [ annotationType, escapedValue ].join( '::' ); |
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.
Is it really necessary to create a temporary array here?
* | ||
* @private | ||
* @param {Object} scope - VM scope | ||
* @param {any} expected - expected value to search for |
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.
any
is not valid.
* @private | ||
* @param {string} filepath - TypeScript declaration file path | ||
* @param {string} implementationPath - relative path to implementation | ||
* @returns {string|null} resolved implementation path or null if not found |
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.
Missing parens.
|
||
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.
options = context.options[ 0 ] || {}; | ||
|
||
// Only process TypeScript declaration files: | ||
if ( !filename.endsWith( '.d.ts' ) ) { |
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 wonder if we should rename this rule to make this more explicit that it won't work on TS source files. E.g., tsdoc-declarations-doctest
, or similar.
lineCountCache = {}; | ||
|
||
// Resolve implementation path relative to TypeScript declaration file path: | ||
implementationPath = options.implementationPath || '../../lib'; |
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.
Remind me: why don't we want to resolve the nearest package.json
and the associated main entry point?
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.
Left initial comments.
Co-authored-by: Athan <kgryte@gmail.com> Signed-off-by: Philipp Burckhardt <pburckhardt@outlook.com>
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