Skip to content

Commit 77e3fd0

Browse files
authored
Merge pull request #2090 from JBallin/no-method-set-state-docs-url
Fix noMethodSetState docsUrl's
2 parents 9358489 + 7da9e0d commit 77e3fd0

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

lib/util/makeNoMethodSetStateRule.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,27 @@ const docsUrl = require('./docsUrl');
1010
// Rule Definition
1111
// ------------------------------------------------------------------------------
1212

13+
function mapTitle(methodName) {
14+
const map = {
15+
componentDidMount: 'did-mount',
16+
componentDidUpdate: 'did-update',
17+
componentWillUpdate: 'will-update'
18+
};
19+
const title = map[methodName];
20+
if (!title) {
21+
throw Error(`No docsUrl for '${methodName}'`);
22+
}
23+
return `no-${title}-set-state`;
24+
}
25+
1326
function makeNoMethodSetStateRule(methodName, shouldCheckUnsafeCb) {
1427
return {
1528
meta: {
1629
docs: {
1730
description: `Prevent usage of setState in ${methodName}`,
1831
category: 'Best Practices',
1932
recommended: false,
20-
url: docsUrl(methodName)
33+
url: docsUrl(mapTitle(methodName))
2134
},
2235

2336
schema: [{

0 commit comments

Comments
 (0)