Skip to content

Commit

Permalink
feat: js object shorthand
Browse files Browse the repository at this point in the history
  • Loading branch information
scr2em committed Apr 14, 2024
1 parent 4dfa817 commit 981bfce
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions .grit/patterns/js/object_shorthand.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
---
title: Require Object shorthand
tags: [good-practice]
---

Require or disallow method and property shorthand syntax for object literals

This matches the [ESlint object shorthand](https://eslint.org/docs/latest/rules/object-shorthand).


```grit
engine marzano(1.0)
language js
pair(key=$key, value=$value) as $pair where {
if( $key <: $value){
$pair => `$key`
}else if ($value <: function($body, $parameters)){
$pair => `$key($parameters) $body`,
}
}
```

## Code examples:
```js
// properties
var foo = {
x,
y: y,
z: z,
a: 12,
b: a
};

// methods
var foo = {
a: function() {},
b: function( x) {},
x: function y() {},
y: function y() {},
z: function y(x) {},
y(x) {},
"o-o" : ()=> 5
};
```
will become
```js
// properties
var foo = {
x,
y,
z,
a: 12,
b: a
};

// methods
var foo = {
a() {},
b(x) {},
x() {},
y() {},
z(x) {},
y(x) {},
"o-o" : ()=> 5
};
```

0 comments on commit 981bfce

Please sign in to comment.