Skip to content

Latest commit

 

History

History
56 lines (40 loc) · 1.93 KB

no-bare-strings.md

File metadata and controls

56 lines (40 loc) · 1.93 KB

no-bare-strings

In order to be able to internationalize your application, you will need to avoid using plain strings in your templates. Instead, you would need to use a template helper specializing in translation (ember-intl is the recommended project to use this for).

Examples

This rule forbids the following:

<h2>Some string here!</h2>

This rule allows the following:

{{!-- ember-intl example  --}}
<h2>{{t 'photos.banner' numPhotos=model.photos.length}}</h2>

Configuration

The following values are valid configuration:

  • boolean -- true for enabled / false for disabled
  • array -- an array of allowlisted strings
  • object -- An object with the following keys:
    • allowlist -- An array of allowlisted strings
    • whitelist -- Deprecated, use allowlist. If both are provided, whitelist will be ignored.
    • globalAttributes -- An array of attributes to check on every element.
    • elementAttributes -- An object whose keys are tag names and value is an array of attributes to check for that tag name.

When the config value of true is used the following configuration is used:

  • allowlist - refer to the DEFAULT_CONFIG.allowlist property in the rule
  • globalAttributes - title, aria-label, aria-placeholder, aria-roledescription, aria-valuetext
  • elementAttributes - { img: ['alt'], input: ['placeholder'] }

The DEFAULT_CONFIG is available as an export. Example use in configuration:

const {
  DEFAULT_CONFIG
} = require('ember-template-lint/lib/rules/no-bare-strings');
const additionalCharsToIgnore = ['a', 'b', 'c'];

module.exports = {
  rules: {
    'no-bare-strings': [...DEFAULT_CONFIG.allowlist, ...additionalCharsToIgnore]
  }
};

References