149

Language / Framework: Ruby

Categories: Complexity, Security, Clarity, Performance, Bug Risk, Style

Channels: stable: StandardRB v1.1.5, beta: StandardRB v.1.1.5

The codeclimate-standard plugin is a Code Climate Engine that uses the standardrb gem to lint and analyze your Ruby code. StandardRB enforces a set of widely accepted coding standards and best practices, making it easier for developers to write consistent and maintainable code.

This document will help you get started with the codeclimate-standard plugin, configure it, and interpret the results.

Enable the Plugin

To begin using the codeclimate-standard plugin, you must first enable it in your Code Climate configuration file, .codeclimate.yml. If you don't have a .codeclimate.yml file in your project, create one with the following content:

version: "2"
plugins:
  standard:
    enabled: true

If you already have a .codeclimate.yml file, add the standard plugin under the plugins key:

plugins:
...other plugin configurations....
	standard:
		enabled: true

More information about the CLI is available in the README here: https://github.com/codeclimate/codeclimate

Configure the Plugin

The codeclimate-standard plugin supports several configuration options. You can customize the behavior of the plugin by adding these options to your .codeclimate.yml file.

Excluding Files

To exclude specific files or directories from analysis, use the exclude_patterns key under the standard plugin. The patterns should be specified as a list of glob patterns:

plugins:
  standard:
    enabled: true
    exclude_patterns:
      - "vendor/**/*"
      - "db/schema.rb"

Customizing the StandardRB Configuration

If you need to customize the StandardRB configuration, create a .standard.yml file in your project's root directory. The codeclimate-standard plugin will automatically use the configuration specified in this file. For more information on customizing the StandardRB configuration, visit the StandardRB documentation.

Understand the Plugin

The codeclimate-standard plugin will report issues found by StandardRB during the analysis. The issues will be displayed in the Code Climate interface, along with a description and a link to the relevant StandardRB documentation.

Issues are grouped into categories based on their severity:

  • Style: Issues related to code formatting and consistency, such as indentation and spacing.
  • Lint: Issues related to potential bugs, such as unused variables and incorrect method calls.
  • Performance: Issues related to inefficient code that could impact performance.
  • Security: Issues related to potential security vulnerabilities, such as unsafe method calls.

By addressing the issues reported by the codeclimate-standard plugin, you can improve the quality, consistency, and maintainability of your Ruby code.