diff --git a/docs/rules/no-extend.md b/docs/rules/no-extend.md index 2f5a074..e324987 100644 --- a/docs/rules/no-extend.md +++ b/docs/rules/no-extend.md @@ -21,6 +21,7 @@ $.extend( true, {}, foo ); extend(); myMethod.extend(); myMethod.extend; +$.extend( { myUtil: fn } ); ``` ❌ Examples of **incorrect** code with `[{"allowDeep":true}]` options: diff --git a/src/rules/no-extend.js b/src/rules/no-extend.js index 73f179c..99f61b5 100644 --- a/src/rules/no-extend.js +++ b/src/rules/no-extend.js @@ -30,10 +30,14 @@ module.exports = { const name = node.callee.property.name; if ( name !== 'extend' || - !utils.isjQueryConstructor( context, node.callee.object.name ) + !utils.isjQueryConstructor( context, node.callee.object.name ) ) { return; } + if ( node.arguments.length === 1 ) { + // $.extend with one argument merges the object onto the jQuery namespace + return; + } const allowDeep = context.options[ 0 ] && context.options[ 0 ].allowDeep; const isDeep = node.arguments[ 0 ] && node.arguments[ 0 ].value === true; if ( allowDeep && isDeep ) { diff --git a/tests/rules/no-extend.js b/tests/rules/no-extend.js index ce3563a..dd04dd3 100644 --- a/tests/rules/no-extend.js +++ b/tests/rules/no-extend.js @@ -14,7 +14,8 @@ ruleTester.run( 'no-extend', rule, { { code: '$.extend(true, {}, foo)', options: [ { allowDeep: true } ] - } + }, + '$.extend({myUtil:fn})' ], invalid: [ {