rubocop-select 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 675258f67f991723a9018e2997dfbf71ff0c220d
4
+ data.tar.gz: f48186d89eb393ac6255987f1e993a4838823a49
5
+ SHA512:
6
+ metadata.gz: 137d7228e9df503c1a848ce0acb9e2f2373cf56a82863293c4285caea67e8b517cd87d09f45d33c871f47568474ce4ad82a66d9ceded40c49703f5a57b6cc524
7
+ data.tar.gz: 53ae36a19a1f3618089a3cba1e5d0643dcf7eec1741e6588eb1b6c3660fb0feb6067cbf3c767856c4a5e2f73372828ca0decd93cb18a64e2ca00157b1cdefd19
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # Ignore bundler binstubs
12
+ /bundle_bin
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,24 @@
1
+ # This configuration was generated by `rubocop --auto-gen-config`
2
+ # on 2015-02-12 02:36:39 +0900 using RuboCop version 0.29.0.
3
+ # The point is for the user to remove these configuration records
4
+ # one by one as the offenses are removed from the code base.
5
+ # Note that changes in the inspected code, or installation of new
6
+ # versions of RuboCop, may require this file to be generated again.
7
+
8
+ # Offense count: 3
9
+ # Configuration parameters: AllowURI, URISchemes.
10
+ Metrics/LineLength:
11
+ Max: 100
12
+
13
+ # Offense count: 2
14
+ Style/Documentation:
15
+ Enabled: false
16
+
17
+ # Offense count: 2
18
+ Style/RegexpLiteral:
19
+ MaxSlashes: 0
20
+
21
+ Style/FileName:
22
+ Exclude:
23
+ - bin/*
24
+ - bundle_bin/*
data/.travis.yml ADDED
@@ -0,0 +1,14 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9
4
+ - 2.0
5
+ - 2.1
6
+ - 2.2
7
+ before_install:
8
+ - gem update bundler
9
+ notifications:
10
+ email:
11
+ - ogataken@gmail.com
12
+ branches:
13
+ only:
14
+ - master
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rubocop-select.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 sanemat
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,102 @@
1
+ # RuboCop::Select
2
+
3
+ [![Gem Version](http://img.shields.io/gem/v/rubocop-select.svg?style=flat)](http://badge.fury.io/rb/rubocop-select)
4
+ [![Build Status](http://img.shields.io/travis/packsaddle/rubocop-select/master.svg?style=flat)](https://travis-ci.org/packsaddle/rubocop-select)
5
+
6
+ Select file path only executable by RuboCop. **Diff RuboCop** comes!
7
+
8
+ ## Usage
9
+
10
+ Pipe between `git diff` and `rubocop`.
11
+
12
+ ```sh
13
+ $ git diff -z --name-only origin/master..HEAD | xargs -0 bundle exec rubocop-select | xargs rubocop
14
+ ```
15
+
16
+ ## What is this?
17
+
18
+ I changed files.
19
+
20
+ ```sh
21
+ $ git diff --name-only origin/master..HEAD
22
+ .rubocop.yml
23
+ README.md
24
+ Rakefile
25
+ lib/rubocop/select/file.rb
26
+ ```
27
+
28
+ I want to run rubocop on changed files.
29
+
30
+ ```sh
31
+ $ git diff --name-only origin/master..HEAD | xargs rubocop
32
+ Inspecting 4 files
33
+ EF.C
34
+
35
+ Offenses:
36
+
37
+ .rubocop.yml:10:9: E: unexpected token tLABEL
38
+ Metrics/LineLength:
39
+ ^^^^^^^^^^^
40
+ .rubocop.yml:14:7: E: unexpected token tLABEL
41
+ Style/Documentation:
42
+ ^^^^^^^^^^^^^^
43
+ .rubocop.yml:19:7: E: unexpected token tLABEL
44
+ Style/RegexpLiteral:
45
+ ^^^^^^^^^^^^^^
46
+ (snip)
47
+ ```
48
+
49
+ I don't want to run rubocop with `.rubocop.yml`, `README.md`.
50
+ This is why `rubocop-select` comes.
51
+
52
+ ```sh
53
+ $ git diff -z --name-only origin/master..HEAD | xargs -0 bundle exec rubocop-select
54
+ /Users/sane/work/ruby-study/rubocop-select/Rakefile
55
+ /Users/sane/work/ruby-study/rubocop-select/lib/rubocop/select/file.rb
56
+ ```
57
+
58
+ Great!
59
+
60
+ ```sh
61
+ $ git diff -z --name-only origin/master..HEAD | xargs -0 bundle exec rubocop-select| xargs rubocop
62
+ Inspecting 2 files
63
+ .C
64
+
65
+ Offenses:
66
+
67
+ lib/rubocop/select/file.rb:21:1: C: Trailing whitespace detected.
68
+
69
+ 2 files inspected, 1 offense detected
70
+ ```
71
+
72
+ Done. :) :) :)
73
+
74
+ ## Installation
75
+
76
+ Add this line to your application's Gemfile:
77
+
78
+ ```ruby
79
+ gem 'rubocop-select'
80
+ ```
81
+
82
+ And then execute:
83
+
84
+ $ bundle
85
+
86
+ Or install it yourself as:
87
+
88
+ $ gem install rubocop-select
89
+
90
+ ## Development
91
+
92
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
93
+
94
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
95
+
96
+ ## Contributing
97
+
98
+ 1. Fork it ( https://github.com/packsaddle/rubocop-select/fork )
99
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
100
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
101
+ 4. Push to the branch (`git push origin my-new-feature`)
102
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ desc 'Run all specs in spec directory'
5
+ RSpec::Core::RakeTask.new(:spec) do |spec|
6
+ spec.rspec_opts = ['-cfd --backtrace']
7
+ end
8
+
9
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'rubocop/select'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubocop/select'
4
+
5
+ cli = RuboCop::Select::CLI.new
6
+ result = cli.run
7
+ exit result
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/example/simple.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'rubocop/select'
2
+ require 'rubocop'
3
+
4
+ # use same option as rubocop
5
+ config_store = RuboCop::ConfigStore.new
6
+ target_finder = RuboCop::TargetFinder.new(config_store)
7
+ full_scan_files = target_finder.find(paths)
8
+
9
+ selector = RuboCop::Select.new(full_scan_files)
10
+ diff_files = [
11
+ '.rubocop.yml',
12
+ 'app/jobs/repo_synchronization_job.rb'
13
+ ]
14
+ # full_scan_files
15
+ # .map {|f| Pathname.new File.expand_path(f)} &\
16
+ # diff_files
17
+ # .map{|f| Pathname.new File.expand_path(f)}
18
+ selector.intersect(diff_files) #=> target_files
@@ -0,0 +1,9 @@
1
+ require 'rubocop/select/version'
2
+ require 'rubocop/select/file'
3
+ require 'rubocop/select/cli'
4
+
5
+ module RuboCop
6
+ module Select
7
+ # Your code goes here...
8
+ end
9
+ end
@@ -0,0 +1,51 @@
1
+ require 'rubocop'
2
+
3
+ module RuboCop
4
+ module Select
5
+ class CLI
6
+ attr_reader :options, :config_store, :output
7
+
8
+ def initialize
9
+ @options = {}
10
+ @config_store = ::RuboCop::ConfigStore.new
11
+ @output = $stdout
12
+ end
13
+ # Entry point for the application logic. Here we
14
+ # do the command line arguments processing and inspect
15
+ # the target files
16
+ # @return [Fixnum] UNIX exit code
17
+ def run(args = ARGV)
18
+ @options, paths = ::RuboCop::Options.new.parse(args)
19
+ act_on_options
20
+
21
+ target_finder = ::RuboCop::TargetFinder.new(@config_store)
22
+ full_scan_files = target_finder.find('')
23
+ @output.puts File.intersect(full_scan_files, Dir.pwd, paths, Dir.pwd)
24
+ 0
25
+ rescue StandardError => e
26
+ $stderr.puts e.message
27
+ $stderr.puts e.backtrace
28
+ return 1
29
+ end
30
+
31
+ private
32
+
33
+ def act_on_options
34
+ handle_exiting_options
35
+
36
+ ConfigLoader.debug = @options[:debug]
37
+ ConfigLoader.auto_gen_config = @options[:auto_gen_config]
38
+
39
+ @config_store.options_config = @options[:config] if @options[:config]
40
+ end
41
+
42
+ def handle_exiting_options
43
+ return unless ::RuboCop::Options::EXITING_OPTIONS.any? { |o| @options.key? o }
44
+
45
+ puts RuboCop::Select.version(false) if @options[:version]
46
+ puts RuboCop::Select.version(true) if @options[:verbose_version]
47
+ exit(0)
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,21 @@
1
+ require 'pathname'
2
+ module RuboCop
3
+ module Select
4
+ class File
5
+ def self.intersect(
6
+ before_files = [],
7
+ before_base_dir = Dir.pwd,
8
+ after_files = [],
9
+ after_base_dir = Dir.pwd
10
+ )
11
+ expand_files(before_files, before_base_dir) \
12
+ & expand_files(after_files, after_base_dir)
13
+ end
14
+
15
+ # TODO: I don't want to access actual file system
16
+ def self.expand_files(files, base_dir)
17
+ files.map { |f| Pathname.new(::File.expand_path(f, base_dir)) }
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,18 @@
1
+ module RuboCop
2
+ module Select
3
+ VERSION = '0.1.0'
4
+
5
+ MSG = '%s (using RuboCop %s, running on %s %s %s)'
6
+
7
+ module_function
8
+
9
+ def version(debug = false)
10
+ if debug
11
+ format(MSG, VERSION, ::RuboCop::Version.version(false),
12
+ RUBY_ENGINE, RUBY_VERSION, RUBY_PLATFORM)
13
+ else
14
+ VERSION
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rubocop/select/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'rubocop-select'
8
+ spec.version = RuboCop::Select::VERSION
9
+ spec.authors = ['sanemat']
10
+ spec.email = ['o.gata.ken@gmail.com']
11
+
12
+ spec.summary = 'Select file path only executable by RuboCop. For Diff RuboCop!'
13
+ spec.description = 'Pipe between git diff and rubocop.'
14
+ spec.homepage = 'https://github.com/packsaddle/rubocop-select'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`
18
+ .split("\x0")
19
+ .reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ spec.executables = spec
21
+ .files
22
+ .reject { |f| f.match(%r{^bin/(console|setup)}) }
23
+ .grep(%r{^(exe|bin)/}) { |f| File.basename(f) }
24
+ spec.require_paths = ['lib']
25
+
26
+ spec.add_runtime_dependency 'rubocop'
27
+ spec.add_development_dependency 'bundler', '< 1.9', '>= 1.7'
28
+ spec.add_development_dependency 'rake', '~> 10.0'
29
+ spec.add_development_dependency 'rspec', '~> 3.2.0'
30
+ end
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubocop-select
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - sanemat
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-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: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "<"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.9'
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: '1.7'
37
+ type: :development
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - "<"
42
+ - !ruby/object:Gem::Version
43
+ version: '1.9'
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '1.7'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '10.0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '10.0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rspec
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: 3.2.0
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: 3.2.0
75
+ description: Pipe between git diff and rubocop.
76
+ email:
77
+ - o.gata.ken@gmail.com
78
+ executables:
79
+ - rubocop-select
80
+ extensions: []
81
+ extra_rdoc_files: []
82
+ files:
83
+ - ".gitignore"
84
+ - ".rspec"
85
+ - ".rubocop.yml"
86
+ - ".travis.yml"
87
+ - CODE_OF_CONDUCT.md
88
+ - Gemfile
89
+ - LICENSE.txt
90
+ - README.md
91
+ - Rakefile
92
+ - bin/console
93
+ - bin/rubocop-select
94
+ - bin/setup
95
+ - example/simple.rb
96
+ - lib/rubocop/select.rb
97
+ - lib/rubocop/select/cli.rb
98
+ - lib/rubocop/select/file.rb
99
+ - lib/rubocop/select/version.rb
100
+ - rubocop-select.gemspec
101
+ homepage: https://github.com/packsaddle/rubocop-select
102
+ licenses:
103
+ - MIT
104
+ metadata: {}
105
+ post_install_message:
106
+ rdoc_options: []
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ requirements: []
120
+ rubyforge_project:
121
+ rubygems_version: 2.4.5
122
+ signing_key:
123
+ specification_version: 4
124
+ summary: Select file path only executable by RuboCop. For Diff RuboCop!
125
+ test_files: []