Skip to content

Commit 4418534

Browse files
insinyannickcr
authored andcommitted
Add ignore option to no-unknown-property rule
1 parent 2508576 commit 4418534

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

docs/rules/no-unknown-property.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,17 @@ var React = require('react');
2222
var Hello = <div className="hello">Hello World</div>;
2323
```
2424

25+
## Rule Options
26+
27+
```js
28+
...
29+
"no-unknown-property": [<enabled>, { ignore: <ignore> }]
30+
...
31+
```
32+
33+
* `enabled`: for enabling the rule. 0=off, 1=warn, 2=error. Defaults to 0.
34+
* `ignore`: optional array of property and attribute names to ignore during validation.
35+
2536
## When Not To Use It
2637

2738
If you are not using JSX you can disable this rule.

lib/rules/no-unknown-property.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ var versionUtil = require('../util/version');
1010
// Constants
1111
// ------------------------------------------------------------------------------
1212

13+
var DEFAULTS = {
14+
ignore: []
15+
};
16+
1317
var UNKNOWN_MESSAGE = 'Unknown property \'{{name}}\' found, use \'{{standardName}}\' instead';
1418

1519
var DOM_ATTRIBUTE_NAMES = {
@@ -116,14 +120,19 @@ function getStandardName(context, name) {
116120

117121
module.exports = function(context) {
118122

123+
function getIgnoreConfig() {
124+
return context.options[0] && context.options[0].ignore || DEFAULTS.ignore;
125+
}
126+
119127
var sourceCode = context.getSourceCode();
120128

121129
return {
122130

123131
JSXAttribute: function(node) {
132+
var ignoreNames = getIgnoreConfig();
124133
var name = sourceCode.getText(node.name);
125134
var standardName = getStandardName(context, name);
126-
if (!isTagName(node) || !standardName) {
135+
if (!isTagName(node) || !standardName || ignoreNames.indexOf(name) >= 0) {
127136
return;
128137
}
129138
context.report({
@@ -142,4 +151,15 @@ module.exports = function(context) {
142151

143152
};
144153

145-
module.exports.schema = [];
154+
module.exports.schema = [{
155+
type: 'object',
156+
properties: {
157+
ignore: {
158+
type: 'array',
159+
items: {
160+
type: 'string'
161+
}
162+
}
163+
},
164+
additionalProperties: false
165+
}];

tests/lib/rules/no-unknown-property.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ ruleTester.run('no-unknown-property', rule, {
3838
{code: '<div {...this.props} class="foo" is="my-elem"></div>;', parserOptions: parserOptions},
3939
{code: '<atom-panel class="foo"></atom-panel>;', parserOptions: parserOptions},
4040
{code: '<use xlink:href="bar" />;', parserOptions: parserOptions},
41-
{code: '<rect clip-path="bar" />;', parserOptions: parserOptions}
41+
{code: '<rect clip-path="bar" />;', parserOptions: parserOptions}, {
42+
code: '<div class="bar"></div>;',
43+
options: [{ignore: ['class']}],
44+
parserOptions: parserOptions
45+
}
4246
],
4347
invalid: [{
4448
code: '<div class="bar"></div>;',

0 commit comments

Comments
 (0)