diff --git a/docs/rules/no-danger.md b/docs/rules/no-danger.md
index 0b16dc4847..6ffe8b9a93 100644
--- a/docs/rules/no-danger.md
+++ b/docs/rules/no-danger.md
@@ -29,19 +29,14 @@ var Hello =
Hello World
;
```js
...
"react/no-danger": [, {
- "checkCustomComponents": boolean,
"customComponentNames": Array,
}]
...
```
-### checkCustomComponents
-
-Defaults to `false`, when `enabled` allows the rule to check for custom components.
-
### customComponentNames
-If you want to enable this rule for a specific set of custom components, you can pass `checkCustomComponents` as `true` and `customComponentNames` as the array of name of your custom components.
+Defaults to `[]`, if you want to enable this rule for all custom components you can pass `customComponentNames` as `['*']`, or else you can pass specific components name to the array.
## When Not To Use It
diff --git a/lib/rules/no-danger.js b/lib/rules/no-danger.js
index 2dfcc118ca..760a565ec5 100644
--- a/lib/rules/no-danger.js
+++ b/lib/rules/no-danger.js
@@ -58,10 +58,6 @@ module.exports = {
schema: [{
type: 'object',
properties: {
- checkCustomComponents: {
- default: false,
- type: 'boolean',
- },
customComponentNames: {
items: {
type: 'string',
@@ -76,16 +72,14 @@ module.exports = {
create(context) {
const configuration = context.options[0] || {};
- const checkCustomComponents = configuration.checkCustomComponents;
- const customComponentNames = configuration.customComponentNames;
+ const customComponentNames = configuration.customComponentNames || [];
return {
JSXAttribute(node) {
const functionName = node.parent.name.name;
- const enableCheckingCustomComponent = customComponentNames
- ? checkCustomComponents && customComponentNames.some((name) => functionName === name)
- : checkCustomComponents;
+ const enableCheckingCustomComponent = customComponentNames.length > 0
+ && (customComponentNames[0] === '*' || customComponentNames.some((name) => functionName === name));
if ((enableCheckingCustomComponent || jsxUtil.isDOMComponent(node.parent)) && isDangerous(node.name.name)) {
report(context, messages.dangerousProp, 'dangerousProp', {
diff --git a/tests/lib/rules/no-danger.js b/tests/lib/rules/no-danger.js
index c6392bc841..2c463de4d4 100644
--- a/tests/lib/rules/no-danger.js
+++ b/tests/lib/rules/no-danger.js
@@ -32,17 +32,14 @@ ruleTester.run('no-danger', rule, {
{ code: ';' },
{ code: ';' },
{ code: ';' },
- { code: ';', options: [{ checkCustomComponents: false }] },
- { code: ';', options: [{ checkCustomComponents: true }] },
- { code: ';', options: [{ checkCustomComponents: false }] },
- { code: ';', options: [{ checkCustomComponents: false }] },
+ { code: ';', options: [{ customComponentNames: ['*'] }] },
{
code: `
function App() {
return hello" }} />;
}
`,
- options: [{ checkCustomComponents: true, customComponentNames: ['Home'] }],
+ options: [{ customComponentNames: ['Home'] }],
},
]),
invalid: parsers.all([
@@ -63,7 +60,7 @@ ruleTester.run('no-danger', rule, {
data: { name: 'dangerouslySetInnerHTML' },
},
],
- options: [{ checkCustomComponents: true }],
+ options: [{ customComponentNames: ['*'] }],
},
{
code: `
@@ -77,7 +74,7 @@ ruleTester.run('no-danger', rule, {
data: { name: 'dangerouslySetInnerHTML' },
},
],
- options: [{ checkCustomComponents: true, customComponentNames: ['Title'] }],
+ options: [{ customComponentNames: ['Title'] }],
},
]),
});