Skip to content

Commit 981bfce

Browse files
committed
feat: js object shorthand
1 parent 4dfa817 commit 981bfce

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

.grit/patterns/js/object_shorthand.md

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
---
2+
title: Require Object shorthand
3+
tags: [good-practice]
4+
---
5+
6+
Require or disallow method and property shorthand syntax for object literals
7+
8+
This matches the [ESlint object shorthand](https://eslint.org/docs/latest/rules/object-shorthand).
9+
10+
11+
```grit
12+
engine marzano(1.0)
13+
language js
14+
15+
pair(key=$key, value=$value) as $pair where {
16+
if( $key <: $value){
17+
$pair => `$key`
18+
}else if ($value <: function($body, $parameters)){
19+
$pair => `$key($parameters) $body`,
20+
}
21+
}
22+
```
23+
24+
## Code examples:
25+
```js
26+
// properties
27+
var foo = {
28+
x,
29+
y: y,
30+
z: z,
31+
a: 12,
32+
b: a
33+
};
34+
35+
// methods
36+
var foo = {
37+
a: function() {},
38+
b: function( x) {},
39+
x: function y() {},
40+
y: function y() {},
41+
z: function y(x) {},
42+
y(x) {},
43+
"o-o" : ()=> 5
44+
};
45+
```
46+
will become
47+
```js
48+
// properties
49+
var foo = {
50+
x,
51+
y,
52+
z,
53+
a: 12,
54+
b: a
55+
};
56+
57+
// methods
58+
var foo = {
59+
a() {},
60+
b(x) {},
61+
x() {},
62+
y() {},
63+
z(x) {},
64+
y(x) {},
65+
"o-o" : ()=> 5
66+
};
67+
```

0 commit comments

Comments
 (0)