Skip to content

Latest commit

 

History

History
108 lines (81 loc) · 2.07 KB

File metadata and controls

108 lines (81 loc) · 2.07 KB

ember/template-no-bare-strings

💼 This rule is enabled in the following configs: strict-gjs, strict-gts.

Disallows bare strings in templates to encourage internationalization.

Bare strings in templates make internationalization (i18n) difficult. This rule encourages using translation helpers or properties to enable easy localization of your application.

Rule Details

This rule disallows text content in templates that isn't wrapped in a translation helper or passed as a property.

The following are allowed:

  • Whitespace-only strings
  • Strings containing only numbers and punctuation
  • Strings in an allowlist (configurable)

Examples

Examples of incorrect code for this rule:

<template>
  <div>Hello World</div>
</template>
<template>
  <button>Click me</button>
</template>
<template>
  <h1>Welcome to our app</h1>
</template>

Examples of correct code for this rule:

<template>
  <div>{{t "hello.world"}}</div>
</template>
<template>
  <button>{{@buttonText}}</button>
</template>
<template>
  <div>123</div>
</template>
<template>
  <div>   </div>
</template>

Configuration

allowlist

An array of strings that are allowed to appear as bare strings:

module.exports = {
  rules: {
    'ember/template-no-bare-strings': [
      'error',
      {
        allowlist: ['Welcome', 'Home', 'About'],
      },
    ],
  },
};

globalAttributes

An array of attribute names where bare strings will be checked (defaults to ["title", "aria-label", "alt", "placeholder"]):

module.exports = {
  rules: {
    'ember/template-no-bare-strings': [
      'error',
      {
        globalAttributes: ['title', 'aria-label', 'alt'],
      },
    ],
  },
};

References