Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: js object shorthand #194

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
feat: js object shorthand
  • Loading branch information
scr2em committed Apr 14, 2024
commit 981bfcebc4599c81a799f2d13a1b350bc1a297aa
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
};
```
Loading