Skip to content

Commit

Permalink
Fix noMethodSetState docsUrl's
Browse files Browse the repository at this point in the history
Fixes #2078
  • Loading branch information
JBallin committed Dec 18, 2018
1 parent 9358489 commit 7da9e0d
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion lib/util/makeNoMethodSetStateRule.js
Expand Up @@ -10,14 +10,27 @@ 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: {
docs: {
description: `Prevent usage of setState in ${methodName}`,
category: 'Best Practices',
recommended: false,
url: docsUrl(methodName)
url: docsUrl(mapTitle(methodName))
},

schema: [{
Expand Down

0 comments on commit 7da9e0d

Please sign in to comment.