Skip to content

Commit 1708d89

Browse files
authored
Rule fix: Fix fixer for no-extend to ignore single argument mode (#322)
1 parent d585239 commit 1708d89

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

docs/rules/no-extend.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ $.extend( true, {}, foo );
2121
extend();
2222
myMethod.extend();
2323
myMethod.extend;
24+
$.extend( { myUtil: fn } );
2425
```
2526

2627
❌ Examples of **incorrect** code with `[{"allowDeep":true}]` options:

src/rules/no-extend.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,14 @@ module.exports = {
3030
const name = node.callee.property.name;
3131
if (
3232
name !== 'extend' ||
33-
!utils.isjQueryConstructor( context, node.callee.object.name )
33+
!utils.isjQueryConstructor( context, node.callee.object.name )
3434
) {
3535
return;
3636
}
37+
if ( node.arguments.length === 1 ) {
38+
// $.extend with one argument merges the object onto the jQuery namespace
39+
return;
40+
}
3741
const allowDeep = context.options[ 0 ] && context.options[ 0 ].allowDeep;
3842
const isDeep = node.arguments[ 0 ] && node.arguments[ 0 ].value === true;
3943
if ( allowDeep && isDeep ) {

tests/rules/no-extend.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ ruleTester.run( 'no-extend', rule, {
1414
{
1515
code: '$.extend(true, {}, foo)',
1616
options: [ { allowDeep: true } ]
17-
}
17+
},
18+
'$.extend({myUtil:fn})'
1819
],
1920
invalid: [
2021
{

0 commit comments

Comments
 (0)