Skip to content

Banned use of explicit any#526

Merged
allouis merged 1 commit intomainfrom
stricter-biome-config
Apr 15, 2025
Merged

Banned use of explicit any#526
allouis merged 1 commit intomainfrom
stricter-biome-config

Conversation

@allouis
Copy link
Collaborator

@allouis allouis commented Apr 15, 2025

We had this set to warning to allow our legacy code to pass lint, but this has result in more uses of explicit any being added to the codebase. The approach here is to add comments to allow the existing cases but ban all new cases.

We had this set to warning to allow our legacy code to pass lint, but this has
result in more uses of explicit any being added to the codebase. The approach
here is to add comments to allow the existing cases but ban all new cases.
@coderabbitai
Copy link

coderabbitai bot commented Apr 15, 2025

Walkthrough

This change set introduces a series of comments and lint suppression directives across the codebase to address the use of the any type, which is currently present due to legacy code. In multiple source and test files, TODO comments were added to mark areas where any is used, signaling an intent to improve type safety in the future. Alongside these comments, biome-ignore lint directives were inserted to suppress warnings from the linter about explicit or implicit use of any. No functional, logical, or structural changes were made to the code; all modifications are limited to annotations for code quality and future refactoring. Additionally, the linting configuration was updated to simplify the "suspicious" rules by removing certain checks related to any usage. In a few interface definitions, index signatures using any were explicitly added, accompanied by the same style of comments and lint suppression. No exported or public API signatures were altered.

Tip

⚡💬 Agentic Chat (Pro Plan, General Availability)
  • We're introducing multi-step agentic chat in review comments and issue comments, within and outside of PR's. This feature enhances review and issue discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments and add commits to existing pull requests.
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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 generate docstrings to generate docstrings for this 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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 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 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: 0

🧹 Nitpick comments (2)
src/post/post.entity.ts (1)

155-157: Properly documented legacy any usage in handleDeleted method.

The added comments provide appropriate context for this type cast while suppressing the linting warning. For future improvement, consider refactoring this method to avoid type casting.

In the future, you might want to consider refactoring this to use a better typing approach instead of casting to any. For example, you could define a mutable version of the interface with optional properties that can be modified.

src/post/post.entity.unit.test.ts (1)

208-210: Consistently documented any usage across test cases.

The pattern of adding TODO comments and lint directives has been consistently applied to all occurrences of any casting in the test file.

For future refactoring, consider creating a test utility function that creates a properly typed mock post with an ID, which would eliminate the need for multiple any casts throughout these tests.

Also applies to: 225-227, 242-244, 259-261, 277-279

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bd6fed6 and 1154554.

📒 Files selected for processing (21)
  • biome.json (1 hunks)
  • cedar/query-runner/src/app.ts (2 hunks)
  • src/activity-handlers/create.handler.ts (1 hunks)
  • src/app.ts (1 hunks)
  • src/core/events.ts (1 hunks)
  • src/db.ts (1 hunks)
  • src/dispatchers.ts (2 hunks)
  • src/dispatchers.unit.test.ts (6 hunks)
  • src/helpers/activitypub/activity.ts (1 hunks)
  • src/helpers/user.ts (1 hunks)
  • src/helpers/user.unit.test.ts (1 hunks)
  • src/http/api/helpers/account.ts (1 hunks)
  • src/http/api/helpers/account.unit.test.ts (3 hunks)
  • src/http/api/views/account.follows.view.ts (1 hunks)
  • src/kv-helpers.ts (1 hunks)
  • src/lookup-helpers.unit.test.ts (5 hunks)
  • src/post/post.entity.ts (1 hunks)
  • src/post/post.entity.unit.test.ts (6 hunks)
  • src/post/post.repository.knex.ts (3 hunks)
  • src/post/post.service.ts (2 hunks)
  • src/post/post.service.unit.test.ts (2 hunks)
🔇 Additional comments (34)
src/helpers/user.unit.test.ts (1)

63-65: Legacy any usage is properly annotated and suppressed.

The addition of the TODO and biome-ignore comments above the legacy any cast is appropriate and aligns with the project's new linting policy. No further action needed.

biome.json (1)

31-32: Lint configuration update aligns with new type safety policy.

Removing global "noExplicitAny" and "noImplicitAnyLet" rules is correct, given the new approach of inline suppression for legacy code. This supports incremental migration to stricter typing.

src/activity-handlers/create.handler.ts (1)

47-49: Legacy any usage is clearly annotated and suppressed.

The TODO and biome-ignore comments above the legacy any usage for database retrieval are appropriate and support the project's linting policy. No further action required.

src/helpers/user.ts (1)

147-150: Legacy any usage is properly annotated and suppressed.

The TODO and biome-ignore comments above the legacy any usage for keypair retrieval are appropriate and align with the project's linting policy. No further action needed.

src/core/events.ts (1)

4-6: Legacy any usage is properly annotated and suppressed.

The TODO and biome-ignore comments above the legacy any usage for event arguments are appropriate and align with the project's linting policy. No further action needed.

src/kv-helpers.ts (1)

13-15: Appropriate annotation and lint suppression for legacy any usage.

The addition of a TODO and biome-ignore directive above the explicit any parameter is a good practice for managing legacy code. This makes technical debt visible and prevents new untracked uses of any.

src/app.ts (1)

300-302: Appropriate annotation and lint suppression for legacy any usage.

The TODO and biome-ignore directive above the explicit any cast make the technical debt visible and prevent new untracked uses of any. This is a good interim solution for legacy code.

cedar/query-runner/src/app.ts (1)

46-48: Appropriate annotation and lint suppression for legacy any usage.

The TODO and biome-ignore directives above the explicit any parameters in both functions make the technical debt visible and prevent new untracked uses of any. This is a good interim solution for legacy code.

Also applies to: 56-58

src/lookup-helpers.unit.test.ts (1)

39-41: Appropriate annotation and lint suppression for legacy any usage in tests.

The TODO and biome-ignore directives above the explicit any casts in test calls make the technical debt visible and prevent new untracked uses of any. This is a good interim solution for legacy code in tests.

Also applies to: 59-61, 84-86, 99-101, 129-131

src/http/api/views/account.follows.view.ts (1)

198-200: Appropriate annotation and lint suppression for legacy any usage.

The TODO and biome-ignore directive above the explicit any cast make the technical debt visible and prevent new untracked uses of any. This is a good interim solution for legacy code.

src/db.ts (1)

28-30: Properly documented legacy any usage.

The added comments appropriately identify this index signature as legacy code that requires future typing improvements, while allowing the current code to function.

src/helpers/activitypub/activity.ts (2)

20-22: Properly documented legacy any usage in ActivityObject interface.

The added comments clearly indicate this is technical debt to be addressed in the future while suppressing linting warnings.


28-30: Properly documented legacy any usage in Activity interface.

The comments follow the consistent pattern established across the codebase for handling legacy any types.

src/post/post.entity.unit.test.ts (1)

193-195: Properly documented any usage in test code.

The added comments help identify this test-specific type casting as a technical debt item to be addressed later.

src/http/api/helpers/account.ts (1)

86-88: Properly documented use of any type.

The added TODO comment and biome-ignore directive appropriately document this legacy use of any type while suppressing the linter warning. This approach aligns with the PR's objective of preventing new uses of any while preserving existing ones.

src/dispatchers.unit.test.ts (6)

31-33: Appropriate annotation for test-specific any usage.

The added comments properly document this test-specific use of any with RequestContext and align with the PR's goal of flagging legacy any usage for future cleanup.


47-49: Properly documented test data with any type.

Good documentation of the Record<string, any> test data structure with appropriate TODO and lint suppression directive.


88-90: Consistently marked legacy any usage in test context.

The added comments maintain consistency with other similar annotations in this file for RequestContext casting.


156-158: Properly documented test data with any type.

Another instance of Record<string, any> being appropriately documented with TODO and lint suppression directive.


273-275: Consistently marked legacy any usage in test context.

The added comments maintain consistency with other similar annotations in this file for RequestContext casting.


341-343: Properly documented use of any in nodeInfoDispatcher test.

The added comments appropriately document this test-specific use of any with RequestContext and align with the PR's goal.

src/http/api/helpers/account.unit.test.ts (5)

237-239: Properly documented use of any in test context.

The added comments appropriately document this test-specific use of Context and align with the PR's goal of marking legacy any usage for future cleanup.


272-274: Consistently documented use of any type in test context.

The comments maintain consistency with other annotations for Context cases throughout the tests.


276-278: Properly documented direct any cast in test.

Good annotation for the direct cast to any for the accountService mock in the test context.


290-292: Consistently documented use of any in test context.

The comments maintain consistency with other annotations for Context cases throughout the tests.


294-296: Consistently documented direct any cast in test.

Maintains consistency with the previous annotation for the accountService mock, properly documenting direct use of any in test context.

src/post/post.service.unit.test.ts (2)

100-102: Properly documented any cast for accessing private method.

The added comments appropriately document this test-specific case where any is used to access a private method during testing. This follows the PR's approach of marking legacy any usage while allowing tests to continue functioning.


164-166: Consistently documented any cast for accessing private method.

Maintains consistency with the previous annotation for accessing the private mapActivityToPostDTO method, properly documenting use of any in test context.

src/post/post.repository.knex.ts (2)

105-117: Appropriate suppression of 'any' type with descriptive comments

The added TODO comment and biome-ignore directive properly document the legacy use of any while allowing the codebase to function. This follows the PR's objective of banning new uses of explicit any while accommodating existing instances.

For future improvement, you could consider using a more specific type like:

type PostAttachment = {
  url: string;
  [key: string]: unknown;
};

444-448: Appropriate use of comment and lint suppression for property mutation

The TODO comment and lint directive are correctly added to acknowledge and temporarily allow this use of any for property mutation.

For a future refactor, consider creating a setter method on the Post class to handle ID assignment, which would eliminate the need for type casting:

// In Post class
setId(id: number): void {
  this.id = id;
}

// Then here
post.setId(id);
src/post/post.service.ts (2)

151-153: Properly documented legacy 'any' type in method signature

The added comments correctly highlight this as an area needing type cleanup while allowing the codebase to function with the existing code.

In a future refactor, consider creating a proper interface for the Activity structure:

interface ActivityWithObject {
  object: {
    id: string;
    type: string;
    name?: string;
    preview?: { content?: string };
    content?: string;
    /* other properties */
  };
  actor: {
    id: string;
    preferredUsername?: string;
    name?: string;
    /* other properties */
  };
  type: string;
  /* other properties */
}

661-666: Appropriate documentation of 'any' type cast from toJsonLd result

The comment and biome-ignore directive correctly identify another instance of legacy any usage that needs future cleanup.

For a future improvement, consider working with the library maintainers to enhance the typing of the toJsonLd() method's return value, or create a proper type definition for the expected structure.

src/dispatchers.ts (2)

379-383: Well-documented suppression of 'any' for database retrieval

The added comments appropriately document this legacy use of any in the database retrieval code. This follows the PR objectives of marking legacy code for future improvement while keeping the codebase functional.

For future improvement, consider creating a type for the expected structure of the database entry:

interface ReplyTargetData {
  attributedTo?: { id: string };
  [key: string]: unknown;
}

955-966: Properly documented index signatures using 'any'

The comments and biome-ignore directives correctly document both instances of index signatures using the any type. This follows the PR's approach to addressing legacy code.

For future improvement, consider:

interface ObjectWithAttributes {
  [key: string]: unknown;
  attributedTo?: string | { [key: string]: unknown };
}

interface LikedActivity {
  object: string | ObjectWithAttributes;
  [key: string]: unknown;
}

This would provide better type safety while maintaining flexibility for the diverse data structures.

@allouis allouis enabled auto-merge (rebase) April 15, 2025 05:45
@allouis allouis merged commit 5eb7fba into main Apr 15, 2025
6 checks passed
@allouis allouis deleted the stricter-biome-config branch April 15, 2025 05:51
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