From 6287da6a827d4e7729789ff27309edfa602a7003 Mon Sep 17 00:00:00 2001 From: Vladislav Trotsenko Date: Sun, 11 Dec 2022 19:59:01 +0100 Subject: [PATCH] Technical/Increase project code quality (#98) * Added cspell * Changed mdlrc to markdownlint * Updated lefthook, yamlint configs * Updated rubocop/codeclimate/circleci configs * Fixed linters issues * Updated gemspecs, gem version --- .circleci/config.yml | 31 ++++----- .circleci/gemspecs/latest | 3 +- .circleci/linter_configs/.cspell.yml | 30 ++++++++ .../linter_configs/.lefthook.yml | 17 ++++- .circleci/linter_configs/.markdownlint.yml | 9 +++ .circleci/linter_configs/.mdlrc | 8 --- .circleci/linter_configs/.rubocop.yml | 3 + .circleci/linter_configs/.yamllint.yml | 2 + .circleci/scripts/release.sh | 12 ++-- .../scripts/set_publisher_credentials.sh | 2 +- .codeclimate.yml | 2 +- .github/BRANCH_NAMING_CONVENTION.md | 4 +- .github/FUNDING.yml | 2 + CHANGELOG.md | 69 ++++++++++++------- CONTRIBUTING.md | 2 +- README.md | 2 +- lib/dns_mock/version.rb | 2 +- 17 files changed, 133 insertions(+), 67 deletions(-) create mode 100644 .circleci/linter_configs/.cspell.yml rename lefthook.yml => .circleci/linter_configs/.lefthook.yml (51%) create mode 100644 .circleci/linter_configs/.markdownlint.yml delete mode 100644 .circleci/linter_configs/.mdlrc diff --git a/.circleci/config.yml b/.circleci/config.yml index f334317..f2b1ad6 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -31,19 +31,16 @@ references: paths: - ~/vendor/bundle - install_yamllint: &install_yamllint + install_linters: &install_linters run: - name: Installing Yamllint - command: | - sudo apt-get update -y - sudo apt-get install -y yamllint - - install_lefthook: &install_lefthook - run: - name: Installing Lefthook + name: Installing bunch of linters command: | curl -1sLf 'https://dl.cloudsmith.io/public/evilmartians/lefthook/setup.deb.sh' | sudo -E bash - sudo apt-get install -y lefthook + sudo apt-get update -y + sudo apt-get install -y lefthook shellcheck yamllint + npm install --prefix='~/.local' --global --save-dev git+https://github.com/streetsidesoftware/cspell-cli markdownlint-cli + cp .circleci/linter_configs/.fasterer.yml .fasterer.yml + cp .circleci/linter_configs/.lefthook.yml lefthook.yml install_codeclimate_reporter: &install_codeclimate_reporter run: @@ -77,8 +74,7 @@ jobs: - <<: *restore_bundle_cache - <<: *bundle_install - <<: *save_bundle_cache - - <<: *install_yamllint - - <<: *install_lefthook + - <<: *install_linters - run: name: Running code style linters @@ -86,15 +82,16 @@ jobs: - run: name: Running code performance linters - command: | - cp .circleci/linter_configs/.fasterer.yml .fasterer.yml - lefthook run code-performance-linters - rm .fasterer.yml + command: lefthook run code-performance-linters - run: name: Running code vulnerability linters command: lefthook run code-vulnerability-linters + - run: + name: Running code documentation linters + command: lefthook run code-documentation-linters + tests-ruby: parameters: ruby-version: @@ -177,7 +174,7 @@ workflows: - linters-ruby: matrix: parameters: - ruby-version: ["3.1"] + ruby-version: ["3.1-node"] - tests-ruby: matrix: parameters: diff --git a/.circleci/gemspecs/latest b/.circleci/gemspecs/latest index a69ee66..f1f0171 100644 --- a/.circleci/gemspecs/latest +++ b/.circleci/gemspecs/latest @@ -21,14 +21,13 @@ Gem::Specification.new do |spec| spec.add_development_dependency 'bundler-audit', '~> 0.9.1' spec.add_development_dependency 'fasterer', '~> 0.10.0' spec.add_development_dependency 'ffaker', '~> 2.21' - spec.add_development_dependency 'mdl', '~> 0.12.0' spec.add_development_dependency 'net-ftp', '~> 0.2.0' spec.add_development_dependency 'pry-byebug', '~> 3.10', '>= 3.10.1' spec.add_development_dependency 'rake', '~> 13.0', '>= 13.0.6' spec.add_development_dependency 'reek', '~> 6.1', '>= 6.1.2' spec.add_development_dependency 'rspec', '~> 3.12' spec.add_development_dependency 'rspec-dns', '~> 0.1.8' - spec.add_development_dependency 'rubocop', '~> 1.39' + spec.add_development_dependency 'rubocop', '~> 1.40' spec.add_development_dependency 'rubocop-performance', '~> 1.15', '>= 1.15.1' spec.add_development_dependency 'rubocop-rspec', '~> 2.15' spec.add_development_dependency 'simplecov', '~> 0.21.2' diff --git a/.circleci/linter_configs/.cspell.yml b/.circleci/linter_configs/.cspell.yml new file mode 100644 index 0000000..1b57851 --- /dev/null +++ b/.circleci/linter_configs/.cspell.yml @@ -0,0 +1,30 @@ +--- + +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: + - Commiting + - Punycode + - PORO + - RDNS + - Trotsenko + - Vladislav + - bestwebua + - codebases + - gemspecs diff --git a/lefthook.yml b/.circleci/linter_configs/.lefthook.yml similarity index 51% rename from lefthook.yml rename to .circleci/linter_configs/.lefthook.yml index f43fb86..8eb1581 100644 --- a/lefthook.yml +++ b/.circleci/linter_configs/.lefthook.yml @@ -2,21 +2,32 @@ skip_output: - meta + code-style-linters: commands: - markdownlint: - run: bundle exec mdl . -s './.circleci/linter_configs/.mdlrc' reek: run: bundle exec reek rubocop: run: bundle exec rubocop -c '.circleci/linter_configs/.rubocop.yml' + shellcheck: + glob: '*.{sh}' + run: shellcheck --norc {all_files} yamllint: run: yamllint -c '.circleci/linter_configs/.yamllint.yml' . + code-performance-linters: commands: fasterer: run: bundle exec fasterer + code-vulnerability-linters: commands: bundle-audit: - run: bundle exec bundle-audit check --update -c '.circleci/linter_configs/.bundler-audit.yml' + run: bundle exec bundle-audit check -c '.circleci/linter_configs/.bundler-audit.yml' --update + +code-documentation-linters: + commands: + cspell: + run: cspell-cli lint -c '.circleci/linter_configs/.cspell.yml' '**/*.{txt,md}' + markdownlint: + run: markdownlint -c '.circleci/linter_configs/.markdownlint.yml' '**/*.md' diff --git a/.circleci/linter_configs/.markdownlint.yml b/.circleci/linter_configs/.markdownlint.yml new file mode 100644 index 0000000..065b285 --- /dev/null +++ b/.circleci/linter_configs/.markdownlint.yml @@ -0,0 +1,9 @@ +--- + +default: true + +MD013: + line_length: 500 + +MD024: + siblings_only: true diff --git a/.circleci/linter_configs/.mdlrc b/.circleci/linter_configs/.mdlrc deleted file mode 100644 index 3cfa9ce..0000000 --- a/.circleci/linter_configs/.mdlrc +++ /dev/null @@ -1,8 +0,0 @@ -# frozen_string_literal: true - -all -rule 'MD013', line_length: 500 -rule 'MD029', style: :ordered -exclude_rule 'MD007' -exclude_rule 'MD010' -exclude_rule 'MD024' diff --git a/.circleci/linter_configs/.rubocop.yml b/.circleci/linter_configs/.rubocop.yml index 8645cc6..26ed510 100644 --- a/.circleci/linter_configs/.rubocop.yml +++ b/.circleci/linter_configs/.rubocop.yml @@ -56,6 +56,9 @@ Style/ParallelAssignment: Style/RescueStandardError: Enabled: false +Style/RedundantConstantBase: + Enabled: false + # Layout ---------------------------------------------------------------------- Layout/LineLength: diff --git a/.circleci/linter_configs/.yamllint.yml b/.circleci/linter_configs/.yamllint.yml index c4899b8..10a4ecf 100644 --- a/.circleci/linter_configs/.yamllint.yml +++ b/.circleci/linter_configs/.yamllint.yml @@ -1,5 +1,7 @@ --- +extends: default + rules: line-length: max: 200 diff --git a/.circleci/scripts/release.sh b/.circleci/scripts/release.sh index 41d641f..13c0de3 100755 --- a/.circleci/scripts/release.sh +++ b/.circleci/scripts/release.sh @@ -1,4 +1,4 @@ -# !/bin/sh +#!/bin/sh set -e GH_CLI_RELEASES_URL="https://github.com/cli/cli/releases" @@ -8,7 +8,7 @@ DELIMETER="_" PACKAGE_FILE="$FILE_NAME$DELIMETER$BUILD_ARCHITECTURE" gh_cli_latest_release() { - curl -sL -o /dev/null -w %{url_effective} "$GH_CLI_RELEASES_URL/latest" | rev | cut -f1 -d'/'| rev + curl -sL -o /dev/null -w '%{url_effective}' "$GH_CLI_RELEASES_URL/latest" | rev | cut -f1 -d'/'| rev } download_gh_cli() { @@ -17,7 +17,7 @@ download_gh_cli() { echo "Unable to get GitHub CLI release." >&2 exit 1 } - curl -s -L -o "$PACKAGE_FILE" "$GH_CLI_RELEASES_URL/download/$VERSION/$FILE_NAME$DELIMETER${VERSION:1}$DELIMETER$BUILD_ARCHITECTURE" + curl -s -L -o "$PACKAGE_FILE" "$GH_CLI_RELEASES_URL/download/$VERSION/$FILE_NAME$DELIMETER$(printf '%s' "$VERSION" | cut -c 2-100)$DELIMETER$BUILD_ARCHITECTURE" } install_gh_cli() { @@ -26,7 +26,7 @@ install_gh_cli() { } get_release_candidate_version() { - echo $(ruby -r rubygems -e "puts Gem::Specification::load('$(ls *.gemspec)').version") + ruby -r rubygems -e "puts Gem::Specification::load('$(ls -- *.gemspec)').version" } release_candidate_tag="v$(get_release_candidate_version)" @@ -39,8 +39,8 @@ release_to_rubygems() { echo "Setting RubyGems publisher credentials..." ./.circleci/scripts/set_publisher_credentials.sh echo "Preparation for release..." - git config --global user.email ${PUBLISHER_EMAIL} - git config --global user.name ${PUBLISHER_NAME} + git config --global user.email "${PUBLISHER_EMAIL}" + git config --global user.name "${PUBLISHER_NAME}" git stash git checkout develop gem install yard gem-ctags diff --git a/.circleci/scripts/set_publisher_credentials.sh b/.circleci/scripts/set_publisher_credentials.sh index f3d725b..36abc15 100755 --- a/.circleci/scripts/set_publisher_credentials.sh +++ b/.circleci/scripts/set_publisher_credentials.sh @@ -1,4 +1,4 @@ -# !/bin/sh +#!/bin/sh set -e set +x mkdir -p ~/.gem diff --git a/.codeclimate.yml b/.codeclimate.yml index db21ad1..d0e2a25 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -9,7 +9,7 @@ checks: plugins: rubocop: enabled: true - channel: rubocop-1-39 + channel: rubocop-1-40 config: file: .circleci/linter_configs/.rubocop.yml diff --git a/.github/BRANCH_NAMING_CONVENTION.md b/.github/BRANCH_NAMING_CONVENTION.md index 1eacce6..a01188b 100644 --- a/.github/BRANCH_NAMING_CONVENTION.md +++ b/.github/BRANCH_NAMING_CONVENTION.md @@ -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 @@ -25,7 +25,7 @@ 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: ``` Technical/Add info files # should be the same name as your branch name diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index ae2d9cf..0844874 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -1 +1,3 @@ +--- + github: [bestwebua] diff --git a/CHANGELOG.md b/CHANGELOG.md index b5bedf5..804cfd9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,27 @@ 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.5.14] - 2022-12-11 + +### 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 + +### Fixed + +- Fixed typos in project's codebase +- Fixed new project's linter issues + +### Updated + +- Updated `CircleCI` config +- Updated [`lefthook`](https://github.com/evilmartians/lefthook) linters aggregator config +- Updated releasing script, gemspecs +- Updated gem version + ## [1.5.13] - 2022-12-01 ### Updated @@ -26,7 +47,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ### Updated - Updated gemspecs -- Updated codeclimate/circleci configs +- Updated `codeclimate`/`circleci` configs - Updated gem development dependencies - Updated gem version @@ -39,7 +60,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ### Updated - Updated gemspecs -- Updated codeclimate/circleci configs +- Updated `codeclimate`/`circleci` configs - Updated gem development dependencies - Updated gem version @@ -48,7 +69,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ### Updated - Updated gemspecs -- Updated rubocop/codeclimate/circleci configs +- Updated `rubocop`/`codeclimate`/`circleci` configs - Updated gem development dependencies - Updated gem version @@ -57,7 +78,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ### Updated - Updated gemspecs -- Updated codeclimate/circleci configs +- Updated `codeclimate`/`circleci` configs - Updated gem development dependencies - Updated gem version @@ -70,7 +91,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ### Updated - Updated gemspecs -- Updated codeclimate/circleci configs +- Updated `codeclimate`/`circleci` configs - Updated gem development dependencies - Updated gem version @@ -79,7 +100,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ### Updated - Updated native Ruby test environment from 2.5 to 3.1 -- Updated codeclimate/circleci configs +- Updated `codeclimate`/`circleci` configs - Updated gem development dependencies - Updated gem docs, version @@ -91,7 +112,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ### Updated -- Updated rubocop/codeclimate/circleci configs +- Updated `rubocop`/`codeclimate`/`circleci` configs - Updated gem development dependencies - Updated gem docs, version @@ -131,7 +152,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ### Added -- Added ability to use internationalized hostnames. All hostnames in UTF-8 will be represented as [Punycode](https://en.wikipedia.org/wiki/Punycode) +- Added ability to use internationalized host names. All host names in UTF-8 will be represented as [Punycode](https://en.wikipedia.org/wiki/Punycode) - Added `simpleidn` as runtime dependency - Added `DnsMock::Representer::Punycode`, tests @@ -161,10 +182,10 @@ dig @localhost -p 5300 MX xn--maana-pta.com ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 4096 ;; QUESTION SECTION: -;xn--maana-pta.com. IN MX +;xn--maana-pta.com. IN MX ;; ANSWER SECTION: -xn--maana-pta.com. 1 IN MX 10 xn--msletras-8ya.xn--maana-pta.com. +xn--maana-pta.com. 1 IN MX 10 xn--msletras-8ya.xn--maana-pta.com. ;; Query time: 0 msec ;; SERVER: 127.0.0.1#5300(127.0.0.1) @@ -191,7 +212,7 @@ xn--maana-pta.com. 1 IN MX 10 xn--msletras-8ya.xn--maana-pta.com. ### Changed - Updated gem development dependencies -- Updated rubocop/codeclimate config +- Updated `rubocop`/`codeclimate` config - Updated gem documentation, version ## [1.3.0] - 2021-06-14 @@ -219,29 +240,29 @@ xn--maana-pta.com. 1 IN MX 10 xn--msletras-8ya.xn--maana-pta.com. ### Changed - Updated gem development dependencies -- Updated CircleCI config +- Updated `circleci` config ## [1.2.3] - 2021-05-11 ### Changed - Updated gem development dependencies -- Updated CircleCI config +- Updated `circleci` config ## [1.2.2] - 2021-05-06 ### Changed - Updated gem development dependencies -- Updated rubocop/codeclimate config -- Updated CircleCI config +- Updated `rubocop`/`codeclimate` config +- Updated `circleci` config ## [1.2.1] - 2021-03-23 ### Changed - Updated gem development dependencies -- Updated rubocop/codeclimate config +- Updated `rubocop`/`codeclimate` config - Updated gem documentation - Updated tests @@ -271,10 +292,10 @@ dig @localhost -p 5300 MX example.com ; <<>> DiG 9.10.6 <<>> @localhost -p 5300 MX example.com ;; ANSWER SECTION: -example.com. 1 IN MX 0 . -example.com. 1 IN MX 10 mx1.domain.com. -example.com. 1 IN MX 10 mx2.domain.com. -example.com. 1 IN MX 40 mx3.domain.com. +example.com. 1 IN MX 0 . +example.com. 1 IN MX 10 mx1.domain.com. +example.com. 1 IN MX 10 mx2.domain.com. +example.com. 1 IN MX 40 mx3.domain.com. ;; Query time: 0 msec ;; SERVER: 127.0.0.1#5300(127.0.0.1) @@ -342,7 +363,7 @@ dig @localhost -p 5300 A example.com ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 4096 ;; QUESTION SECTION: -;example.com. IN A +;example.com. IN A ;; Query time: 0 msec ;; SERVER: 127.0.0.1#5300(127.0.0.1) @@ -368,7 +389,7 @@ DnsMock.start_server(exception_if_not_found: true) ### Fixed -- RDNS lookup representatin for IP address in PTR record feature. +- RDNS lookup representation for IP address in PTR record feature. ## [0.2.0] - 2021-01-26 @@ -397,8 +418,8 @@ dig @localhost -p 5300 -x 1.2.3.4 ; (2 servers found) ;; ANSWER SECTION: -4.3.2.1.in-addr.arpa. 1 IN PTR domain_1.com. -4.3.2.1.in-addr.arpa. 1 IN PTR domain_2.com. +4.3.2.1.in-addr.arpa. 1 IN PTR domain_1.com. +4.3.2.1.in-addr.arpa. 1 IN PTR domain_2.com. ;; Query time: 0 msec ;; SERVER: 127.0.0.1#5300(127.0.0.1) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 62369ee..362c28e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -22,7 +22,7 @@ A good bug report shouldn't leave others needing to chase you up for more inform ## Feature requests -Feature requests are welcome. But take a moment to find out whether your idea fits with the scope and aims of the project. It's up to *you* to make a strong case to convince the project's developers of the merits of this feature. Please provide as much detail and context as possible. +Feature requests are welcome. But take a moment to find out whether your idea fits with the scope and aims of the project. It's up to _you_ to make a strong case to convince the project's developers of the merits of this feature. Please provide as much detail and context as possible. ## Questions diff --git a/README.md b/README.md index fe037ba..6d2dcb2 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ ## Features - Ability to mimic any DNS records (`A`, `AAAA`, `CNAME`, `MX`, `NS`, `PTR`, `SOA` and `TXT`) -- Automatically converts hostnames to RDNS/[Punycode](https://en.wikipedia.org/wiki/Punycode) representation +- Automatically converts host names to RDNS/[Punycode](https://en.wikipedia.org/wiki/Punycode) representation - Lightweight UDP DNS mock server with dynamic/manual port assignment - Test framework agnostic (it's PORO, so you can use it outside of `RSpec`, `Test::Unit` or `MiniTest`) - Simple and intuitive DSL diff --git a/lib/dns_mock/version.rb b/lib/dns_mock/version.rb index 772bbea..f700d71 100644 --- a/lib/dns_mock/version.rb +++ b/lib/dns_mock/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module DnsMock - VERSION = '1.5.13' + VERSION = '1.5.14' end