Skip to content

Commit

Permalink
#patch: add linting
Browse files Browse the repository at this point in the history
  • Loading branch information
circa10a committed Feb 21, 2021
1 parent a67c3e0 commit 622f303
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
with:
version: v1.33
version: v1.37.1
41 changes: 41 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
linters:
enable:
- bodyclose
- cyclop
- deadcode
- depguard
- dogsled
- dupl
- errcheck
- errorlint
- exhaustive
- exportloopref
- forbidigo
- funlen
- goconst
- gocritic
- gocyclo
- gofmt
- goimports
- golint
- gomnd
- goprintffuncname
- gosec
- gosimple
- govet
- ineffassign
- interfacer
- lll
- misspell
- nakedret
- rowserrcheck
- scopelint
- staticcheck
- structcheck
- stylecheck
- typecheck
- unconvert
- unparam
- unused
- varcheck
- whitespace
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ clean:
$(GOCMD) clean
rm -rf $(BINARY) bin/

lint:
golangci-lint run -v

release: clean compile package

docker-build:
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func mainExec() error {
providers := providers.GetProviders()

if len(providers) == 0 {
return errors.New("No providers enabled. See configuration.")
return errors.New("no providers enabled. see configuration")
}
for _, p := range providers {
log.Info(fmt.Sprintf("[%v] Provider registered", p.GetName()))
Expand Down
2 changes: 1 addition & 1 deletion news/announcements.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func Yesterday() (Announcements, error) {
// Output: Jan 7, 2020
// parseDate Extracts a standarized date format from the AWS html document.
func parseDate(postDate string) string {
r, _ := regexp.Compile(`[A-Z][a-z]{2}\s[0-9]{1,2},\s[0-9]{4}`)
r := regexp.MustCompile(`[A-Z][a-z]{2}\s[0-9]{1,2},\s[0-9]{4}`)
// AWS sometimes doesn't have a post date
if len(r.FindStringSubmatch(postDate)) > 0 {
return r.FindStringSubmatch(postDate)[0]
Expand Down
6 changes: 6 additions & 0 deletions news/examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func ExampleThisMonth() {
// Handle error
}
for _, n := range news {
//nolint
fmt.Println(n.Title)
}
}
Expand All @@ -33,6 +34,7 @@ func ExampleToday() {
if err != nil {
// Handle error
}
//nolint
fmt.Println(news)
}

Expand All @@ -41,6 +43,7 @@ func ExampleYesterday() {
if err != nil {
// Handle error
}
//nolint
fmt.Println(news)
}

Expand All @@ -62,6 +65,7 @@ func (a Announcements) ExampleJSON() {
if jsonErr != nil {
// Handle error
}
//nolint
fmt.Println(string(json))
}

Expand All @@ -70,6 +74,7 @@ func (a Announcements) ExampleHTML() {
if err != nil {
// Handle error
}
//nolint
fmt.Println(news.Filter([]string{"S3"}).HTML())
}

Expand All @@ -78,5 +83,6 @@ func (a Announcements) ExampleFilter() {
if err != nil {
// Handle error
}
//nolint
fmt.Println(news.Filter([]string{"S3"}))
}
6 changes: 4 additions & 2 deletions news/newsdoc.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ type newsDoc struct {

// getNewsDocYear Fetches html from AWS depending on the year/month specified.
func getNewsDocYear(year int) (*goquery.Document, error) {
var httpTimeout time.Duration = 10
url := fmt.Sprintf("https://aws.amazon.com/about-aws/whats-new/%d", year)
client := &http.Client{Timeout: 10 * time.Second}
client := &http.Client{Timeout: httpTimeout * time.Second}
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return nil, err
Expand All @@ -36,8 +37,9 @@ func getNewsDocYear(year int) (*goquery.Document, error) {

// getNewsDocMonth Fetches html from AWS depending on the year/month specified.
func getNewsDocMonth(year int, month int) (*goquery.Document, error) {
var httpTimeout time.Duration = 10
url := fmt.Sprintf("https://aws.amazon.com/about-aws/whats-new/%v/%02d/", year, month)
client := &http.Client{Timeout: 10 * time.Second}
client := &http.Client{Timeout: httpTimeout * time.Second}
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return nil, err
Expand Down
4 changes: 4 additions & 0 deletions news/newsdoc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func init() {
defer monthFile.Close()
monthDoc, err := goquery.NewDocumentFromReader(monthFile)
if err != nil {
//nolint
log.Fatal(err)
}
monthTestDoc = monthDoc
Expand Down Expand Up @@ -60,15 +61,18 @@ func TestGetSelectionItems(t *testing.T) {

func TestGetSelectionTitle(t *testing.T) {
news := newsDoc{monthTestDoc}
//nolint
assert.Equal(t, news.getSelectionTitle(news.getSelectionItems().First()), "Amazon EKS Announces Beta Release of Amazon FSx for Lustre CSI Driver")
}

func TestGetSelectionLink(t *testing.T) {
news := newsDoc{monthTestDoc}
//nolint
assert.Equal(t, news.getSelectionItemLink(news.getSelectionItems().First()), "https://aws.amazon.com/about-aws/whats-new/2019/12/amazon-eks-announces-beta-release-amazon-fsx-lustre-csi-driver/")
}

func TestGetSelectionDate(t *testing.T) {
news := newsDoc{monthTestDoc}
//nolint
assert.Equal(t, news.getSelectionItemDate(news.getSelectionItems().First()), "\n Posted On: Dec 23, 2019 \n ")
}
4 changes: 2 additions & 2 deletions providers/discord/discord.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,13 @@ func (p *Provider) post(embeds []Embed) error {

json, err := json.Marshal(payload)
if err != nil {
return fmt.Errorf("[%s] %v", p.GetName(), err)
return fmt.Errorf("[%s] %w", p.GetName(), err)
}

log.Info(fmt.Sprintf("[%v] Firing notification", p.GetName()))
res, err := http.Post(p.WebhookURL, "application/json", bytes.NewBuffer(json))
if err != nil {
return fmt.Errorf("[%v] %v", p.GetName(), err)
return fmt.Errorf("[%v] %w", p.GetName(), err)
}
defer res.Body.Close()

Expand Down
1 change: 0 additions & 1 deletion providers/rocketchat/rocketchat.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ func (*Provider) GetName() string {

// Notify is the function executed to POST to a provider's webhook url.
func (p *Provider) Notify(news news.Announcements) {

var b strings.Builder
for _, v := range news {
b.WriteString(fmt.Sprintf("[%s](%s) - %s\n", v.Title, v.Link, v.PostDate))
Expand Down
1 change: 0 additions & 1 deletion providers/slack/slack.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ func (*Provider) GetName() string {

// Notify is the function executed to POST to a provider's webhook url.
func (p *Provider) Notify(news news.Announcements) {

var b strings.Builder
for _, v := range news {
b.WriteString(fmt.Sprintf("<%s|%s> - %s\n", v.Link, v.Title, v.PostDate))
Expand Down
1 change: 0 additions & 1 deletion providers/smtp/smtp.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ func (*Provider) GetName() string {

// Notify is the function executed to POST to a provider's webhook url.
func (p *Provider) Notify(news news.Announcements) {

m := &email{
addr: fmt.Sprintf("%s:%s", p.Server, p.Port),
from: p.From,
Expand Down

0 comments on commit 622f303

Please sign in to comment.