Skip to content

refactor: improve type safety with proper type guards and add ESLint#6

Merged
eli0shin merged 2 commits intomainfrom
eslint-for-ai
Dec 26, 2025
Merged

refactor: improve type safety with proper type guards and add ESLint#6
eli0shin merged 2 commits intomainfrom
eslint-for-ai

Conversation

@eli0shin
Copy link
Owner

Summary

  • Add ESLint configuration with eslint-for-ai for improved code quality
  • Replace type assertions with proper type guard functions for better type safety
  • Refactor internal query compilation logic for cleaner separation of concerns

Changes

ESLint Configuration:

  • Added eslint-for-ai package with recommended rules for AI-assisted development
  • Configured ESLint to use TypeScript parser and resolver
  • Added lint and lint:fix scripts to package.json

Type Safety Improvements:

  • Introduced type guard functions: isBaseQuery(), isQueryValue(), and isOperator()
  • Replaced type assertions with type guards throughout the codebase
  • Changed queryBuilder return type from any to unknown for better type safety

Code Refactoring:

  • Extracted internal query compilation logic to compileQueryInternal() helper function
  • Updated compileDatadogQuery() to use the new internal helper
  • Added ESLint disable comment for the wrapper pattern with explanation
  • Improved test types using satisfies instead of explicit type annotations

Test plan

  • All existing tests pass
  • Type checking passes
  • ESLint runs without errors on the codebase

🤖 Generated with Claude Code

- Add eslint-for-ai configuration with recommended rules
- Replace type assertions with proper type guard functions (isBaseQuery, isQueryValue)
- Refactor compileDatadogQuery to use internal helper for cleaner separation
- Fix return type from 'any' to 'unknown' in queryBuilder
- Update test types to use 'satisfies' instead of explicit annotations
- Add lint and lint:fix npm scripts

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@changeset-bot
Copy link

changeset-bot bot commented Dec 26, 2025

🦋 Changeset detected

Latest commit: fbd411c

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

This PR includes changesets to release 1 package
Name Type
barkql 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

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@eli0shin eli0shin marked this pull request as ready for review December 26, 2025 04:15
Copilot AI review requested due to automatic review settings December 26, 2025 04:15
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR improves type safety by replacing type assertions with proper type guard functions and adds ESLint configuration for better code quality enforcement in AI-assisted development.

Key changes:

  • Introduced type guard functions (isBaseQuery(), isQueryValue(), isOperator()) to replace unsafe type assertions
  • Extracted query compilation logic into compileQueryInternal() helper for better separation of concerns
  • Changed queryBuilder return type from any to unknown for stricter type checking

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/index.ts Core refactoring with type guards replacing type assertions, new internal compilation function, and improved type safety with unknown return type
src/index.test-d.ts Updated type tests to use satisfies operator instead of explicit type annotations for better type inference
package.json Added ESLint packages and configuration, including eslint-for-ai, TypeScript parser, and resolver
eslint.config.js New ESLint configuration file using eslint-for-ai recommended rules
bun.lock Lock file updates for new ESLint-related dependencies
.changeset/smooth-lions-dance.md Changeset documenting the patch-level changes

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@eli0shin eli0shin merged commit 2850afe into main Dec 26, 2025
8 checks passed
@github-actions github-actions bot mentioned this pull request Dec 26, 2025
eli0shin pushed a commit that referenced this pull request Dec 26, 2025
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## barkql@0.1.2

### Patch Changes

- [#6](#6)
[`2850afe`](2850afe)
Thanks [@eli0shin](https://github.com/eli0shin)! - Refactor to use type
guards instead of type assertions for improved type safety, and add
ESLint configuration with TypeScript resolver support.

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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