Mmohebifar

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.

eslintdot-notationjavascripttypescriptstandardization
Public
0 executions

Run locally

npx codemod javascript-eslint-dot-notation

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'], and obj['#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:

  • allowKeywords defaults to true and allows rewrites such as obj['default'] -> obj.default
  • allowPattern preserves matching property names in bracket notation
  • unicodeIdentifiers defaults to false; enable it to allow non-ASCII IdentifierNames

Development

bash

License

MIT

Ready to contribute?

Build your own codemod and share it with the community.