Skip to content

Commit 9f26001

Browse files
authored
feat: run all patterns through formatter (#248)
1 parent ae44ae7 commit 9f26001

File tree

215 files changed

+6329
-6861
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

215 files changed

+6329
-6861
lines changed

Diff for: .grit/grit.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ patterns:
55
body: |
66
engine marzano(0.1)
77
language markdown
8-
8+
99
file($name, $body) where {
10-
$name <: r".*?/?([^/]+)\.[a-zA-Z]*"($base_name),
11-
! $base_name <: r"^[a-zA-Z_][a-zA-Z0-9_]*$",
10+
$name <: r".*?/?([^/]+)\.[a-zA-Z]*"($base_name),
11+
! $base_name <: r"^[a-zA-Z_][a-zA-Z0-9_]*$"
1212
}
1313
samples:
1414
- input: |

Diff for: .grit/patterns/css/aspect_ratio.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ title: Aspect ratio
55
```grit
66
language css
77
8-
`a { $props }` where {
9-
$props <: contains `aspect-ratio: $x`
10-
}
8+
`a { $props }` where { $props <: contains `aspect-ratio: $x` }
119
```
1210

1311
## Matches the right selector and declaration block

Diff for: .grit/patterns/go/channel_guarded_with_mutex.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ Detected a channel guarded with a `mutex`. Channels already have an internal `mu
1313
language go
1414
1515
`{ $body } ` where {
16-
$body <: contains `$channel := make(chan $dataType)`,
17-
$body <: contains `var $mutax sync.Mutex` => .,
18-
$body <: contains `$mutax.Lock()` => .,
19-
$body <: contains `$mutax.Unlock()` => .,
16+
$body <: contains `$channel := make(chan $dataType)`,
17+
$body <: contains `var $mutax sync.Mutex` => .,
18+
$body <: contains `$mutax.Lock()` => .,
19+
$body <: contains `$mutax.Unlock()` => .
2020
}
2121
```
2222

Diff for: .grit/patterns/go/cloudflare_go_v2.md

+623-623
Large diffs are not rendered by default.

Diff for: .grit/patterns/go/common.grit

+4-12
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,10 @@
11
language go
22

33
// All core stdlib functions can be done here
4-
private pattern before_each_file_stdlib() {
5-
before_each_file_prep_imports()
6-
}
4+
private pattern before_each_file_stdlib() { before_each_file_prep_imports() }
75

8-
private pattern after_each_file_stdlib() {
9-
after_each_file_handle_imports()
10-
}
6+
private pattern after_each_file_stdlib() { after_each_file_handle_imports() }
117

12-
pattern before_each_file() {
13-
before_each_file_stdlib()
14-
}
8+
pattern before_each_file() { before_each_file_stdlib() }
159

16-
pattern after_each_file() {
17-
after_each_file_stdlib()
18-
}
10+
pattern after_each_file() { after_each_file_stdlib() }

Diff for: .grit/patterns/go/exported_loop_pointer.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ tags: [fix, correctness]
1414
language go
1515
1616
`for _, $val := range $values { $body }` where {
17-
$body <: not contains `$val := $val`,
18-
$body <: contains `&$val`
17+
$body <: not contains `$val := $val`,
18+
$body <: contains `&$val`
1919
} => `for _, $val := range $values {
2020
$val := $val \n $body
2121
}`

Diff for: .grit/patterns/go/go_importing.md

+12-12
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@ engine marzano(0.1)
1111
language go
1212
1313
contains bubble or {
14-
`use_real_getenv()` where {
15-
$os = require_import(source="somepackage/somemodule")
16-
} => `$os.Getenv()`,
17-
`second_case()` where {
18-
$case_two = require_import(source="somepackage/somemodule")
19-
} => `$case_two.CaseTwo()`,
20-
`module_two()` where {
21-
$module = require_import(source="somepackage/packagetwo")
22-
} => `$module.ModuleTwo()`,
23-
`add_aliased_import()` where {
24-
$alias = require_import(source="somepackage/my-model", as="model")
25-
} => `$alias.my_import()`
14+
`use_real_getenv()` where {
15+
$os = require_import(source="somepackage/somemodule")
16+
} => `$os.Getenv()`,
17+
`second_case()` where {
18+
$case_two = require_import(source="somepackage/somemodule")
19+
} => `$case_two.CaseTwo()`,
20+
`module_two()` where {
21+
$module = require_import(source="somepackage/packagetwo")
22+
} => `$module.ModuleTwo()`,
23+
`add_aliased_import()` where {
24+
$alias = require_import(source="somepackage/my-model", as="model")
25+
} => `$alias.my_import()`
2626
}
2727
```
2828

Diff for: .grit/patterns/go/go_imports.grit

+52-57
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,68 @@
11
language go
22

33
pattern before_each_file_prep_imports() {
4-
$_ where {
5-
// Array of global imports. Each import is a tuple of (source, as)
6-
$GLOBAL_NEW_IMPORTS = [],
7-
}
4+
$_ where {
5+
// Array of global imports. Each import is a tuple of (source, as)
6+
$GLOBAL_NEW_IMPORTS = []
7+
}
88
}
99

1010
// Handle inserting imports if we accumulated any
1111
pattern after_each_file_handle_imports() {
12-
$_ where {
13-
if ($GLOBAL_NEW_IMPORTS <: not []) {
14-
$program <: or {
15-
contains import_declaration(imports=$list) as $outer where {
16-
$list <: or {
17-
import_spec_list(imports=$imports) where {
18-
$GLOBAL_NEW_IMPORTS <: some bubble($imports) $import where {
19-
$imports += `"$import"`,
20-
}
21-
},
22-
import_spec() where {
23-
$GLOBAL_NEW_IMPORTS <: some bubble($outer) $import where {
24-
$outer += `\nimport "$import"`,
25-
}
26-
}
27-
},
28-
},
29-
contains package_clause() as $anchor where {
30-
$GLOBAL_NEW_IMPORTS <: some bubble($anchor) $import where {
31-
$anchor += `\nimport "$import"`,
32-
}
33-
}
34-
}
35-
}
36-
}
12+
$_ where {
13+
if ($GLOBAL_NEW_IMPORTS <: not []) {
14+
$program <: or {
15+
contains import_declaration(imports=$list) as $outer where {
16+
$list <: or {
17+
import_spec_list(imports=$imports) where {
18+
$GLOBAL_NEW_IMPORTS <: some bubble($imports) $import where {
19+
$imports += `"$import"`
20+
}
21+
},
22+
import_spec() where {
23+
$GLOBAL_NEW_IMPORTS <: some bubble($outer) $import where {
24+
$outer += `\nimport "$import"`
25+
}
26+
}
27+
}
28+
},
29+
contains package_clause() as $anchor where {
30+
$GLOBAL_NEW_IMPORTS <: some bubble($anchor) $import where {
31+
$anchor += `\nimport "$import"`
32+
}
33+
}
34+
}
35+
}
36+
}
3737
}
3838

3939
function require_import($source, $as) {
40-
// Default condition
41-
$split_source = split($source, "/"),
42-
if ($as <: undefined) {
43-
$name_to_use = $split_source[-1],
44-
} else {
45-
$name_to_use = $as,
46-
},
47-
or {
48-
$program <: contains bubble($source, $name_to_use) import_spec($name, path=$path) where {
49-
$path <: contains $source,
50-
if ($name <: not .) {
51-
$name_to_use=$name,
52-
}
53-
},
54-
// $GLOBAL_NEW_IMPORTS <: some bubble($source) `$import` where $import <: $source,
55-
$GLOBAL_NEW_IMPORTS += $source
56-
},
57-
return $name_to_use
40+
// Default condition
41+
$split_source = split($source, "/"),
42+
if ($as <: undefined) { $name_to_use = $split_source[-1] } else {
43+
$name_to_use = $as
44+
},
45+
or {
46+
$program <: contains bubble($source, $name_to_use) import_spec($name, path=$path) where {
47+
$path <: contains $source,
48+
if ($name <: not .) { $name_to_use = $name }
49+
},
50+
// $GLOBAL_NEW_IMPORTS <: some bubble($source) `$import` where $import <: $source,
51+
$GLOBAL_NEW_IMPORTS += $source
52+
},
53+
return $name_to_use
5854
}
5955

6056
pattern import_of($source) {
61-
import_declaration(imports=import_spec_list(imports=$mod)) where {
62-
$mod <: not contains $source,
63-
$mod += $source
64-
}
57+
import_declaration(imports=import_spec_list(imports=$mod)) where {
58+
$mod <: not contains $source,
59+
$mod += $source
60+
}
6561
}
6662

67-
6863
pattern ensure_import($source) {
69-
import_declaration(imports=import_spec_list(imports=$mod)) where {
70-
$mod <: not contains $source,
71-
$mod += $source
72-
}
73-
}
64+
import_declaration(imports=import_spec_list(imports=$mod)) where {
65+
$mod <: not contains $source,
66+
$mod += $source
67+
}
68+
}

Diff for: .grit/patterns/go/hidden_goroutine.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ Function invocations are expected to synchronous, and this function will execute
99
language go
1010
1111
file($name, $body) where {
12-
$body <: contains `func $func() { go func() { $funcBody }() }` as $hiddenFunc => `func $func() {
12+
$body <: contains `func $func() { go func() { $funcBody }() }` as $hiddenFunc => `func $func() {
1313
$funcBody
1414
}`,
15-
$body <: maybe contains `func main(){ $mainBody }` where {
16-
$mainBody <: contains `$func()` => `go $func()`
17-
}
15+
$body <: maybe contains `func main(){ $mainBody }` where {
16+
$mainBody <: contains `$func()` => `go $func()`
17+
}
1818
}
1919
```
2020

Diff for: .grit/patterns/go/mux_go_v5.md

+20-25
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ The Go SDK has been rewritten for v5 and contains significant changes.
99
language go
1010
1111
pattern fix_api_client() {
12-
`$muxgo.NewAPIClient($cfg)` where {
13-
$cfg <: contains `muxgo.NewConfiguration($opts)`,
14-
$muxoption = require_import(source=`github.com/muxinc/mux-go/muxoption`),
15-
$opts <: some bubble($muxgo, $muxoption) or {
16-
`$muxgo.WithBasicAuth($a, $b)` => `$muxoption.WithTokenID($a), $muxoption.WithTokenSecret($b)`
17-
}
18-
} => `mux.NewClient($opts)`
12+
`$muxgo.NewAPIClient($cfg)` where {
13+
$cfg <: contains `muxgo.NewConfiguration($opts)`,
14+
$muxoption = require_import(source=`github.com/muxinc/mux-go/muxoption`),
15+
$opts <: some bubble($muxgo, $muxoption) or {
16+
`$muxgo.WithBasicAuth($a, $b)` => `$muxoption.WithTokenID($a), $muxoption.WithTokenSecret($b)`
17+
}
18+
} => `mux.NewClient($opts)`
1919
}
2020
2121
private pattern wrap_mux_fields() {
@@ -33,21 +33,19 @@ private pattern wrap_mux_fields() {
3333
pattern rename_params() {
3434
or {
3535
`$muxgo.ListDimensionValuesParams{$params}` where {
36-
$data = require_import(source=`github.com/muxinc/mux-go/data`),
36+
$data = require_import(source=`github.com/muxinc/mux-go/data`)
3737
} => `$data.DimensionListValuesParams{$params}`,
3838
`$muxgo.CreateAssetRequest{$params}` where {
39-
$video = require_import(source=`github.com/muxinc/mux-go/video`),
40-
} => `$video.AssetNewParams{$params}`,
41-
} where {
42-
$params <: maybe wrap_mux_fields(),
43-
}
39+
$video = require_import(source=`github.com/muxinc/mux-go/video`)
40+
} => `$video.AssetNewParams{$params}`
41+
} where { $params <: maybe wrap_mux_fields() }
4442
}
4543
4644
pattern final_mux_renames() {
4745
or {
48-
`[]$muxgo.InputSettings{$params}` where {
46+
`[]$muxgo.InputSettings{$params}` where {}
4947
// $video = require_import(source=`github.com/muxinc/mux-go/video`),
50-
} => `[]video.AssetNewParamsInput{$params}`,
48+
=> `[]video.AssetNewParamsInput{$params}`
5149
}
5250
}
5351
@@ -57,25 +55,22 @@ pattern fix_api_calls() {
5755
$call <: or {
5856
`$client.DimensionsApi.ListDimensions` => `$client.Data.Dimensions.List`,
5957
`$client.DimensionsApi.ListDimensionValues` => `$client.Data.Dimensions.ListValues`,
60-
`$client.AssetsApi.CreateAsset` => `$client.Video.Assets.New`,
58+
`$client.AssetsApi.CreateAsset` => `$client.Video.Assets.New`
6159
},
6260
$ctx = require_import(source=`context`),
63-
if ($args <: .) {
64-
$overall => `$call($ctx.TODO())`
65-
} else {
61+
if ($args <: .) { $overall => `$call($ctx.TODO())` } else {
6662
$overall => `$call($ctx.TODO(), $args)`
6763
}
6864
}
6965
}
7066
71-
7267
sequential {
7368
bubble file($name, $body) where {
74-
$body <: contains or {
75-
fix_api_client(),
76-
fix_api_calls(),
77-
rename_params(),
78-
}
69+
$body <: contains or {
70+
fix_api_client(),
71+
fix_api_calls(),
72+
rename_params()
73+
}
7974
},
8075
maybe bubble file($name, $body) where $body <: contains final_mux_renames()
8176
}

Diff for: .grit/patterns/go/no_unnecessary_conditionals.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ language go
1111
1212
or {
1313
`if(false){ $body }` => .,
14-
`if(true){ $body }` => $body
14+
`if(true){ $body }` => $body
1515
}
1616
```
1717

@@ -74,4 +74,4 @@ func mainFunc() {
7474
var y = "hello";
7575

7676
}
77-
```
77+
```

Diff for: .grit/patterns/go/path_to_filepath.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ Utilize `filepath.Join(...)` instead of `path.Join(...)` as it accommodates OS-s
1515
language go
1616
1717
or {
18-
`path.Join($params)` => `filepath.Join($params)`,
19-
ensure_import(`"path/filepath"`)
18+
`path.Join($params)` => `filepath.Join($params)`,
19+
ensure_import(`"path/filepath"`)
2020
}
2121
```
2222

Diff for: .grit/patterns/go/useless_if_else_body.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ Identical statements found in both the `if` and `else` bodies of an `if-statemen
99
language go
1010
1111
or {
12-
`if ($conditon) { $body } else { $body }`,
13-
`if ($conditon) { $body } else if ($conditon) { $body }`
12+
`if ($conditon) { $body } else { $body }`,
13+
`if ($conditon) { $body } else if ($conditon) { $body }`
1414
} => `if ($conditon) {
1515
$body
1616
}`

Diff for: .grit/patterns/java/correct_false_comparison_operator.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ Assignment inside a condition like this `$x = false` is usually accidental, this
99
language java
1010
1111
`$var = false` => `$var == false` where {
12-
$var <: within `if ($cond) { $body }`,
13-
$var <: within $cond,
14-
}
12+
$var <: within `if ($cond) { $body }` ,
13+
$var <: within $cond
14+
}
1515
```
1616

1717
## $x = true
@@ -36,4 +36,4 @@ class Bar {
3636
}
3737
}
3838
}
39-
```
39+
```

0 commit comments

Comments
 (0)