Giter VIP home page Giter VIP logo

reek's Introduction

CICDToolbox Logo
Github Build Status Release Commits since release

Overview

A tool to check your Ruby code for code smells in CI/CD pipelines using reek.

This tool has been written and tested using GitHub Actions but it should work out of the box with a lot of other CI/CD tools.

Usage

on: [push, pull_request]

jobs:
  build:
    runs-on: ubuntu-latest
    - name: Set up Ruby 3.0
      uses: ruby/setup-ruby@v1
      with:
        ruby-version: 3.0
    - name: Run Reek
      run: bash <(curl -s https://raw.githubusercontent.com/CICDToolbox/reek/master/pipeline.sh)

Other Options

The following environment variables can be set in order to customise the script.

Name Purpose Default Value
EXCLUDE_FILES A comma separated list of files to exclude from being scanned. You can also use regex to do pattern matching. Unset
REPORT_ONLY Generate the report but do not fail the build even if an error occurred. False
SHOW_ERRORS Show the actual errors instead of just which files had errors. True
SHOW_SKIPPED Show which files are being skipped. False

You can use any combination of the above settings.

on: [push, pull_request]

jobs:
  build:
    runs-on: ubuntu-latest
    - name: Set up Ruby 3.0
      uses: ruby/setup-ruby@v1
      with:
        ruby-version: 3.0
    - name: Run Reek
      env:
        REPORT_ONLY: true
        SHOW_ERRORS: true
      run: bash <(curl -s https://raw.githubusercontent.com/CICDToolbox/reek/master/pipeline.sh)

Example Output

This is an example of the output report generated by this tool, this is the actual output from the tool running against itself.

-------------------------------------------------------------------------- Stage 1 - Parameters --
 No parameters given
--------------------------------------------------------------- Stage 2 - Install Prerequisites --
 [  OK  ] gem install --quiet reek
------------------------------------------------------------------- Stage 3 - Run reek (v6.0.6) --
 [  OK  ] tests/test-no-extension
 [  OK  ] tests/test.rb
------------------------------------------------------------------------------ Stage 4 - Report --
 Total: 2, OK: 2, Failed: 0, Skipped: 0
---------------------------------------------------------------------------- Stage 5 - Complete --

File Identification

Target files are identified using the following code:

file -b "${filename}" | grep -qE '(Ruby|ruby) script'

AND

[[ ${filename} =~ \.rb$ ]]

Workaround

We have had to implement one work around due to how reek identifies ruby files. In short by default it will not scan any file that doesn't have a .rb suffix and it scans all the files it can find. We wanted this scanner to work on a file by file basis, so we have had to create a simple workaround.

reek --stdin-filename "${filename}" < "${filename}"

This allows us to pass in any file we identify and convince reek to honour the filename while accepting the file contents via STDIN.

Known Issues

If your ruby code fails to compile then reek will error but set the exit value to 0 causing the scanning to assume success. We have add an additional pre-test of ruby -c which tries to compile the ruby code first before moving onto the linting phase to cope with this.

reek's People

Contributors

tgwolf avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.