Skip to content

Commit

Permalink
Added early termination for no-unsafe, adjusted tests to support ESLint3
Browse files Browse the repository at this point in the history
  • Loading branch information
sergei-startsev committed Jun 19, 2018
1 parent 5e17159 commit e41500a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
8 changes: 6 additions & 2 deletions lib/rules/no-unsafe.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ module.exports = {
},

create: Components.detect((context, components, utils) => {
const isApplicable = versionUtil.testReactVersion(context, '16.3.0');
if (!isApplicable) {
return {};
}

/**
* Returns a list of unsafe methods
* @returns {Array} A list of unsafe methods
Expand All @@ -45,8 +50,7 @@ module.exports = {
*/
function isUnsafe(method) {
const unsafeMethods = getUnsafeMethods();
const isApplicable = versionUtil.testReactVersion(context, '16.3.0');
return unsafeMethods.indexOf(method) !== -1 && isApplicable;
return unsafeMethods.indexOf(method) !== -1;
}

/**
Expand Down
18 changes: 6 additions & 12 deletions tests/lib/rules/no-unsafe.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,22 +105,19 @@ ruleTester.run('no-unsafe', rule, {
message: errorMessage('UNSAFE_componentWillMount'),
line: 2,
column: 7,
endLine: 6,
endColumn: 8
type: 'ClassDeclaration'
},
{
message: errorMessage('UNSAFE_componentWillReceiveProps'),
line: 2,
column: 7,
endLine: 6,
endColumn: 8
type: 'ClassDeclaration'
},
{
message: errorMessage('UNSAFE_componentWillUpdate'),
line: 2,
column: 7,
endLine: 6,
endColumn: 8
type: 'ClassDeclaration'
}
]
},
Expand All @@ -138,22 +135,19 @@ ruleTester.run('no-unsafe', rule, {
message: errorMessage('UNSAFE_componentWillMount'),
line: 2,
column: 38,
endLine: 6,
endColumn: 10
type: 'ObjectExpression'
},
{
message: errorMessage('UNSAFE_componentWillReceiveProps'),
line: 2,
column: 38,
endLine: 6,
endColumn: 10
type: 'ObjectExpression'
},
{
message: errorMessage('UNSAFE_componentWillUpdate'),
line: 2,
column: 38,
endLine: 6,
endColumn: 10
type: 'ObjectExpression'
}
]
}
Expand Down

0 comments on commit e41500a

Please sign in to comment.