Skip to content

Latest commit

 

History

History
88 lines (59 loc) · 1.58 KB

style-prop-object.md

File metadata and controls

88 lines (59 loc) · 1.58 KB

Enforce style prop value is an object (inferno/style-prop-object)

Require that the value of the prop style be an object or a variable that is an object.

Rule Details

Examples of incorrect code for this rule:

<div style="color: 'red'" />

<div style={true} />

<Hello style={true} />

const styles = true;
<div style={styles} />
Inferno.createElement("div", { style: "color: 'red'" });

Inferno.createElement("div", { style: true });

Inferno.createElement("Hello", { style: true });

const styles = true;
Inferno.createElement("div", { style: styles });

Examples of correct code for this rule:

<div style={{ color: "red" }} />

<Hello style={{ color: "red" }} />

const styles = { color: "red" };
<div style={styles} />
Inferno.createElement("div", { style: { color: 'red' }});

Inferno.createElement("Hello", { style: { color: 'red' }});

const styles = { height: '100px' };
Inferno.createElement("div", { style: styles });

Rule Options

...
"inferno/style-prop-object": [<enabled>, {
  "allow": [<string>]
}]
...

allow

A list of elements that are allowed to have a non-object value in their style attribute. The default value is [].

Example

{
  "allow": ["MyComponent"]
}

Examples of incorrect code for this rule:

<Hello style="a string">
Inferno.createElement(Hello, { style: "some styling" });

Examples of correct code for this rule:

<MyComponent style="a string">
Inferno.createElement(MyComponent, { style: "some styling" });