eslint-plugin-panda icon indicating copy to clipboard operation
eslint-plugin-panda copied to clipboard

perf(worker): avoid accessing panda context to scan all files

Open farlock opened this issue 1 week ago • 0 comments

What kind of change does this PR introduce?

Fixes https://github.com/chakra-ui/eslint-plugin-panda/issues/160

The getFiles() method is part of PandaContext It scans the entire project and returns all files matching the Panda CSS include/exclude patterns. This is slow on large projects (Complexity O(N)).

Code Changes:

  • Modified plugin/src/utils/worker.ts to use Generator instead of PandaContext:
    • Before: loadConfigAndCreateContext() → Creates full PandaContext
    • After: loadConfig() + new Generator() → Creates minimal context

isValidFile needed to be adapted. It now:

  • Gets the include and exclude patterns from config ( e.g. ['src/**/*.{ts,tsx}'])
  • Convert the file path to be relative to the config directory
  • Use micromatch to check if the path matches the patterns directly (Complexity O(1))

Performance Impact

Tested on a large scale repository with TIMING=1 npx eslint --fix someFile

Before

Rule                                    | Time (ms) | Relative
:---------------------------------------|----------:|--------:
@pandacss/file-not-included             | 12138.285 |    98.9%

After

Rule                                    | Time (ms) | Relative
:---------------------------------------|----------:|--------:
@pandacss/file-not-included             |  1154.767 |    90.9%

-> perf gain is ~10x

Breaking Changes

no isValidFile should have the same behaviour

How can this change be tested

Unfortunately the tests are failing because isValidFile with micromatch isn't working correctly with the new Generator. -> TBD

farlock avatar Nov 25 '25 13:11 farlock