tape-testing / tape

tap-producing test harness for node and browsers
MIT License
5.77k stars 307 forks source link

[New] add types #603

Open ljharb opened 6 months ago

ljharb commented 6 months ago

Normally I'd just push this commit up and publish it, but since @types/tape already exists, I thought this was worth a PR so others can double check me.

Raynos commented 6 months ago

Are these hand written or generated from JSDoc ? It's unclear to me. Either way looks reasonable to me.

ljharb commented 6 months ago

Hand-written.

coderabbitai[bot] commented 5 months ago
Walkthrough ## Walkthrough The update introduces comprehensive JSDoc type annotations across various JavaScript files to enhance type safety and documentation. This includes adjustments to function parameters and return types, new type definitions, and enhancements to existing logic, improving code clarity and robust type-checking during development. ## Changes | File Path | Change Summary | |-----------------------------------------|----------------| | `.github/.../node-aught.yml` | Changed the `skip-ls-check` option to `true` under the `jobs` section. | | `bin/import-or-require.js` | Added JSDoc type annotation for the `importOrRequire` function's parameter and return type. | | `bin/tape` | Added JSDoc type annotations for the `importFiles` function and `filesPromise` variable. | | `index.d.ts` | Introduced new type declarations, functions, and interfaces for a testing harness using `tape`. | | `index.js` | Added JSDoc type annotations for multiple functions and updated module exports. | | `lib/default_stream.d.ts`, `lib/default_stream.js` | Introduced type annotations for the buffer `buf` in the `write` function. | | `lib/results.d.ts`, `lib/results.js` | Defined the `Results` class, added numerous type annotations, and enhanced functions. | | `lib/test.d.ts`, `lib/test.js` | Added the `Test` class with constructors and methods for testing functionalities; included extensive JSDoc type annotations. | | `test/common.js` | Added JSDoc typedefs for imported modules and defined new functions with specific signatures. | ## Sequence Diagrams No sequence diagrams generated due to the nature of changes primarily adding type annotations and enhancing existing functionality.

Recent review details **Configuration used: CodeRabbit UI** **Review profile: CHILL**
Commits Files that changed from the base of the PR and between 92aa51c39456097c56a0c91eb8be7b5fe0f7382c and e80d1288495503b7b4054e8554d9aa4037816dd9.
Files ignored due to path filters (2) * `package.json` is excluded by `!**/*.json` * `tsconfig.json` is excluded by `!**/*.json`
Files selected for processing (12) * .github/workflows/node-aught.yml (1 hunks) * bin/import-or-require.js (1 hunks) * bin/tape (2 hunks) * index.d.ts (1 hunks) * index.js (8 hunks) * lib/default_stream.d.ts (1 hunks) * lib/default_stream.js (2 hunks) * lib/results.d.ts (1 hunks) * lib/results.js (9 hunks) * lib/test.d.ts (1 hunks) * lib/test.js (41 hunks) * test/common.js (4 hunks)
Files skipped from review due to trivial changes (3) * .github/workflows/node-aught.yml * lib/default_stream.d.ts * lib/results.d.ts
Files skipped from review as they are similar to previous changes (7) * bin/import-or-require.js * bin/tape * index.d.ts * index.js * lib/default_stream.js * lib/results.js * test/common.js
Additional context used
Biome
lib/test.d.ts
[error] 112-112: Don't use 'Function' as a type. Prefer explicitly define the function shape. This type accepts any function-like value, which can be a common source of bugs. (lint/complexity/noBannedTypes) --- [error] 126-126: Don't use 'Function' as a type. Prefer explicitly define the function shape. This type accepts any function-like value, which can be a common source of bugs. (lint/complexity/noBannedTypes) --- [error] 192-192: Don't use '{}' as a type. Prefer explicitly define the object shape. '{}' means "any non-nullable value". (lint/complexity/noBannedTypes) --- [error] 198-198: Don't use '{}' as a type. Prefer explicitly define the object shape. '{}' means "any non-nullable value". (lint/complexity/noBannedTypes)
Additional comments not posted (3)
lib/test.d.ts (2)
`210-210`: **Avoid using `{}` as a type.** The use of `{}` as a type is discouraged. Consider defining a specific object shape instead. Apply this diff to define a specific object shape: ```diff - export type RestoreFunction = Exclude, undefined>; + export type RestoreFunction = () => void; ``` > Likely invalid or redundant comment. --- `38-38`: **Avoid using `Function` as a type.** The use of `Function` as a type is discouraged. Consider defining a specific function type instead. Apply this diff to define a specific function type: ```diff - /** @typedef {Function} Callback */ + /** @typedef {(...args: unknown[]) => unknown} Callback */ ``` > Likely invalid or redundant comment.
lib/test.js (1)
Line range hint `83-123`: **Constructor implementation is appropriate.** The constructor correctly initializes properties and binds methods. Ensure all methods are correctly bound to the instance. Run the following script to verify method bindings:
Verification successful --- **Method bindings are correctly implemented.** The `Test` constructor iterates over its properties and binds functions using `callBind`, confirming that method bindings are handled as expected. The use of `@ts-expect-error` is acknowledged in the code. No further issues were found. - Method bindings are correctly handled in lines 121-126.
Scripts executed The following scripts were executed for the analysis: Script: ```shell #!/bin/bash # Description: Verify all methods are correctly bound to the `Test` instance. # Test: Search for method bindings. Expect: All instance methods are bound. rg --type js -A 5 $'this[prop] = callBind(this[prop], this)' ``` Length of output: 61 --- Script: ```shell #!/bin/bash # Description: Search for method definitions within the `Test` class and check for bindings. # Find the `Test` constructor and methods within the same file. ast-grep --lang javascript --pattern $'function Test($_, $_, $_) { $$$ this.$_ = $_; $$$ }' ``` Length of output: 1727
--- Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?
Share - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)
Tips ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - Review comments: Directly reply to a review comment made by CodeRabbit. Example: - `I pushed a fix in commit .` - `Generate unit testing code for this file.` - `Open a follow-up GitHub issue for this discussion.` - Files and specific lines of code (under the "Files changed" tab): Tag `@coderabbitai` in a new review comment at the desired location with your query. Examples: - `@coderabbitai generate unit testing code for this file.` - `@coderabbitai modularize this function.` - PR comments: Tag `@coderabbitai` in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples: - `@coderabbitai generate interesting stats about this repository and render them as a table.` - `@coderabbitai show all the console.log statements in this repository.` - `@coderabbitai read src/utils.ts and generate unit testing code.` - `@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.` - `@coderabbitai help me debug CodeRabbit configuration file.` Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. ### CodeRabbit Commands (invoked as PR comments) - `@coderabbitai pause` to pause the reviews on a PR. - `@coderabbitai resume` to resume the paused reviews. - `@coderabbitai review` to trigger an incremental review. This is useful when automatic reviews are disabled for the repository. - `@coderabbitai full review` to do a full review from scratch and review all the files again. - `@coderabbitai summary` to regenerate the summary of the PR. - `@coderabbitai resolve` resolve all the CodeRabbit review comments. - `@coderabbitai configuration` to show the current CodeRabbit configuration for the repository. - `@coderabbitai help` to get help. Additionally, you can add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed. ### CodeRabbit Configuration File (`.coderabbit.yaml`) - You can programmatically configure CodeRabbit by adding a `.coderabbit.yaml` file to the root of your repository. - Please see the [configuration documentation](https://docs.coderabbit.ai/guides/configure-coderabbit) for more information. - If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: `# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json` ### Documentation and Community - Visit our [Documentation](https://coderabbit.ai/docs) for detailed information on how to use CodeRabbit. - Join our [Discord Community](https://discord.com/invite/GsXnASn26c) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.
ljharb commented 5 months ago

Thanks, I've updated the PR and gotten it down to 4 errors (i swear it was at zero when I put up the PR :-p)

I'd love to get suggestions for those.

JoshuaKGoldberg commented 5 months ago

Oop, sorry for taking so long - I'd added this tab on my phone and forgot about it 😅. Looking now!

it down to 4 errors

On the latest commit I get no errors. So, nicely done! 😄

socket-security[bot] commented 1 week ago

New dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/@arethetypeswrong/cli@0.15.4 Transitive: environment, filesystem, network, shell, unsafe +50 40 MB andrewbranch
npm/@ljharb/tsconfig@0.2.0 None 0 16.2 kB ljharb
npm/@types/array.prototype.every@1.1.1 None 0 3.54 kB types
npm/@types/array.prototype.find@2.2.0 None 0 3.99 kB types
npm/@types/array.prototype.flatmap@1.2.6 None 0 4.04 kB types
npm/@types/call-bind@1.0.5 None +1 62.3 kB types
npm/@types/concat-stream@2.0.3 None +2 2.22 MB types
npm/@types/deep-equal@1.0.4 None 0 3.1 kB types
npm/@types/defined@1.0.2 None 0 2.76 kB types
npm/@types/eslint@8.4.10 None +2 223 kB types
npm/@types/falafel@2.2.2 None +2 2.22 MB types
npm/@types/for-each@0.3.3 None 0 4.06 kB types
npm/@types/get-package-type@0.1.0 None 0 3.27 kB types
npm/@types/glob@8.1.0 None +3 2.23 MB types
npm/@types/inherits@0.0.33 None +2 2.21 MB types
npm/@types/is-regex@1.0.2 None 0 3.07 kB types
npm/@types/js-yaml@4.0.9 None 0 9.12 kB types
npm/@types/minimist@1.2.5 None 0 6.27 kB types
npm/@types/object-inspect@1.13.0 None 0 6.05 kB types
npm/@types/object-is@1.1.0 None 0 3.23 kB types
npm/@types/object-keys@1.0.3 None 0 3.08 kB types
npm/@types/resolve@1.20.6 None 0 10.1 kB types
npm/@types/string.prototype.trim@1.2.0 None 0 3.12 kB types
npm/typescript@5.7.0-dev.20240821 None 0 22.4 MB typescript-bot

View full report↗︎