Skip to content

Latest commit

 

History

History
56 lines (42 loc) · 996 Bytes

text-restrictions.md

File metadata and controls

56 lines (42 loc) · 996 Bytes

text-restrictions

Check that translated messages doesn't contain patterns from the rules.

This rule enforces a consistency rules inside your messages.

rules

rules is array of rules when one rule has structure

{
  "patterns": ["first", "second"],
  "message": "error message"
}

each rule has a structure:

  • patterns is an array of regex or strings
  • message is an error message that will be displayed if restricting pattern matches text
  • flags is a string with regex flags for patterns

Example

Restrict specific quotes to be used in the messages:

{
  "lingui/text-restrictions": [
    "error",
    {
      "rules": [
        {
          "patterns": ["''", "", ""],
          "message": "Quotes should be ' or \""
        }
      ]
    }
  ]
}

Example of invalid code with this rule:

t`Hello “mate“`
msg`Hello “mate“`
t({ message: `Hello “mate“` })

Example of valid code with this rule:

t`Hello "mate"`