Skip to content

Commit

Permalink
Merge pull request #2090 from JBallin/no-method-set-state-docs-url
Browse files Browse the repository at this point in the history
Fix noMethodSetState docsUrl's
  • Loading branch information
ljharb committed Dec 18, 2018
2 parents 9358489 + 7da9e0d commit 77e3fd0
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 77e3fd0

Please sign in to comment.