Skip to content

feat: add enforceType option to control type annotation auto-fix behavior#445

Merged
Newbie012 merged 2 commits intomainfrom
feat-enforce-type
Jan 26, 2026
Merged

feat: add enforceType option to control type annotation auto-fix behavior#445
Newbie012 merged 2 commits intomainfrom
feat-enforce-type

Conversation

@Newbie012
Copy link
Collaborator

@Newbie012 Newbie012 commented Jan 26, 2026

Summary by CodeRabbit

  • New Features
    • Added enforceType option to the ESLint plugin (default: "fix"; supports "fix" or "suggest") to control whether type-annotation issues are auto-fixed or offered as IDE suggestions. Rule now exposes suggestion behavior when configured to "suggest".

✏️ Tip: You can customize this high-level summary in your review settings.

@changeset-bot
Copy link

changeset-bot bot commented Jan 26, 2026

🦋 Changeset detected

Latest commit: 44022ab

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 17 packages
Name Type
@ts-safeql/eslint-plugin Minor
@ts-safeql-demos/basic-flat-config Patch
@ts-safeql-demos/basic-migrations-raw Patch
@ts-safeql-demos/basic-transform-type Patch
@ts-safeql-demos/basic Patch
@ts-safeql-demos/big-project Patch
@ts-safeql-demos/config-file-flat-config Patch
@ts-safeql-demos/from-config-file Patch
@ts-safeql-demos/multi-connections Patch
@ts-safeql-demos/playground Patch
@ts-safeql-demos/postgresjs-custom-types Patch
@ts-safeql-demos/postgresjs-demo Patch
@ts-safeql-demos/vercel-postgres Patch
@ts-safeql/generate Minor
@ts-safeql/shared Minor
@ts-safeql/sql-ast Minor
@ts-safeql/test-utils Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link

vercel bot commented Jan 26, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Review Updated (UTC)
safeql Ignored Ignored Preview Jan 26, 2026 7:13pm

@coderabbitai
Copy link

coderabbitai bot commented Jan 26, 2026

📝 Walkthrough

Walkthrough

Adds a new enforceType configuration option to @ts-safeql/eslint-plugin (default "fix", values "fix" | "suggest") and threads it through the rule and reporting utilities so type-annotation issues are either auto-fixed or offered as suggestions.

Changes

Cohort / File(s) Summary
Configuration & Schema
packages/eslint-plugin/src/rules/RuleOptions.ts
Added optional enforceType enum ("fix"
Changeset Documentation
.changeset/fair-steaks-poke.md
Documented new enforceType option, default value, and accepted values.
Rule Implementation
packages/eslint-plugin/src/rules/check-sql.rule.ts
Propagated connection.enforceType into reporting calls for missing/incorrect annotations; added hasSuggestions: true to rule metadata.
Reporting Utilities
packages/eslint-plugin/src/rules/check-sql.utils.ts
Extended reportMissingTypeAnnotations and reportIncorrectTypeAnnotations signatures to accept enforceType; conditionally attach fixes or suggestions based on value.
Test Coverage
packages/eslint-plugin/src/rules/check-sql.test.ts
Added tests covering enforceType behavior for both "fix" and "suggest" modes (valid and invalid cases).

Sequence Diagram

sequenceDiagram
    participant User
    participant Rule as check-sql.rule
    participant Utils as check-sql.utils
    participant ESLint

    User->>Rule: Run lint with enforceType config
    Rule->>Rule: Detect missing/incorrect type annotation
    Rule->>Utils: reportMissingTypeAnnotations(..., enforceType)
    alt enforceType == "fix"
        Utils->>Utils: build fixFn
        Utils->>ESLint: report(..., fix: fixFn)
        ESLint->>User: Apply auto-fix
    else enforceType == "suggest"
        Utils->>Utils: build fixFn
        Utils->>ESLint: report(..., suggestions: [{desc, fix: fixFn}])
        ESLint->>User: Show suggestion (manual accept)
    end
Loading

Estimated Code Review Effort

🎯 3 (Moderate) | ⏱️ ~23 minutes

Poem

🐰 I nibbled at types both wrong and right,
A toggle now toggles fix or light,
"fix" will patch while "suggest" will say,
Choose how your code blooms today. ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and specifically describes the main change: adding an enforceType option to control whether type annotation issues are auto-fixed or suggested.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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

Comment @coderabbitai help to get the list of available commands and usage tips.

@greptile-apps
Copy link

greptile-apps bot commented Jan 26, 2026

Greptile Overview

Greptile Summary

This PR adds a new enforceType configuration option to control whether type annotation issues are auto-fixed or provided as suggestions. The implementation allows users to set enforceType: "suggest" to require manual acceptance of type fixes in their IDE, or enforceType: "fix" (default) for automatic fixes with --fix.

Key Changes

  • Added enforceType enum option to rule configuration schema (RuleOptions.ts)
  • Updated ESLint rule meta to include hasSuggestions: true (check-sql.rule.ts)
  • Modified reportMissingTypeAnnotations and reportIncorrectTypeAnnotations to conditionally use fix or suggest based on the option (check-sql.utils.ts)
  • Added comprehensive test coverage for both fix and suggest modes (check-sql.test.ts)
  • Documented the new feature in changeset

Issue Found

  • Type signature inconsistency in reportMissingTypeAnnotations where enforceType parameter is marked as required instead of optional, which could cause TypeScript errors when connection.enforceType is undefined

Confidence Score: 4/5

  • This PR is safe to merge with minimal risk after fixing the type signature issue
  • The implementation is well-structured with comprehensive tests and proper documentation. The only issue is a type signature inconsistency that should be fixed to ensure TypeScript compatibility. The feature itself is non-breaking since it defaults to the current behavior (fix).
  • Pay close attention to packages/eslint-plugin/src/rules/check-sql.utils.ts where the enforceType parameter signature needs to be made optional

Important Files Changed

Filename Overview
packages/eslint-plugin/src/rules/RuleOptions.ts Added new enforceType option to zod schema with proper documentation and type export
packages/eslint-plugin/src/rules/check-sql.rule.ts Added hasSuggestions: true to meta and passed enforceType to reporting functions in two locations
packages/eslint-plugin/src/rules/check-sql.utils.ts Updated report functions to support suggest mode - found type signature inconsistency where enforceType should be optional

Sequence Diagram

sequenceDiagram
    participant User as Developer
    participant ESLint as ESLint Engine
    participant Rule as check-sql Rule
    participant Utils as Report Utils
    participant Editor as IDE/CLI

    User->>ESLint: Run eslint with/without --fix
    ESLint->>Rule: Execute check-sql rule
    Rule->>Rule: Check SQL query type annotations
    
    alt Missing or Incorrect Type Annotation
        Rule->>Rule: Get connection.enforceType option
        
        alt enforceType === "suggest"
            Rule->>Utils: reportMissingTypeAnnotations()<br/>or reportIncorrectTypeAnnotations()<br/>with enforceType: "suggest"
            Utils->>ESLint: Return error with suggestions array
            ESLint->>Editor: Show error with suggestions<br/>(requires manual acceptance)
            Editor->>User: Display suggestion in IDE
        else enforceType === "fix" (default)
            Rule->>Utils: reportMissingTypeAnnotations()<br/>or reportIncorrectTypeAnnotations()<br/>with enforceType: "fix"
            Utils->>ESLint: Return error with fix function
            ESLint->>Editor: Auto-fix when --fix flag present
            Editor->>User: Applied fix automatically
        end
    else Type Annotation Valid
        Rule->>ESLint: No error reported
        ESLint->>User: Validation passed
    end
Loading

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

1 file reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

tag: TSESTree.TaggedTemplateExpression;
baseNode: TSESTree.BaseNode;
actual: string;
enforceType?: EnforceTypeOption;
Copy link

Choose a reason for hiding this comment

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

parameter should be optional (add ?) to match reportIncorrectTypeAnnotations signature and allow undefined to be passed from connection.enforceType

Suggested change
enforceType?: EnforceTypeOption;
enforceType?: EnforceTypeOption;
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/eslint-plugin/src/rules/check-sql.utils.ts
Line: 193:193

Comment:
parameter should be optional (add `?`) to match `reportIncorrectTypeAnnotations` signature and allow `undefined` to be passed from `connection.enforceType`

```suggestion
  enforceType?: EnforceTypeOption;
```

How can I resolve this? If you propose a fix, please make it concise.

@Newbie012 Newbie012 merged commit 604ed87 into main Jan 26, 2026
5 checks passed
@Newbie012 Newbie012 deleted the feat-enforce-type branch January 26, 2026 19:20
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.

1 participant