Giter Club home page Giter Club logo

rubocop-sequel's Introduction

RuboCop Logo


Ruby Style Guide Gem Version Actions Status Test Coverage Maintainability Discord

Role models are important.
-- Officer Alex J. Murphy / RoboCop

RuboCop is a Ruby static code analyzer (a.k.a. linter) and code formatter. Out of the box it will enforce many of the guidelines outlined in the community Ruby Style Guide. Apart from reporting the problems discovered in your code, RuboCop can also automatically fix many of them for you.

RuboCop is extremely flexible and most aspects of its behavior can be tweaked via various configuration options.


Patreon OpenCollective OpenCollective Tidelift

Working on RuboCop is often fun, but it also requires a great deal of time and energy.

Please consider financially supporting its ongoing development.

Installation

RuboCop's installation is pretty standard:

$ gem install rubocop

If you'd rather install RuboCop using bundler, add a line for it in your Gemfile (but set the require option to false, as it is a standalone tool):

gem 'rubocop', require: false

RuboCop is stable between minor versions, both in terms of API and cop configuration. We aim to ease the maintenance of RuboCop extensions and the upgrades between RuboCop releases. All big changes are reserved for major releases. To prevent an unwanted RuboCop update you might want to use a conservative version lock in your Gemfile:

gem 'rubocop', '~> 1.65', require: false

See our versioning policy for further details.

Quickstart

Just type rubocop in a Ruby project's folder and watch the magic happen.

$ cd my/cool/ruby/project
$ rubocop

You can also use this magic in your favorite editor with RuboCop's built-in LSP server.

Documentation

You can read a lot more about RuboCop in its official docs.

Compatibility

RuboCop officially supports the following runtime Ruby implementations:

  • MRI 2.7+
  • JRuby 9.4+

Targets Ruby 2.0+ code analysis.

See the compatibility documentation for further details.

Readme Badge

If you use RuboCop in your project, you can include one of these badges in your readme to let people know that your code is written following the community Ruby Style Guide.

Ruby Style Guide

Ruby Style Guide

Here are the Markdown snippets for the two badges:

[![Ruby Style Guide](https://img.shields.io/badge/code_style-rubocop-brightgreen.svg)](https://github.com/rubocop/rubocop)

[![Ruby Style Guide](https://img.shields.io/badge/code_style-community-brightgreen.svg)](https://rubystyle.guide)

Team

Here's a list of RuboCop's core developers:

See the team page for more details.

Logo

RuboCop's logo was created by Dimiter Petrov. You can find the logo in various formats here.

The logo is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.

Contributors

Here's a list of all the people who have contributed to the development of RuboCop.

I'm extremely grateful to each and every one of them!

If you'd like to contribute to RuboCop, please take the time to go through our short contribution guidelines.

Converting more of the Ruby Style Guide into RuboCop cops is our top priority right now. Writing a new cop is a great way to dive into RuboCop!

Of course, bug reports and suggestions for improvements are always welcome. GitHub pull requests are even better! :-)

Funding

While RuboCop is free software and will always be, the project would benefit immensely from some funding. Raising a monthly budget of a couple of thousand dollars would make it possible to pay people to work on certain complex features, fund other development related stuff (e.g. hardware, conference trips) and so on. Raising a monthly budget of over $5000 would open the possibility of someone working full-time on the project which would speed up the pace of development significantly.

We welcome both individual and corporate sponsors! We also offer a wide array of funding channels to account for your preferences (although currently Open Collective is our preferred funding platform).

If you're working in a company that's making significant use of RuboCop we'd appreciate it if you suggest to your company to become a RuboCop sponsor.

You can support the development of RuboCop via GitHub Sponsors, Patreon, PayPal, Open Collective and Tidelift .

Note: If doing a sponsorship in the form of donation is problematic for your company from an accounting standpoint, we'd recommend the use of Tidelift, where you can get a support-like subscription instead.

Open Collective Backers

Support us with a monthly donation and help us continue our activities. [Become a backer]

Open Collective Sponsors

Become a sponsor and get your logo on our README on GitHub with a link to your site. [Become a sponsor]

Changelog

RuboCop's changelog is available here.

Copyright

Copyright (c) 2012-2024 Bozhidar Batsov. See LICENSE.txt for further details.

rubocop-sequel's People

Contributors

artofhuman avatar bbatsov avatar bgentry avatar bquorning avatar cyberdelia avatar darhazer avatar dependabot[bot] avatar francktrouillez avatar koic avatar numbata avatar rickselby avatar tycooon avatar ydah avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  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  avatar  avatar  avatar  avatar

rubocop-sequel's Issues

Failing rubocops, not run in CI

There are a couple of failing rubocops on the latest version of this codebase. Apparently these aren't being run in CI so they went unnoticed.

False negative Sequel/ConcurrentIndex in some cases. Ignores options passed in hash.

Ignores options passed in an options hash along with gin_trgm_ops relevant with pg_trgm extension.
This way concurrently: true, though provided, is not detected by linter.

Sequel.migration do
  no_transaction

  up do
    DB.execute('CREATE EXTENSION IF NOT EXISTS pg_trgm;')
    alter_table(:foos) do
      opts = {
        name: :foos_bar_search_index,
        type: :gin,
        concurrently: true
      }
      add_index(Sequel.lit(" gin_trgm_ops"), opts)
    end
  end
end

Issue produced with the following version

GIT
  remote: git://github.com/rubocop-hq/rubocop-sequel.git
  revision: 99fc07d33c6dd4a2b38627316764ab2cc7ce750c
  ref: 99fc07d33c6dd4a2b38627316764ab2cc7ce750c
  specs:
    rubocop-sequel (0.1.0)
      rubocop (~> 1.0)

Feature: Migrations require up/down methods instead of change when not automatically-reversible

A migration file that uses migration methods like set_column_type, or other non-reversible ones mentioned here https://sequel.jeremyevans.net/rdoc/files/doc/migration_rdoc.html#label-A+Basic+Migration is not reversible automatically, and should require specific up/down methods in migrations in projects where reversibility is important. I imagine a rubocop rule could check for this.

Curious if maintainers would merge a PR that adds a new cop for this?

Suggestion: validate boolean field conditions style

Hi rubocop & sequel users and rubocop-sequel maintainers!

We've recently faced an issue with partial indexes using boolean field.

Basically, when index has condition WHERE field and sequel generates (where(field: true) as WHERE field IS TRUE, index isn't used, by postgres regardless of the nullability of the field. The same is true vice-versa. This is the expected behavior, but we only faced it recently when we discovered that partial index can help us. Before, we didn't pay attention to which conditions we used and used them interchangeably (and it didn't create a problem because of not-nullable columns).

What I think would be great in rubocop-sequel is to enforce boolean conditions to one style:
either you use where(field: true), where { field =~ true } and where: Sequel[:field] =~ true,
or you use where(:field), where { field } and where: Sequel[:field].

The former is preferred and should be default because of null handling, but one may have a different setup, so I guess having it configurable might make sense.

I think such cop may help with different kinds of related problems.

Do you think it make sense to have such cop?

deprecation warning on latest rubocop

/Users/bgentry/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/rubocop-sequel-0.0.1/lib/rubocop/cop/sequel/save_changes.rb:13
Warning: The usage of positional location, message, and severity
parameters to Cop#add_offense is deprecated.
Please use keyword arguments instead.

The positional arguments version of Cop#add_offense will be removed in
RuboCop 0.52

Sequel/SaveChanges should not auto-correct

I do not believe this cop should be auto-correctable.

From the docs on Model#save_changes, "If the object has not been modified, returns nil".

My code relied on the fact that Model#save returns self if successful, even if no changes were made. When auto-corrected my tests broke.

Support major release rubocop version >= 1.0.0

Bundler could not find compatible versions for gem "rubocop":
  In Gemfile:
    rubocop (~> 1.2.0)

    rubocop-sequel was resolved to 0.0.6, which depends on
      rubocop (>= 0.55, ~> 0.55)

Is there any work that needs to be done to support the >= 1.0.0 releases?

There are some breaking changes listed in rubocop changelog. Does this gem need any code changes or just update to the gemspec?

https://github.com/rubocop-hq/rubocop-sequel/blob/7099c0bd3ea5c04a2e3dadb7c0f63fa18f2c3436/rubocop-sequel.gemspec#L18

Thanks!

Bug: concurrent_index complaining when creating/dropping an index on a partitioned table in PostgreSQL

I got the cop RuboCop(Sequel/ConcurrentIndex) complaining when I'm trying to run a migration to create/drop an index on a partitioned table in PostgreSQL when concurrently: true is not set, while it is currently not possible in PostgreSQL.

Steps to reproduce

  1. Create a migration that adds an index to a partitioned table
  2. Don't add concurrently: true
  3. Check that the cop RuboCop(Sequel/ConcurrentIndex) is complaining
  4. Add concurrently: true
  5. Run the migration
  6. Get an exception
Sequel::DatabaseError: PG::FeatureNotSupported: ERROR:  cannot create index on partitioned table "my_table" concurrently
ROM::SQL.migration do
  no_transaction

  change do
    alter_table :my_table do
      add_index :my_index, concurrently: true
    end
  end
end

Expected behavior

The cop should not complain, as the proposed change is not working for partitioned table in PostgreSQL

Actual behavior

The cop is complaining, forcing me to change to a non-working solution where a Sequel::DatabaseError: PG::FeatureNotSupported is raised.

Proposed change

If this situation is still happening with up-to-date gems and ruby versions, I believe we could go in 2 directions:

  • Remove the cop: fast and simple, but might decrease experience for people that don't fact this issue.
  • Make the cop less restrictive or more clear: we could enforce to specify concurrently, even if it is set to false, and change the message from 'Prefer creating or dropping new index concurrently' to 'Specify concurrently option when creating or dropping an index.
  • I'm of course open for other solutions!

I'm more in favor of the second option of keeping the cop but forcing it to say we should specify the concurrently option, instead of setting it to true, but I'm open for suggestions!

I've opened a PR for this if it makes sense.

System configuration

rubocop-sequel version:
0.3.4

sequel version:
5.76.0

pg version:
1.5.4

Ruby version:
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x86_64-linux]

What's the reasoning behind ColumnDefault?

class ColumnDefault < Base
MSG = "Don't create new column with default values"
RESTRICT_ON_SEND = %i[add_column].freeze
def_node_matcher :add_column_default?, <<-MATCHER
(send _ :add_column ... (hash (pair (sym :default) _)))
MATCHER
def on_send(node)
return unless add_column_default?(node)
add_offense(node.loc.selector, message: MSG)

I'm a bit puzzled why this is a cop. I can imagine theoretical reasons, but not particularly practical ones, where the gains outweigh the costs (more nullable columns, being unable to use change blocks)

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.