Skip to content

Commit

Permalink
Update lint-staged scripts (#321)
Browse files Browse the repository at this point in the history
* update lint-staged scripts

* update lint-staged

* force prettier to run against whole repo

* add .prettierignore

* add .idea to prettierignore

* remove trailing slash

* alter mage fmt to run prettier on entire project

* prettier changes on yml files

* update .prettierignore

* Revert "prettier changes on yml files"

This reverts commit 60a3dde.

* ignore prettier for all /testdata/

* prettier changes
  • Loading branch information
Aggelos Arvanitakis authored Mar 6, 2020
1 parent 2079427 commit e2dc727
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 122 deletions.
22 changes: 22 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# General
.git
.idea
.setup
keys

# Deps
venv
node_modules

# Service artifacts
out

# Web artifacts
web/dist

# Docs
docs/gitbook


# Direct file content assertion
tools/**/testdata
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Resources:
Version: 2012-10-17
Statement:
- Effect: Allow
Action: # permissions which can't be restricted to specific resources
Action: # permissions which can't be restricted to specific resources
- acm:*
- apigateway:*
- appsync:*
Expand Down Expand Up @@ -143,4 +143,4 @@ Resources:
Resource: !Sub arn:${AWS::Partition}:sns:${AWS::Region}:${AWS::AccountId}:panther-*
- Effect: Allow
Action: sqs:*
Resource: !Sub arn:${AWS::Partition}:sqs:${AWS::Region}:${AWS::AccountId}:panther-*
Resource: !Sub arn:${AWS::Partition}:sqs:${AWS::Region}:${AWS::AccountId}:panther-*
Original file line number Diff line number Diff line change
@@ -1,79 +1,75 @@
{
"eventVersion": "1.05",
"userIdentity": {
"type": "AssumedRole",
"principalId": "AROA4PIQ2YYOGH2G27YIM:nicholas_hakmiller",
"arn": "arn:aws:sts::857418155548:assumed-role/PantherDevNickAdministrator/nicholas_hakmiller",
"eventVersion": "1.05",
"userIdentity": {
"type": "AssumedRole",
"principalId": "AROA4PIQ2YYOGH2G27YIM:nicholas_hakmiller",
"arn": "arn:aws:sts::857418155548:assumed-role/PantherDevNickAdministrator/nicholas_hakmiller",
"accountId": "857418155548",
"accessKeyId": "ASIA4PIQ2YYODXL3QAZ3",
"sessionContext": {
"sessionIssuer": {
"type": "Role",
"principalId": "AROA4PIQ2YYOGH2G27YIM",
"arn": "arn:aws:iam::857418155548:role/PantherDevNickAdministrator",
"accountId": "857418155548",
"accessKeyId": "ASIA4PIQ2YYODXL3QAZ3",
"sessionContext": {
"sessionIssuer": {
"type": "Role",
"principalId": "AROA4PIQ2YYOGH2G27YIM",
"arn": "arn:aws:iam::857418155548:role/PantherDevNickAdministrator",
"accountId": "857418155548",
"userName": "PantherDevNickAdministrator"
},
"webIdFederationData": {},
"attributes": {
"mfaAuthenticated": "true",
"creationDate": "2019-08-27T20:07:51Z"
}
}
},
"eventTime": "2019-08-27T20:27:51Z",
"eventSource": "cloudtrail.amazonaws.com",
"eventName": "PutEventSelectors",
"awsRegion": "us-west-2",
"sourceIPAddress": "71.198.154.250",
"userAgent": "console.amazonaws.com",
"requestParameters": {
"trailName": "arn:aws:cloudtrail:us-west-2:857418155548:trail/cloudtrail-public-s3",
"eventSelectors": [
{
"readWriteType": "ReadOnly",
"includeManagementEvents": true,
"dataResources": []
},
{
"readWriteType": "All",
"includeManagementEvents": false,
"dataResources": [
{
"type": "AWS::S3::Object",
"values": [
"arn:aws:s3:::s3-polling-test-bucket/"
]
}
]
}
"userName": "PantherDevNickAdministrator"
},
"webIdFederationData": {},
"attributes": {
"mfaAuthenticated": "true",
"creationDate": "2019-08-27T20:07:51Z"
}
}
},
"eventTime": "2019-08-27T20:27:51Z",
"eventSource": "cloudtrail.amazonaws.com",
"eventName": "PutEventSelectors",
"awsRegion": "us-west-2",
"sourceIPAddress": "71.198.154.250",
"userAgent": "console.amazonaws.com",
"requestParameters": {
"trailName": "arn:aws:cloudtrail:us-west-2:857418155548:trail/cloudtrail-public-s3",
"eventSelectors": [
{
"readWriteType": "ReadOnly",
"includeManagementEvents": true,
"dataResources": []
},
{
"readWriteType": "All",
"includeManagementEvents": false,
"dataResources": [
{
"type": "AWS::S3::Object",
"values": ["arn:aws:s3:::s3-polling-test-bucket/"]
}
]
},
"responseElements": {
"trailARN": "arn:aws:cloudtrail:us-west-2:857418155548:trail/cloudtrail-public-s3",
"eventSelectors": [
{
"readWriteType": "ReadOnly",
"includeManagementEvents": true,
"dataResources": []
},
{
"readWriteType": "All",
"includeManagementEvents": false,
"dataResources": [
{
"type": "AWS::S3::Object",
"values": [
"arn:aws:s3:::s3-polling-test-bucket/"
]
}
]
}
}
]
},
"responseElements": {
"trailARN": "arn:aws:cloudtrail:us-west-2:857418155548:trail/cloudtrail-public-s3",
"eventSelectors": [
{
"readWriteType": "ReadOnly",
"includeManagementEvents": true,
"dataResources": []
},
{
"readWriteType": "All",
"includeManagementEvents": false,
"dataResources": [
{
"type": "AWS::S3::Object",
"values": ["arn:aws:s3:::s3-polling-test-bucket/"]
}
]
},
"requestID": "8c23b35f-befd-4bef-ada7-65979032e589",
"eventID": "5ce81ddc-351e-4e5f-bbc6-75be5db63eed",
"readOnly": false,
"eventType": "AwsApiCall",
"recipientAccountId": "857418155548"
}
]
},
"requestID": "8c23b35f-befd-4bef-ada7-65979032e589",
"eventID": "5ce81ddc-351e-4e5f-bbc6-75be5db63eed",
"readOnly": false,
"eventType": "AwsApiCall",
"recipientAccountId": "857418155548"
}
50 changes: 24 additions & 26 deletions internal/core/analysis_api/main/test_policies/always_true.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
{
"ActionDelaySeconds": 10,
"AnalysisType": "policy",
"AutoRemediationID": "fix-it",
"AutoRemediationParameters": {
"hello": "goodbye"
},
"Description": "Matches every resource",
"DisplayName": "AlwaysTrue",
"Enabled": true,
"Filename": "always_true.py",
"PolicyID": "Test:Policy:JSON",
"ResourceTypes": [
"AWS.S3.Bucket"
],
"Severity": "Medium",
"Tags": [],
"Tests": [
{
"ExpectedResult": true,
"Name": "This will be True",
"Resource": {
"Bucket": "empty"
},
"ResourceType": "AWS.S3.Bucket"
}
]
"ActionDelaySeconds": 10,
"AnalysisType": "policy",
"AutoRemediationID": "fix-it",
"AutoRemediationParameters": {
"hello": "goodbye"
},
"Description": "Matches every resource",
"DisplayName": "AlwaysTrue",
"Enabled": true,
"Filename": "always_true.py",
"PolicyID": "Test:Policy:JSON",
"ResourceTypes": ["AWS.S3.Bucket"],
"Severity": "Medium",
"Tags": [],
"Tests": [
{
"ExpectedResult": true,
"Name": "This will be True",
"Resource": {
"Bucket": "empty"
},
"ResourceType": "AWS.S3.Bucket"
}
]
}
11 changes: 3 additions & 8 deletions lint-staged.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,9 @@ module.exports = {
*/

/*
* Run prettier on:
* 1. All JSON/YAML inside the /web dir
* 2. All JSON/YAML found in the root project dir
* 3. All TS, JS and Markdown files found anywhere in the project
* Run prettier TS, JS, JSON, YAML and Markdown files found anywhere in the project
*/
'web/**/*.{json,yml}': ['prettier --write', 'git add'],
'./*.{json,yml}': ['prettier --write', 'git add'],
'*.{ts,tsx,js,md}': ['prettier --write', 'git add'],
'*.{ts,tsx,js,md,yaml,yml,json}': ['prettier --write', 'git add'],

/*
* Run ESLint checks for all TS & JS files found anywhere in hte project
Expand All @@ -40,5 +35,5 @@ module.exports = {
/*
* only run the TS compiler when there are changes inTS files
*/
'**/*.ts?(x)': () => 'tsc -p .',
'*.ts?(x)': () => 'tsc -p .',
};
15 changes: 3 additions & 12 deletions tools/mage/fmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,14 @@ func Fmt() {
logger.Fatalf("failed to format python: %v", err)
}

// prettier (cloudformation)
// prettier
logger.Info("fmt: prettier")
args = []string{"--write", "deployments/**.yml"}
args = []string{"--write", "**/*.{ts,js,tsx,md,json,yaml,yml}"}
if !mg.Verbose() {
args = append(args, "--loglevel", "error")
}
if err := sh.Run(nodePath("prettier"), args...); err != nil {
logger.Fatalf("failed to format deployments/**.yml: %v", err)
}

// prettier (web)
args = []string{"--write", "{web/src/**,web/__generated__,.}/*.{ts,js,tsx,md,json,yml}"}
if !mg.Verbose() {
args = append(args, "--loglevel", "error")
}
if err := sh.Run(nodePath("prettier"), args...); err != nil {
logger.Fatalf("failed to format {web/src/**,.}: %v", err)
logger.Fatalf("failed to format with prettier: %v", err)
}

// Generate documentation
Expand Down

0 comments on commit e2dc727

Please sign in to comment.