Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
ngtan committed Sep 19, 2021
1 parent 9bea9cd commit 11374ca
Show file tree
Hide file tree
Showing 3 changed files with 774 additions and 710 deletions.
14 changes: 8 additions & 6 deletions lib/rules/no-arrow-function-lifecycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* @fileoverview Lifecycle methods should be methods on the prototype, not class fields
* @author Tan Nguyen
*/

'use strict';

const Components = require('../util/Components');
Expand All @@ -17,35 +18,36 @@ module.exports = {
recommended: false,
url: docsUrl('no-arrow-function-lifecycle')
},
schema: []
schema: [],
fixable: 'code',
},

create: Components.detect((context, components) => {
/**
* @param {Array} properties list of component properties
*/
function reportNoArrowFunctionLifecycle(properties) {
properties.forEach(node => {
properties.forEach((node) => {
const propertyName = astUtil.getPropertyName(node);
const nodeType = node.value && node.value.type;
const isLifecycleMethod = lifecycleMethods.indexOf(propertyName) !== -1;
const isLifecycleMethod = lifecycleMethods.includes(propertyName);

if (nodeType === 'ArrowFunctionExpression' && isLifecycleMethod) {
context.report({
node,
message: '{{propertyName}} is a React lifecycle method, and should not be an arrow function or in a class field. Use an instance method instead.',
data: {
propertyName
}
},
});
}
});
}

return {
'Program:exit': function() {
'Program:exit'() {
const list = components.list();
Object.keys(list).forEach(component => {
Object.keys(list).forEach((component) => {
const properties = astUtil.getComponentProperties(list[component].node);
reportNoArrowFunctionLifecycle(properties);
});
Expand Down
1 change: 1 addition & 0 deletions lib/util/lifecycleMethods.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* @fileoverview lifecycle methods
* @author Tan Nguyen
*/

'use strict';

module.exports = [
Expand Down
Loading

0 comments on commit 11374ca

Please sign in to comment.