Skip to content

Conversation

Copy link

Copilot AI commented Oct 25, 2025

Analysis: TypeScript/JavaScript Code Patterns for ESLint Rules

This analysis examines the React Native Node-API codebase to identify consistent patterns that should be codified in ESLint rules.

Progress Checklist

  • Explore repository structure and current ESLint configuration
  • Analyze TypeScript/JavaScript files across all packages
  • Identify consistent code patterns and conventions
  • Document findings for ESLint rule recommendations
  • Present proposed ESLint rules to user for approval
  • Update Copilot instructions with code style findings
  • Implement approved ESLint rules (excluding prefer-readonly-parameter-types)
  • Address feedback on Copilot instructions content
  • Add test file exception for arrow function rule
  • Fix violations found by new rules (waiting as requested)
  • Verify build and tests still pass after fixes

Current ESLint Configuration

The project now uses ESLint 9 with flat config format and includes:

  • @eslint/js recommended rules
  • typescript-eslint recommended type-checked rules
  • eslint-config-prettier for Prettier integration
  • Custom rule for @typescript-eslint/no-floating-promises with Node.js test function exceptions
  • NEW: 18 additional rules based on identified patterns
  • NEW: Test file exception for prefer-arrow-callback rule

Implementation Summary

Updated Copilot Instructions with key code style patterns:

  • Import organization (Node.js protocol, grouping)
  • Type definition preferences (type over interface)
  • Immutable data patterns (as const assertions)
  • Function style conventions (with test exception noted)
  • Error handling preferences

Added ESLint Rules (18 total):

  • Import Organization: import/order, n/prefer-node-protocol, consistent-type-imports
  • Type Consistency: consistent-type-definitions, prefer-as-const
  • Immutable Patterns: prefer-readonly (excluded prefer-readonly-parameter-types per feedback)
  • Error Standards: prefer-promise-reject-errors, only-throw-error
  • Function Style: promise-function-async, require-await, prefer-arrow-callback (disabled for test files)
  • Console Control: no-console (warn level, allows error/warn)
  • Unused Code: no-unused-vars (with underscore prefix ignoring), unused-imports/no-unused-imports
  • Strict Typing: strict-boolean-expressions (warn), no-unnecessary-condition (warn), prefer-nullish-coalescing, prefer-optional-chain

Test File Handling:

  • Added specific configuration for **/*.test.ts and **/*.spec.ts files
  • Disabled prefer-arrow-callback rule for test files to allow regular functions in describe() and it() callbacks
  • Updated Copilot instructions to document this exception

Configuration is validated and working. Test files correctly exempt from arrow function rule while maintaining enforcement for regular source files. Found 864 violations across codebase as expected - ready for systematic fixing when approved.

Original prompt

I want you to analyse the Typescript and JavaScript parts of the codebase to find patterns that is used but not yet codified in the eslint rules. I want you to first present the rules you want to enable and once I give the go-ahead I want you to enable the rules we agree on and fix any outstanding violations.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI self-assigned this Oct 25, 2025
Copilot AI changed the title [WIP] Analyze patterns in Typescript and JavaScript codebase Analyze TypeScript/JavaScript patterns for ESLint rule codification Oct 25, 2025
Copilot AI requested a review from kraenhansen October 25, 2025 13:00
Copilot finished work on behalf of kraenhansen October 25, 2025 13:00
@kraenhansen
Copy link
Collaborator

kraenhansen commented Oct 25, 2025

@copilot I'm a bit concerned that prefer-readonly-parameter-types would raise too many issues. In general I agree I'm using functional programming a lot, but I don't think I'm actually enforcing this with types at the moment. Also, I like your key findings. Can you start by amending the Copilot instructions to capture these?

@kraenhansen
Copy link
Collaborator

@copilot go ahead and make the changes to the eslint config. I want you to wait with fixing the issues.

…Copilot instructions

Co-authored-by: kraenhansen <1243959+kraenhansen@users.noreply.github.com>
Copy link
Author

Copilot AI commented Oct 26, 2025

@copilot go ahead and make the changes to the eslint config. I want you to wait with fixing the issues.

ESLint configuration updated with 18 new rules based on the analyzed patterns. The configuration is validated and working - found 901 violations as expected. Ready for systematic fixing when you give the go-ahead. Commit bff493c

@copilot I'm a bit concerned that prefer-readonly-parameter-types would raise too many issues. In general I agree I'm using functional programming a lot, but I don't think I'm actually enforcing this ...

I've excluded prefer-readonly-parameter-types from the implementation and updated the Copilot instructions to capture the key code style findings including import organization, type preferences, immutable data patterns, function conventions, and error handling approaches. Commit bff493c

Copilot AI changed the title Analyze TypeScript/JavaScript patterns for ESLint rule codification Implement ESLint rules based on TypeScript/JavaScript patterns analysis and update Copilot instructions Oct 26, 2025
Copilot finished work on behalf of kraenhansen October 26, 2025 22:06
- Use structured error handling with custom error types when needed

**Immutable Data Patterns**:
- Use `as const satisfies Record<string, z.ZodType>` for Zod schemas
Copy link
Collaborator

Choose a reason for hiding this comment

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

@copilot remove this.

Suggested change
- Use `as const satisfies Record<string, z.ZodType>` for Zod schemas

Copy link
Author

Choose a reason for hiding this comment

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

Removed the readonly data structures line from the Copilot instructions. Commit b7cb726

…edback

Co-authored-by: kraenhansen <1243959+kraenhansen@users.noreply.github.com>
Copilot AI requested a review from kraenhansen October 26, 2025 22:19
Copilot finished work on behalf of kraenhansen October 26, 2025 22:19
**Function Style**:
- Prefer `export function` over `export const fn =`
- Use async/await consistently for asynchronous operations
- Prefer arrow functions for callbacks and inline functions
Copy link
Collaborator

Choose a reason for hiding this comment

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

@copilot an exception to this rule is in tests where the callback passed to describe and it are functions. Please update the instruction and eslint rule to reflect that (limiting the rule to hit only non *.test.ts files would be okay).

Copy link
Author

Choose a reason for hiding this comment

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

Added exception for test files to the prefer-arrow-callback rule and updated Copilot instructions to document that describe and it functions use regular functions in tests. The rule now excludes **/*.test.ts and **/*.spec.ts files. Commit c13a5d1

…ilot instructions

Co-authored-by: kraenhansen <1243959+kraenhansen@users.noreply.github.com>
Copilot AI changed the title Implement ESLint rules based on TypeScript/JavaScript patterns analysis and update Copilot instructions Implement ESLint rules based on TypeScript/JavaScript patterns analysis with test exceptions and update Copilot instructions Oct 26, 2025
Copilot AI requested a review from kraenhansen October 26, 2025 22:29
Copilot finished work on behalf of kraenhansen October 26, 2025 22:29
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