maximus 0.1.5.1 → 0.1.6.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8c7fee2775fc5f24bcb70edfe70ade2c8f0e68a9
4
- data.tar.gz: 565a9109eda74ce453e8d1c768cd369b7c75f054
3
+ metadata.gz: 3dacd7121350ac5d7ac834d3df60a3691712fb0a
4
+ data.tar.gz: 5d2662c81e42754cb68dcd15a556b93e83ae4b01
5
5
  SHA512:
6
- metadata.gz: 2cd898e33840532940ea3cef058f2d75d6b01516d9386efc7626c78c786f1b9902ad8862b7775e9598e6e8699d817dc298dda467e067a3491ca18e317f96bc5d
7
- data.tar.gz: 0c1f8c5a14e03c0b682e1fb3b7127afa3c0e7862693178479ba421d81e667ca3c756efb24c344e5efba40923632b34f7d9c6d0d9e2258e5057e05dfda8a16882
6
+ metadata.gz: 97a96d4a95abfd20cacd25c4d277e0b8981b0a63b04667456ffa69efd5d0390b03042e7dde811d40a73af0be54bd5dcf84e591f8b99a89cc7fb41767790e1884
7
+ data.tar.gz: c7a3fd83cc45e5e72fa8f93cf184a2c99649e1401bd73bd06919b9ff8c558ac795b513f9f0f250364f22173ae8f650132420d4f5ae9bc29c46e7055c8a28d78a
data/.gitignore CHANGED
@@ -23,3 +23,4 @@ mkmf.log
23
23
  # generated spec config files
24
24
  spec/.maximus.yml
25
25
  .maximus.yml
26
+ .rvmrc
@@ -0,0 +1,72 @@
1
+ # Change log
2
+
3
+ ## master
4
+
5
+ ## 0.1.6.1 (March 1, 2015)
6
+
7
+ Features:
8
+
9
+ * Remote config files can be specified
10
+
11
+ Bugfixes:
12
+
13
+ * Clean up config option loading/overriding
14
+ * Remove some command line defaults
15
+ * Performance and syntax optimizations
16
+ * Handle Middleman and generic app paths better
17
+
18
+ ## 0.1.5.1 (February 2, 2015)
19
+
20
+ Bugfixes:
21
+
22
+ * Active Support requirement was too strict
23
+
24
+ ## 0.1.5 (February 1, 2015)
25
+
26
+ Bugfixes:
27
+
28
+ * Wraith outputs percentages properly
29
+ * Diff data for initial commits
30
+ * More intuitive config path discovery
31
+ * Flip GitControl#diff around for old to new comparison
32
+ * More stability/defensive programming in Config, Wraith, and GitControl
33
+
34
+ Features:
35
+
36
+ * Wraith includes images in output
37
+
38
+ ## 0.1.4 (January 3, 2015)
39
+
40
+ Bugfixes:
41
+
42
+ * Added basic tests
43
+ * Modified git-lines to show unified=1 instead of unified=0
44
+ * Remove tmp files error
45
+ * Better documentation to README
46
+
47
+ ## 0.1.3 (December 22, 2014)
48
+
49
+ Features:
50
+
51
+ * Options are defined once in Config class
52
+ * `maximus.yml` can be loaded to set the config
53
+ * All lint and statistic options can be in the maximus config file
54
+ * More command line flags
55
+
56
+ ## 0.1.2 (December 18, 2014)
57
+
58
+ Features:
59
+
60
+ * Better inline documentation
61
+
62
+ Bugfixes:
63
+
64
+ * Resolve exiting error when no lint errors are preset (0efef67)
65
+
66
+ ## 0.1.1 (December 9, 2014)
67
+
68
+ * Description and homepage update
69
+
70
+ ## 0.1.0 (December 9, 2014)
71
+
72
+ * Initial
@@ -1,4 +1,4 @@
1
- Copyright (c) 2015 Tim Shedor
1
+ Copyright (c) 2014-2015 Tim Shedor
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Maximus
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/maximus.svg)](http://badge.fury.io/rb/maximus) [![Code Climate](https://codeclimate.com/github/wearefine/maximus/badges/gpa.svg)](https://codeclimate.com/github/wearefine/maximus) [![Build Status](https://travis-ci.org/wearefine/maximus.svg)](https://travis-ci.org/wearefine/maximus) [![Coverage Status](https://coveralls.io/repos/wearefine/maximus/badge.svg)](https://coveralls.io/r/wearefine/maximus) [![Inline docs](http://inch-ci.org/github/wearefine/maximus.svg?branch=master&style=flat)](http://inch-ci.org/github/wearefine/maximus)
3
+ [![Gem Version](https://badge.fury.io/rb/maximus.svg)](http://badge.fury.io/rb/maximus) [![Code Climate](https://codeclimate.com/github/wearefine/maximus/badges/gpa.svg)](https://codeclimate.com/github/wearefine/maximus) [![Build Status](https://travis-ci.org/wearefine/maximus.svg)](https://travis-ci.org/wearefine/maximus) [![Coverage Status](https://coveralls.io/repos/wearefine/maximus/badge.svg)](https://coveralls.io/r/wearefine/maximus) [![Inline docs](http://inch-ci.org/github/wearefine/maximus.svg?branch=master&style=flat)](http://inch-ci.org/github/wearefine/maximus) [![Yard Docs](http://img.shields.io/badge/yard-docs-blue.svg)](http://www.rubydoc.info/gems/maximus)
4
4
 
5
5
  The all-in-one linting solution.
6
6
 
@@ -138,63 +138,3 @@ When adding new lints, the JSON output should obey the following format:
138
138
  ## Notes
139
139
 
140
140
  If calling Maximus::Wraith from a script, please see the note in lib/statistics/wraith.rb#result
141
-
142
- ## Changelog
143
-
144
- ### 0.1.5.1 (February 2, 2015)
145
-
146
- Bugfixes:
147
-
148
- * Active Support requirement was too strict
149
-
150
- ### 0.1.5 (February 1, 2015)
151
-
152
- Bugfixes:
153
-
154
- * Wraith outputs percentages properly
155
- * Diff data for initial commits
156
- * More intuitive config path discovery
157
- * Flip GitControl#diff around for old to new comparison
158
- * More stability/defensive programming in Config, Wraith, and GitControl
159
-
160
- Features:
161
-
162
- * Wraith includes images in output
163
-
164
- ### 0.1.4 (January 3, 2015)
165
-
166
- Bugfixes:
167
-
168
- * Added basic tests
169
- * Modified git-lines to show unified=1 instead of unified=0
170
- * Remove tmp files error
171
- * Better documentation to README
172
-
173
- ### 0.1.3 (December 22, 2014)
174
-
175
- Features:
176
-
177
- * Options are defined once in Config class
178
- * `maximus.yml` can be loaded to set the config
179
- * All lint and statistic options can be in the maximus config file
180
- * More command line flags
181
-
182
- ### 0.1.2 (December 18, 2014)
183
-
184
- Features:
185
-
186
- * Better inline documentation
187
-
188
- Bugfixes:
189
-
190
- * Resolve exiting error when no lint errors are preset (0efef67)
191
-
192
- ### 0.1.1 (December 9, 2014)
193
-
194
- * Description and homepage update
195
-
196
- ### 0.1.0 (December 9, 2014)
197
-
198
- * Initial
199
-
200
-
@@ -6,23 +6,24 @@ class Maximus::CLI < Thor
6
6
 
7
7
  include Thor::Actions
8
8
 
9
- class_option :frontend, aliases: ['-f', '--front-end'], type: :boolean, default: false, lazy_default: false, desc: "Do front-end lints"
10
- class_option :backend, aliases: ['-b', '--back-end'], type: :boolean, default: false, lazy_default: false, desc: "Do back-end lints"
11
- class_option :statistics, aliases: ['-s'], type: :boolean, default: false, lazy_default: false, desc: "Do statistics"
9
+ class_option :frontend, aliases: ['-f', '--front-end'], type: :boolean, default: false, lazy_default: true, desc: "Do front-end lints"
10
+ class_option :backend, aliases: ['-b', '--back-end'], type: :boolean, default: false, lazy_default: true, desc: "Do back-end lints"
11
+ class_option :statistics, aliases: ['-s'], type: :boolean, default: false, lazy_default: true, desc: "Do statistics"
12
12
  class_option :all, aliases: ['-a'], type: :boolean, default: false, lazy_default: false, desc: "Do everything"
13
13
 
14
14
  class_option :filepath, aliases: ['-fp'], type: :array, default: [], desc: "Space-separated path(s) to files"
15
- class_option :urls, aliases: ['-u'], type: :array, default: ['/'], desc: "Statistics only - Space-separated path(s) to relative URL paths"
16
- class_option :domain, aliases: ['-d'], type: :string, default: 'http://localhost', desc: "Statistics only - Web address (prepended to paths)"
17
- class_option :port, aliases: ['-po'], type: :numeric, default: 3000, desc: 'Statistics only - Port to use if required (appended to domain)'
15
+ class_option :urls, aliases: ['-u'], type: :array, desc: "Statistics only - Space-separated path(s) to relative URL paths"
16
+ class_option :domain, aliases: ['-d'], type: :string, desc: "Statistics only - Web address (prepended to paths)"
17
+ class_option :port, aliases: ['-po'], type: :numeric, desc: 'Statistics only - Port to use if required (appended to domain)'
18
18
 
19
19
  class_option :include, aliases: ['-i'], type: :array, default: [], desc: "Include only specific lints or statistics"
20
20
  class_option :exclude, aliases: ['-e'], type: :array, default: [], desc: "Exlude specific lints or statistics"
21
21
 
22
- class_option :config, aliases: ['-c'], type: :string, default: nil, desc: 'Path to config file'
22
+ class_option :config, aliases: ['-c'], type: :string, desc: 'Path to config file'
23
23
 
24
24
  class_option :git, aliases: ['-g', '--git', '--sha'], type: :string, default: 'working', banner: "working, last, master, or sha", desc: "Lint by commit or working copy"
25
25
 
26
+ # Inherit from original Thor and add @config instance var
26
27
  def initialize(*args)
27
28
  super
28
29
  @config ||= Maximus::Config.new(default_options)
@@ -56,12 +57,16 @@ class Maximus::CLI < Thor
56
57
  desc "git", "Display lint data based on working copy, last commit, master branch or specific sha"
57
58
  def git
58
59
  all_tasks = ['frontend', 'backend', 'statistics']
60
+
59
61
  # If all flag is enabled, run everything
60
62
  return all_tasks.each { |a| send(a) } if options[:all]
63
+
61
64
  # Lint by category unless all flags are blank
62
65
  return all_tasks.each { |a| check_option(a) } unless options[:frontend].blank? && options[:backend].blank? && options[:statistics].blank?
66
+
63
67
  # If include flag is enabled, run based on what's included
64
68
  return options[:include].each { |i| send(i) } unless options[:include].blank?
69
+
65
70
  # If all flag is not enabled, lint working copy as it's supposed to be
66
71
  @config.settings[:commit] = options[:git]
67
72
  Maximus::GitControl.new({config: @config}).lints_and_stats(true)
@@ -79,12 +84,14 @@ class Maximus::CLI < Thor
79
84
  def check_option(opt)
80
85
  send(opt) if options[opt.to_sym]
81
86
  end
87
+
82
88
  # Don't run command if it's present in the exlude options
83
89
  def check_exclude(opt)
84
90
  send(opt) unless options[:exclude].include?(opt)
85
91
  end
92
+
86
93
  def default_options
87
- {
94
+ opts = {
88
95
  file_paths: options[:filepath],
89
96
  paths: options[:urls],
90
97
  domain: options[:domain],
@@ -92,6 +99,14 @@ class Maximus::CLI < Thor
92
99
  is_dev: true,
93
100
  config_file: options[:config]
94
101
  }
102
+ stats = {
103
+ stylestats: options[:include].include?('stylestats'),
104
+ wraith: options[:include].include?('wraith'),
105
+ phantomas: options[:include].include?('phantomas')
106
+ }
107
+
108
+ opts.merge!(stats) unless options[:include].include?('statistics') || options[:statistics]
109
+ opts
95
110
  end
96
111
 
97
112
  def scsslint
@@ -1,5 +1,6 @@
1
1
  require 'active_support'
2
2
  require 'active_support/core_ext/hash/keys'
3
+ require 'open-uri'
3
4
 
4
5
  module Maximus
5
6
 
@@ -22,7 +23,7 @@ module Maximus
22
23
  # @option opts [String, Boolean] :git_log (false) path to log file or don't log
23
24
  # The git gem is very noisey
24
25
  # @option opts [String] :root_dir base directory
25
- # @option opts [String] :domain ('http://localhost:3000') the host - used for Statistics
26
+ # @option opts [String] :domain ('http://localhost') the host - used for Statistics
26
27
  # @option opts [String, Integer] :port ('') port number - used for Statistics
27
28
  # and appended to domain. If blank (false, empty string, etc.), will not
28
29
  # append to domain
@@ -34,25 +35,18 @@ module Maximus
34
35
  # @return [#load_config_file #group_families #evaluate_settings] this method is used to set up instance variables
35
36
  def initialize(opts = {})
36
37
 
37
- default_options = {
38
- root_dir: root_dir,
39
- domain: 'http://localhost',
40
- port: is_rails? ? 3000 : '',
41
- paths: { 'home' => '/' },
42
- is_dev: false,
43
- phantomas: false,
44
- stylestats: false,
45
- wraith: false
46
- }
38
+ # Strips from command line
39
+ opts = opts.delete_if { |k, v| v.nil? }
40
+
41
+ default_options = YAML.load_file(File.join(File.dirname(__FILE__), 'config', 'maximus.yml')).symbolize_keys
42
+ default_options[:root_dir] = root_dir
43
+ default_options[:port] = 3000 if is_rails?
44
+
45
+ @root = opts[:root_dir] ? opts[:root_dir] : default_options[:root_dir]
47
46
 
48
47
  yaml = default_options.merge load_config_file(opts[:config_file])
49
48
  @settings = yaml.merge opts
50
49
 
51
- # Only set log file if it's set to true.
52
- # Otherwise, allow it to be nil or a path
53
- @settings[:log] = false if @settings[:log].nil?
54
- @settings[:log] ||= 'log/maximus.log' if @settings[:log].is_a?(TrueClass)
55
-
56
50
  @settings[:git_log] = false if @settings[:git_log].nil?
57
51
  @settings[:git_log] ||= 'log/maximus_git.log' if @settings[:git_log].is_a?(TrueClass)
58
52
 
@@ -85,7 +79,7 @@ module Maximus
85
79
  # global config variables (last when statement in this switch)
86
80
  value = load_config(value)
87
81
 
88
- if settings_data[key].is_a?(Hash) && settings_data[key].has_key?('jshintignore')
82
+ if settings_data[key].is_a?(Hash) && settings_data[key].key?('jshintignore')
89
83
  jshintignore_file = []
90
84
  settings_data[key]['jshintignore'].each { |i| jshintignore_file << "#{i}\n" }
91
85
  @settings[:jshintignore] = temp_it('jshintignore.json', jshintignore_file)
@@ -137,15 +131,11 @@ module Maximus
137
131
  @settings[:is_dev]
138
132
  end
139
133
 
140
- # Defines base logger
141
- # @param out [String, STDOUT] location for logging
142
- # Accepts file path
143
- # @return [Logger] self.log
144
- def log
145
- out = @settings[:log] || STDOUT
146
- @log ||= Logger.new(out)
147
- @log.level ||= Logger::INFO
148
- @log
134
+ # Grab root directory
135
+ # @since 0.1.6
136
+ # @return [String]
137
+ def working_dir
138
+ @settings[:root_dir]
149
139
  end
150
140
 
151
141
  # Remove all or one created temporary config file
@@ -166,7 +156,7 @@ module Maximus
166
156
  # Combine domain with port if necessary
167
157
  # @return [String] complete domain/host address
168
158
  def domain
169
- (!@settings[:port].blank?) ? "#{@settings[:domain]}:#{@settings[:port]}" : @settings[:domain]
159
+ @settings[:port].blank? ? @settings[:domain] : "#{@settings[:domain]}:#{@settings[:port]}"
170
160
  end
171
161
 
172
162
 
@@ -187,11 +177,13 @@ module Maximus
187
177
  conf_location = if !file_path.nil? && File.exist?(file_path)
188
178
  file_path
189
179
  else
190
- config_exists('.maximus.yml') || config_exists('maximus.yml') || check_default_config_path('config/maximus.yml')
180
+ config_exists('.maximus.yml') || config_exists('maximus.yml') || config_exists('config/maximus.yml')
191
181
  end
192
182
 
193
- yaml = YAML.load_file(conf_location)
183
+ return {} if conf_location.is_a?(FalseClass)
194
184
 
185
+ yaml = YAML.load_file conf_location
186
+ yaml = {} if yaml.blank?
195
187
  yaml.symbolize_keys
196
188
 
197
189
  end
@@ -207,7 +199,7 @@ module Maximus
207
199
  # @param family [Array] group of other @settings keys to be disabled
208
200
  # @return [void] modified @settings
209
201
  def set_families(head_of_house, family)
210
- if @settings.has_key?(head_of_house)
202
+ if @settings.key?(head_of_house)
211
203
  family.each { |f| @settings[f] ||= @settings[head_of_house].is_a?(TrueClass) }
212
204
  end
213
205
  end
@@ -219,12 +211,21 @@ module Maximus
219
211
  # the reset of the process doesn't break
220
212
  def load_config(value)
221
213
  return value unless value.is_a?(String)
222
- if File.exist?(value)
223
- return YAML.load_file(value)
214
+
215
+ if value =~ /^http/
216
+ begin open(value)
217
+ YAML.load open(value).read
218
+ rescue
219
+ puts "#{value} not accessible"
220
+ {}
221
+ end
222
+ elsif File.exist?(value)
223
+ YAML.load_file(value)
224
224
  else
225
225
  puts "#{value} not found"
226
- return {}
226
+ {}
227
227
  end
228
+
228
229
  end
229
230
 
230
231
  # Create a temp file with config data
@@ -255,7 +256,8 @@ module Maximus
255
256
  # @return [String, FalseClass] if file is found return the absolute path
256
257
  # otherwise return false so we can keep checking
257
258
  def config_exists(file)
258
- File.exist?(File.join(File.dirname(__FILE__), file)) ? File.join(File.dirname(__FILE__), file) : false
259
+ present_location = File.join(@root, file)
260
+ File.exist?(present_location) ? present_location : false
259
261
  end
260
262
 
261
263
  # Accounting for space-separated command line arrays
@@ -293,7 +295,7 @@ module Maximus
293
295
  # @return [String] temp file path
294
296
  def wraith_setup(value, name = 'phantomjs')
295
297
 
296
- if @settings.has_key?(:urls)
298
+ if @settings.key?(:urls)
297
299
  value['domains'] = @settings[:urls]
298
300
  else
299
301
  value['domains'] = {}
@@ -1,9 +1,19 @@
1
+ domain: 'http://localhost'
2
+ # Note: is_dev should be set to false always in maximus.yml files
3
+ # Really, it shouldn't be set in a maximus.yml file period, it's only
4
+ # here because this is the default file. If set to true, output is logged directly
5
+ # to the parent process and does not appear in the log.
6
+ is_dev: false
1
7
  paths:
2
8
  home: '/'
3
9
 
4
10
  scsslint: true
5
11
 
6
- rubocop: true
12
+ rubocop:
13
+ AllCops:
14
+ Exclude:
15
+ - 'db/**/*'
16
+ - 'vendor/**/*'
7
17
 
8
18
  railsbp: true
9
19
 
@@ -1,12 +1,13 @@
1
1
  require 'git'
2
2
 
3
3
  module Maximus
4
+ # Git management
4
5
  # @since 0.1.0
5
6
  class GitControl
6
7
 
7
8
  include Helper
8
9
 
9
- # Git management
10
+ # Set up instance variables
10
11
  #
11
12
  # Inherits settings from {Config#initialize}
12
13
  # @param opts [Hash] options passed directly to config
@@ -19,7 +20,7 @@ module Maximus
19
20
  @settings = @config.settings
20
21
  @psuedo_commit = ( !@settings[:commit].blank? && %w(working last master).include?(@settings[:commit]) )
21
22
 
22
- @g = Git.open(@settings[:root_dir])
23
+ @g = Git.open(@config.working_dir)
23
24
  end
24
25
 
25
26
  # 30,000 foot view of a commit
@@ -69,7 +70,7 @@ module Maximus
69
70
  def compare(sha1 = master_commit_sha, sha2 = head_sha)
70
71
  diff_return = {}
71
72
 
72
- sha1 = set_psuedo_commit if @settings[:commit]
73
+ sha1 = define_psuedo_commit if @settings[:commit]
73
74
  # Reverse so that we go in chronological order
74
75
  git_spread = commit_range(sha1, sha2).reverse
75
76
 
@@ -77,7 +78,7 @@ module Maximus
77
78
 
78
79
  # Grab all files in that commit and group them by extension
79
80
  # If working copy, just give the diff names of the files changed
80
- files = @psuedo_commit ? `git -C #{@settings[:root_dir]} diff --name-only` : `git -C #{@settings[:root_dir]} show --pretty="format:" --name-only #{git_sha}`
81
+ files = @psuedo_commit ? `git -C #{@config.working_dir} diff --name-only` : `git -C #{@config.working_dir} show --pretty="format:" --name-only #{git_sha}`
81
82
 
82
83
  diff_return[git_sha.to_s] = match_associations(git_sha, files)
83
84
  end
@@ -87,6 +88,7 @@ module Maximus
87
88
  # Run appropriate lint for every sha in commit history.
88
89
  # For each sha a new branch is created then deleted
89
90
  #
91
+ # This is where everything goes down
90
92
  # @example sample output
91
93
  # {
92
94
  # 'sha': {
@@ -109,19 +111,16 @@ module Maximus
109
111
  # @return [Hash] data all data grouped by task
110
112
  def lints_and_stats(lint_by_path = false, git_shas = compare, nuclear = false)
111
113
  return false if git_shas.blank?
114
+
112
115
  base_branch = branch
113
- git_output = {}
116
+ git_ouput = {}
117
+
114
118
  git_shas.each do |sha, exts|
115
119
  create_branch(sha) unless @psuedo_commit
116
120
  sha = sha.to_s
117
121
  puts sha.color(:blue)
118
- git_output[sha] = {lints: {}, statistics: {}}
119
- lints = git_output[sha][:lints]
120
- statistics = git_output[sha][:statistics]
121
122
 
122
- # This is where everything goes down
123
123
  exts.each do |ext, files|
124
-
125
124
  # For relevant_lines data
126
125
  lint_opts = {
127
126
  git_files: files,
@@ -130,53 +129,23 @@ module Maximus
130
129
  }
131
130
 
132
131
  if nuclear
133
- lints[:scsslint] = Maximus::Scsslint.new(lint_opts).result
134
- lints[:jshint] = Maximus::Jshint.new(lint_opts).result
135
- lints[:rubocop] = Maximus::Rubocop.new(lint_opts).result
136
- lints[:railsbp] = Maximus::Railsbp.new(lint_opts).result
137
- lints[:brakeman] = Maximus::Brakeman.new(lint_opts).result
138
- statistics[:stylestat] = Maximus::Stylestats.new({config: @config}).result
139
- statistics[:phantomas] = Maximus::Phantomas.new({config: @config}).result
140
- statistics[:wraith] = Maximus::Wraith.new({config: @config}).result
132
+ git_ouput[sha] = lints_and_stats_nuclear(lint_opts)
141
133
  else
142
- case ext
143
- when :scss
144
- lints[:scsslint] = Maximus::Scsslint.new(lint_opts).result
145
-
146
- # @todo stylestat is singular here because model name in Rails is singular.
147
- # But adding a .classify when it's converted to a model chops off the end s on 'phantomas',
148
- # which breaks the model name.
149
- statistics[:stylestat] = Maximus::Stylestats.new({config: @config}).result
150
-
151
- # @todo double pipe here is best way to say, if it's already run, don't run again, right?
152
- statistics[:phantomas] ||= Maximus::Phantomas.new({config: @config}).result
153
- statistics[:wraith] ||= Maximus::Wraith.new({config: @config}).result
154
- when :js
155
- lints[:jshint] = Maximus::Jshint.new(lint_opts).result
156
-
157
- statistics[:phantomas] ||= Maximus::Phantomas.new({config: @config}).result
158
-
159
- # @todo double pipe here is best way to say, if it's already run, don't run again, right?
160
- statistics[:wraith] ||= Maximus::Wraith.new({config: @config}).result
161
- when :ruby
162
- lints[:rubocop] = Maximus::Rubocop.new(lint_opts).result
163
- lints[:railsbp] ||= Maximus::Railsbp.new(lint_opts).result
164
- lints[:brakeman] = Maximus::Brakeman.new(lint_opts).result
165
- when :rails
166
- lints[:railsbp] ||= Maximus::Railsbp.new(lint_opts).result
167
- end
134
+ git_ouput[sha] = lints_and_stats_switch(ext, lint_opts)
168
135
  end
169
136
  end
137
+
170
138
  destroy_branch(base_branch, sha) unless @psuedo_commit
171
139
  end
172
- git_output
140
+
141
+ git_ouput
173
142
  end
174
143
 
175
144
  # Find first commit
176
145
  # @since 0.1.5
177
146
  # @return [String]
178
147
  def first_commit
179
- `git -C #{@settings[:root_dir]} rev-list --max-parents=0 HEAD`.strip!
148
+ `git -C #{@config.working_dir} rev-list --max-parents=0 HEAD`.strip!
180
149
  end
181
150
 
182
151
  # Get commit before current
@@ -185,7 +154,7 @@ module Maximus
185
154
  # @param previous_by [Integer] (1) commit n commits ago
186
155
  # @return [String]
187
156
  def previous_commit(current_commit = head_sha, previous_by = 1)
188
- `git -C #{@settings[:root_dir]} rev-list --max-count=#{previous_by + 1} #{current_commit} --reverse | head -n1`.strip!
157
+ `git -C #{@config.working_dir} rev-list --max-count=#{previous_by + 1} #{current_commit} --reverse | head -n1`.strip!
189
158
  end
190
159
 
191
160
  # Define associations to linters based on file extension
@@ -194,7 +163,7 @@ module Maximus
194
163
  {
195
164
  scss: ['scss', 'sass'],
196
165
  js: ['js'],
197
- ruby: ['rb', 'Gemfile', 'lock', 'yml', 'Rakefile', 'ru', 'rdoc', 'rake', 'Capfile'],
166
+ ruby: ['rb', 'Gemfile', 'lock', 'yml', 'Rakefile', 'ru', 'rdoc', 'rake', 'Capfile', 'jbuilder'],
198
167
  rails: ['slim', 'haml', 'jbuilder', 'erb']
199
168
  }
200
169
  end
@@ -217,7 +186,7 @@ module Maximus
217
186
  # @param sha2 [String]
218
187
  # @return [Array] shas
219
188
  def commit_range(sha1, sha2)
220
- git_spread = @psuedo_commit ? "git #{sha1}" : `git -C #{@settings[:root_dir]} rev-list #{sha1}..#{sha2} --no-merges`
189
+ git_spread = @psuedo_commit ? "git #{sha1}" : `git -C #{@config.working_dir} rev-list #{sha1}..#{sha2} --no-merges`
221
190
  git_spread = git_spread.nil? ? [] : git_spread.split("\n")
222
191
 
223
192
  git_spread << sha1 unless @psuedo_commit
@@ -227,7 +196,7 @@ module Maximus
227
196
  # Get sha if words passed for :commit config option
228
197
  # @since 0.1.5
229
198
  # @return [String] commit sha
230
- def set_psuedo_commit
199
+ def define_psuedo_commit
231
200
  case @settings[:commit]
232
201
  when 'master' then master_commit_sha
233
202
  when 'last' then previous_commit(head_sha)
@@ -241,7 +210,7 @@ module Maximus
241
210
  # @since 0.1.5
242
211
  # @param sha [String]
243
212
  def create_branch(sha)
244
- quietly { `git -C #{@settings[:root_dir]} checkout #{sha} -b maximus_#{sha}` }
213
+ quietly { `git -C #{@config.working_dir} checkout #{sha} -b maximus_#{sha}` }
245
214
  end
246
215
 
247
216
  # Destroy created branch
@@ -282,7 +251,7 @@ module Maximus
282
251
  # @return [Hash] ranges by lines added in a commit by file name
283
252
  def lines_added(git_sha)
284
253
  new_lines = {}
285
- git_lines = `#{File.join(File.dirname(__FILE__), 'reporter/git-lines.sh')} #{@settings[:root_dir]} #{git_sha}`.split("\n")
254
+ git_lines = `#{File.join(File.dirname(__FILE__), 'reporter', 'git-lines.sh')} #{@config.working_dir} #{git_sha}`.split("\n")
286
255
  git_lines.each do |filename|
287
256
  fsplit = filename.split(':')
288
257
  # if file isn't already part of the array
@@ -310,7 +279,7 @@ module Maximus
310
279
  # Get last commit sha on the master branch
311
280
  # @return [String]
312
281
  def master_commit_sha
313
- @g.branches[:master].gcommit.sha
282
+ @g.branches[:master].blank? ? head_sha : @g.branches[:master].gcommit.sha
314
283
  end
315
284
 
316
285
  # Get general stats of commit on HEAD versus last commit on master branch
@@ -323,7 +292,7 @@ module Maximus
323
292
  lines = lines_added(new_commit.sha)
324
293
  return if !lines.is_a?(Hash) || stats.blank?
325
294
  lines.each do |filename, filelines|
326
- stats[:files][filename][:lines_added] = filelines if stats[:files].has_key?(filename)
295
+ stats[:files][filename][:lines_added] = filelines if stats[:files].key?(filename)
327
296
  end
328
297
  stats
329
298
  end
@@ -336,7 +305,7 @@ module Maximus
336
305
  # @return [Hash] stat data similar to Ruby-git's Diff.stats return
337
306
  def diff_initial(commit_sha)
338
307
  # Start after the commit information
339
- data = `git -C #{@settings[:root_dir]} log --numstat --oneline #{commit_sha}`.split("\n")[1..-1]
308
+ data = `git -C #{@config.working_dir} log --numstat --oneline #{commit_sha}`.split("\n")[1..-1]
340
309
  value = {
341
310
  total: {
342
311
  insertions: 0,
@@ -387,7 +356,7 @@ module Maximus
387
356
  unless files[child].blank?
388
357
  files[child].each do |c|
389
358
  # hack to ignore deleted files
390
- files[child] = new_lines[c].blank? ? [] : [ filename: "#{@settings[:root_dir]}/#{c}", changes: new_lines[c] ]
359
+ files[child] = new_lines[c].blank? ? [] : [ filename: File.join(@config.working_dir, c), changes: new_lines[c] ]
391
360
  end
392
361
  files[ext].concat(files[child])
393
362
  files.delete(child)
@@ -399,5 +368,70 @@ module Maximus
399
368
  files
400
369
  end
401
370
 
371
+ # All data retrieved from reports
372
+ # @since 0.1.6
373
+ # @param lint_opts [Hash]
374
+ # @return [Hash]
375
+ def lints_and_stats_nuclear(lint_opts)
376
+ {
377
+ lints: {
378
+ scsslint: Maximus::Scsslint.new(lint_opts).result,
379
+ jshint: Maximus::Jshint.new(lint_opts).result,
380
+ rubocop: Maximus::Rubocop.new(lint_opts).result,
381
+ railsbp: Maximus::Railsbp.new(lint_opts).result,
382
+ brakeman: Maximus::Brakeman.new(lint_opts).result
383
+ },
384
+ statistics: {
385
+ stylestat: Maximus::Stylestats.new({config: @config}).result,
386
+ phantomas: Maximus::Phantomas.new({config: @config}).result,
387
+ wraith: Maximus::Wraith.new({config: @config}).result
388
+ }
389
+ }
390
+ end
391
+
392
+ # Specific data retrieved by file extension
393
+ # @since 0.1.6
394
+ # @param ext [String]
395
+ # @param lint_opts [Hash]
396
+ # @return [Hash]
397
+ def lints_and_stats_switch(ext, lint_opts)
398
+ result = {
399
+ lints: {},
400
+ statistics: {}
401
+ }
402
+
403
+ lints = result[:lints]
404
+ statistics = result[:statistics]
405
+
406
+ case ext
407
+ when :scss
408
+ lints[:scsslint] = Maximus::Scsslint.new(lint_opts).result
409
+
410
+ # @todo stylestat is singular here because model name in Rails is singular.
411
+ # But adding a .classify when it's converted to a model chops off the end s on 'phantomas',
412
+ # which breaks the model name.
413
+ statistics[:stylestat] = Maximus::Stylestats.new({config: @config}).result
414
+
415
+ # @todo double pipe here is best way to say, if it's already run, don't run again, right?
416
+ statistics[:phantomas] ||= Maximus::Phantomas.new({config: @config}).result
417
+ statistics[:wraith] ||= Maximus::Wraith.new({config: @config}).result
418
+ when :js
419
+ lints[:jshint] = Maximus::Jshint.new(lint_opts).result
420
+
421
+ statistics[:phantomas] ||= Maximus::Phantomas.new({config: @config}).result
422
+
423
+ # @todo double pipe here is best way to say, if it's already run, don't run again, right?
424
+ statistics[:wraith] ||= Maximus::Wraith.new({config: @config}).result
425
+ when :ruby
426
+ lints[:rubocop] = Maximus::Rubocop.new(lint_opts).result
427
+ lints[:railsbp] ||= Maximus::Railsbp.new(lint_opts).result
428
+ lints[:brakeman] = Maximus::Brakeman.new(lint_opts).result
429
+ when :rails
430
+ lints[:railsbp] ||= Maximus::Railsbp.new(lint_opts).result
431
+ end
432
+
433
+ result
434
+ end
435
+
402
436
  end
403
437
  end