Skip to content

feat: support ESLint Flat Configs #55

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

Merged
merged 44 commits into from
Apr 11, 2025
Merged
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
95fc2a7
feat: support ESLint v9 and Flat Configs
arthurgeron Dec 15, 2024
fe0ec84
fix: husky false fail on pre-commit
arthurgeron Dec 15, 2024
9745414
feat: export on both cjs and esm
arthurgeron Dec 15, 2024
282f522
chore: increase minor version
arthurgeron Dec 15, 2024
05e4954
feat: introduce ESLint V9 flat config support and update tests
arthurgeron Mar 13, 2025
8a90450
feat: add ESLint v9 test configurations and shared test cases
arthurgeron Mar 13, 2025
a0207e3
docs: update README for ESLint v8 and v9 compatibility
arthurgeron Mar 13, 2025
9a041ff
chore: remove unused config
arthurgeron Mar 13, 2025
ac15b54
docs: add ESLint v9 migration guide
arthurgeron Mar 13, 2025
e5e4503
chore: remove default export from ESLint flat config
arthurgeron Mar 13, 2025
f3e410c
feat: replace tsprune with knip
arthurgeron Mar 13, 2025
58adeb5
feat: add flat and traditional ESLint config support
arthurgeron Mar 13, 2025
4716871
fix: import path
arthurgeron Mar 13, 2025
c8ec4cb
revert: beta package version
arthurgeron Mar 13, 2025
d6b6734
chore: update pull_request_template.md
arthurgeron Mar 13, 2025
0287720
feat: set asdf tools versions
arthurgeron Mar 31, 2025
a84ba29
fix: eslint v9 tests not working
arthurgeron Mar 31, 2025
9fa4ec0
feat: enhance ESLint rule testing framework
arthurgeron Mar 31, 2025
fad34a0
feat: also run eslint v9 tests by default
arthurgeron Mar 31, 2025
3be1065
fix: rule tester export
arthurgeron Mar 31, 2025
8e88056
fix: calling removed getScope on ESLint v9
arthurgeron Mar 31, 2025
3dfafc4
feat: add example projects for ESLint plugin usage
arthurgeron Mar 31, 2025
70123e7
feat: simplify test into extracted test cases and two runners v8 and v9
arthurgeron Mar 31, 2025
5b312ea
feat: eslint v9 migration guide
arthurgeron Mar 31, 2025
4f54a0a
feat: update ESLint plugin for v9 compatibility
arthurgeron Mar 31, 2025
6cceb2a
fix: false positive for dead code for test cases
arthurgeron Mar 31, 2025
4ea99b1
fix: type error
arthurgeron Mar 31, 2025
1c815bc
chore: organize test descriptions
arthurgeron Mar 31, 2025
1ce0ebb
fix: remove duplicate tests
arthurgeron Mar 31, 2025
5599a76
feat: add code style, ESLint, project general, and testing AI guideli…
arthurgeron Mar 31, 2025
c8f7767
chore: update AI guidelines
arthurgeron Mar 31, 2025
48c4b9d
fix: Jest config and ESLint test cases
arthurgeron Mar 31, 2025
6f580d6
fix: examples
arthurgeron Apr 1, 2025
778f05b
feat: check examples for eslint errors
arthurgeron Apr 1, 2025
693efc1
chore: use Node.js and Yarn versions set in .tool-versions
arthurgeron Apr 1, 2025
8638968
chore: ignore tests during builds
arthurgeron Apr 1, 2025
65d1218
chore: remove old directory
arthurgeron Apr 1, 2025
c02acbb
fix: case sensitive issues with testcases dir
arthurgeron Apr 1, 2025
b17cac8
fix: knip thinking lint binary is missing
arthurgeron Apr 1, 2025
e8b10d1
chore: re-enable tests
arthurgeron Apr 2, 2025
de61aaa
feat: add performance and eslint data to cursor rules
arthurgeron Apr 2, 2025
d79d091
chore: remove unecessary comments
arthurgeron Apr 2, 2025
27cb5bd
refactor: add custom rule options to ESLint example configurations
arthurgeron Apr 2, 2025
beee70c
chore: reword comment
arthurgeron Apr 2, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .cursor/rules/code-style.mdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
description:
globs: src/**/*,*.tsx,*.ts,*.js
alwaysApply: false
---

# Code Style Guidelines

## TypeScript

The project uses TypeScript.

## React Best Practices

Follow React best practices for component design, state management, and performance optimization.

## Memoization

Use `useMemo`, `useCallback`, and `React.memo` appropriately to optimize performance.

## Error Handling

Implement robust error handling and validation.

## Performance Considerations

- Avoid RegExp where simple string operations suffice
- Consider the real-time nature of ESLint plugins in IDEs
- Optimize for frequent calls and minimal overhead
- Profile critical paths before making optimizations
- Prefer simple, direct implementations over complex ones
- Be especially careful with operations that run on every file parse
61 changes: 61 additions & 0 deletions .cursor/rules/eslint.mdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
---
description:
globs:
alwaysApply: true
---

# ESLint Guidelines

## What is ESLint?

ESLint is a static code analysis tool for identifying problematic patterns found in ECMAScript/JavaScript code.

## Purpose

To enforce code style, catch potential errors, and improve code quality.

## Configuration

This project supports both ESLint v8 (traditional configuration using `.eslintrc.json`) and ESLint v9 (flat configuration using `eslint.config.js`).

## Plugin

This project provides an ESLint plugin named `@arthurgeron/eslint-plugin-react-usememo`.

## Rules

The plugin includes the following rules:

- `require-usememo`: Requires complex values passed as props or used as hook dependencies to be wrapped in `useMemo` or `useCallback`.
- `require-memo`: Requires all function components to be wrapped in `React.memo()`.
- `require-usememo-children`: Requires complex values passed as children to be wrapped in `useMemo` or `useCallback`.

## Compatibility

The plugin is designed to be compatible with both ESLint v8 and v9, using utility functions in `src/utils/compatibility.ts` to handle differences between the versions.


## Documentation

For more details on individual rules and migration guides, refer to the documentation files in the `docs/rules` directory:

- [require-memo](mdc:../docs/rules/require-memo.md)
- [require-usememo](mdc:../docs/rules/require-usememo.md)
- [require-usememo-children](mdc:../docs/rules/require-usememo-children.md)
- [Migrating to V9.x](mdc:https:/eslint.org/docs/latest/use/migrate-to-9.0.0)
- [ESLint v9 Migration Guide](mdc:../docs/rules/eslint-v9-migration-guide.md)
- [Creating ESLint V9 Plugins](mdc:https:/eslint.org/docs/latest/extend/plugins)
- [Sharing ESLint V9 Configurations](mdc:https:/eslint.org/docs/latest/extend/shareable-configs)
- [Custom ESLint V9 Processors](mdc:https:/eslint.org/docs/latest/extend/custom-processors)
- [Custom ESLint V9 Parsers](mdc:https:/eslint.org/docs/latest/extend/custom-parsers)
- [Custom ESLint V9 Formatters](mdc:https:/eslint.org/docs/latest/extend/custom-formatters)
- [Custom ESLint V9 Rules](mdc:https:/eslint.org/docs/latest/extend/custom-rules)
- [Custom ESLint V9 Rule Tutorial](mdc:https:/eslint.org/docs/latest/extend/custom-rule-tutorial)

## ESLint Plugin Development

- Remember rules run frequently in IDE environments
- Optimize core operations that run on every node visit
- Cache results where possible
- Use simple type checks and string operations over complex regex
- Consider the impact on IDE performance
37 changes: 37 additions & 0 deletions .cursor/rules/project-general.mdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
description:
globs: package.json,README.md,src/**/*
alwaysApply: false
---
# Project General Guidelines

## Project Objective

The primary goal of this project is to provide an ESLint plugin that helps developers optimize React applications by enforcing the use of `useMemo`, `useCallback`, and `React.memo` to prevent unnecessary re-renders and improve performance.

## General Structure

- `src/`: Contains the source code for the ESLint plugin, including the rule implementations and utility functions.
- `docs/`: Contains documentation for the plugin and its rules.
- `examples/`: Contains example React projects demonstrating the use of the plugin with different ESLint configurations.
- `__tests__/`: Contains test cases for the plugin rules.
- `src/utils/compatibility.ts`: Provides compatibility utilities for ESLint v8 and v9.

## Key Dependencies

- `yarn`: Package manager
- `eslint`: The core ESLint library. Both V8 and V9 (eslint-v9).
- `react`: The React library (used in examples and tests).

## ESLint Version Support

The project is designed to work with both ESLint v8 and v9. The `src/utils/compatibility.ts` file provides utilities to handle differences between the two versions.

## Configuration Files

- ESLint v8: `.eslintrc.json`
- ESLint v9: `eslint.config.js`

## Documentation

For more details on project setup and overall guidelines, please refer to [README.md](mdc:../../README.md) and the documentation in the `docs/` directory.
72 changes: 72 additions & 0 deletions .cursor/rules/testing.mdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
---
description: Testing Guidelines for AI Agents
globs:
- "__tests__/**/*"
- "test-plugin.js"
alwaysApply: false
---

# Testing Guidelines

## Testing Approach

The project uses Jest for testing.

## Test Case Structure

Test cases are located in the `__tests__` directory and are separated into `validTestCases` and `invalidTestCases` to cover both passing and failing scenarios.

## Version Compatibility Testing

The same test cases are executed against both ESLint v8 and ESLint v9 to ensure compatibility. This is achieved by extracting shared test cases into the `__tests__/testcases` directory and utilizing the appropriate ESLint runner in:
- `__tests__/eslint-v8/rules.test.ts` for ESLint v8
- `__tests__/eslint-v9/rules.test.ts` for ESLint v9

## Test Execution

Tests are executed using the command `yarn test`.

## Test Case Utility

The test cases are generated by a set of utility functions located in the `__tests__/testcases` directory:
- `createRequireMemoTestCases` from `__tests__/testcases/requireMemo.ts`
- `createRequireUseCallbackTestCases` from `__tests__/testcases/requireUseCallback.ts`
- `createRequireUseMemoTestCases` from `__tests__/testcases/requireUseMemo.ts`
- `createRequireUseMemoChildrenTestCases` from `__tests__/testcases/requireUseMemoChildren.ts`

## Example Test Execution

```bash
yarn test
```

**4. `.cursor/rules/code-style.mdc`**

```markdown
---
description: Code Style Guidelines for AI Agents
globs:
- "src/**/*"
alwaysApply: false
---

# Code Style Guidelines

## TypeScript

The project uses TypeScript.

## React Best Practices

Follow React best practices for component design, state management, and performance optimization.

## Memoization

Use `useMemo`, `useCallback`, and `React.memo` appropriately to optimize performance.

## Error Handling

Implement robust error handling and validation.
```

These files are now ready to be placed in the `.cursor/rules` directory of your project.
19 changes: 12 additions & 7 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
<!--
# Pull Request Template

-->
## Description
<!-- Please provide a clear and concise description of the changes and the purpose they serve. -->
<!-- Please provide a clear and concise description of the changes and their intended purpose. -->

## Checklist
<!--Before submitting your pull request, please confirm the following: -->
<!-- Before submitting your pull request, please confirm the following: -->


- [ ] **Tests**: I have created multiple test case scenarios for my changes.
- [ ] **Passing Tests**: All existing and new tests are passing.
- [ ] **Version Bump**: I have increased the package version number in `package.json` following the [Semantic Versioning](https://semver.org/) (SEMVER) standard.
- [ ] **Tests**: I have created multiple test scenarios for my changes.
- [ ] **Passing Tests**: All existing and new tests are pass successfully.
- [ ] **Version Bump**: I have increased the package version number in package.json, following the [Semantic Versioning](https://semver.org/) (SEMVER) standard.
- [ ] **Version Bump**: I have increased the package version number in src/flat-config.ts and src/traditional-config.ts, following the [Semantic Versioning](https://semver.org/) (SEMVER) standard.
- [ ] **Documentation**: I have updated documentation to reflect the changes made, if necessary.
- [ ] **Focused Changes**: My code changes are focused solely on the matter described above.

## Additional Information
<!-- If applicable, please provide any additional information or context for your changes. -->
<!-- Include any additional information or context about your changes here. -->

Loading