Git Product home page Git Product logo

rubocop-faker's Introduction

RuboCop Faker

Gem Version CircleCI

A RuboCop extension for Faker.

RuboCop Faker is a tool for converting your Faker's methods to the latest Faker argument style with static code analysis.

With RuboCop Faker you can upgrade your Faker 1 codes to Faker 2 in no time. It supports conversions for almost all of the Faker 2 changes.

Installation

Just install the rubocop-faker gem

gem install rubocop-faker

or if you use bundler put this in your Gemfile

gem 'rubocop-faker'

Examples

Here's an example.

Faker::Avatar.image(slug, size, format, set, bgset)

RuboCop Faker would convert it to the following Faker 2 form:

Faker::Avatar.image(slug: slug, size: size, format: format, set: set, bgset: bgset)

Usage

You need to tell RuboCop to load the Faker extension.

This gem offers the only Faker/DeprecatedArguments cop. It is intended to convert a Faker 2 compatible interface.

Command line

Check positional argument style before Faker 2.

% rubocop --require rubocop-faker --only Faker/DeprecatedArguments

Auto-correction to keyword argument style on Faker 2.

% rubocop --require rubocop-faker --only Faker/DeprecatedArguments --autocorrect

RuboCop configuration file

Add rubocop-faker to required extension.

# .rubocop.yml
require:
  - rubocop-faker

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/koic/rubocop-faker.

License

The gem is available as open source under the terms of the MIT License.

rubocop-faker's People

Contributors

dpep avatar koic avatar mekajiki avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

rubocop-faker's Issues

Files inspected, no offenses detected for data_magic gem

I'm using in Gemfile:

gem 'data_magic'
gem 'page-object'
gem 'rubocop-faker'
gem 'rspec'
gem 'rspec-expectations'

Code in default.yml is:

forgot_password_page: email_address: ~email_address

and in forgot_password_page.rb is:

  include PageObject
  include DataMagic

  def submit_forgot_password(data = {})
    populate_page_with data_for(:forgot_password_page, data)
  end
end

After I ran the test the following error is displayed:

gems/data_magic-1.2/lib/data_magic/standard_translation.rb:187: Passing name with the 1st argument of email is deprecated. Use keyword argument like email(name: ...) instead.

After I ran:
rubocop \ --require rubocop-faker \ --only Faker/DeprecatedArguments \ --auto-correct

the output is:

44 files inspected, no offenses detected

rubocop-faker can not find offenses in factorybot models.

When I run the command to upgrade deprecated usages, it found and fixed deprecated code on controller specs.
But we're also using faker to generate random data for factorybot models. It doesn't find those usages and cannot fix them.

Here is an example of factorybot model.

./spec/factories/component.rb

  factory :component do
    event
    type_id { Faker::Number.between(from: 1, to: 11) }
    custom_name { Faker::Name.name }
    custom_picture { Faker::Placeholdit.image }
    order_value { Faker::Number.number(1) }
    is_hidden { false }
    classification { Faker::Number.number(4) }
  end
end

Fix keyword argument not applied

I got this error message:

ruby-2.6.5/gems/faker-2.10.2/lib/helpers/unique_generator.rb:22: Passing `number` with the 1st argument of `characters` is deprecated. Use keyword argument like `characters(number: ...)` instead.

To automatically update from positional arguments to keyword arguments,
install rubocop-faker and run:

rubocop \
  --require rubocop-faker \
  --only Faker/DeprecatedArguments \
  --auto-correct

Although I have ran the rubocop-faker (and it fixed some issues).

This code I have in a factory wasn't fixed however :

public_key { Faker::Lorem.unique.characters(255) }

Changing it into

public_key { Faker::Lorem.unique.characters(number: 255) }

Resolved the issue.

rubocop --require rubocop-faker does not find file

When I use

rubocop --require rubocop-faker --only Faker/DeprecatedArguments --auto-correct

then I get

cannot load such file -- rubocop-faker

ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-darwin18]

*** LOCAL GEMS ***

rubocop (0.76.0)
rubocop-faker (0.2.0)
rubocop-rails (2.3.2)
rubocop-require_tools (0.1.2)
rubocop-rspec (1.36.0)

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.