Skip to content

Commit

Permalink
Technical/Increase project code quality
Browse files Browse the repository at this point in the history
* Added, configured cspell
* Added, configured markdownlint
* Added, configured shellcheck
* Added, configured yamllint
* Updated, refactored circleci config
* Fixed linters issues through all codebase
  • Loading branch information
bestwebua committed Dec 26, 2022
1 parent 4bc3cb4 commit bad6fc6
Show file tree
Hide file tree
Showing 13 changed files with 157 additions and 15 deletions.
52 changes: 45 additions & 7 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,43 @@
---

version: 2.1

defaults: &defaults
working_directory: ~/truemail-go
docker:
- image: cimg/go:1.19

jobs:
linters:
docker:
- image: golangci/golangci-lint:v1.50.1-alpine

steps:
- checkout
- run: golangci-lint run

test:
docker:
- image: cimg/go:1.19.3
working_directory: ~/truemail-go
- run:
name: Installing linters
command: |
apk add --update npm shellcheck yamllint
npm install --global --save-dev git+https://github.com/streetsidesoftware/cspell-cli markdownlint-cli lefthook
cp .circleci/linter_configs/.lefthook.yml lefthook.yml
- run:
name: Running linters
command: lefthook run linters

tests:
<<: *defaults

steps:
- checkout

- run:
name: Running tests with Gotestsum
name: Installing Gotestsum
command: go get gotest.tools/gotestsum

- run:
name: Running tests
command: gotestsum --format standard-verbose -- -coverprofile=coverage_report ./...

- run:
Expand All @@ -41,8 +62,25 @@ jobs:
command: |
bash <(curl -s https://codecov.io/bash) -f coverage_report
release:
<<: *defaults

steps:
- checkout

- run:
name: Publishing new release to Go Packages
command: |
./.circleci/scripts/release.sh
workflows:
build:
jobs:
- linters
- test
- tests
- release:
filters:
branches:
ignore: /.*/
tags:
only: /v[0-9]+(\.[0-9]+)*(-.*)*/
33 changes: 33 additions & 0 deletions .circleci/linter_configs/.cspell.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---

enableGlobDot: true

patterns:
- name: GithubUser
pattern: /\[@.+\]/gmx
- name: MarkdownCode
pattern: /`{1,3}.+`{1,3}/gmx
- name: MarkdownCodeBlock
pattern: /^\s*```[\s\S]*?^\s*```/gmx

languageSettings:
- languageId: markdown
ignoreRegExpList:
- Email
- GithubUser
- MarkdownCode
- MarkdownCodeBlock

words:
- Codecov
- Unmarshal
- Trotsenko
- Vladislav
- bestwebua
- codebases
- consts
- dockerized
- struct
- substeps
- truemail
- unexported
2 changes: 2 additions & 0 deletions .golangci.yml → .circleci/linter_configs/.golangci.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
---

linters:
enable:
- gocyclo
Expand Down
19 changes: 19 additions & 0 deletions .circleci/linter_configs/.lefthook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---

no_tty: true
skip_output:
- meta

linters:
commands:
cspell:
run: cspell-cli lint -c '.circleci/linter_configs/.cspell.yml' '**/*.{txt,md}'
golangci:
run: golangci-lint -c '.circleci/linter_configs/.golangci.yml' run
markdownlint:
run: markdownlint -c '.circleci/linter_configs/.markdownlint.yml' '**/*.md'
shellcheck:
glob: '*.{sh}'
run: shellcheck --norc {all_files}
yamllint:
run: yamllint -c '.circleci/linter_configs/.yamllint.yml' .
9 changes: 9 additions & 0 deletions .circleci/linter_configs/.markdownlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---

default: true

MD013:
line_length: 500

MD024:
siblings_only: true
7 changes: 7 additions & 0 deletions .circleci/linter_configs/.yamllint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---

extends: default

rules:
line-length:
max: 200
13 changes: 13 additions & 0 deletions .circleci/scripts/release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/sh
set -e

latest_tag() {
git tag -l | grep -E "^v[0-9]+\.[0-9]+\.[0-9]+" | cut -d"-" -f 1 | sort | tail -n 1
}

publish_release() {
echo "Triggering pkg.go.dev about new truemail-go release..."
curl -X POST "https://pkg.go.dev/fetch/github.com/truemail-rb/truemail-go@$(latest_tag)"
}

publish_release
6 changes: 3 additions & 3 deletions .github/BRANCH_NAMING_CONVENTION.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ bugfix/fix-some-bug-name

### Squash commits

Please squash all branch commits into the one before openning your PR from your fork. It's simple to do with the git:
Please squash all branch commits into the one before opening your PR from your fork. It's simple to do with the git:

```bash
git rebase -i [hash your first commit of your branch]~1
Expand All @@ -25,9 +25,9 @@ git rebase -i 6467fe36232401fa740af067cfd8ac9ec932fed2~1 # example

### Add commit description

Please complete your commit description folowing next pattern:
Please complete your commit description following next pattern:

```
```code
Technical/Add info files # should be the same name as your branch name
* Added license, changelog, contributing, code of conduct docs
Expand Down
2 changes: 2 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
---

github: [bestwebua]
21 changes: 20 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,25 @@

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.0.3] - 2022-12-26

### Added

- Added [`cspell`](https://cspell.org) linter
- Added [`markdownlint`](https://github.com/DavidAnson/markdownlint) linter
- Added [`shellcheck`](https://www.shellcheck.net) linter
- Added [`yamllint`](https://yamllint.readthedocs.io) linter
- Added [`lefthook`](https://github.com/evilmartians/lefthook) linters aggregator

### Fixed

- Fixed typos in project's codebase
- Fixed new project's linter issues

### Updated

- Updated `CircleCI` config

## [1.0.2] - 2022-11-20

- Updated dependencies
Expand Down Expand Up @@ -32,7 +51,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
### Updated

- Updated `ConfigurationAttr#validate`, tests
- Updated golangci config
- Updated `golangci` config
- Updated package documentation

## [0.1.2] - 2022-02-28
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ configuration := truemail.NewConfiguration(
// This parameter uses for SMTP session in SMTP validation layer.
SmtpPort: 2525,

// Optional parameter. This option will provide to use smtp fail fast behaviour. When
// Optional parameter. This option will provide to use smtp fail fast behavior. When
// smtpFailFast = true it means that Truemail ends smtp validation session after first
// attempt on the first mx server in any fail cases (network connection/timeout error,
// smtp validation error). This feature helps to reduce total time of SMTP validation
Expand Down Expand Up @@ -487,7 +487,7 @@ By default, you don't need pass with-parameter to use it. Example of usage is sp

##### SMTP fail fast enabled

Truemail can use fail fast behaviour for SMTP validation layer. When `SmtpFailFast = true` it means that `truemail` ends smtp validation session after first attempt on the first mx server in any fail cases (network connection/timeout error, smtp validation error). This feature helps to reduce total time of SMTP validation session up to 1 second.
Truemail can use fail fast behavior for SMTP validation layer. When `SmtpFailFast = true` it means that `truemail` ends smtp validation session after first attempt on the first mx server in any fail cases (network connection/timeout error, smtp validation error). This feature helps to reduce total time of SMTP validation session up to 1 second.

```go
import "github.com/truemail-rb/truemail-go"
Expand Down
2 changes: 1 addition & 1 deletion dns_resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func TestDnsResolverCnameRecord(t *testing.T) {

t.Run("when target CNAME record found", func(t *testing.T) {
otherDomain := randomDomain()
dnsRecords := map[string]mockdns.Zone{domain: {CNAME: toDnsHostName(otherDomain)}} // TODO: different go-mockdns behaviour for domain key, should be with dot
dnsRecords := map[string]mockdns.Zone{domain: {CNAME: toDnsHostName(otherDomain)}} // TODO: different go-mockdns behavior for domain key, should be with dot
dnsResolver := createDnsResolver(dnsRecords)
resolvedHostName, err := dnsResolver.cnameRecord(domain)

Expand Down
2 changes: 1 addition & 1 deletion validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func (validatorResult *validatorResult) addError(key, value string) {
validatorResult.Errors[key] = value
}

// Structure with behaviour. Responsible for the
// Structure with behavior. Responsible for the
// logic of calling the validation layers sequence
type validator struct {
result *validatorResult
Expand Down

0 comments on commit bad6fc6

Please sign in to comment.