Skip to content

Commit e41500a

Browse files
Added early termination for no-unsafe, adjusted tests to support ESLint3
1 parent 5e17159 commit e41500a

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

lib/rules/no-unsafe.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ module.exports = {
2626
},
2727

2828
create: Components.detect((context, components, utils) => {
29+
const isApplicable = versionUtil.testReactVersion(context, '16.3.0');
30+
if (!isApplicable) {
31+
return {};
32+
}
33+
2934
/**
3035
* Returns a list of unsafe methods
3136
* @returns {Array} A list of unsafe methods
@@ -45,8 +50,7 @@ module.exports = {
4550
*/
4651
function isUnsafe(method) {
4752
const unsafeMethods = getUnsafeMethods();
48-
const isApplicable = versionUtil.testReactVersion(context, '16.3.0');
49-
return unsafeMethods.indexOf(method) !== -1 && isApplicable;
53+
return unsafeMethods.indexOf(method) !== -1;
5054
}
5155

5256
/**

tests/lib/rules/no-unsafe.js

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -105,22 +105,19 @@ ruleTester.run('no-unsafe', rule, {
105105
message: errorMessage('UNSAFE_componentWillMount'),
106106
line: 2,
107107
column: 7,
108-
endLine: 6,
109-
endColumn: 8
108+
type: 'ClassDeclaration'
110109
},
111110
{
112111
message: errorMessage('UNSAFE_componentWillReceiveProps'),
113112
line: 2,
114113
column: 7,
115-
endLine: 6,
116-
endColumn: 8
114+
type: 'ClassDeclaration'
117115
},
118116
{
119117
message: errorMessage('UNSAFE_componentWillUpdate'),
120118
line: 2,
121119
column: 7,
122-
endLine: 6,
123-
endColumn: 8
120+
type: 'ClassDeclaration'
124121
}
125122
]
126123
},
@@ -138,22 +135,19 @@ ruleTester.run('no-unsafe', rule, {
138135
message: errorMessage('UNSAFE_componentWillMount'),
139136
line: 2,
140137
column: 38,
141-
endLine: 6,
142-
endColumn: 10
138+
type: 'ObjectExpression'
143139
},
144140
{
145141
message: errorMessage('UNSAFE_componentWillReceiveProps'),
146142
line: 2,
147143
column: 38,
148-
endLine: 6,
149-
endColumn: 10
144+
type: 'ObjectExpression'
150145
},
151146
{
152147
message: errorMessage('UNSAFE_componentWillUpdate'),
153148
line: 2,
154149
column: 38,
155-
endLine: 6,
156-
endColumn: 10
150+
type: 'ObjectExpression'
157151
}
158152
]
159153
}

0 commit comments

Comments
 (0)