Skip to content

Commit

Permalink
chore: clean up some patterns for biome compatibility (#247)
Browse files Browse the repository at this point in the history
  • Loading branch information
morgante authored Feb 5, 2025
1 parent 7d6095f commit ae44ae7
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 109 deletions.
5 changes: 0 additions & 5 deletions .grit/patterns/js/es6_arrow_functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ Converts function expressions to ES6 arrow functions, including eliminating the
engine marzano(0.1)
language js
/*
The following pattern transforms JS traditional functions to arrow functions.
To see how it works, follow the tutorial.
*/
or {
// Rewrite traditional functions to arrow functions
or {
Expand Down
23 changes: 11 additions & 12 deletions .grit/patterns/js/serverless_to_spin.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ This pattern converts a serverless function to a spin function designed to run o

Note: the full migration is packaged as a workflow. This is just a subcomponent.


```grit
engine marzano(0.1)
language js
Expand All @@ -16,7 +15,7 @@ predicate insert_statement($statement) {
$program <: or {
contains `export $_` as $old => `$statement\n\n$old`,
contains `"use strict"` as $old => `$old\n\n$statement`,
$program => js"$statement\n\n$program"
$program => `$statement\n\n$program`
}
}
Expand All @@ -26,22 +25,22 @@ pattern spin_fix_response() {
$properties <: contains bubble {
pair($key, $value) where {
$key <: "statusCode",
$key => js"status"
$key => `status`
}
},
},
object() as $obj where {
$obj => js"{
$obj => `{
status: 200,
body: JSON.stringify($obj)
}"
}`
}
}
}
pattern spin_fix_request($event) {
`$event.request.$prop` => `JSON.parse(decoder.decode($event.body)).$prop` where {
insert_statement(statement=js"const decoder = new TextDecoder('utf-8')")
insert_statement(statement=`const decoder = new TextDecoder('utf-8')`)
}
}
Expand All @@ -51,8 +50,8 @@ predicate spin_uses_ts() {
pattern spin_main_fix_handler() {
or {
js"module.exports.$_ = ($args) => { $body }",
js"export const $_ = ($args) => {$body }"
`module.exports.$_ = ($args) => { $body }`,
`export const $_ = ($args) => {$body }`
} as $func where {
$request = `request`,
$args <: or { [$event_arg], [$event_arg, $context, $callback] },
Expand All @@ -73,13 +72,13 @@ pattern spin_main_fix_handler() {
$req_type <: ensure_import_from(source=`"@fermyon/spin-sdk"`),
$res_type = `HttpResponse`,
$res_type <: ensure_import_from(source=`"@fermyon/spin-sdk"`),
$new = js"export async function handleRequest($event: $req_type): Promise<$res_type> {
$new = `export async function handleRequest($event: $req_type): Promise<$res_type> {
$body
}",
}`,
} else {
$new = js"export async function handleRequest($event) {
$new = `export async function handleRequest($event) {
$body
}",
}`,
}
} => $new
}
Expand Down
180 changes: 88 additions & 92 deletions .grit/patterns/json/public_s3_bucket.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ tags: [aws, cloudformation]
Detected public S3 bucket. This policy allows anyone to have some kind of access to the bucket. The exact level of access and types of actions allowed will depend on the configuration of bucket policy and ACLs. Please review the bucket configuration to make sure they are set with intended values.

### references
- [AmazonS3](https://docs.aws.amazon.com/AmazonS3/latest/userguide/access-control-block-public-access.html)

- [AmazonS3](https://docs.aws.amazon.com/AmazonS3/latest/userguide/access-control-block-public-access.html)

```grit
language json
`{ $json }` where {
$json <: contains `"Type": "AWS::S3::Bucket"`,
$json <: contains`"PublicAccessBlockConfiguration": { $config }` where {
$json <: contains `"PublicAccessBlockConfiguration": { $config }` where {
any {
$config <: contains `"RestrictPublicBuckets": false` => `"RestrictPublicBuckets": true`,
$config <: contains `"IgnorePublicAcls": false` => `"IgnorePublicAcls": true`,
Expand All @@ -30,111 +30,107 @@ language json
## Upgrades an existing dependency

```json

{

"Resources": {
"MyBucketF68F3FF0": {
"Type": "AWS::S3::Bucket",
"Properties": {
"BucketEncryption": {
"ServerSideEncryptionConfiguration": [
{
"ServerSideEncryptionByDefault": {
"SSEAlgorithm": "aws:kms"
}
{
"Resources": {
"MyBucketF68F3FF0": {
"Type": "AWS::S3::Bucket",
"Properties": {
"BucketEncryption": {
"ServerSideEncryptionConfiguration": [
{
"ServerSideEncryptionByDefault": {
"SSEAlgorithm": "aws:kms"
}
]
},
// public-s3-bucket
"PublicAccessBlockConfiguration": {
"BlockPublicAcls": false,
"BlockPublicPolicy": true,
"IgnorePublicAcls": false,
"RestrictPublicBuckets": true
}
}
]
},
"UpdateReplacePolicy": "Delete",
"DeletionPolicy": "Delete"
// public-s3-bucket
"PublicAccessBlockConfiguration": {
"BlockPublicAcls": false,
"BlockPublicPolicy": true,
"IgnorePublicAcls": false,
"RestrictPublicBuckets": true
}
},
"MyBucketF68F3FF1": {
"Type": "AWS::S3::Bucket",
"Properties": {
"BucketEncryption": {
"ServerSideEncryptionConfiguration": [
{
"ServerSideEncryptionByDefault": {
"SSEAlgorithm": "aws:kms"
}
"UpdateReplacePolicy": "Delete",
"DeletionPolicy": "Delete"
},
"MyBucketF68F3FF1": {
"Type": "AWS::S3::Bucket",
"Properties": {
"BucketEncryption": {
"ServerSideEncryptionConfiguration": [
{
"ServerSideEncryptionByDefault": {
"SSEAlgorithm": "aws:kms"
}
]
},
// public-s3-bucket
"PublicAccessBlockConfiguration": {
"BlockPublicAcls": true,
"BlockPublicPolicy": true,
"IgnorePublicAcls": true,
"RestrictPublicBuckets": false
}
}
]
},
"UpdateReplacePolicy": "Delete",
"DeletionPolicy": "Delete"
}
// public-s3-bucket
"PublicAccessBlockConfiguration": {
"BlockPublicAcls": true,
"BlockPublicPolicy": true,
"IgnorePublicAcls": true,
"RestrictPublicBuckets": false
}
},
"UpdateReplacePolicy": "Delete",
"DeletionPolicy": "Delete"
}
}
}
```

```json

{

"Resources": {
"MyBucketF68F3FF0": {
"Type": "AWS::S3::Bucket",
"Properties": {
"BucketEncryption": {
"ServerSideEncryptionConfiguration": [
{
"ServerSideEncryptionByDefault": {
"SSEAlgorithm": "aws:kms"
}
{
"Resources": {
"MyBucketF68F3FF0": {
"Type": "AWS::S3::Bucket",
"Properties": {
"BucketEncryption": {
"ServerSideEncryptionConfiguration": [
{
"ServerSideEncryptionByDefault": {
"SSEAlgorithm": "aws:kms"
}
]
},
// public-s3-bucket
"PublicAccessBlockConfiguration": {
"BlockPublicAcls": true,
"BlockPublicPolicy": true,
"IgnorePublicAcls": true,
"RestrictPublicBuckets": true
}
}
]
},
"UpdateReplacePolicy": "Delete",
"DeletionPolicy": "Delete"
// public-s3-bucket
"PublicAccessBlockConfiguration": {
"BlockPublicAcls": true,
"BlockPublicPolicy": true,
"IgnorePublicAcls": true,
"RestrictPublicBuckets": true
}
},
"MyBucketF68F3FF1": {
"Type": "AWS::S3::Bucket",
"Properties": {
"BucketEncryption": {
"ServerSideEncryptionConfiguration": [
{
"ServerSideEncryptionByDefault": {
"SSEAlgorithm": "aws:kms"
}
"UpdateReplacePolicy": "Delete",
"DeletionPolicy": "Delete"
},
"MyBucketF68F3FF1": {
"Type": "AWS::S3::Bucket",
"Properties": {
"BucketEncryption": {
"ServerSideEncryptionConfiguration": [
{
"ServerSideEncryptionByDefault": {
"SSEAlgorithm": "aws:kms"
}
]
},
// public-s3-bucket
"PublicAccessBlockConfiguration": {
"BlockPublicAcls": true,
"BlockPublicPolicy": true,
"IgnorePublicAcls": true,
"RestrictPublicBuckets": true
}
}
]
},
"UpdateReplacePolicy": "Delete",
"DeletionPolicy": "Delete"
}
// public-s3-bucket
"PublicAccessBlockConfiguration": {
"BlockPublicAcls": true,
"BlockPublicPolicy": true,
"IgnorePublicAcls": true,
"RestrictPublicBuckets": true
}
},
"UpdateReplacePolicy": "Delete",
"DeletionPolicy": "Delete"
}
}
}
```

0 comments on commit ae44ae7

Please sign in to comment.