Skip to content

Commit 2d89d22

Browse files
committed
Improve performance
1 parent 2844a94 commit 2d89d22

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

src/oxlint.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,15 @@ import { appPage, component, componentInterface } from './rules'
2727
/**
2828
* Wrap a rule to handle unsupported context properties in oxlint
2929
* (e.g., context.parserPath throws in oxlint)
30+
* Uses Object.create for O(1) property lookup instead of Proxy trap on every access.
3031
*/
3132
function wrapRuleForOxlint(rule: Rule.RuleModule): Rule.RuleModule {
3233
return {
3334
...rule,
3435
create(context) {
35-
const proxiedContext = new Proxy(context, {
36-
get(target, prop) {
37-
// Return undefined for unsupported properties instead of throwing
38-
if (prop === 'parserPath') {
39-
return undefined
40-
}
41-
// Pass through all other properties directly to preserve Proxy invariants
42-
// (non-configurable properties must return their actual value)
43-
return target[prop as keyof typeof target]
44-
},
45-
})
46-
return rule.create(proxiedContext)
36+
const wrapped = Object.create(context) as typeof context
37+
Object.defineProperty(wrapped, 'parserPath', { value: undefined })
38+
return rule.create(wrapped)
4739
},
4840
}
4941
}

src/rules/component/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import { ESLintUtils, TSESTree } from '@typescript-eslint/utils'
22
import { relative } from 'path'
33

4+
const KEBAB_SNAKE_PATTERN = /[-_](.)/g
5+
const FIRST_LOWER_PATTERN = /^[a-z]/
6+
47
function toPascal(str: string) {
58
return str
6-
.replace(/[-_](.)/g, (_, c: string) => c.toUpperCase())
7-
.replace(/^[a-z]/, (c) => c.toUpperCase())
9+
.replace(KEBAB_SNAKE_PATTERN, (_, c: string) => c.toUpperCase())
10+
.replace(FIRST_LOWER_PATTERN, (c) => c.toUpperCase())
811
}
912

1013
const createRule = ESLintUtils.RuleCreator(

0 commit comments

Comments
 (0)