Skip to content

Commit 6ee7bb2

Browse files
committed
Revert "no-context: boost test coverage, remove ClassProperty"
This reverts commit 4611c86.
1 parent dab4781 commit 6ee7bb2

File tree

2 files changed

+21
-30
lines changed

2 files changed

+21
-30
lines changed

lib/rules/no-context.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,18 @@ module.exports = {
4040
* @returns {Boolean} True if we are declaring a context, false if not.
4141
*/
4242
function isContextTypesDeclaration(node) {
43+
// Special case for class properties
44+
// (babel-eslint does not expose property name so we have to rely on tokens)
45+
if (node && node.type === 'ClassProperty') {
46+
var tokens = context.getFirstTokens(node, 2);
47+
if (
48+
tokens[0].value === 'contextTypes' ||
49+
(tokens[1] && tokens[1].value === 'contextTypes')
50+
) {
51+
return true;
52+
}
53+
return false;
54+
}
4355
return Boolean(
4456
node &&
4557
node.name === 'contextTypes'
@@ -75,6 +87,15 @@ module.exports = {
7587

7688
return {
7789

90+
ClassProperty: function(node) {
91+
if (isContextTypesDeclaration(node)) {
92+
context.report({
93+
node: node,
94+
message: 'Using context is not allowed.'
95+
});
96+
}
97+
},
98+
7899
MemberExpression: function(node) {
79100
if (
80101
isContextUsage(node) ||

tests/lib/rules/no-context.js

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,6 @@ ruleTester.run('no-context', rule, {
4242
'};'
4343
].join('\n'),
4444
parserOptions: parserOptions
45-
}, {
46-
code: [
47-
'var Hello = React.createClass({',
48-
' render: function() {',
49-
' return <div>Hello {this.props.name}</div>;',
50-
' }',
51-
'});'
52-
].join('\n'),
53-
parser: 'babel-eslint'
54-
}, {
55-
code: [
56-
'var Hello = function() {',
57-
' var context;',
58-
' return context;',
59-
'};'
60-
].join('\n'),
61-
parser: 'babel-eslint'
6245
}],
6346

6447
invalid: [{
@@ -113,19 +96,6 @@ ruleTester.run('no-context', rule, {
11396
errors: [{
11497
message: 'Using context is not allowed.'
11598
}]
116-
}, {
117-
code: [
118-
'class Hello extends React.Component {',
119-
' render() {',
120-
' const {name} = this.context;',
121-
' return <div>Hello {name}</div>;',
122-
' }',
123-
'};'
124-
].join('\n'),
125-
parser: 'babel-eslint',
126-
errors: [{
127-
message: 'Using context is not allowed.'
128-
}]
12999
}, {
130100
code: [
131101
'const Hello = (props, context) => {',

0 commit comments

Comments
 (0)