javascript-eslint-dot-notation
Transform bracket notation with static string literal keys (e.g., obj['prop']) into equivalent dot notation (obj.prop) across JavaScript/TypeScript codebases when semantics are preserved, aligning with ESLint dot-notation best practices and improving readability and maintainability.
Installation
bash
Usage
This codemod rewrites runtime subscript_expression member access into dot notation when the key is a compile-time string literal and the rewrite is semantically safe.
Targets:
**/*.{js,jsx,mjs,cjs,ts,tsx}
Examples:
js
becomes:
js
Preserve/no-op cases:
- Dynamic access like
obj[key] - Keys that are not valid dot-notation identifiers like
obj['kebab-case'],obj['with space'],obj['0'],obj['a.b'], andobj['#private'] - Keys expressed with escapes or comments inside the brackets when the exact trivia cannot be preserved safely
- Type-only indexed access such as
type Name = User['name']
Parameters:
allowKeywordsdefaults totrueand allows rewrites such asobj['default'] -> obj.defaultallowPatternpreserves matching property names in bracket notationunicodeIdentifiersdefaults tofalse; enable it to allow non-ASCII IdentifierNames
Development
bash
License
MIT