Testing.

Monday, 11 February 2019

Ruby on Rails: Some Static Code analysers in ruby on rails

What is Overcommit?
Overcommit is a tool to manage and configure Git hooks.

Installation

Add below line into your Gemfile.
gem 'overcommit'
Now we need to create a configuration file in root directory for overriding default hooks.
Name of configuration file should be .overcommit.yml. And it will look like this.
CommitMsg:
  ALL:
    requires_files: false
    quiet: false
EmptyMessage:
    enabled: true
    description: 'Check for empty commit message'
    quiet: true
TrailingPeriod:
    enabled: true
    description: 'Check for trailing periods in subject'
PreCommit:
  ALL:
    problem_on_unmodified_line: report
    requires_files: true
    required: false
    quiet: false
AuthorEmail:
    enabled: true
    description: 'Check author email'
    requires_files: false
    required: true
    quiet: true
    pattern: '^[^@]+@.*$'
AuthorName:
    enabled: true
    description: 'Check for author name'
    requires_files: false
    required: true
    quiet: true
MergeConflicts:
    enabled: true
    description: 'Check for merge conflicts'
    quiet: true
    required_executable: 'grep'
    flags: ['-IHn', "^<<<<<<<[ \t]"]
RailsSchemaUpToDate:
    enabled: true
    description: 'Check if database schema is up to date'
    include:
      - 'db/migrate/*.rb'
      - 'db/schema.rb'
TrailingWhitespace:
    enabled: true
    description: 'Check for trailing whitespace'
    required_executable: 'grep'
    flags: ['-IHn', "[ \t]$"]
    include: '**/*.rb'
  RuboCop:
    enabled: true
    on_warn: fail
  Fasterer:
    enabled: true
    on_warn: fail
  Reek:
    enabled: true
    on_warn: fail
  RailsBestPractices:
    enabled: true
    on_warn: fail
    command: ['rails_best_practices', '--config', 'config/rails_best_practices.yml']
  HamlLint:
    enabled: true
    on_warn: fail
  ScssLint:
    enabled: true
    on_warn: fail
  HardTabs:
    enabled: true
    on_warn: fail
  BundleCheck:
    enabled: true
    on_warn: fail
  EsLint:
    enabled: true
    on_warn: fail
  CoffeeLint:
    enabled: true
    on_warn: fail
PrePush:
  Brakeman:
    enabled: true
    on_warn: fail
Few of above hooks are self descriptive, So I will describe rest of them.

Rubocop
RuboCop is a Ruby static code analyser and code formatter. Out of the box it will enforce many of the guidelines outlined in the community Ruby Style Guide.

Installation

Please add following lines to your Gemfile
gem 'rubocop', require: false
Fasterer
Fasterer will suggest some speed improvements which you can check in detail at the fast-ruby repo.

Installation

Please add following line to your Gemfile
gem 'fasterer'
Reek
Reek is a tool that examines Ruby classes, modules and methods and reports any Code Smells it finds.

Installation

Please add following line to your Gemfile
gem 'reek'
RailsBestPractices
rails_best_practices is a code metric tool to check the quality of Rails code.

Installation

Please add following line to your Gemfile
gem "rails_best_practices"
HamlLint
haml-lint is a tool to help keep your HAML files clean and readable. In addition to HAML-specific style and lint checks, it integrates with RuboCop to bring its powerful static analysis tools to your HAML documents.

Installation

Please add following line to your Gemfile
gem 'haml_lint', require: false
ScssLint
scss-lint is a tool to help keep your SCSS files clean and readable by running it against a collection of configurable linter rules.

Installation

Please add following line to your Gemfile
gem 'scss_lint', require: false
EsLint
ESLint is a tool for identifying and reporting on patterns found in ECMAScript/JavaScript code, with the goal of making code more consistent and avoiding bugs. In many ways, it is similar to JSLint and JSHint with a few exceptions:

Installation

If you want to make ESLint available to tools that run across all of your projects, we recommend installing ESLint globally. You can do so using npm:
$ npm install -g eslint
You should then setup a configuration file:
$ eslint --init
After that, you can run ESLint on any file or directory like this:
$ eslint yourfile.js
CoffeeLint
CoffeeLint is a style checker that helps keep CoffeeScript code clean and consistent. CoffeeScript does a great job at insulating programmers from many of JavaScript’s bad parts, but it won’t help enforce a consistent style across a code base. CoffeeLint can help with that.

Installation

To install, make sure you have a working version of the latest stable version of Node and NPM (the Node Package Manager) and then run:
npm install -g coffeelint
Brakeman
Brakeman is a static analysis tool which checks Ruby on Rails applications for security vulnerabilities.

Installation

Please add following line to your Gemfile
gem 'brakeman'

1 comment: