-
Notifications
You must be signed in to change notification settings - Fork 4
Implement ESLint rules based on TypeScript/JavaScript patterns analysis with test exceptions and update Copilot instructions #290
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
base: main
Are you sure you want to change the base?
Conversation
|
@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? |
|
@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>
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
I've excluded |
.github/copilot-instructions.md
Outdated
| - Use structured error handling with custom error types when needed | ||
|
|
||
| **Immutable Data Patterns**: | ||
| - Use `as const satisfies Record<string, z.ZodType>` for Zod schemas |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot remove this.
| - Use `as const satisfies Record<string, z.ZodType>` for Zod schemas |
There was a problem hiding this comment.
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>
.github/copilot-instructions.md
Outdated
| **Function Style**: | ||
| - Prefer `export function` over `export const fn =` | ||
| - Use async/await consistently for asynchronous operations | ||
| - Prefer arrow functions for callbacks and inline functions |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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>
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
Current ESLint Configuration
The project now uses ESLint 9 with flat config format and includes:
@eslint/jsrecommended rulestypescript-eslintrecommended type-checked ruleseslint-config-prettierfor Prettier integration@typescript-eslint/no-floating-promiseswith Node.js test function exceptionsprefer-arrow-callbackruleImplementation Summary
Updated Copilot Instructions with key code style patterns:
typeoverinterface)as constassertions)Added ESLint Rules (18 total):
import/order,n/prefer-node-protocol,consistent-type-importsconsistent-type-definitions,prefer-as-constprefer-readonly(excludedprefer-readonly-parameter-typesper feedback)prefer-promise-reject-errors,only-throw-errorpromise-function-async,require-await,prefer-arrow-callback(disabled for test files)no-console(warn level, allows error/warn)no-unused-vars(with underscore prefix ignoring),unused-imports/no-unused-importsstrict-boolean-expressions(warn),no-unnecessary-condition(warn),prefer-nullish-coalescing,prefer-optional-chainTest File Handling:
**/*.test.tsand**/*.spec.tsfilesprefer-arrow-callbackrule for test files to allow regular functions indescribe()andit()callbacksConfiguration 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
💡 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.