GoogleCloudPlatform / security-response-automation

Take automated actions against threats and vulnerabilities.
Apache License 2.0
209 stars 52 forks source link

Add pre-commit config for the project. #98

Closed kieras closed 4 years ago

kieras commented 4 years ago

Adding pre-commit so everyone could follow the same standards, and avoid some code reviews that can be automated.

Check https://pre-commit.com/#install and https://pre-commit.com/#usage.

kieras commented 4 years ago

Example output if we execute in all files...

Check for added large files..............................................Passed
Check for case conflicts.................................................Passed
Check JSON...............................................................Passed
Check for merge conflicts................................................Passed
Check Toml...........................................(no files to check)Skipped
Check Xml............................................(no files to check)Skipped
Check Yaml...............................................................Passed
Detect Private Key.......................................................Passed
Mixed line ending........................................................Passed
Fix End of Files.........................................................Failed
hookid: end-of-file-fixer

Files were modified by this hook. Additional output:

Fixing CONTRIBUTING.md
Fixing providers/etd/protos/etd.proto
Fixing LICENSE

Trim Trailing Whitespace.................................................Failed
hookid: trailing-whitespace

Files were modified by this hook. Additional output:

Fixing providers/sha/protos/sha.proto
Fixing README.md
Fixing providers/etd/protos/etd.proto

go fmt...................................................................Passed
go lint..................................................................Passed
go imports...............................................................Failed
hookid: go-imports

Files were modified by this hook. Additional output:

entities/email.go
clients/sendgrid.go
entities/email_test.go

go-cyclo.................................................................Passed
validate toml........................................(no files to check)Skipped
Check files aren't using go's testing package........(no files to check)Skipped
golangci-lint............................................................Failed
hookid: golangci-lint

clients/virustotal.go:65:35: Error return value of `(*encoding/json.Decoder).Decode` is not checked (errcheck)
    json.NewDecoder(resp.Body).Decode(&dr)
                                     ^
clients/stubs/storage.go:26:2: `service` is unused (structcheck)
    service              *storage.Client
    ^
entities/finding.go:53:6: `badNetworkFinding` is unused (deadcode)
type badNetworkFinding struct {
     ^
cloudfunctions/gce/createsnapshot/createsnapshot.go:36:2: `maxLabelLength` is unused (deadcode)
    maxLabelLength = 60
    ^
cloudfunctions/cloud-sql/removepublic/removepublic_test.go:131:3: U1000: field `finding` is unused (unused)
        finding                 pubsub.Message
        ^
cloudfunctions/cloud-sql/requiressl/requiressl_test.go:130:3: U1000: field `finding` is unused (unused)
        finding         pubsub.Message
        ^
cloudfunctions/gce/openfirewall/openfirewall_test.go:139:3: U1000: field `finding` is unused (unused)
        finding           pubsub.Message
        ^
cloudfunctions/gcs/closebucket/closebucket_test.go:144:3: U1000: field `expectedError` is unused (unused)
        expectedError  string
        ^
entities/cloudsql_test.go:30:3: U1000: const `projectID` is unused (unused)
        projectID = "project1"
        ^
entities/cloudsql_test.go:31:3: U1000: const `region` is unused (unused)
        region    = "us-central1"
        ^

go-unit-tests............................................................Passed
go-build.................................................................Passed
Terraform fmt............................................................Passed
Terraform docs...........................................................Passed
kieras commented 4 years ago

If necessary, pre-commits can be skipped by doing: git commit -n or git commit --no-verify

tomscript commented 4 years ago

WHOA! this is amazing!

i wonder if we can also explore having something in platform with github? like whenever you push it does a similar check