diff --git a/lib/util/makeNoMethodSetStateRule.js b/lib/util/makeNoMethodSetStateRule.js index f885dab715..0b7e164312 100644 --- a/lib/util/makeNoMethodSetStateRule.js +++ b/lib/util/makeNoMethodSetStateRule.js @@ -10,6 +10,19 @@ const docsUrl = require('./docsUrl'); // Rule Definition // ------------------------------------------------------------------------------ +function mapTitle(methodName) { + const map = { + componentDidMount: 'did-mount', + componentDidUpdate: 'did-update', + componentWillUpdate: 'will-update' + }; + const title = map[methodName]; + if (!title) { + throw Error(`No docsUrl for '${methodName}'`); + } + return `no-${title}-set-state`; +} + function makeNoMethodSetStateRule(methodName, shouldCheckUnsafeCb) { return { meta: { @@ -17,7 +30,7 @@ function makeNoMethodSetStateRule(methodName, shouldCheckUnsafeCb) { description: `Prevent usage of setState in ${methodName}`, category: 'Best Practices', recommended: false, - url: docsUrl(methodName) + url: docsUrl(mapTitle(methodName)) }, schema: [{