From 7da9e0da38b1f6a61ac8de786809f2a84ddbad1c Mon Sep 17 00:00:00 2001 From: JBallin Date: Tue, 18 Dec 2018 09:49:58 -0800 Subject: [PATCH] Fix noMethodSetState docsUrl's Fixes #2078 --- lib/util/makeNoMethodSetStateRule.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) 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: [{