Skip to content
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

refactor: package optimizations #69

Merged
merged 10 commits into from
Jan 25, 2025
Merged

Conversation

DaveMBush
Copy link
Owner

@DaveMBush DaveMBush commented Jan 25, 2025

Issue Number: #66 #67 #68 #52

Body

Update to eslint flat config for project
Remove dependency on common-tags
Remove dependency on tsutils-etc
Build no longer bundles 3rd party libs
Update tsutils to ts-api-utils
Remove unused files

Summary by CodeRabbit

Based on the comprehensive summary, here are the updated release notes:

  • Package Updates

    • Updated ESLint configuration to use new flat config system.
    • Updated TypeScript ESLint utility dependencies.
    • Removed several deprecated dependencies.
  • Configuration Changes

    • Migrated from legacy .eslintrc.json to new eslint.config.cjs.
    • Updated package and project configurations.
    • Enhanced module boundary and dependency checks.
  • Code Maintenance

    • Removed unused test utility functions.
    • Refactored type checking utilities.
    • Simplified description formatting in ESLint rules.
  • Type Utilities

    • Added new type checking functions for TypeScript AST.
    • Improved type inference and type predicate functions.

Copy link

coderabbitai bot commented Jan 25, 2025

Warning

Rate limit exceeded

@DaveMBush has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 12 minutes and 22 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between c546447 and 476b211.

📒 Files selected for processing (1)
  • packages/eslint-plugin-rxjs/eslint.config.cjs (1 hunks)

Walkthrough

This pull request introduces significant changes to the ESLint configuration and utility functions in the eslint-plugin-rxjs package. The modifications include transitioning from the traditional .eslintrc.json configuration to the new flat configuration system (eslint.config.cjs), updating package dependencies, and refactoring type-checking utility functions. The changes aim to modernize the ESLint plugin's configuration, improve type safety, and streamline the project's dependency management.

Changes

File Change Summary
.eslintrc.json Deleted legacy ESLint configuration file
eslint.config.cjs New flat configuration file using FlatCompat for ESLint
nx.json Updated input configurations for ESLint
package.json Updated dependencies, added/removed packages
packages/eslint-plugin-rxjs/package.json Updated package dependencies
packages/eslint-plugin-rxjs/project.json Added release and dependency check configurations
Multiple rule files Simplified description formatting, removed stripIndent
packages/eslint-plugin-rxjs/src/lib/tsutils-etc/ Added multiple type-checking utility functions

Sequence Diagram

sequenceDiagram
    participant Dev as Developer
    participant ESLint as ESLint Plugin
    participant TypeChecker as Type Checking Utilities

    Dev->>ESLint: Configure with new flat config
    ESLint->>TypeChecker: Use new utility functions
    TypeChecker-->>ESLint: Provide type analysis
    ESLint-->>Dev: Lint code with enhanced type checking
Loading

Possibly related PRs

  • fix: lat config fix #8: The changes in this PR involve modifications to the ESLint configuration for the RxJS plugin, specifically related to how the recommended configuration is structured, which aligns with the changes made in the main PR regarding ESLint configurations.
  • docs: flat config documentation #10: This PR updates the documentation to reflect changes in the ESLint configurations, including Flat Config, which is relevant to the changes made in the main PR regarding the ESLint configuration file.
  • build: updates readme and dependencies #20: Similar to the main PR, this PR updates the README to clarify the plugin's compatibility with modern configurations, including Flat Config, which relates to the changes in the main PR.

Poem

🐰 A Rabbit's Ode to ESLint Delight
Config files dance, old ways take flight,
Flat configs sparkle with type-checking might.
Dependencies pruned, utilities new,
Our linting adventure begins anew!
Hop, hop, hooray for clean code's bright! 🌟


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>, 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. (Beta)
  • @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

nx-cloud bot commented Jan 25, 2025

View your CI Pipeline Execution ↗ for commit 476b211.

Command Status Duration Result
nx affected -t lint test build ✅ Succeeded 1m 31s View ↗

☁️ Nx Cloud last updated this comment at 2025-01-25 19:55:45 UTC

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

🔭 Outside diff range comments (1)
packages/eslint-plugin-rxjs/src/lib/rules/no-unsafe-first.ts (1)

Update required: getTypeServices.ts needs migration from tsutils-etc to ts-api-utils

The verification confirms that getTypeServices.ts directly depends on tsutils-etc and needs to be updated as part of the migration to ts-api-utils. This file is a critical utility that provides type checking services and uses multiple tsutils-etc functions:

  • couldBeType
  • couldBeFunction
  • isAny
  • isReferenceType
  • isUnknown
🔗 Analysis chain

Line range hint 2-2: Verify if eslint-etc uses updated dependencies.

Since the PR objectives mention updating from tsutils-etc to ts-api-utils, let's verify the implementation of these utility functions.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check the implementation of getTypeServices in eslint-etc
# to ensure it's not using deprecated dependencies

# Check the content of eslint-etc
rg -p "getTypeServices" "../eslint-etc"

# Check for any remaining uses of tsutils-etc
rg -l "tsutils-etc"

Length of output: 361


Script:

#!/bin/bash
# Check the implementation of getTypeServices
cat packages/eslint-plugin-rxjs/src/lib/eslint-etc/get-type-services.ts

# Check for any imports of tsutils-etc in this file
rg "tsutils-etc" packages/eslint-plugin-rxjs/src/lib/eslint-etc/get-type-services.ts

Length of output: 4556

🧹 Nitpick comments (8)
packages/eslint-plugin-rxjs/src/lib/tsutils-etc/could-implement.function.ts (1)

31-53: Ensure consistent naming to reduce confusion.

This function's qualified parameter includes both a name and a typeChecker, while its node parameter also references a typeChecker inside the function. Renaming either could improve clarity. For instance, rename qualified to qualifiedTypeChecker or rename the type variable in lines 41-42 to avoid overshadowing the outer scope's type. This helps readers quickly understand the difference between the ts.Type being tested and the typeChecker used to retrieve additional information.

-function isMatchingNode(
-  node: ts.ExpressionWithTypeArguments,
-  name: string | RegExp,
-  qualified?: {
-    name: RegExp;
-    typeChecker: ts.TypeChecker;
-  },
-): boolean {
-  const { expression } = node;
-  if (qualified) {
-    const type = qualified.typeChecker.getTypeAtLocation(expression);
+function isMatchingNode(
+  node: ts.ExpressionWithTypeArguments,
+  name: string | RegExp,
+  qualifiedTypeChecker?: {
+    name: RegExp;
+    typeChecker: ts.TypeChecker;
+  },
+): boolean {
+  const { expression } = node;
+  if (qualifiedTypeChecker) {
+    const innerType = qualifiedTypeChecker.typeChecker.getTypeAtLocation(expression);
   ...
 }
packages/eslint-plugin-rxjs/src/lib/tsutils-etc/is-reference-type.function.ts (1)

4-9: Consider adding a type guard before the cast.

The type cast to ts.ObjectType could be unsafe if the type is null/undefined.

Consider this safer implementation:

 export function isReferenceType(type: ts.Type): type is ts.TypeReference {
   return (
     tsutils.isTypeFlagSet(type, ts.TypeFlags.Object) &&
-    tsutils.isObjectFlagSet(type as ts.ObjectType, ts.ObjectFlags.Reference)
+    ((type as ts.ObjectType)?.flags !== undefined) &&
+    tsutils.isObjectFlagSet(type as ts.ObjectType, ts.ObjectFlags.Reference)
   );
 }
packages/eslint-plugin-rxjs/src/lib/tsutils-etc/could-be-function.function.ts (1)

4-11: Consider optimizing the checks and handling edge cases.

The implementation could benefit from:

  1. Adding null/undefined checks
  2. Optimizing the order of checks (put the fastest checks first)
  3. Considering additional function-like types (e.g., Method, Constructor)

Consider this enhanced implementation:

 export function couldBeFunction(type: ts.Type): boolean {
+  if (!type) return false;
   return (
-    type.getCallSignatures().length > 0 ||
     couldBeType(type, 'Function') ||
     couldBeType(type, 'ArrowFunction') ||
-    couldBeType(type, ts.InternalSymbolName.Function)
+    couldBeType(type, ts.InternalSymbolName.Function) ||
+    couldBeType(type, 'Method') ||
+    couldBeType(type, 'Constructor') ||
+    type.getCallSignatures().length > 0
   );
 }

Note: The getCallSignatures() check is moved to the end as it's likely more expensive than string comparisons.

packages/eslint-plugin-rxjs/src/lib/tsutils-etc/could-be-type.function.ts (1)

28-31: Use optional chaining for better null safety.

The baseTypes check could be simplified using optional chaining.

-  const baseTypes = type.getBaseTypes();
-  if (baseTypes && baseTypes.some((t) => couldBeType(t, name, qualified))) {
+  if (type.getBaseTypes()?.some((t) => couldBeType(t, name, qualified))) {
     return true;
   }
🧰 Tools
🪛 Biome (1.9.4)

[error] 29-29: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

eslint.config.cjs (2)

38-43: Remove unnecessary empty rule objects.

The TypeScript and JavaScript configurations spread empty rule objects which can be simplified.

    .map((config) => ({
      ...config,
      files: ['**/*.ts', '**/*.tsx', '**/*.cts', '**/*.mts'],
-      rules: {
-        ...config.rules,
-      },
    })),

Also applies to: 48-54


18-30: Consider adding more specific module boundary constraints.

The current module boundary constraints are very permissive with '*' tags. Consider adding more specific constraints based on your project's architecture.

Example structure:

       depConstraints: [
         {
-          sourceTag: '*',
-          onlyDependOnLibsWithTags: ['*'],
+          sourceTag: 'rules',
+          onlyDependOnLibsWithTags: ['utils', 'shared'],
         },
       ],
packages/eslint-plugin-rxjs/src/lib/eslint-etc/get-type-services.ts (2)

10-34: Add JSDoc comments to TypeServices interface.

The new TypeServices interface would benefit from documentation explaining the purpose of each method.

Example for the first few methods:

+/**
+ * Services for TypeScript type checking and analysis.
+ */
 interface TypeServices {
+  /** Checks if the node could be a BehaviorSubject instance */
   couldBeBehaviorSubject: (node: es.Node) => boolean;
+  /** Checks if the node could be an Error instance */
   couldBeError: (node: es.Node) => boolean;
   // ... add docs for other methods

Line range hint 46-54: Add error handling for missing TypeScript services.

The getType function should handle cases where TypeScript services are not available.

   const getType = (node: es.Node) => {
+    if (!program || !typeChecker) {
+      throw new Error('TypeScript services not available');
+    }
     const tsNode = esTreeNodeToTSNodeMap.get(node);
     if (!tsNode) {
       return undefined;
     }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7edfd99 and 7a65dcc.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (31)
  • .eslintrc.json (0 hunks)
  • eslint.config.cjs (1 hunks)
  • nx.json (2 hunks)
  • package.json (2 hunks)
  • packages/eslint-plugin-rxjs/.eslintrc.json (0 hunks)
  • packages/eslint-plugin-rxjs/eslint.config.cjs (1 hunks)
  • packages/eslint-plugin-rxjs/package.json (1 hunks)
  • packages/eslint-plugin-rxjs/project.json (2 hunks)
  • packages/eslint-plugin-rxjs/src/lib/eslint-etc/from-fixture.spec.ts (0 hunks)
  • packages/eslint-plugin-rxjs/src/lib/eslint-etc/from-fixture.ts (0 hunks)
  • packages/eslint-plugin-rxjs/src/lib/eslint-etc/get-type-services.ts (5 hunks)
  • packages/eslint-plugin-rxjs/src/lib/eslint-etc/index.ts (0 hunks)
  • packages/eslint-plugin-rxjs/src/lib/rules/ban-observables.ts (1 hunks)
  • packages/eslint-plugin-rxjs/src/lib/rules/ban-operators.ts (1 hunks)
  • packages/eslint-plugin-rxjs/src/lib/rules/no-cyclic-action.ts (1 hunks)
  • packages/eslint-plugin-rxjs/src/lib/rules/no-unsafe-catch.ts (1 hunks)
  • packages/eslint-plugin-rxjs/src/lib/rules/no-unsafe-first.ts (1 hunks)
  • packages/eslint-plugin-rxjs/src/lib/rules/no-unsafe-subject-next.ts (1 hunks)
  • packages/eslint-plugin-rxjs/src/lib/rules/no-unsafe-switchmap.ts (1 hunks)
  • packages/eslint-plugin-rxjs/src/lib/rules/no-unsafe-takeuntil.ts (1 hunks)
  • packages/eslint-plugin-rxjs/src/lib/rules/throw-error.ts (1 hunks)
  • packages/eslint-plugin-rxjs/src/lib/tsutils-etc/could-be-function.function.ts (1 hunks)
  • packages/eslint-plugin-rxjs/src/lib/tsutils-etc/could-be-type.function.ts (1 hunks)
  • packages/eslint-plugin-rxjs/src/lib/tsutils-etc/could-implement.function.ts (1 hunks)
  • packages/eslint-plugin-rxjs/src/lib/tsutils-etc/index.ts (1 hunks)
  • packages/eslint-plugin-rxjs/src/lib/tsutils-etc/is-any.function.ts (1 hunks)
  • packages/eslint-plugin-rxjs/src/lib/tsutils-etc/is-intersection-type.function.ts (1 hunks)
  • packages/eslint-plugin-rxjs/src/lib/tsutils-etc/is-reference-type.function.ts (1 hunks)
  • packages/eslint-plugin-rxjs/src/lib/tsutils-etc/is-type.function.ts (1 hunks)
  • packages/eslint-plugin-rxjs/src/lib/tsutils-etc/is-union-type.function.ts (1 hunks)
  • packages/eslint-plugin-rxjs/src/lib/tsutils-etc/is-unknown.function.ts (1 hunks)
💤 Files with no reviewable changes (5)
  • packages/eslint-plugin-rxjs/src/lib/eslint-etc/index.ts
  • packages/eslint-plugin-rxjs/.eslintrc.json
  • .eslintrc.json
  • packages/eslint-plugin-rxjs/src/lib/eslint-etc/from-fixture.spec.ts
  • packages/eslint-plugin-rxjs/src/lib/eslint-etc/from-fixture.ts
✅ Files skipped from review due to trivial changes (5)
  • packages/eslint-plugin-rxjs/src/lib/rules/no-unsafe-takeuntil.ts
  • packages/eslint-plugin-rxjs/src/lib/rules/ban-observables.ts
  • packages/eslint-plugin-rxjs/src/lib/rules/no-unsafe-catch.ts
  • packages/eslint-plugin-rxjs/src/lib/rules/no-unsafe-switchmap.ts
  • packages/eslint-plugin-rxjs/src/lib/rules/ban-operators.ts
🧰 Additional context used
🪛 Biome (1.9.4)
packages/eslint-plugin-rxjs/src/lib/tsutils-etc/could-be-type.function.ts

[error] 29-29: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🔇 Additional comments (21)
packages/eslint-plugin-rxjs/src/lib/rules/no-unsafe-first.ts (1)

29-29: LGTM! Clean removal of stripIndent dependency.

The schema description maintains clarity while successfully removing the common-tags dependency, aligning with the PR's optimization objectives.

packages/eslint-plugin-rxjs/src/lib/tsutils-etc/could-implement.function.ts (1)

3-29: Consider handling interfaces and additional edge cases.

Currently, the couldImplement function handles the scenario where the valueDeclaration is specifically a ClassDeclaration with an ImplementsKeyword. If your intention is to capture instances where a type could correspond to an interface or abstract class, you may need to account for those possibilities here. Additionally, types that are unions or intersections won't be handled in the present logic. Depending on your usage, you might need to add checks for InterfaceDeclarations or recursively traverse union and intersection constituents.

packages/eslint-plugin-rxjs/src/lib/tsutils-etc/is-any.function.ts (1)

4-6: Looks good; straightforward implementation.

This is a clean, concise helper function that leverages ts-api-utils for type checks. No further changes needed.

packages/eslint-plugin-rxjs/src/lib/tsutils-etc/is-unknown.function.ts (1)

4-6: Concise and correct approach.

Similar to isAny, this helper function correctly identifies unknown types by checking the TypeFlags.Unknown flag. No changes required.

packages/eslint-plugin-rxjs/src/lib/tsutils-etc/is-union-type.function.ts (1)

4-6: Well-implemented type guard!

Good use of type predicate (type is ts.UnionType) for proper type narrowing in TypeScript.

packages/eslint-plugin-rxjs/src/lib/tsutils-etc/index.ts (2)

1-5: Well-documented source attribution and testing status.

Good practice to document the source of copied code and acknowledge the testing situation. This helps future maintainers understand the context.


6-11: Verify the copied utility functions.

Since these functions were copied from tsutils-etc, we should verify their functionality in the new context.

✅ Verification successful

Utility functions are properly implemented and integrated ✓

All required utility functions are present in the codebase with proper TypeScript type signatures and are actively used in the rules implementation. The functions maintain consistency with TypeScript utility patterns and show proper integration with the existing codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the copied utility functions exist and match their source.

# Check if all the exported functions exist
for func in could-be-type could-be-function is-any is-reference-type is-unknown is-union-type; do
  if ! fd -e ts "$func.function" src/lib/tsutils-etc/; then
    echo "Missing function file: $func"
    exit 1
  fi
done

# Compare with original source
echo "Checking original source at https://github.com/cartant/tsutils-etc"

Length of output: 350


Script:

#!/bin/bash
# First, find the correct location of these files
echo "Searching for the utility function files:"
fd -e ts -t f "function\.ts$" --full-path

echo -e "\nChecking file contents for tsutils-etc references:"
rg -l "tsutils-etc" -g "*.ts"

echo -e "\nExamining imports and exports:"
rg "export.*function" -g "*.function.ts"

Length of output: 2446

packages/eslint-plugin-rxjs/src/lib/tsutils-etc/is-type.function.ts (1)

3-25: Clean and well-structured type checking implementation.

The function provides comprehensive type checking with:

  • Proper null checks for type.symbol
  • Support for both string and RegExp matching
  • Optional qualified name checking with TypeScript's type checker
packages/eslint-plugin-rxjs/src/lib/tsutils-etc/could-be-type.function.ts (1)

8-37: Comprehensive type checking with good separation of concerns.

The function effectively handles various type scenarios:

  • Reference types
  • Intersection and union types
  • Base types
  • Implementation checks
🧰 Tools
🪛 Biome (1.9.4)

[error] 29-29: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

packages/eslint-plugin-rxjs/eslint.config.cjs (2)

37-55: Well-structured dependency checking configuration.

Good configuration of @nx/dependency-checks with:

  • Explicit ignored files and dependencies
  • Comprehensive checks for missing, obsolete, and version mismatches
  • Clear control over transitive dependencies

16-24: Consider adding specific rules for TypeScript/JavaScript files.

The rules object is currently empty. Consider adding specific rules that were present in the previous configuration.

eslint.config.cjs (1)

1-8: LGTM! Good use of FlatCompat for ESLint configuration.

The setup correctly uses the new flat configuration format with proper initialization of FlatCompat.

packages/eslint-plugin-rxjs/src/lib/rules/no-unsafe-subject-next.ts (1)

8-9: Verify imported functions exist in new locations.

The change from tsutils to ts-api-utils and local tsutils-etc aligns with PR objectives. Let's verify these imports:

packages/eslint-plugin-rxjs/package.json (1)

5-6: Verify compatibility of updated dependencies.

The update to @typescript-eslint/utils and addition of ts-api-utils needs verification:

✅ Verification successful

Dependencies are compatible with project requirements

  • eslint ~9.18.0 satisfies the requirement ^8.57.0 || ^9.0.0
  • typescript 5.6.3 satisfies both >=4.8.4 (ts-api-utils) and >=4.8.4 <5.8.0 (@typescript-eslint/utils)
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for compatibility issues between dependencies
echo "Checking @typescript-eslint/utils compatibility..."
npm info "@typescript-eslint/utils@^8.21.0" peerDependencies

echo "Checking ts-api-utils compatibility..."
npm info "ts-api-utils@^2.0.0" peerDependencies

Length of output: 398


Script:

#!/bin/bash
# Check project's eslint and typescript versions
echo "Project dependencies:"
jq '.dependencies.eslint, .dependencies.typescript, .devDependencies.eslint, .devDependencies.typescript' packages/eslint-plugin-rxjs/package.json

Length of output: 221


Script:

#!/bin/bash
# Check root package.json for dependencies
echo "Root package.json dependencies:"
if [ -f "package.json" ]; then
    jq '.dependencies.eslint, .dependencies.typescript, .devDependencies.eslint, .devDependencies.typescript' package.json
else
    echo "No root package.json found"
fi

# Look for workspace configuration
echo -e "\nChecking for workspace configuration:"
if [ -f "package.json" ]; then
    jq '.workspaces' package.json
fi

Length of output: 399

nx.json (1)

13-14: LGTM! Configuration updates align with ESLint flat config migration.

The changes appropriately exclude the new ESLint flat config from production builds while including it in lint targets.

Also applies to: 30-31

package.json (2)

13-15: LGTM! Dependencies updated according to PR objectives.

Successfully removed common-tags, tsutils, and tsutils-etc while adding ts-api-utils as a replacement.


14-14: Verify ts-api-utils compatibility with the codebase.

Let's verify that the ts-api-utils version is compatible with our TypeScript version and check for any breaking changes.

✅ Verification successful

ts-api-utils v2.0.0 is compatible with the codebase

The upgrade is safe as our TypeScript version (5.6.3) exceeds the minimum requirement (4.8.4), and the current usage patterns in the codebase are not affected by any breaking changes.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check ts-api-utils compatibility with our TypeScript version
echo "Checking ts-api-utils compatibility..."
curl -s "https://registry.npmjs.org/ts-api-utils/2.0.0" | jq -r '.engines.typescript'

# Check for any breaking changes in the changelog
echo "Checking for breaking changes..."
curl -s "https://raw.githubusercontent.com/JoshuaKGoldberg/ts-api-utils/main/CHANGELOG.md" | head -n 20

Length of output: 1476


Script:

#!/bin/bash
# Check project's TypeScript version
echo "Project TypeScript version:"
cat package.json | jq -r '.dependencies.typescript, .devDependencies.typescript'

# Get ts-api-utils v2.0.0 release notes
echo -e "\nts-api-utils v2.0.0 release notes:"
curl -s "https://api.github.com/repos/JoshuaKGoldberg/ts-api-utils/releases/tags/v2.0.0"

# Find usage patterns
echo -e "\nChecking ts-api-utils usage patterns:"
rg "from ['|\"]ts-api-utils" -A 2

Length of output: 6546

packages/eslint-plugin-rxjs/project.json (2)

30-30: LGTM! Correctly configured to stop bundling third-party libraries.

Setting thirdParty to false aligns with the PR objective to no longer bundle third-party libraries.


6-16: LGTM! Release configuration properly structured.

The release configuration is well-structured with appropriate package root and version resolver settings.

packages/eslint-plugin-rxjs/src/lib/rules/throw-error.ts (1)

4-4: LGTM! Import updated to use local implementation.

Successfully migrated from tsutils-etc to local utility implementation.

✅ Verification successful

✅ Verified: All required utility functions exist in local implementation

The import statement correctly references the local implementations of couldBeFunction, couldBeType, isAny, and isUnknown functions, which are properly exported from the tsutils-etc directory.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify the local implementation exists and matches the required interface
echo "Checking local implementation..."
# Look for the utility functions in the local tsutils-etc file
ast-grep --pattern 'export function couldBeFunction'
ast-grep --pattern 'export function couldBeType'
ast-grep --pattern 'export function isAny'
ast-grep --pattern 'export function isUnknown'

Length of output: 274


Script:

#!/bin/bash
# First, find the tsutils-etc file
echo "Locating tsutils-etc file..."
fd tsutils-etc.ts

# If found, examine its contents
echo -e "\nChecking file contents..."
rg "export.*(?:couldBeFunction|couldBeType|isAny|isUnknown)" --type ts

Length of output: 703

packages/eslint-plugin-rxjs/src/lib/rules/no-cyclic-action.ts (1)

35-35: LGTM! Description formatting updated.

Successfully removed common-tags dependency by converting the description to a single-line string without changing the content.

Comment on lines 4 to 6
export function isIntersectionType(type: ts.Type): type is ts.UnionType {
return tsutils.isTypeFlagSet(type, ts.TypeFlags.Intersection);
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix incorrect type predicate return type.

The function checks for TypeFlags.Intersection but incorrectly declares the return type as type is ts.UnionType. This is a type safety issue.

Apply this fix:

-export function isIntersectionType(type: ts.Type): type is ts.UnionType {
+export function isIntersectionType(type: ts.Type): type is ts.IntersectionType {
   return tsutils.isTypeFlagSet(type, ts.TypeFlags.Intersection);
 }
📝 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. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export function isIntersectionType(type: ts.Type): type is ts.UnionType {
return tsutils.isTypeFlagSet(type, ts.TypeFlags.Intersection);
}
export function isIntersectionType(type: ts.Type): type is ts.IntersectionType {
return tsutils.isTypeFlagSet(type, ts.TypeFlags.Intersection);
}

Comment on lines 4 to 7
"dependencies": {
"@typescript-eslint/utils": "^8.19.0",
"@typescript-eslint/rule-tester": "^8.19.1",
"common-tags": "^1.8.2",
"decamelize": "^6.0.0",
"typescript": "~5.5.4",
"tsutils": "^3.21.0",
"tsutils-etc": "^1.4.2",
"@angular-eslint/test-utils": "19.0.2"
"@typescript-eslint/utils": "^8.21.0",
"ts-api-utils": "^2.0.0"
},
Copy link

@coderabbitai coderabbitai bot Jan 25, 2025

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider adding TypeScript as a peer dependency.

Since the plugin relies heavily on TypeScript functionality, it should specify TypeScript as a peer dependency.

   "dependencies": {
     "@typescript-eslint/utils": "^8.21.0",
     "ts-api-utils": "^2.0.0"
   },
+  "peerDependencies": {
+    "typescript": ">=4.7.0"
+  }
📝 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. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"dependencies": {
"@typescript-eslint/utils": "^8.19.0",
"@typescript-eslint/rule-tester": "^8.19.1",
"common-tags": "^1.8.2",
"decamelize": "^6.0.0",
"typescript": "~5.5.4",
"tsutils": "^3.21.0",
"tsutils-etc": "^1.4.2",
"@angular-eslint/test-utils": "19.0.2"
"@typescript-eslint/utils": "^8.21.0",
"ts-api-utils": "^2.0.0"
},
"dependencies": {
"@typescript-eslint/utils": "^8.21.0",
"ts-api-utils": "^2.0.0"
},
"peerDependencies": {
"typescript": ">=4.7.0"
}

Copy link
Owner Author

Choose a reason for hiding this comment

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

There are reasons to leave this out as not every rule requires typescript

Copy link

Choose a reason for hiding this comment

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

@DaveMBush I see your point. After analyzing the codebase, indeed most rules (about 90%) don't directly depend on TypeScript functionality. They appear to be pure ESLint rules that work with JavaScript syntax. I apologize for the incorrect suggestion.

🔗 Analysis chain
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Find all rule files
echo "=== Rule files ==="
fd "\.ts$" "packages/eslint-plugin-rxjs/src/lib/rules"

# Check TypeScript imports in rule files
echo -e "\n=== Files importing TypeScript (ts) ==="
rg "import.*ts['\"]" "packages/eslint-plugin-rxjs/src/lib/rules"

# Check files not using TypeScript
echo -e "\n=== Files not importing TypeScript ==="
fd "\.ts$" "packages/eslint-plugin-rxjs/src/lib/rules" --exec sh -c 'if ! grep -q "import.*ts" "$1"; then echo "$1"; fi' sh {}

Length of output: 5474


✏️ Learnings added
Learnt from: DaveMBush
PR: DaveMBush/eslint-plugin-rxjs#69
File: packages/eslint-plugin-rxjs/package.json:4-7
Timestamp: 2025-01-25T19:46:28.370Z
Learning: In eslint-plugin-rxjs, TypeScript should not be added as a peer dependency since most rules don't require TypeScript functionality. Only specific rules like no-unsafe-switchmap, no-unsafe-first, no-unsafe-catch, and no-cyclic-action use TypeScript features.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

@DaveMBush DaveMBush merged commit 0437d2b into main Jan 25, 2025
3 checks passed
@DaveMBush DaveMBush deleted the dmb/package-optimizations/66 branch January 25, 2025 19:57
@coderabbitai coderabbitai bot mentioned this pull request Jan 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

This plugin is bundling all of its dependencies unnecessarily, meaning they are included twice
1 participant