Set up linting and tests workflow

This commit is contained in:
Erick Guan 2024-03-02 01:50:42 +01:00
parent 30b31ab66c
commit 9e273bbd6c
4 changed files with 120 additions and 38 deletions

30
.github/workflows/linting.yml vendored Normal file
View File

@ -0,0 +1,30 @@
name: Linting
on:
pull_request:
push:
branches:
- master
permissions:
contents: read
jobs:
linting:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Lint YAML
run: yamllint .
- name: Set up Ruby and install dependencies
uses: ruby/setup-ruby@v1
with:
# uses .ruby-version implicitly
bundler-cache: true
- name: Lint Ruby code
run: bundle exec rubocop

43
.github/workflows/tests.yml vendored Normal file
View File

@ -0,0 +1,43 @@
name: Tests
on:
pull_request:
push:
branches:
- master
permissions:
contents: read
jobs:
tests:
strategy:
matrix:
# test a range of Ruby to ensure gem works
# keep ruby until EOL. Read more on https://endoflife.date/ruby
ruby-version:
- '3.0'
- '3.1'
- '3.2'
- '3.3'
- head
# test distributions up to 4 years
runner:
- ubuntu-22.04
- ubuntu-20.04
fail-fast: false # allow contributors understand failure builds
runs-on: ${{ matrix.runner }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Ruby and install dependencies
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby-version }}
bundler-cache: true
- name: Run tests
run: bundle exec rake spec

View File

@ -12,6 +12,7 @@ AllCops:
NewCops: enable
StyleGuideBaseURL: https://rubystyle.guide
TargetRubyVersion: 3.0
SuggestExtensions: false # reduce noise. consider add rubocop-benchmark
Exclude:
- bin/**/*
@ -21,39 +22,27 @@ Bundler/OrderedGems:
Include:
- '*.gemspec'
# Documentation
# Allow no documentation.
Style/Documentation:
Enabled: false
# Allow more flexibility with string literals
# Enforce single quotes in the gem
Style/StringLiterals:
Enabled: true
EnforcedStyle: single_quotes
Style/HashSyntax:
EnforcedStyle: no_mixed_keys # consistent hash syntax
EnforcedShorthandSyntax: consistent # enforce explicit hash syntax
# Enforce dots on the next line for multi-line method calls
Layout/DotPosition:
EnforcedStyle: trailing
# Project maximum code line length
Layout/LineLength:
Max: 120
# Enforce comma after the last item of a multiline array or hash
Style/TrailingCommaInArrayLiteral:
Enabled: true
EnforcedStyleForMultiline: comma
Style/TrailingCommaInHashLiteral:
Enabled: true
EnforcedStyleForMultiline: comma
Style/TrailingCommaInArguments:
Enabled: true
EnforcedStyleForMultiline: comma
Layout/ArgumentAlignment:
Enabled: true
EnforcedStyle: with_fixed_indentation
Layout/FirstArrayElementIndentation:
Enabled: true
EnforcedStyle: consistent
@ -62,40 +51,25 @@ Layout/MultilineMethodCallIndentation:
Enabled: true
EnforcedStyle: indented
Style/SymbolArray:
EnforcedStyle: brackets # Prefer brackets
Style/WordArray:
# difficult to figure out source text
EnforcedStyle: brackets
# Encourage the use of method call with args parentheses
Style/MethodCallWithArgsParentheses:
Enabled: true
EnforcedStyle: require_parentheses
# Allow guard clauses
Style/GuardClause:
Enabled: true
EnforcedStyle: brackets # Prefer brackets
Style/FrozenStringLiteralComment:
Enabled: false
Layout/EmptyLineAfterMagicComment:
Enabled: true
# Exclude test files from BlockComments check
Style/BlockComments:
Exclude:
- 'test/**/*'
# Naming conventions
Naming/PredicateName:
Enabled: true
Metrics/ClassLength:
Max: 500
Metrics/BlockLength:
Max: 50
Exclude:
# allows longer block for RSpec
- spec/**/*.rb

35
.yamllint Normal file
View File

@ -0,0 +1,35 @@
extends: default
locale: en_US.UTF-8
# ignored directories
ignore: |
.git/
rules:
octal-values: enable
document-start: disable
document-end: disable
# allow 120 characters in a line
line-length:
max: 120
level: error
indentation:
spaces: 2
indent-sequences: true
# allow one space indent
comments:
level: error
min-spaces-from-content: 1
# disallow boolean values to avoid surprise
truthy:
level: error
# github workflows uses `on` as trigger
ignore: |
.github/workflows/*.yml