Skip to content

Latest commit

 

History

History
54 lines (39 loc) · 1.42 KB

no-text-as-attribute.md

File metadata and controls

54 lines (39 loc) · 1.42 KB

Verify that JSX nodes do not contain non-i18n'd text as specified attribute values (preact-i18n/no-text-as-attributes)

Rule Details

Examples of incorrect code for this rule

// string for a checked attribute
<img alt="foo" />

// JSX expression that evaluates to a string for a checked attribute
<input placeholder={"foo"} />

Examples of correct code for this rule

// no attributes to check
<img/>

// alt attribute is using i18n mechanism
<img alt={<Text id="helloWorld"/>} />

// baz is not in list of checked attributes
<img baz="foo bar" />

// placholder cannot verify if props.foo is a string or an i18n mechanism, so no error is thrown
<input type="text" placeholder={props.foo} />

// Ignore smiling faces
/*eslint preact-i18n/no-text-as-attribute: ["error", { "ignoreTextRegex": "^:\\)$"]*/
<img alt={:)} >

Options

attributes [optional]

An array of strings of attributes that should be checked that overrides the default. Default is:

{
	"attributes": ["alt", "aria-label", "placeholder", "title"]
}

ignoreTextRegex [optional]

A regular expression that, if supplied, ignores the content of text matching the regex. Useful if you want to ignore things like / in a text attribute. For example, to ignore any slash or colon surrounded by whitespace you would provide:

{
	"ignoreTextRegex": "^\\s*[/:]\\s*$"
}