rubocop-oracle 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f08071efb4fee0574a8a1665daf6a4206c836de8a8f3924a6b74b1267e654f46
4
+ data.tar.gz: 2193018fe03e09ed648a00639edf46dfe663148f29d0e61d64487af1b21857f9
5
+ SHA512:
6
+ metadata.gz: 332761e4fabe2affbb55327b46b6e8d60a6620a59f91aabbe3b770a0e1ac3bf267ae02878698800c621651e28aac4d8e27ea92b0d7f22801900fc1bda5ff1804
7
+ data.tar.gz: 2c67d042742a50cc6d784e9769b7f705ec6a29ca3b5b08918518c348685f2fb5edbd2a757a308cc99d926477bc50215238ff127c87b4a88708b4f717adafb08b
@@ -0,0 +1,43 @@
1
+ version: 2.1
2
+
3
+ jobs:
4
+ rake_default:
5
+ parameters:
6
+ image:
7
+ description: "Name of the Docker image."
8
+ type: string
9
+ default: "circleci/ruby"
10
+ docker:
11
+ - image: << parameters.image >>
12
+ environment:
13
+ # CircleCI container has two cores, but Ruby can see 32 cores. So we
14
+ # configure test-queue.
15
+ # See https://github.com/tmm1/test-queue#environment-variables
16
+ TEST_QUEUE_WORKERS: 2
17
+ JRUBY_OPTS: "--dev -J-Xmx1000M"
18
+ steps:
19
+ - checkout
20
+ - run: bundle install
21
+ - run: bundle exec rake
22
+
23
+ workflows:
24
+ build:
25
+ jobs:
26
+ - rake_default:
27
+ name: Ruby 2.5
28
+ image: circleci/ruby:2.5
29
+ - rake_default:
30
+ name: Ruby 2.6
31
+ image: circleci/ruby:2.6
32
+ - rake_default:
33
+ name: Ruby 2.7
34
+ image: circleci/ruby:2.7
35
+ - rake_default:
36
+ name: Ruby 3.0
37
+ image: circleci/ruby:3.0
38
+ - rake_default:
39
+ name: Ruby HEAD
40
+ image: rubocophq/circleci-ruby-snapshot:latest # Nightly snapshot build
41
+ - rake_default:
42
+ name: JRuby 9.2
43
+ image: circleci/jruby:9.2
@@ -0,0 +1 @@
1
+ github: koic
data/.gitignore ADDED
@@ -0,0 +1,62 @@
1
+ # rcov generated
2
+ coverage
3
+ coverage.data
4
+
5
+ # rdoc generated
6
+ rdoc
7
+
8
+ # yard generated
9
+ doc
10
+ .yardoc
11
+
12
+ # bundler
13
+ .bundle
14
+ Gemfile.lock
15
+ Gemfile.local
16
+
17
+ # rbenv
18
+ .ruby-version
19
+
20
+ # rspec
21
+ /spec/examples.txt
22
+ /.test_queue_stats
23
+ .rspec_status
24
+
25
+ # jeweler generated
26
+ pkg
27
+
28
+ # etags
29
+ TAGS
30
+
31
+ # Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
32
+ #
33
+ # * Create a file at ~/.gitignore
34
+ # * Include files you want ignored
35
+ # * Run: git config --global core.excludesfile ~/.gitignore
36
+ #
37
+ # After doing this, these files will be ignored in all your git projects,
38
+ # saving you from having to 'pollute' every project you touch with them
39
+ #
40
+ # Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
41
+ #
42
+ # For MacOS:
43
+ #
44
+ #.DS_Store
45
+
46
+ # For TextMate
47
+ #*.tmproj
48
+ #tmtags
49
+
50
+ # For emacs:
51
+ #*~
52
+ #\#*
53
+ #.\#*
54
+
55
+ # For vim:
56
+ *.swp
57
+
58
+ # For redcar:
59
+ #.redcar
60
+
61
+ # For rubinius:
62
+ #*.rbc
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,84 @@
1
+ # This is the configuration used to check the rubocop source code.
2
+
3
+ require:
4
+ - rubocop/cop/internal_affairs
5
+ - rubocop-performance
6
+
7
+ AllCops:
8
+ NewCops: enable
9
+ TargetRubyVersion: 2.5
10
+ SuggestExtensions: false
11
+
12
+ Naming/PredicateName:
13
+ # Method define macros for dynamically generated method.
14
+ MethodDefinitionMacros:
15
+ - define_method
16
+ - define_singleton_method
17
+ - def_node_matcher
18
+ - def_node_search
19
+
20
+ Style/FormatStringToken:
21
+ # Because we parse a lot of source codes from strings. Percent arrays
22
+ # look like unannotated format string tokens to this cop.
23
+ Exclude:
24
+ - test/**/*
25
+
26
+ Layout/EndOfLine:
27
+ EnforcedStyle: lf
28
+
29
+ Layout/ClassStructure:
30
+ Enabled: true
31
+ Categories:
32
+ module_inclusion:
33
+ - include
34
+ - prepend
35
+ - extend
36
+ ExpectedOrder:
37
+ - module_inclusion
38
+ - constants
39
+ - public_class_methods
40
+ - initializer
41
+ - instance_methods
42
+ - protected_methods
43
+ - private_methods
44
+
45
+ # Trailing white space is meaningful in code examples
46
+ Layout/TrailingWhitespace:
47
+ AllowInHeredoc: true
48
+
49
+ Lint/AmbiguousBlockAssociation:
50
+ Exclude:
51
+ - 'test/**/*.rb'
52
+
53
+ Lint/InterpolationCheck:
54
+ Exclude:
55
+ - 'test/**/*.rb'
56
+
57
+ Lint/UselessAccessModifier:
58
+ MethodCreatingMethods:
59
+ - 'def_matcher'
60
+ - 'def_node_matcher'
61
+
62
+ Lint/BooleanSymbol:
63
+ Enabled: false
64
+
65
+ Metrics/AbcSize:
66
+ Max: 20
67
+
68
+ Metrics/BlockLength:
69
+ Exclude:
70
+ - 'Rakefile'
71
+ - '**/*.rake'
72
+ - 'spec/**/*.rb'
73
+ - '**/*.gemspec'
74
+
75
+ Naming/FileName:
76
+ Exclude:
77
+ - lib/rubocop-oracle.rb
78
+
79
+ Metrics/ModuleLength:
80
+ Exclude:
81
+ - 'test/**/*.rb'
82
+
83
+ Performance/ChainArrayAllocation:
84
+ Enabled: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,11 @@
1
+ # Change log
2
+
3
+ ## master (unreleased)
4
+
5
+ ## 0.1.0 (2021-04-13)
6
+
7
+ ### New features
8
+
9
+ * Create RuboCop Oracle gem. ([@koic][])
10
+
11
+ [@koic]: https://github.com/koic
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in rubocop-oracle.gemspec
6
+ gemspec
7
+
8
+ gem 'rake', '~> 13.0'
9
+ gem 'rspec', '~> 3.0'
10
+ gem 'rubocop'
11
+ gem 'rubocop-performance'
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Koichi ITO
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,66 @@
1
+ # RuboCop Oracle
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/rubocop-oracle.svg)](https://badge.fury.io/rb/rubocop-oracle)
4
+ [![CircleCI](https://circleci.com/gh/koic/rubocop-oracle.svg?style=svg)](https://circleci.com/gh/koic/rubocop-oracle)
5
+
6
+ A [RuboCop](https://github.com/rubocop-hq/rubocop) extension for [Active Record Oracle enhanced adapter](https://github.com/rsim/oracle-enhanced).
7
+
8
+ ## Installation
9
+
10
+ Just install the `rubocop-oracle` gem
11
+
12
+ ```sh
13
+ gem install rubocop-oracle
14
+ ```
15
+
16
+ or if you use bundler put this in your `Gemfile`
17
+
18
+ ```ruby
19
+ gem 'rubocop-oracle'
20
+ ```
21
+
22
+ ## Usage
23
+
24
+ You need to tell RuboCop to load the Oracle extension. There are three
25
+ ways to do this:
26
+
27
+ ### RuboCop configuration file
28
+
29
+ Put this into your `.rubocop.yml`.
30
+
31
+ ```yaml
32
+ require: rubocop-oracle
33
+ ```
34
+
35
+ Alternatively, use the following array notation when specifying multiple extensions.
36
+
37
+ ```yaml
38
+ require:
39
+ - rubocop-other-extension
40
+ - rubocop-oracle
41
+ ```
42
+
43
+ Now you can run `rubocop` and it will automatically load the RuboCop Oracle
44
+ cops together with the standard cops.
45
+
46
+ ### Command line
47
+
48
+ ```sh
49
+ rubocop --require rubocop-oracle
50
+ ```
51
+
52
+ ### Rake task
53
+
54
+ ```ruby
55
+ RuboCop::RakeTask.new do |task|
56
+ task.requires << 'rubocop-oracle'
57
+ end
58
+ ```
59
+
60
+ ## Contributing
61
+
62
+ Bug reports and pull requests are welcome on GitHub at https://github.com/koic/rubocop-oracle.
63
+
64
+ ## License
65
+
66
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require 'rubocop/rake_task'
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'rubocop/oracle'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,26 @@
1
+ # Common configuration.
2
+
3
+ inherit_mode:
4
+ merge:
5
+ - Exclude
6
+
7
+ AllCops:
8
+ Exclude:
9
+ - bin/*
10
+ - db/schema.rb
11
+ # What version of Rails is the inspected code using? If a value is specified
12
+ # for TargetRailsVersion then it is used. Acceptable values are specificed
13
+ # as a float (i.e. 5.1); the patch version of Rails should not be included.
14
+ # If TargetRailsVersion is not set, RuboCop will parse the Gemfile.lock or
15
+ # gems.locked file to find the version of Rails that has been bound to the
16
+ # application. If neither of those files exist, RuboCop will use Rails 5.0
17
+ # as the default.
18
+ TargetRailsVersion: ~
19
+
20
+ Oracle/OnlineIndex:
21
+ Description: 'Checks for uses `options: online` option on `add_index`.'
22
+ Enabled: true
23
+ VersionAdded: '0.1'
24
+ MigratedSchemaVersion: ~
25
+ Include:
26
+ - 'db/migrate/**/*.rb'
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rubocop'
4
+
5
+ require_relative 'rubocop/oracle'
6
+ require_relative 'rubocop/oracle/version'
7
+ require_relative 'rubocop/oracle/inject'
8
+
9
+ RuboCop::Oracle::Inject.defaults!
10
+
11
+ require_relative 'rubocop/cop/oracle_cops'
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Oracle
6
+ #
7
+ # This cop checks for uses `options: online` option on `add_index`.
8
+ # The `ONLINE` option is required if you want to run with OLTP when indexing migration in Oracle.
9
+ # By specifying `MigratedSchemaVersion` option, migration files that have been migrated can be ignored.
10
+ #
11
+ # @example
12
+ #
13
+ # # bad
14
+ # add_index :table_name, :column_name
15
+ #
16
+ # # good
17
+ # add_index :table_name, :column_name, options: :online
18
+ #
19
+ # @example MigratedSchemaVersion: '202104130150'
20
+ #
21
+ # # bad - Migration files higher than '202104130150' will be registered an offense.
22
+ # add_index :table_name, :column_name
23
+ #
24
+ # # good - Migration files lower than or equal to '202104130150' will be ignored.
25
+ # add_index :table_name, :column_name
26
+ #
27
+ class OnlineIndex < Base
28
+ extend AutoCorrector
29
+
30
+ MSG = 'Specify `options: :online` option to `add_index`.'
31
+ RESTRICT_ON_SEND = %i[add_index].freeze
32
+
33
+ def on_send(node)
34
+ return if already_migrated_file? || use_online_option?(node.last_argument)
35
+
36
+ add_offense(node.loc.selector) do |corrector|
37
+ corrector.insert_after(node, ', options: :online')
38
+ end
39
+ end
40
+
41
+ private
42
+
43
+ def already_migrated_file?
44
+ schema_version = File.basename(processed_source.file_path).match(/(?<timestamp>\d{12})/)['timestamp']
45
+ return false unless migrated_schema_version
46
+
47
+ schema_version <= migrated_schema_version # Ignore applied migration files.
48
+ end
49
+
50
+ def use_online_option?(options)
51
+ if options.hash_type?
52
+ options.each_pair do |key, value|
53
+ return true if key.source.match?(/\A:?options\z/i) && value.source.match?(/\A:?online\z/i)
54
+ end
55
+ end
56
+
57
+ false
58
+ end
59
+
60
+ def migrated_schema_version
61
+ cop_config.fetch('MigratedSchemaVersion', nil)
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'oracle/online_index'
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'yaml'
4
+ require_relative 'oracle/version'
5
+
6
+ module RuboCop
7
+ # RuboCop Oralce project namespace
8
+ module Oracle
9
+ PROJECT_ROOT = Pathname.new(__dir__).parent.parent.expand_path.freeze
10
+ CONFIG_DEFAULT = PROJECT_ROOT.join('config', 'default.yml').freeze
11
+ CONFIG = YAML.safe_load(CONFIG_DEFAULT.read).freeze
12
+
13
+ private_constant(:CONFIG_DEFAULT, :PROJECT_ROOT)
14
+ end
15
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Oracle
5
+ # Because RuboCop doesn't yet support plugins, we have to monkey patch in a
6
+ # bit of our configuration.
7
+ module Inject
8
+ def self.defaults!
9
+ path = CONFIG_DEFAULT.to_s
10
+ hash = ConfigLoader.send(:load_yaml_configuration, path)
11
+ config = Config.new(hash, path).tap(&:make_excludes_absolute)
12
+ puts "configuration from #{path}" if ConfigLoader.debug?
13
+ config = ConfigLoader.merge_with_default(config, path, unset_nil: false)
14
+ ConfigLoader.instance_variable_set(:@default_configuration, config)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Oracle
5
+ VERSION = '0.1.0'
6
+ end
7
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/rubocop/oracle/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'rubocop-oracle'
7
+ spec.version = RuboCop::Oracle::VERSION
8
+ spec.authors = ['Koichi ITO']
9
+ spec.email = ['koic.ito@gmail.com']
10
+
11
+ spec.summary = 'A RuboCop extension for Active Record Oracle enhanced adapter.'
12
+ spec.description = 'A RuboCop extension for Active Record Oracle enhanced adapter.'
13
+ spec.homepage = 'https://github.com/koic/rubocop-oracle'
14
+ spec.license = 'MIT'
15
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.5.0')
16
+
17
+ spec.metadata['homepage_uri'] = spec.homepage
18
+
19
+ # Specify which files should be added to the gem when it is released.
20
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
22
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
23
+ end
24
+ spec.bindir = 'exe'
25
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ['lib']
27
+
28
+ spec.add_runtime_dependency 'rubocop', '~> 1.0'
29
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubocop-oracle
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Koichi ITO
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-04-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rubocop
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ description: A RuboCop extension for Active Record Oracle enhanced adapter.
28
+ email:
29
+ - koic.ito@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".circleci/config.yml"
35
+ - ".github/FUNDING.yml"
36
+ - ".gitignore"
37
+ - ".rspec"
38
+ - ".rubocop.yml"
39
+ - CHANGELOG.md
40
+ - Gemfile
41
+ - LICENSE.txt
42
+ - README.md
43
+ - Rakefile
44
+ - bin/console
45
+ - bin/setup
46
+ - config/default.yml
47
+ - lib/rubocop-oracle.rb
48
+ - lib/rubocop/cop/oracle/online_index.rb
49
+ - lib/rubocop/cop/oracle_cops.rb
50
+ - lib/rubocop/oracle.rb
51
+ - lib/rubocop/oracle/inject.rb
52
+ - lib/rubocop/oracle/version.rb
53
+ - rubocop-oracle.gemspec
54
+ homepage: https://github.com/koic/rubocop-oracle
55
+ licenses:
56
+ - MIT
57
+ metadata:
58
+ homepage_uri: https://github.com/koic/rubocop-oracle
59
+ post_install_message:
60
+ rdoc_options: []
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: 2.5.0
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ requirements: []
74
+ rubygems_version: 3.2.15
75
+ signing_key:
76
+ specification_version: 4
77
+ summary: A RuboCop extension for Active Record Oracle enhanced adapter.
78
+ test_files: []