hound-cli 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: 483245c29d53fc7fdeae5ac6349978f54dce8539
4
+ data.tar.gz: 9714e80febfa1571e228d08097db02d668489844
5
+ SHA512:
6
+ metadata.gz: 0a7edb7d47bdea4c630d7ead838e4d5cfcbd548a52885e8a98c41ad5e03b025d2c12bb77963f3d21534a3b227e0371493b01aaae819eadceace54cc6d3ff3db9
7
+ data.tar.gz: c75017139604ebecdfca3eda9508730f543e75b7ab9890e82bcb879fcc7516f5800275cacab54f68e84068798abbc41d0c521413f3384dbb50e52eb674c8094e
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.3
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.12.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in hound.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright 2016 Platanus
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,97 @@
1
+ # Hound CLI
2
+
3
+ Ruby CLI created to get and build style rules we use in Platanus to play with linters.
4
+ This tool was built to recreate locally, the same behavior we have in [our forked version](https://github.com/platanus/hound) of [Hound](https://github.com/houndci/hound).
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'hound'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ ```bash
17
+ $ bundle install
18
+ ```
19
+
20
+ ## Usage
21
+
22
+ ### Update command
23
+
24
+ This command allows you to update style rules for enabled linters.
25
+
26
+ ```
27
+ $ hound rules update
28
+ ```
29
+
30
+ After running this command you will get one file (with style rules) for each enabled linter in the **remote** [.hound.yml](https://raw.githubusercontent.com/platanus/la-guia/master/.hound.yml) file. Those files are understood by linters installed in your system. For example: with `ruby` language, a `.rubocop.yml` file will be created. This `.rubocop.yml`, is read by the [rubocop gem](https://github.com/bbatsov/rubocop) (a ruby linter).
31
+
32
+ Example:
33
+
34
+ Having...
35
+
36
+ ```yaml
37
+ javascript:
38
+ enabled: false
39
+ eslint:
40
+ enabled: true
41
+ config_file: style/config/.eslintrc.json
42
+ tslint:
43
+ enabled: false
44
+ config_file: style/config/tslint.json
45
+ ruby:
46
+ enabled: true
47
+ config_file: style/config/.rubocop.yml
48
+ scss:
49
+ enabled: true
50
+ config_file: style/config/.scss-lint.yml
51
+ ```
52
+
53
+ And running...
54
+
55
+ ```bash
56
+ $ hound rules update
57
+ ```
58
+
59
+ You will get in your `$HOME` path the following files:
60
+
61
+ ```
62
+ .eslintrc.json
63
+ .rubocop.yml
64
+ .scss-lint.yml
65
+ ```
66
+
67
+ Also, you can pass a linter's name to update rules for a specific language.
68
+
69
+ For example:
70
+
71
+ Running...
72
+
73
+ ```
74
+ $ hound rules update ruby
75
+ ```
76
+
77
+ You will get an updated `.rubocop.yml` file in your `$HOME` path.
78
+
79
+ ## Contributing
80
+
81
+ 1. Fork it
82
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
83
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
84
+ 4. Push to the branch (`git push origin my-new-feature`)
85
+ 5. Create new Pull Request
86
+
87
+ ## Credits
88
+
89
+ Thank you [contributors](https://github.com/platanus/hound-cli/graphs/contributors)!
90
+
91
+ <img src="http://platan.us/gravatar_with_text.png" alt="Platanus" width="250"/>
92
+
93
+ Paperclip Attributes is maintained by [platanus](http://platan.us).
94
+
95
+ ## License
96
+
97
+ Hound CLI is © 2016 platanus, spa. It is free software and may be redistributed under the terms specified in the LICENSE file.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "hound"
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
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
data/exe/hound ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+ lib = File.expand_path(File.dirname(__FILE__) + "/../lib")
3
+ $LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
4
+
5
+ require "commander"
6
+ require "hound"
7
+ require "hound/cli"
8
+
9
+ Hound::Cli.new.run
data/hound.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'hound/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "hound-cli"
8
+ spec.version = Hound::VERSION
9
+ spec.authors = ["Platanus"]
10
+ spec.email = ["rubygems@platan.us"]
11
+
12
+ spec.summary = "Ruby CLI to generate style rules"
13
+ spec.description = "Ruby CLI to generate style rules for several linters"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
+ spec.bindir = "exe"
17
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency "colorize", "~> 0.7", ">= 0.7.7"
21
+ spec.add_dependency "activesupport", "~> 4.2", ">= 4.2.6"
22
+ spec.add_dependency "rest-client", "~> 1.8", ">= 1.8.0"
23
+ spec.add_dependency "commander", "~> 4.4", ">= 4.4.0"
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.12"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rspec", "~> 3.4"
28
+ spec.add_development_dependency "pry"
29
+ end
data/lib/hound/cli.rb ADDED
@@ -0,0 +1,35 @@
1
+ module Hound
2
+ class Cli
3
+ include Commander::Methods
4
+
5
+ def run
6
+ program :name, "Hound"
7
+ program :version, Hound::VERSION
8
+ program :description, "CLI to generate style rules"
9
+ define_update_cmds
10
+ run!
11
+ end
12
+
13
+ private
14
+
15
+ def define_update_cmds
16
+ command("rules update") do |c|
17
+ c.syntax = "hound rules updates"
18
+ c.description = "Update rules for enabled linters"
19
+ c.action { RulesUpdater.update }
20
+ end
21
+
22
+ ConfigCollection::LINTER_NAMES.each do |linter|
23
+ define_update_linter_cmd(linter)
24
+ end
25
+ end
26
+
27
+ def define_update_linter_cmd(linter)
28
+ command("rules update #{linter}") do |c|
29
+ c.syntax = "hound rules update #{linter}"
30
+ c.description = "Update rules for #{linter} linter"
31
+ c.action { RulesUpdater.update(linter) }
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,25 @@
1
+ module Hound
2
+ module Config
3
+ class Base
4
+ attr_reader :linters_file_name
5
+
6
+ def name
7
+ name_from_class
8
+ end
9
+
10
+ def linters_file_path
11
+ File.join(File.expand_path("~"), linters_file_name)
12
+ end
13
+
14
+ def rules_url
15
+ HoundConfig.rules_url_for(name)
16
+ end
17
+
18
+ private
19
+
20
+ def name_from_class
21
+ self.class.name.demodulize.underscore
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,9 @@
1
+ module Hound
2
+ module Config
3
+ class Eslint < Base
4
+ def initialize
5
+ @linters_file_name = ".eslintrc.json"
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Hound
2
+ module Config
3
+ class Ruby < Base
4
+ def initialize
5
+ @linters_file_name = ".rubocop.yml"
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Hound
2
+ module Config
3
+ class Scss < Base
4
+ def initialize
5
+ @linters_file_name = ".scss-lint.yml"
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Hound
2
+ module Config
3
+ class Tslint < Base
4
+ def initialize
5
+ @linters_file_name = "tslint.json"
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,23 @@
1
+ module Hound
2
+ class ConfigCollection
3
+ LINTER_NAMES = %w{ruby eslint tslint scss}
4
+
5
+ def self.config_instances(linter_names = [])
6
+ linter_names = LINTER_NAMES if linter_names.empty?
7
+ linter_names.map do |linter|
8
+ ensure_valid_linter(linter)
9
+ "Hound::Config::#{linter.classify}".constantize.new
10
+ end
11
+ end
12
+
13
+ class << self
14
+ private
15
+
16
+ def ensure_valid_linter(linter)
17
+ if !LINTER_NAMES.include?(linter)
18
+ raise Hound::Error::InvalidLang.new("Invalid #{linter} linter")
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,6 @@
1
+ module Hound
2
+ module Error
3
+ class ConfigError < Exception; end
4
+ class InvalidLang < Exception; end
5
+ end
6
+ end
@@ -0,0 +1,46 @@
1
+ class HoundConfig
2
+ CONFIG_FILE_REPOSITORY = "https://raw.githubusercontent.com/platanus/la-guia/master/"
3
+
4
+ def self.content
5
+ @@content ||= load_content
6
+ end
7
+
8
+ def self.enabled_for?(linter_name)
9
+ # disabled if linter_name key does not exist in hound.yml
10
+ return false unless content.has_key?(linter_name)
11
+ options = options_for(linter_name)
12
+ # enabled if linter_name key exists and enabled key is not defined.
13
+ return true unless options.keys.select { |k| k.downcase === "enabled" }.any?
14
+ # enabled "enabled" or "Enabled" keys are true.
15
+ !!options["enabled"] || !!options["Enabled"]
16
+ end
17
+
18
+ def self.options_for(linter_name)
19
+ return content[linter_name] if content.try(:has_key?, linter_name)
20
+ Hash.new
21
+ end
22
+
23
+ def self.rules_url_for(linter_name)
24
+ path_in_repo = options_for(linter_name)["config_file"].to_s
25
+ HoundConfig::CONFIG_FILE_REPOSITORY + path_in_repo
26
+ end
27
+
28
+ class << self
29
+ private
30
+
31
+ def config_file_url
32
+ CONFIG_FILE_REPOSITORY + ".hound.yml"
33
+ end
34
+
35
+ def load_content
36
+ Hound::Parser.yaml(RestClient.get(config_file_url))
37
+ rescue RestClient::ResourceNotFound
38
+ inform_config_not_found(config_file_url)
39
+ Hash.new
40
+ end
41
+
42
+ def inform_config_not_found(url)
43
+ puts "config file not found in #{url}".red
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,7 @@
1
+ module Hound
2
+ class Parser
3
+ def self.yaml(content)
4
+ YAML.safe_load(content, [Regexp])
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,48 @@
1
+ module Hound
2
+ class RulesUpdater
3
+ def self.update(*linter_names)
4
+ ConfigCollection.config_instances(linter_names).each do |linter_config|
5
+ get_rules(linter_config)
6
+ end
7
+ end
8
+
9
+ class << self
10
+ private
11
+
12
+ def get_rules(linter_config)
13
+ if !HoundConfig.enabled_for?(linter_config.name)
14
+ inform_disabled(linter_config)
15
+ return
16
+ end
17
+
18
+ rules = get_rules_from_url(linter_config)
19
+ return unless rules
20
+ write_linters_file(linter_config, rules)
21
+ inform_update(linter_config)
22
+ end
23
+
24
+ def get_rules_from_url(linter_config)
25
+ RestClient.get(linter_config.rules_url)
26
+ rescue RestClient::ResourceNotFound
27
+ inform_rules_not_found(linter_config)
28
+ end
29
+
30
+ def write_linters_file(linter_config, rules)
31
+ File.write(linter_config.linters_file_path, rules)
32
+ end
33
+
34
+ def inform_update(linter_config)
35
+ puts "#{linter_config.linters_file_name} (#{linter_config.name} style) was updated".green
36
+ end
37
+
38
+ def inform_disabled(linter_config)
39
+ puts "#{linter_config.linters_file_name} (#{linter_config.name} style) wasn't updated \
40
+ because the style was undefined or disabled in .hound.yml file".yellow
41
+ end
42
+
43
+ def inform_rules_not_found(linter_config)
44
+ puts "rules for #{linter_config.name} not found in #{linter_config.rules_url}".red
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,3 @@
1
+ module Hound
2
+ VERSION = "0.1.0"
3
+ end
data/lib/hound.rb ADDED
@@ -0,0 +1,19 @@
1
+ require "colorize"
2
+ require "rest-client"
3
+ require "active_support/all"
4
+ require "yaml"
5
+
6
+ require "hound/version"
7
+ require "hound/errors"
8
+ require "hound/parser"
9
+ require "hound/hound_config"
10
+ require "hound/rules_updater"
11
+ require "hound/config_collection"
12
+ require "hound/config/base"
13
+ require "hound/config/ruby"
14
+ require "hound/config/eslint"
15
+ require "hound/config/tslint"
16
+ require "hound/config/scss"
17
+
18
+ module Hound
19
+ end
metadata ADDED
@@ -0,0 +1,205 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hound-cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Platanus
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-07-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: colorize
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.7'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.7.7
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '0.7'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 0.7.7
33
+ - !ruby/object:Gem::Dependency
34
+ name: activesupport
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '4.2'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 4.2.6
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '4.2'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 4.2.6
53
+ - !ruby/object:Gem::Dependency
54
+ name: rest-client
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '1.8'
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 1.8.0
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '1.8'
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: 1.8.0
73
+ - !ruby/object:Gem::Dependency
74
+ name: commander
75
+ requirement: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - "~>"
78
+ - !ruby/object:Gem::Version
79
+ version: '4.4'
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 4.4.0
83
+ type: :runtime
84
+ prerelease: false
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '4.4'
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: 4.4.0
93
+ - !ruby/object:Gem::Dependency
94
+ name: bundler
95
+ requirement: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - "~>"
98
+ - !ruby/object:Gem::Version
99
+ version: '1.12'
100
+ type: :development
101
+ prerelease: false
102
+ version_requirements: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - "~>"
105
+ - !ruby/object:Gem::Version
106
+ version: '1.12'
107
+ - !ruby/object:Gem::Dependency
108
+ name: rake
109
+ requirement: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - "~>"
112
+ - !ruby/object:Gem::Version
113
+ version: '10.0'
114
+ type: :development
115
+ prerelease: false
116
+ version_requirements: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - "~>"
119
+ - !ruby/object:Gem::Version
120
+ version: '10.0'
121
+ - !ruby/object:Gem::Dependency
122
+ name: rspec
123
+ requirement: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - "~>"
126
+ - !ruby/object:Gem::Version
127
+ version: '3.4'
128
+ type: :development
129
+ prerelease: false
130
+ version_requirements: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - "~>"
133
+ - !ruby/object:Gem::Version
134
+ version: '3.4'
135
+ - !ruby/object:Gem::Dependency
136
+ name: pry
137
+ requirement: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ type: :development
143
+ prerelease: false
144
+ version_requirements: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ description: Ruby CLI to generate style rules for several linters
150
+ email:
151
+ - rubygems@platan.us
152
+ executables:
153
+ - hound
154
+ extensions: []
155
+ extra_rdoc_files: []
156
+ files:
157
+ - ".gitignore"
158
+ - ".rspec"
159
+ - ".ruby-version"
160
+ - ".travis.yml"
161
+ - Gemfile
162
+ - LICENSE.txt
163
+ - README.md
164
+ - Rakefile
165
+ - bin/console
166
+ - bin/setup
167
+ - exe/hound
168
+ - hound.gemspec
169
+ - lib/hound.rb
170
+ - lib/hound/cli.rb
171
+ - lib/hound/config/base.rb
172
+ - lib/hound/config/eslint.rb
173
+ - lib/hound/config/ruby.rb
174
+ - lib/hound/config/scss.rb
175
+ - lib/hound/config/tslint.rb
176
+ - lib/hound/config_collection.rb
177
+ - lib/hound/errors.rb
178
+ - lib/hound/hound_config.rb
179
+ - lib/hound/parser.rb
180
+ - lib/hound/rules_updater.rb
181
+ - lib/hound/version.rb
182
+ homepage:
183
+ licenses: []
184
+ metadata: {}
185
+ post_install_message:
186
+ rdoc_options: []
187
+ require_paths:
188
+ - lib
189
+ required_ruby_version: !ruby/object:Gem::Requirement
190
+ requirements:
191
+ - - ">="
192
+ - !ruby/object:Gem::Version
193
+ version: '0'
194
+ required_rubygems_version: !ruby/object:Gem::Requirement
195
+ requirements:
196
+ - - ">="
197
+ - !ruby/object:Gem::Version
198
+ version: '0'
199
+ requirements: []
200
+ rubyforge_project:
201
+ rubygems_version: 2.5.1
202
+ signing_key:
203
+ specification_version: 4
204
+ summary: Ruby CLI to generate style rules
205
+ test_files: []