Skip to content

Commit 4611c86

Browse files
committed
no-context: boost test coverage, remove ClassProperty
1 parent 65fd198 commit 4611c86

File tree

2 files changed

+30
-21
lines changed

2 files changed

+30
-21
lines changed

lib/rules/no-context.js

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,6 @@ 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-
}
5543
return Boolean(
5644
node &&
5745
node.name === 'contextTypes'
@@ -87,15 +75,6 @@ module.exports = {
8775

8876
return {
8977

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-
9978
MemberExpression: function(node) {
10079
if (
10180
isContextUsage(node) ||

tests/lib/rules/no-context.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,23 @@ 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'
4562
}],
4663

4764
invalid: [{
@@ -96,6 +113,19 @@ ruleTester.run('no-context', rule, {
96113
errors: [{
97114
message: 'Using context is not allowed.'
98115
}]
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+
}]
99129
}, {
100130
code: [
101131
'const Hello = (props, context) => {',

0 commit comments

Comments
 (0)