Skip to content

Conversation

@lambdalisue
Copy link
Member

@lambdalisue lambdalisue commented Apr 6, 2024

Summary by CodeRabbit

  • Chores
    • Integrated a new CI job for dry-run publishing using Deno in the GitHub Actions workflow.
  • New Features
    • Added new type checking functions like isAny, isUnknown, isSymbol, isPrimitive, etc.
    • Introduced functions for handling union types, intersection types, required properties, partial objects, picking properties, omitting properties, one of multiple types, and all of multiple types.
  • Bug Fixes
    • Updated import statements to specifically import the is function from the is.ts module.
    • Updated the import statement for Predicate in the metadata.ts file.
    • Removed the export of a specific entity is from mod.ts.
  • Tests
    • Expanded testing coverage for various type checking functions.
    • Updated tests to cover the new functions and their behaviors.

@coderabbitai
Copy link

coderabbitai bot commented Apr 6, 2024

Walkthrough

The changes focus on enhancing type checking functionalities in the codebase. New functions are added for various type checks like isAny, isUnknown, isSymbol, and more. Import statements are updated for better organization. Testing coverage is expanded to include these new functions. Additionally, the export of the is entity is removed from mod.ts.

Changes

Files Change Summary
is_bench.ts Modified import statement to specifically import the is function from the is.ts module.
is_test.ts Added multiple new type checking functions, updated imports, expanded testing coverage, and introduced various functions.
metadata.ts Updated the import statement for Predicate from "./is/type.ts" to "./is.ts" in the metadata.ts file.
mod.ts Removed the export of the is entity while retaining exports from other modules like is.ts, metadata.ts, util.ts.

🐇📝
Types checked, functions new,
is entity bid adieu.
Testing broad, coverage grand,
Codebase thrives, across the land.
Functions plenty, imports neat,
Type checks now, complete and sweet.
🌟🐰

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

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • 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.

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 a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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 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/coderabbit-overrides.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Review Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 92c763d and 6a9bf99.
Files selected for processing (1)
  • .github/workflows/test.yml (1 hunks)

Comment on lines +75 to +84
jsr-publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: denoland/setup-deno@v1
with:
deno-version: ${{ env.DENO_VERSION }}
- name: Publish (dry-run)
run: |
deno publish --dry-run
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a condition to only run the jsr-publish job on specific branches or under certain conditions.

  jsr-publish:
+   if: github.ref == 'refs/heads/main'
    runs-on: ubuntu-latest

This ensures that the publish dry-run only occurs in scenarios where it's relevant, such as merges to the main branch, preventing unnecessary runs on feature branches or in response to other events that wouldn't affect publishing.


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
jsr-publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: denoland/setup-deno@v1
with:
deno-version: ${{ env.DENO_VERSION }}
- name: Publish (dry-run)
run: |
deno publish --dry-run
jsr-publish:
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: denoland/setup-deno@v1
with:
deno-version: ${{ env.DENO_VERSION }}
- name: Publish (dry-run)
run: |
deno publish --dry-run

@codecov
Copy link

codecov bot commented Apr 6, 2024

Codecov Report

Attention: Patch coverage is 99.59267% with 2 lines in your changes are missing coverage. Please review.

Project coverage is 99.37%. Comparing base (92c763d) to head (9857615).
Report is 3 commits behind head on main.

Files Patch % Lines
is.ts 99.59% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #69      +/-   ##
==========================================
- Coverage   99.40%   99.37%   -0.03%     
==========================================
  Files           9        5       -4     
  Lines         669      641      -28     
  Branches       72       72              
==========================================
- Hits          665      637      -28     
  Misses          4        4              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Owing to the principle outlined below, defining everything within the `is.ts`
file is considerably more straightforward.
https://jsr.io/docs/about-slow-types#types-must-be-simply-inferred-or-explicit
@lambdalisue lambdalisue merged commit 3927a33 into main Apr 6, 2024
@lambdalisue lambdalisue deleted the fix-jsr branch April 6, 2024 04:09
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 6a9bf99 and 1006140.
Files ignored due to path filters (4)
  • __snapshots__/is_test.ts.snap is excluded by !**/*.snap
  • is/__snapshots__/_deprecated_test.ts.snap is excluded by !**/*.snap
  • is/__snapshots__/annotation_test.ts.snap is excluded by !**/*.snap
  • is/__snapshots__/utility_test.ts.snap is excluded by !**/*.snap
Files selected for processing (4)
  • is.ts (1 hunks)
  • is_bench.ts (1 hunks)
  • is_test.ts (3 hunks)
  • mod.ts (1 hunks)
Files not summarized due to errors (1)
  • is.ts: Error: Message exceeds token limit
Files skipped from review due to trivial changes (2)
  • is_bench.ts
  • mod.ts
Additional comments not posted (34)
is.ts (30)

11-18: Ensure the usage of Set for primitive type checks is the most efficient approach for your use case.

While using a Set for checking if a type is a primitive is correct, consider if direct comparison (e.g., typeof x === "string") might be more performant or readable in some cases, especially if the set of types is small and unlikely to change.


61-63: The implementation of isAny correctly always returns true, as expected for a type predicate that matches any type.


78-80: The isUnknown function is implemented correctly, always returning true to indicate that any type is considered unknown.


95-97: The isString function correctly checks if the input type is a string.


112-114: The isNumber function is implemented correctly to check for number types.


129-131: The isBigInt function accurately checks for bigint types.


146-148: The isBoolean function correctly identifies boolean types.


163-167: The isArray function uses Array.isArray correctly to check for array types.


182-184: The isSet function correctly checks for instances of Set.


207-211: The isRecordObject function correctly checks for plain object instances.


234-237: The isRecord function is implemented correctly to check for object types, including instances like Set, Map, etc.


246-249: The isRecordLike function is correctly marked as deprecated and its implementation matches the intended functionality.


265-267: The isMap function correctly checks for instances of Map.


282-284: The isFunction function correctly checks for function instances.


299-302: The isSyncFunction function correctly identifies synchronous functions using Object.prototype.toString.


318-321: The isAsyncFunction function accurately identifies asynchronous functions.


337-339: The isNull function correctly checks for null values.


354-356: The isUndefined function is implemented correctly to check for undefined values.


371-373: The isNullish function correctly checks for null or undefined values.


388-390: The isSymbol function correctly checks for symbol types.


414-415: The isPrimitive function correctly checks for primitive types using a predefined set.


421-427: The isOptional function correctly checks if a predicate function is annotated as Optional.


445-464: The isOptionalOf function correctly creates an Optional annotated type predicate function, with proper handling of existing optional predicates.


506-512: The isReadonly function correctly checks if a predicate function is annotated as Readonly.


534-544: The isReadonlyOf function correctly annotates a predicate function as Readonly, as intended.


754-828: The isReadonlyTupleOf function is correctly marked as deprecated and suggests using is.ReadonlyOf(is.TupleOf(...)) instead.


892-929: The isReadonlyUniformTupleOf function is correctly marked as deprecated, with a suggestion to use is.ReadonlyOf(is.UniformTupleOf(...)) instead.


1583-1586: The isOneOf function is correctly marked as deprecated, with a suggestion to use isUnionOf instead.


1600-1603: The isAllOf function is correctly marked as deprecated, with a suggestion to use isIntersectionOf instead.


1617-1666: The exported is object correctly aggregates all the type predicates and utility functions, making them easily accessible.

is_test.ts (4)

7-63: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [1-9]

The import statements are correctly structured and use pinned versions for Deno's standard library, which is a good practice.


107-495: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [110-1768]

The tests are well-structured and organized, using Deno.test and await t.step for clarity and readability.


107-495: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [110-1768]

Consider adding more test cases for complex type checking functions to ensure comprehensive coverage, especially for functions that involve nested or composite types.


107-495: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [110-1768]

Consider refactoring repetitive test patterns to reduce code duplication and enhance error messages for failed assertions to provide more context for debugging.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Actionable comments outside the diff hunks (3)
metadata.ts (3)

Line range hint 17-21: Consider adding a comment explaining the rationale behind using deno-lint-ignore no-explicit-any.


Line range hint 29-44: Ensure robust error handling around Object.defineProperties to gracefully handle potential failures.


Line range hint 46-50: LGTM! The getPredicateFactoryMetadata function is straightforward and effectively utilizes getMetadata.

Review Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 6a9bf99 and 9857615.
Files ignored due to path filters (4)
  • __snapshots__/is_test.ts.snap is excluded by !**/*.snap
  • is/__snapshots__/_deprecated_test.ts.snap is excluded by !**/*.snap
  • is/__snapshots__/annotation_test.ts.snap is excluded by !**/*.snap
  • is/__snapshots__/utility_test.ts.snap is excluded by !**/*.snap
Files selected for processing (5)
  • is.ts (1 hunks)
  • is_bench.ts (1 hunks)
  • is_test.ts (3 hunks)
  • metadata.ts (1 hunks)
  • mod.ts (1 hunks)
Files not summarized due to errors (1)
  • is.ts: Error: Message exceeds token limit
Files skipped from review as they are similar to previous changes (2)
  • is_bench.ts
  • mod.ts
Additional comments not posted (9)
metadata.ts (2)

1-1: Ensure that Predicate is correctly exported from ./is.ts to avoid import errors.

Verification successful

The Predicate type is correctly exported from is.ts, as verified by the script output. This confirms that the import statement in metadata.ts is accurate and should not cause any import errors related to Predicate.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that Predicate is exported from is.ts
rg "export type Predicate" src/is.ts

Length of output: 88



Script:

#!/bin/bash
# Search for the is.ts file across the entire repository
fd is.ts

Length of output: 16



Script:

#!/bin/bash
# Verify that Predicate is exported from is.ts at the root of the repository
rg "export type Predicate" is.ts

Length of output: 158


1-4: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [4-10]

LGTM! The type definitions for handling metadata are well-designed and flexible.

is.ts (3)

60-63: Ensure the use of any is absolutely necessary and documented.

// deno-lint-ignore no-explicit-any
export function isAny(_x: unknown): _x is any {
  return true;
}

1246-1253: Use specific types instead of any where possible to enhance type safety.

// deno-lint-ignore no-explicit-any
export function isInstanceOf<T extends new (...args: any) => unknown>(
  ctor: T,
): Predicate<InstanceType<T>> & WithMetadata<IsInstanceOfMetadata> {
  return setPredicateFactoryMetadata(
    (x: unknown): x is InstanceType<T> => x instanceof ctor,
    { name: "isInstanceOf", args: [ctor] },
  );
}

1617-1666: The export object is is well-organized and provides a clear API for consumers. However, consider documenting each exported function for better developer experience.

is_test.ts (4)

7-63: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [1-9]

Consider grouping imports from the same module to improve readability.

- import {
-   assertEquals,
-   assertStrictEquals,
- } from "https://deno.land/std@0.211.0/assert/mod.ts";
- import {
-   assertSnapshot,
- } from "https://deno.land/std@0.211.0/testing/snapshot.ts";
- import { assertType } from "https://deno.land/std@0.211.0/testing/types.ts";
+ import { assertEquals, assertStrictEquals, assertSnapshot, assertType } from "https://deno.land/std@0.211.0/testing/types.ts";

10-60: Ensure that all imported functions are utilized within the file to avoid unnecessary imports.

Verification successful

The verification process indicates that the imported functions from "./is.ts" are utilized within is_test.ts. This suggests that the imports are necessary and correctly used in the file.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that all imported functions from "./is.ts" are used in `is_test.ts`.
rg --type ts 'is\w+' is_test.ts | cut -d: -f3 | sort | uniq
# Expected to match the list of imported functions.

Length of output: 17612


110-428: The structure and naming of the tests are consistent and follow best practices for Deno testing. However, consider adding more descriptive test names or comments to clarify the specific behavior being tested, especially for complex predicates.


1770-1772: Ensure that the dynamic import and filtering logic correctly identifies and tests all relevant functions from the ./is.ts module. Consider adding explicit tests for any functions that might be missed by this dynamic approach.

Comment on lines +1 to +9
import type { FlatType, UnionToIntersection, Writable } from "./_typeutil.ts";
import {
type GetMetadata,
getMetadata,
getPredicateFactoryMetadata,
type PredicateFactoryMetadata,
setPredicateFactoryMetadata,
type WithMetadata,
} from "./metadata.ts";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider organizing imports to improve readability.

import type { FlatType, UnionToIntersection, Writable } from "./_typeutil.ts";
import {
  type GetMetadata,
  getMetadata,
  getPredicateFactoryMetadata,
  type PredicateFactoryMetadata,
  setPredicateFactoryMetadata,
  type WithMetadata,
} from "./metadata.ts";

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
import type { FlatType, UnionToIntersection, Writable } from "./_typeutil.ts";
import {
type GetMetadata,
getMetadata,
getPredicateFactoryMetadata,
type PredicateFactoryMetadata,
setPredicateFactoryMetadata,
type WithMetadata,
} from "./metadata.ts";

Comment on lines +445 to +464
pred: Predicate<T>,
):
& Predicate<T | undefined>
& WithMetadata<IsOptionalOfMetadata> {
if (isOptional(pred)) {
return pred as
& Predicate<T | undefined>
& WithMetadata<IsOptionalOfMetadata>;
}
return Object.defineProperties(
setPredicateFactoryMetadata(
(x: unknown): x is Predicate<T | undefined> => x === undefined || pred(x),
{ name: "isOptionalOf", args: [pred] },
),
{ optional: { value: true as const } },
) as
& Predicate<T | undefined>
& WithMetadata<IsOptionalOfMetadata>;
}

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implementation of isOptionalOf could be simplified by directly returning the modified predicate without the conditional check, as the metadata addition is idempotent.

export function isOptionalOf<T>(
  pred: Predicate<T>,
):
  & Predicate<T | undefined>
  & WithMetadata<IsOptionalOfMetadata> {
-  if (isOptional(pred)) {
-    return pred as
-      & Predicate<T | undefined>
-      & WithMetadata<IsOptionalOfMetadata>;
-  }
  return Object.defineProperties(
    setPredicateFactoryMetadata(
      (x: unknown): x is Predicate<T | undefined> => x === undefined || pred(x),
      { name: "isOptionalOf", args: [pred] },
    ),
    { optional: { value: true as const } },
  ) as
    & Predicate<T | undefined>
    & WithMetadata<IsOptionalOfMetadata>;
}

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
export function isOptionalOf<T>(
pred: Predicate<T>,
):
& Predicate<T | undefined>
& WithMetadata<IsOptionalOfMetadata> {
if (isOptional(pred)) {
return pred as
& Predicate<T | undefined>
& WithMetadata<IsOptionalOfMetadata>;
}
return Object.defineProperties(
setPredicateFactoryMetadata(
(x: unknown): x is Predicate<T | undefined> => x === undefined || pred(x),
{ name: "isOptionalOf", args: [pred] },
),
{ optional: { value: true as const } },
) as
& Predicate<T | undefined>
& WithMetadata<IsOptionalOfMetadata>;
}
export function isOptionalOf<T>(
pred: Predicate<T>,
):
& Predicate<T | undefined>
& WithMetadata<IsOptionalOfMetadata> {
return Object.defineProperties(
setPredicateFactoryMetadata(
(x: unknown): x is Predicate<T | undefined> => x === undefined || pred(x),
{ name: "isOptionalOf", args: [pred] },
),
{ optional: { value: true as const } },
) as
& Predicate<T | undefined>
& WithMetadata<IsOptionalOfMetadata>;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants