You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/rules/jsx-no-literals.md
+71-1Lines changed: 71 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -34,7 +34,77 @@ The supported options are:
34
34
-`allowedStrings` - An array of unique string values that would otherwise warn, but will be ignored.
35
35
-`ignoreProps` (default: `false`) - When `true` the rule ignores literals used in props, wrapped or unwrapped.
36
36
-`noAttributeStrings` (default: `false`) - Enforces no string literals used in attributes when set to `true`.
37
-
-`elementOverrides` - An object where the keys are the element names and the values are objects with the same options as above. This allows you to specify different options for different elements.
37
+
-`elementOverrides` - An object where the keys are the element names and the
38
+
values are objects with the same options as above. This allows you to specify
39
+
different options for different elements.
40
+
41
+
### `elementOverrides`
42
+
43
+
The `elementOverrides` option allows you to specify different options for
44
+
different elements. This is useful when you want to enforce different rules for
45
+
different elements. For example, you may want to allow string literals in
46
+
`Button` elements, but not in the rest of your application.
47
+
48
+
The element name only accepts component names. HTML element tag names are not supported.
49
+
Component names are case-sensitive and should exactly match the name of
50
+
the component as it is used in the JSX. It can also be the name of a compound
51
+
component (ie. `Modal.Button`).
52
+
53
+
Specifying options creates a new context for the rule, so the rule will only
54
+
apply the new options to the specified element and its children (if
55
+
`applyToNestedElements` is `true` - see below). This means that the root rule options will
56
+
not apply to the specified element.
57
+
58
+
In addition to the options above (`noStrings`, `allowedStrings`,
59
+
`noAttributeStrings` and `ignoreProps`), you can also specify the the following options
60
+
that are specific to `elementOverrides`:
61
+
62
+
-`allowElement` (default: `false`) - When `true` the rule will allow the
63
+
specified element to have string literals as children, wrapped or unwrapped
64
+
without warning.
65
+
-`applyToNestedElements` (default: `true`) - When `false` the rule will not
66
+
apply the current options set to nested elements. This is useful when you want
67
+
to apply the rule to a specific element, but not to its children.
68
+
69
+
**Note**: As this rule has no way of differentiating
70
+
between different componets with the same name, it is recommended to use this
71
+
option with specific components that are unique to your application.
72
+
73
+
#### `elementOverrides` Examples
74
+
75
+
The following are **correct** examples that demonstrate how to use the `elementOverrides` option:
0 commit comments