feat(linter): implement eslint/camelcase rule#16908
feat(linter): implement eslint/camelcase rule#16908tt-a1i wants to merge 10 commits intooxc-project:mainfrom
Conversation
Implements the `camelcase` rule from ESLint that enforces camelCase naming conventions for identifiers. Supports options: - `properties`: "always" (default) or "never" - `ignoreDestructuring`: skip destructuring patterns - `ignoreImports`: skip import specifiers - `allow`: array of allowed names or regex patterns Checks: - Variable declarations - Function declarations and parameters - Object property definitions - Class properties and methods - Assignment expressions - Import/export declarations - Labels
CodSpeed Performance ReportMerging #16908 will not alter performanceComparing Summary
Footnotes
|
- ignoreDestructuring: only skip when local name equals property name
(e.g., { category_id } skipped, but { category_id: other } checked)
- ignoreImports: only skip when local equals imported name
(e.g., import { snake } skipped, but import { snake as other } checked)
- allow: treat each entry as both literal and regex (ESLint behavior)
- Add ExportSpecifier check for named exports
- Add BreakStatement/ContinueStatement label reference checks
…elcase - Add BindingRestElement check for rest destructuring (e.g., `...other_props`) - Add ArrayPattern check for array destructuring (e.g., `[foo_bar]`) - Both respect ignoreDestructuring option - Handles default values in array destructuring (e.g., `[foo_bar = 1]`)
…ucturing ESLint's ignoreDestructuring only skips object destructuring where local name equals property name. Array destructuring has no property names (only indices), so ESLint always checks array elements. - Remove ignoreDestructuring check from check_binding_pattern - Move array destructuring test cases to fail section - Update comments to reflect actual ESLint behavior
camc314
left a comment
There was a problem hiding this comment.
I re-ported the test cases and they're failing.
It looks like you missed a lot of test cases when porting this rule originally.
- Replace AST-handler approach with `run_once` + semantic symbol/reference iteration
- Fix ignoreGlobals to only skip explicitly configured globals + env globals
(matching ESLint behavior, not skipping all unresolved references)
- Add equalsToOriginalName support for AssignmentTargetPropertyProperty
(handles `({ foo: foo } = obj)` pattern)
- Fix AssignmentPattern to only skip identifiers on the `right` side
- Split tests requiring globals config into separate Tester run
- Add fail tests for undefined variables with ignoreGlobals: true
Thanks for re-porting these — you’re right, my initial port missed a bunch of ESLint coverage I’ve reworked the rule to follow ESLint’s approach more closely using semantic analysis in
The rewrite is in 07ef1b6 (plus 1c38fec to resolve conflicts). Could you take another look / |
|
hey @camc314, just checking if you had a chance to look at the rewrite? no rush, happy holidays! |
|
Based on the PR description and code comments I presume this was - at least in large part - generated using AI tooling. Please ensure that the PR description is updated to note the AI usage in accordance with our policy, preferably including models/tools used and a confirmation that you have personally reviewed the code generated and ensured it works/makes sense: https://oxc.rs/docs/contribute/introduction.html#ai-usage-policy. That aside, we've discussed internally and we'd instead be looking to implement |
makes sense, naming-convention is more comprehensive anyway. |
…of another rule. Preference is to implement this via `@typescript-eslint/naming-convention` instead. See this comment for further context: #16908 (comment)
…of another rule. (#17571) Preference is to implement this via [`@typescript-eslint/naming-convention`](https://typescript-eslint.io/rules/naming-convention/) instead. See this comment for further context: #16908 (comment)
Summary
Implements the ESLint
camelcaserule that enforces camelCase naming conventions for identifiers.Features:
properties: "always" | "never"option to control property name checkingignoreDestructuring: trueoption to skip destructuring identifiersignoreImports: trueoption to skip import identifiersallowoption with literal strings or regex patterns (patterns starting with^or ending with$are treated as regex)_private,trailing_)CONSTANT_VALUE)Implementation notes:
from_configurationfor better performanceconst { foo_bar } = obj) and destructuring assignments (({ foo_bar } = obj))Closes #5535