Extract custom label refactoring for string literals

Issue #814 new
Kasper Simiński created an issue

I think this will be huge help for developers, whose deal with old, bad-written code.

Example scenario:

  1. User selects hard-coded string.

  2. User opens 'Refactor this' option.

  3. User selects 'Export to Custom Labels'

  4. IC opens PopUp where user can enter: * ApiName *Description

  5. IC creating new CustomLabel and swap hard-coded string.

Comments (7)

  1. Scott Wells repo owner

    That's a great idea. Would be a perfect extension to the Extract Constant refactoring that I'll be working on pretty soon. If the underlying expression is a string provide an option to extract as a custom label. Thanks for the suggestion!

  2. James Melville

    I'm not sure if it's implicit in the request but this would be useful in apex, visualforce and lightning component markup / javascript.

  3. James Melville

    Apex / Visualforce / Aura markup and JS can all directly replace strings with the appropriate expression to include the created label.

    In LWCs it’d be useful to be able to take the following paths:

    String value in html tag attribute → JS Property <img alt="Logo" ><img alt={logo} >
    String value in html → JS Property <div>hello</div><div>{hello}</div>

    String value in html tag attribute → JS Method returning the string
    String value in html → JS Method

    String value in html tag attribute → CustomLabel + JS import + JS Property
    String value in html → CustomLabel + JS import + JS Property

    String property in JS → CustomLabel + JS import

    Default value for the custom label API name should be the string in PascalCase.

    Default value for the JS property (or method?) and JS import should be the string in camelCase

  4. Log in to comment