Skip to content

Commit

Permalink
Rule fix: Fix fixer for no-extend to ignore single argument mode (#322
Browse files Browse the repository at this point in the history
)
  • Loading branch information
edg2s authored Jun 11, 2024
1 parent d585239 commit 1708d89
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/rules/no-extend.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ $.extend( true, {}, foo );
extend();
myMethod.extend();
myMethod.extend;
$.extend( { myUtil: fn } );
```

❌ Examples of **incorrect** code with `[{"allowDeep":true}]` options:
Expand Down
6 changes: 5 additions & 1 deletion src/rules/no-extend.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down
3 changes: 2 additions & 1 deletion tests/rules/no-extend.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ ruleTester.run( 'no-extend', rule, {
{
code: '$.extend(true, {}, foo)',
options: [ { allowDeep: true } ]
}
},
'$.extend({myUtil:fn})'
],
invalid: [
{
Expand Down

0 comments on commit 1708d89

Please sign in to comment.