Skip to content

Commit

Permalink
Update lint and related dependencies, see phetsims/chipper#1275
Browse files Browse the repository at this point in the history
  • Loading branch information
samreid authored and zepumph committed Oct 22, 2024
1 parent 8055465 commit b05df8c
Showing 1 changed file with 31 additions and 27 deletions.
58 changes: 31 additions & 27 deletions eslint/rules/phet-object-shorthand.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,36 @@
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
module.exports = function( context ) {

return {
'Property:exit'( node ) {

// Ignore destructuring assignment
if ( node.parent.type === 'ObjectPattern' ) {
return;
}

// getters and setters are ignored
if ( node.kind === 'get' || node.kind === 'set' ) {
return;
module.exports = {
meta: { fixable: 'code' },
create( context ) {

return {
fixable: 'code',
'Property:exit'( node ) {

// Ignore destructuring assignment
if ( node.parent.type === 'ObjectPattern' ) {
return;
}

// getters and setters are ignored
if ( node.kind === 'get' || node.kind === 'set' ) {
return;
}

// only computed methods can fail the following checks
if ( node.computed && node.value.type !== 'FunctionExpression' && node.value.type !== 'ArrowFunctionExpression' ) {
return;
}

// { x } should be written as { x: x }
node.shorthand && context.report( {
node: node,
message: 'Expected longform property syntax.',
fix: fixer => fixer.insertTextAfter( node.key, `: ${node.key.name}` )
} );
}

// only computed methods can fail the following checks
if ( node.computed && node.value.type !== 'FunctionExpression' && node.value.type !== 'ArrowFunctionExpression' ) {
return;
}

// { x } should be written as { x: x }
node.shorthand && context.report( {
node: node,
message: 'Expected longform property syntax.',
fix: fixer => fixer.insertTextAfter( node.key, `: ${node.key.name}` )
} );
}
};
};
}
};

0 comments on commit b05df8c

Please sign in to comment.