mirror of
https://github.com/idanoo/GoScrobble.git
synced 2024-11-24 17:35:16 +00:00
45 lines
1.2 KiB
JavaScript
45 lines
1.2 KiB
JavaScript
|
/**
|
||
|
* @fileoverview Report "this" being used in stateless functional components.
|
||
|
*/
|
||
|
|
||
|
'use strict';
|
||
|
|
||
|
const Components = require('../util/Components');
|
||
|
const docsUrl = require('../util/docsUrl');
|
||
|
|
||
|
// ------------------------------------------------------------------------------
|
||
|
// Rule Definition
|
||
|
// ------------------------------------------------------------------------------
|
||
|
|
||
|
module.exports = {
|
||
|
meta: {
|
||
|
docs: {
|
||
|
description: 'Report "this" being used in stateless components',
|
||
|
category: 'Possible Errors',
|
||
|
recommended: false,
|
||
|
url: docsUrl('no-this-in-sfc')
|
||
|
},
|
||
|
|
||
|
messages: {
|
||
|
noThisInSFC: 'Stateless functional components should not use `this`'
|
||
|
},
|
||
|
|
||
|
schema: []
|
||
|
},
|
||
|
|
||
|
create: Components.detect((context, components, utils) => ({
|
||
|
MemberExpression(node) {
|
||
|
if (node.object.type === 'ThisExpression') {
|
||
|
const component = components.get(utils.getParentStatelessComponent());
|
||
|
if (!component || (component.node && component.node.parent && component.node.parent.type === 'Property')) {
|
||
|
return;
|
||
|
}
|
||
|
context.report({
|
||
|
node,
|
||
|
messageId: 'noThisInSFC'
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
}))
|
||
|
};
|