maximus 0.1.6.1 → 0.1.7

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: 3dacd7121350ac5d7ac834d3df60a3691712fb0a
4
- data.tar.gz: 5d2662c81e42754cb68dcd15a556b93e83ae4b01
3
+ metadata.gz: 89b8a115dfe0b3ff7f8bfcb30d3b6295fca5b1f4
4
+ data.tar.gz: 600fa052c43c0c44ddc791de17530f3bd6b7d08f
5
5
  SHA512:
6
- metadata.gz: 97a96d4a95abfd20cacd25c4d277e0b8981b0a63b04667456ffa69efd5d0390b03042e7dde811d40a73af0be54bd5dcf84e591f8b99a89cc7fb41767790e1884
7
- data.tar.gz: c7a3fd83cc45e5e72fa8f93cf184a2c99649e1401bd73bd06919b9ff8c558ac795b513f9f0f250364f22173ae8f650132420d4f5ae9bc29c46e7055c8a28d78a
6
+ metadata.gz: 1a7fba31628c2a22eef4a06d962e61bd74834e2b8519be049599d33fdc38ca7c7bbed4a20cef8429265276648ca7556246056e5ccdc40e01419aeb7b663ce636
7
+ data.tar.gz: 1890c4069918ffd811154b2330c949253b2e012d7dde633aa316432c4f809a849a3ba0409a476e5c7b1d098699f82952406e2e50e6b038b055a3524e77ceaf54
@@ -1,6 +1,16 @@
1
1
  # Change log
2
2
 
3
- ## master
3
+ ## 0.1.7 (April 9, 2015)
4
+
5
+ Features:
6
+
7
+ * More file associations for linting
8
+ * Framework option in config
9
+ * Additional associations sorted when evaluating a codebase
10
+
11
+ Bugfixes:
12
+
13
+ * Fix #11 (`maximus -a` fails)
4
14
 
5
15
  ## 0.1.6.1 (March 1, 2015)
6
16
 
@@ -1,4 +1,5 @@
1
1
  require 'maximus/version'
2
+ require 'maximus/git_helper'
2
3
  require 'maximus/helper'
3
4
  require 'maximus/config'
4
5
  require 'maximus/git_control'
@@ -32,19 +32,16 @@ class Maximus::CLI < Thor
32
32
  desc "frontend", "Execute all front-end tasks"
33
33
  def frontend
34
34
  ['scsslint', 'jshint'].each { |e| check_exclude(e) }
35
- @config.destroy_temp
36
35
  end
37
36
 
38
37
  desc "backend", "Lint with all backend lints"
39
38
  def backend
40
39
  ['rubocop', 'railsbp', 'brakeman'].each { |e| check_exclude(e) }
41
- @config.destroy_temp
42
40
  end
43
41
 
44
42
  desc "statistics", "Run all statistics"
45
43
  def statistics
46
44
  ['stylestats', 'phantomas', 'wraith'].each { |e| check_exclude(e) }
47
- @config.destroy_temp
48
45
  end
49
46
 
50
47
  # Alias ruby to backend
@@ -59,17 +56,23 @@ class Maximus::CLI < Thor
59
56
  all_tasks = ['frontend', 'backend', 'statistics']
60
57
 
61
58
  # If all flag is enabled, run everything
62
- return all_tasks.each { |a| send(a) } if options[:all]
59
+ if options[:all]
60
+ all_tasks.each { |a| send(a) }
63
61
 
64
- # Lint by category unless all flags are blank
65
- return all_tasks.each { |a| check_option(a) } unless options[:frontend].blank? && options[:backend].blank? && options[:statistics].blank?
62
+ elsif options[:frontend].present? && options[:backend].present? && options[:statistics].present?
63
+ all_tasks.each { |a| check_option(a) }
66
64
 
67
65
  # If include flag is enabled, run based on what's included
68
- return options[:include].each { |i| send(i) } unless options[:include].blank?
66
+ elsif options[:include].present?
67
+ options[:include].each { |i| send(i) }
68
+
69
+ else
70
+ # If all flag is not enabled, lint working copy as it's supposed to be
71
+ @config.settings[:commit] = options[:git]
72
+ Maximus::GitControl.new({config: @config}).lints_and_stats(true)
73
+
74
+ end
69
75
 
70
- # If all flag is not enabled, lint working copy as it's supposed to be
71
- @config.settings[:commit] = options[:git]
72
- Maximus::GitControl.new({config: @config}).lints_and_stats(true)
73
76
  @config.destroy_temp
74
77
  end
75
78
 
@@ -80,6 +83,7 @@ class Maximus::CLI < Thor
80
83
  end
81
84
 
82
85
  no_commands do
86
+
83
87
  # Only run command if option is present
84
88
  def check_option(opt)
85
89
  send(opt) if options[opt.to_sym]
@@ -32,6 +32,8 @@ module Maximus
32
32
  # @option opts [String] :commit accepts sha, "working", "last", or "master".
33
33
  # @option opts [String] :config_file ('maximus.yml') path to config file
34
34
  # @option opts [Boolean] :compile_assets (true) compile and destroy assets automagically
35
+ # @option opts [String] :framework (nil) accepts 'rails' and 'middleman' (should only be used
36
+ # when calling Maximus from a Ruby script)
35
37
  # @return [#load_config_file #group_families #evaluate_settings] this method is used to set up instance variables
36
38
  def initialize(opts = {})
37
39
 
@@ -41,10 +43,11 @@ module Maximus
41
43
  default_options = YAML.load_file(File.join(File.dirname(__FILE__), 'config', 'maximus.yml')).symbolize_keys
42
44
  default_options[:root_dir] = root_dir
43
45
  default_options[:port] = 3000 if is_rails?
46
+ default_options[:port] = 4567 if is_middleman?
44
47
 
45
- @root = opts[:root_dir] ? opts[:root_dir] : default_options[:root_dir]
48
+ root = opts[:root_dir] ? opts[:root_dir] : default_options[:root_dir]
46
49
 
47
- yaml = default_options.merge load_config_file(opts[:config_file])
50
+ yaml = default_options.merge load_config_file(opts[:config_file], root)
48
51
  @settings = yaml.merge opts
49
52
 
50
53
  @settings[:git_log] = false if @settings[:git_log].nil?
@@ -74,16 +77,9 @@ module Maximus
74
77
  case key
75
78
 
76
79
  when :jshint, :JSHint, :JShint
77
-
78
- # @todo DRY this load_config up, but can't call it at the start because of the
79
- # global config variables (last when statement in this switch)
80
80
  value = load_config(value)
81
81
 
82
- if settings_data[key].is_a?(Hash) && settings_data[key].key?('jshintignore')
83
- jshintignore_file = []
84
- settings_data[key]['jshintignore'].each { |i| jshintignore_file << "#{i}\n" }
85
- @settings[:jshintignore] = temp_it('jshintignore.json', jshintignore_file)
86
- end
82
+ jshint_ignore settings_data[key]
87
83
  @settings[:jshint] = temp_it('jshint.json', value.to_json)
88
84
 
89
85
  when :scsslint, :SCSSlint
@@ -120,12 +116,10 @@ module Maximus
120
116
  end
121
117
  end
122
118
 
123
- # Finally, we're done
124
119
  @settings
125
120
  end
126
121
 
127
- # If output should be returned to console
128
- # in a pretty display
122
+ # If output should be returned to console in a pretty display
129
123
  # @return [Boolean]
130
124
  def is_dev?
131
125
  @settings[:is_dev]
@@ -160,7 +154,7 @@ module Maximus
160
154
  end
161
155
 
162
156
 
163
- private
157
+ protected
164
158
 
165
159
  # Look for a maximus config file
166
160
  #
@@ -171,13 +165,14 @@ module Maximus
171
165
  #
172
166
  # @since 0.1.4
173
167
  # @param file_path [String]
168
+ # @param root [String] file path to root directory
174
169
  # @return @settings [Hash]
175
- def load_config_file(file_path)
170
+ def load_config_file(file_path, root)
176
171
 
177
- conf_location = if !file_path.nil? && File.exist?(file_path)
172
+ conf_location = if file_path.present? && File.exist?(file_path)
178
173
  file_path
179
174
  else
180
- config_exists('.maximus.yml') || config_exists('maximus.yml') || config_exists('config/maximus.yml')
175
+ config_exists('.maximus.yml', root) || config_exists('maximus.yml', root) || config_exists('config/maximus.yml', root)
181
176
  end
182
177
 
183
178
  return {} if conf_location.is_a?(FalseClass)
@@ -247,19 +242,6 @@ module Maximus
247
242
  file.path
248
243
  end
249
244
 
250
- # See if a config file exists
251
- #
252
- # @see load_config_file
253
- #
254
- # This is used exclusively for the load_config_file method
255
- # @param file [String] file name
256
- # @return [String, FalseClass] if file is found return the absolute path
257
- # otherwise return false so we can keep checking
258
- def config_exists(file)
259
- present_location = File.join(@root, file)
260
- File.exist?(present_location) ? present_location : false
261
- end
262
-
263
245
  # Accounting for space-separated command line arrays
264
246
  # @since 0.1.4
265
247
  # @param paths [Array]
@@ -352,5 +334,34 @@ module Maximus
352
334
 
353
335
  end
354
336
 
337
+
338
+ private
339
+
340
+ # See if a config file exists
341
+ #
342
+ # @see load_config_file
343
+ #
344
+ # This is used exclusively for the load_config_file method
345
+ # @param file [String] file name
346
+ # @param root [String] file path to root directory
347
+ # @return [String, FalseClass] if file is found return the absolute path
348
+ # otherwise return false so we can keep checking
349
+ def config_exists(file, root)
350
+ present_location = File.join(root, file)
351
+ File.exist?(present_location) ? present_location : false
352
+ end
353
+
354
+ # Save jshintignore if available
355
+ # @since 0.1.7
356
+ # @param settings_data_key [Hash]
357
+ # @return updates settings
358
+ def jshint_ignore(settings_data_key)
359
+ return unless settings_data_key.is_a?(Hash) && settings_data_key.key?('jshintignore')
360
+
361
+ jshintignore_file = []
362
+ settings_data_key['jshintignore'].each { |i| jshintignore_file << "#{i}\n" }
363
+ @settings[:jshintignore] = temp_it('jshintignore.json', jshintignore_file)
364
+ end
365
+
355
366
  end
356
- end
367
+ end
@@ -4,6 +4,7 @@ domain: 'http://localhost'
4
4
  # here because this is the default file. If set to true, output is logged directly
5
5
  # to the parent process and does not appear in the log.
6
6
  is_dev: false
7
+
7
8
  paths:
8
9
  home: '/'
9
10
 
@@ -1,4 +1,5 @@
1
1
  require 'git'
2
+ require 'active_support/core_ext/kernel/reporting'
2
3
 
3
4
  module Maximus
4
5
  # Git management
@@ -6,6 +7,7 @@ module Maximus
6
7
  class GitControl
7
8
 
8
9
  include Helper
10
+ include GitHelper
9
11
 
10
12
  # Set up instance variables
11
13
  #
@@ -78,17 +80,17 @@ module Maximus
78
80
 
79
81
  # Grab all files in that commit and group them by extension
80
82
  # If working copy, just give the diff names of the files changed
81
- files = @psuedo_commit ? `git -C #{@config.working_dir} diff --name-only` : `git -C #{@config.working_dir} show --pretty="format:" --name-only #{git_sha}`
83
+ files = @psuedo_commit ? working_copy_files : files_by_sha(git_sha)
82
84
 
83
- diff_return[git_sha.to_s] = match_associations(git_sha, files)
85
+ diff_return[git_sha] = match_associations(git_sha, files)
84
86
  end
87
+
85
88
  diff_return
86
89
  end
87
90
 
88
91
  # Run appropriate lint for every sha in commit history.
89
92
  # For each sha a new branch is created then deleted
90
93
  #
91
- # This is where everything goes down
92
94
  # @example sample output
93
95
  # {
94
96
  # 'sha': {
@@ -128,11 +130,8 @@ module Maximus
128
130
  file_paths: (lint_file_paths(files, ext) if lint_by_path)
129
131
  }
130
132
 
131
- if nuclear
132
- git_ouput[sha] = lints_and_stats_nuclear(lint_opts)
133
- else
134
- git_ouput[sha] = lints_and_stats_switch(ext, lint_opts)
135
- end
133
+ git_ouput[sha] = nuclear ? lints_and_stats_nuclear(lint_opts) : lints_and_stats_switch(ext, lint_opts)
134
+
136
135
  end
137
136
 
138
137
  destroy_branch(base_branch, sha) unless @psuedo_commit
@@ -141,30 +140,20 @@ module Maximus
141
140
  git_ouput
142
141
  end
143
142
 
144
- # Find first commit
145
- # @since 0.1.5
146
- # @return [String]
147
- def first_commit
148
- `git -C #{@config.working_dir} rev-list --max-parents=0 HEAD`.strip!
149
- end
150
-
151
- # Get commit before current
152
- # @since 0.1.5
153
- # @param current_commit [String] (head_sha) commit to start at
154
- # @param previous_by [Integer] (1) commit n commits ago
155
- # @return [String]
156
- def previous_commit(current_commit = head_sha, previous_by = 1)
157
- `git -C #{@config.working_dir} rev-list --max-count=#{previous_by + 1} #{current_commit} --reverse | head -n1`.strip!
158
- end
159
-
160
143
  # Define associations to linters based on file extension
161
144
  # @return [Hash] linters and extension arrays
162
145
  def associations
163
146
  {
147
+ css: ['css'],
164
148
  scss: ['scss', 'sass'],
165
149
  js: ['js'],
166
150
  ruby: ['rb', 'Gemfile', 'lock', 'yml', 'Rakefile', 'ru', 'rdoc', 'rake', 'Capfile', 'jbuilder'],
167
- rails: ['slim', 'haml', 'jbuilder', 'erb']
151
+ rails: ['slim', 'haml', 'jbuilder', 'erb'],
152
+ images: ['png', 'jpg', 'jpeg', 'gif'],
153
+ static: ['pdf', 'txt', 'doc', 'docx', 'csv', 'xls', 'xlsx'],
154
+ markup: ['html', 'xml', 'xhtml'],
155
+ markdown: ['md', 'markdown', 'mdown'],
156
+ php: ['php', 'ini']
168
157
  }
169
158
  end
170
159
 
@@ -186,7 +175,7 @@ module Maximus
186
175
  # @param sha2 [String]
187
176
  # @return [Array] shas
188
177
  def commit_range(sha1, sha2)
189
- git_spread = @psuedo_commit ? "git #{sha1}" : `git -C #{@config.working_dir} rev-list #{sha1}..#{sha2} --no-merges`
178
+ git_spread = @psuedo_commit ? "git #{sha1}" : sha_range(sha1, sha2)
190
179
  git_spread = git_spread.nil? ? [] : git_spread.split("\n")
191
180
 
192
181
  git_spread << sha1 unless @psuedo_commit
@@ -205,40 +194,6 @@ module Maximus
205
194
  end
206
195
  end
207
196
 
208
- # Create branch to run report on
209
- # @todo better way to silence git, in case there's a real error?
210
- # @since 0.1.5
211
- # @param sha [String]
212
- def create_branch(sha)
213
- quietly { `git -C #{@config.working_dir} checkout #{sha} -b maximus_#{sha}` }
214
- end
215
-
216
- # Destroy created branch
217
- # @todo better way to silence git, in case there's a real error?
218
- # @since 0.1.5
219
- # @param base_branch [String] branch we started on
220
- # @param sha [String] used to check against created branch name
221
- def destroy_branch(base_branch, sha)
222
- quietly {
223
- if base_branch == "maximus_#{sha}"
224
- @g.branch('master').checkout
225
- else
226
- @g.branch(base_branch).checkout
227
- end
228
- @g.branch("maximus_#{sha}").delete
229
- }
230
- end
231
-
232
- # Get list of file paths
233
- # @param files [Hash] hash of files denoted by key 'filename'
234
- # @param ext [String] file extension - different extensions are joined different ways
235
- # @return [String] file paths delimited by comma or space
236
- def lint_file_paths(files, ext)
237
- file_list = files.map { |f| f[:filename] }.compact
238
- # Lints accept files differently
239
- ext == :ruby ? file_list.join(' ') : file_list.join(',')
240
- end
241
-
242
197
  # Determine which lines were added (where and how many) in a commit
243
198
  #
244
199
  # @example output from method
@@ -249,9 +204,9 @@ module Maximus
249
204
  #
250
205
  # @param git_sha [String] sha of the commit
251
206
  # @return [Hash] ranges by lines added in a commit by file name
252
- def lines_added(git_sha)
207
+ def lines_added(commit_sha)
253
208
  new_lines = {}
254
- git_lines = `#{File.join(File.dirname(__FILE__), 'reporter', 'git-lines.sh')} #{@config.working_dir} #{git_sha}`.split("\n")
209
+ git_lines = lines_by_sha(commit_sha)
255
210
  git_lines.each do |filename|
256
211
  fsplit = filename.split(':')
257
212
  # if file isn't already part of the array
@@ -264,24 +219,6 @@ module Maximus
264
219
  new_lines
265
220
  end
266
221
 
267
- # Get last commit on current branch
268
- # @return [String] sha
269
- def head_sha
270
- @g.object('HEAD').sha
271
- end
272
-
273
- # Get current branch name
274
- # @return [String]
275
- def branch
276
- `env -i git rev-parse --abbrev-ref HEAD`.strip!
277
- end
278
-
279
- # Get last commit sha on the master branch
280
- # @return [String]
281
- def master_commit_sha
282
- @g.branches[:master].blank? ? head_sha : @g.branches[:master].gcommit.sha
283
- end
284
-
285
222
  # Get general stats of commit on HEAD versus last commit on master branch
286
223
  # @modified 0.1.4
287
224
  # @param old_commit [Git::Object]
@@ -291,9 +228,11 @@ module Maximus
291
228
  stats = @g.diff(old_commit, new_commit).stats
292
229
  lines = lines_added(new_commit.sha)
293
230
  return if !lines.is_a?(Hash) || stats.blank?
231
+
294
232
  lines.each do |filename, filelines|
295
233
  stats[:files][filename][:lines_added] = filelines if stats[:files].key?(filename)
296
234
  end
235
+
297
236
  stats
298
237
  end
299
238
 
@@ -304,8 +243,7 @@ module Maximus
304
243
  # @param commit_sha [String]
305
244
  # @return [Hash] stat data similar to Ruby-git's Diff.stats return
306
245
  def diff_initial(commit_sha)
307
- # Start after the commit information
308
- data = `git -C #{@config.working_dir} log --numstat --oneline #{commit_sha}`.split("\n")[1..-1]
246
+ data = commit_information(commit_sha)
309
247
  value = {
310
248
  total: {
311
249
  insertions: 0,
@@ -329,42 +267,31 @@ module Maximus
329
267
  value
330
268
  end
331
269
 
332
- # Get remote URL
333
- # @return [String, nil] nil returns if remotes is blank
334
- def remote
335
- @g.remotes.first.url unless @g.remotes.blank?
336
- end
337
-
338
270
  # Associate files by extension and match their changes
339
271
  # @since 0.1.5
340
- # @param git_sha [String]
341
- # @param files [String] list of files from git return
272
+ # @param commit_sha [String]
273
+ # @param files [String] list of files from git
342
274
  # @return [Hash] files with matched extensions and changes
343
- def match_associations(git_sha, files)
344
- new_lines = lines_added(git_sha)
275
+ def match_associations(commit_sha, files)
276
+ new_lines = lines_added(commit_sha)
345
277
 
346
- # File.extname is not used here in case dotfiles are encountered
347
278
  files = files.split("\n").group_by { |f| f.split('.').pop }
348
279
 
349
- # Don't worry about files that we don't have a lint or a statistic for
350
- flat_associations = associations.clone.flatten(2)
351
- files.delete_if { |k,v| !flat_associations.include?(k) || k.nil? }
352
-
353
280
  associations.each do |ext, related|
354
281
  files[ext] ||= []
355
282
  related.each do |child|
356
- unless files[child].blank?
357
- files[child].each do |c|
358
- # hack to ignore deleted files
359
- files[child] = new_lines[c].blank? ? [] : [ filename: File.join(@config.working_dir, c), changes: new_lines[c] ]
360
- end
361
- files[ext].concat(files[child])
362
- files.delete(child)
283
+ next if files[child].blank?
284
+
285
+ files[child].each do |c|
286
+ # hack to ignore deleted files
287
+ files[child] = new_lines[c].blank? ? [] : [ filename: File.join(@config.working_dir, c), changes: new_lines[c] ]
363
288
  end
289
+ files[ext].concat(files[child])
290
+ files.delete(child)
364
291
  end
365
292
  end
366
293
 
367
- files.delete_if { |k,v| v.blank? }
294
+ files.delete_if { |k,v| v.blank? || k.nil? }
368
295
  files
369
296
  end
370
297
 
@@ -433,5 +360,38 @@ module Maximus
433
360
  result
434
361
  end
435
362
 
363
+
364
+ private
365
+
366
+ # Create branch to run report on
367
+ # @since 0.1.5
368
+ # @param sha [String]
369
+ def create_branch(sha)
370
+ silence_stream(STDERR) { `git -C #{@config.working_dir} checkout #{sha} -b maximus_#{sha}` }
371
+ end
372
+
373
+ # Destroy created branch
374
+ # @since 0.1.5
375
+ # @param base_branch [String] branch we started on
376
+ # @param sha [String] used to check against created branch name
377
+ def destroy_branch(base_branch, sha)
378
+ if base_branch == "maximus_#{sha}"
379
+ @g.branch('master').checkout
380
+ else
381
+ @g.branch(base_branch).checkout
382
+ end
383
+ @g.branch("maximus_#{sha}").delete
384
+ end
385
+
386
+ # Get list of file paths
387
+ # @param files [Hash] hash of files denoted by key 'filename'
388
+ # @param ext [String] file extension - different extensions are joined different ways
389
+ # @return [String] file paths delimited by comma or space
390
+ def lint_file_paths(files, ext)
391
+ file_list = files.map { |f| f[:filename] }.compact
392
+ # Lints accept files differently
393
+ ext == :ruby ? file_list.join(' ') : file_list.join(',')
394
+ end
395
+
436
396
  end
437
397
  end
@@ -0,0 +1,79 @@
1
+ module Maximus
2
+ # Methods used for git commands
3
+ # @since 0.1.7
4
+ module GitHelper
5
+
6
+ # Find first commit
7
+ # @since 0.1.5
8
+ # @return [String]
9
+ def first_commit
10
+ `git -C #{@config.working_dir} rev-list --max-parents=0 HEAD`.strip!
11
+ end
12
+
13
+ # Get commit before current
14
+ # @since 0.1.5
15
+ # @param current_commit [String] (head_sha) commit to start at
16
+ # @param previous_by [Integer] (1) commit n commits ago
17
+ # @return [String]
18
+ def previous_commit(current_commit = head_sha, previous_by = 1)
19
+ `git -C #{@config.working_dir} rev-list --max-count=#{previous_by + 1} #{current_commit} --reverse | head -n1`.strip!
20
+ end
21
+
22
+ # Get last commit on current branch
23
+ # @return [String] sha
24
+ def head_sha
25
+ @g.object('HEAD').sha
26
+ end
27
+
28
+ # Get current branch name
29
+ # @return [String]
30
+ def branch
31
+ `env -i git rev-parse --abbrev-ref HEAD`.strip!
32
+ end
33
+
34
+ # Get last commit sha on the master branch
35
+ # @return [String]
36
+ def master_commit_sha
37
+ @g.branches[:master].blank? ? head_sha : @g.branches[:master].gcommit.sha
38
+ end
39
+
40
+ # Get remote URL
41
+ # @return [String, nil] nil returns if remotes is blank
42
+ def remote
43
+ @g.remotes.first.url unless @g.remotes.blank?
44
+ end
45
+
46
+ # Return file names of working copy files
47
+ # @since 0.1.7
48
+ def working_copy_files
49
+ `git -C #{@config.working_dir} diff --name-only`
50
+ end
51
+
52
+ # Grab files by sha
53
+ # @since 0.1.7
54
+ def files_by_sha(commit_sha)
55
+ `git -C #{@config.working_dir} show --pretty="format:" --name-only #{commit_sha}`
56
+ end
57
+
58
+ # Retrieve list of shas between two commits
59
+ # @since 0.1.7
60
+ def sha_range(sha1, sha2)
61
+ `git -C #{@config.working_dir} rev-list #{sha1}..#{sha2} --no-merges`
62
+ end
63
+
64
+ # A commit's insertions, deletions, and file names
65
+ # @since 0.1.7
66
+ def commit_information(commit_sha)
67
+ # Start after the commit message
68
+ `git -C #{@config.working_dir} log --numstat --oneline #{commit_sha}`.split("\n")[1..-1]
69
+ end
70
+
71
+ # Retrieve insertions by commit with a custom script
72
+ # @since 0.1.7
73
+ # @return [Array]
74
+ def lines_by_sha(commit_sha)
75
+ `#{File.join(File.dirname(__FILE__), 'reporter', 'git-lines.sh')} #{@config.working_dir} #{commit_sha}`.split("\n")
76
+ end
77
+
78
+ end
79
+ end
@@ -14,14 +14,14 @@ module Maximus
14
14
  # This will usually be stored as a class variable in the inherited class
15
15
  # @return [Boolean]
16
16
  def is_rails?
17
- defined?(Rails)
17
+ (@config.settings[:framework] == 'rails' unless @config.blank?) || defined?(Rails)
18
18
  end
19
19
 
20
20
  # See if project is a Middleman app
21
- # @since 0.1.7
21
+ # @since 0.1.6.1
22
22
  # @return [Boolean]
23
23
  def is_middleman?
24
- Gem::Specification::find_all_by_name('middleman').any?
24
+ (@config.settings[:framework] == 'middleman' unless @config.blank?) || Gem::Specification::find_all_by_name('middleman').any?
25
25
  end
26
26
 
27
27
  # Get root directory of file being called
@@ -110,7 +110,7 @@ module Maximus
110
110
  end
111
111
  end
112
112
  else
113
- path = path.gsub('/**', '').gsub('/*', '').split('.')[0..1].first if path.include?('*')
113
+ path = path.gsub('/**', '').gsub('/*', '').gsub(/\/\.*/, '') if path.include?('*')
114
114
  if File.exist?(path)
115
115
  return true
116
116
  else
@@ -121,17 +121,18 @@ module Maximus
121
121
  end
122
122
 
123
123
  # Default paths to check for lints and some stats
124
- # @since 0.1.7
124
+ # @since 0.1.6.1
125
+ # Note: is_rails? must be defined second-to-last if more frameworks are added
125
126
  # @param root [String] base directory
126
127
  # @param folder [String] nested folder to search for for Rails or Middleman
127
128
  # @param extension [String] file glob type to search for if neither
128
129
  # @return [String] path to desired files
129
130
  def discover_path(root = @config.working_dir, folder = '', extension = '')
130
131
  return @path unless @path.blank?
131
- if is_rails?
132
- File.join(root, 'app', 'assets', folder)
133
- elsif is_middleman?
132
+ if is_middleman?
134
133
  File.join(root, 'source', folder)
134
+ elsif is_rails?
135
+ File.join(root, 'app', 'assets', folder)
135
136
  else
136
137
  extension.blank? ? File.join(root) : File.join(root, '/**', "/*.#{extension}")
137
138
  end
@@ -56,11 +56,11 @@ module Maximus
56
56
 
57
57
  evaluate_severities(data)
58
58
 
59
- puts lint_summarize
59
+ puts summarize
60
60
 
61
61
  if @config.is_dev?
62
- puts lint_dev_format(data)
63
- lint_ceiling
62
+ puts dev_format(data)
63
+ ceiling_warning
64
64
  else
65
65
  # Because this should be returned in the format it was received
66
66
  @output[:raw_data] = data.to_json
@@ -84,12 +84,12 @@ module Maximus
84
84
  # @param lint [Hash] output lint data
85
85
  # @param files [Hash<String: String>] filename: filepath
86
86
  # @return [Array] lints that match the lines in commit
87
- def relevant_lints(lint, files)
87
+ def relevant_output(lint, files)
88
88
  all_files = {}
89
89
  files.each do |file|
90
90
 
91
91
  # sometimes data will be blank but this is good - it means no errors were raised in the lint
92
- next if lint.blank?
92
+ next if lint.blank? || file.blank? || !file.is_a?(Hash) || !file.key?(:filename)
93
93
  lint_file = lint[file[:filename]]
94
94
 
95
95
  next if lint_file.blank?
@@ -99,9 +99,6 @@ module Maximus
99
99
 
100
100
  all_files[revert_name] = []
101
101
 
102
- # @todo originally I tried .map and delete_if, but this works,
103
- # and the other method didn't cover all bases.
104
- # Gotta be a better way to write this though
105
102
  lint_file.each do |l|
106
103
  if expanded.include?(l['line'].to_i)
107
104
  all_files[revert_name] << l
@@ -167,13 +164,12 @@ module Maximus
167
164
  changes_array.map { |e| (e[0]..e[1]).to_a }.flatten!
168
165
  end
169
166
 
167
+
170
168
  private
171
169
 
172
170
  # Send abbreviated results to console or to the log
173
171
  # @return [String] console message to display
174
- def lint_summarize
175
- puts "#{'Warning'.color(:red)}: #{@output[:lint_errors].length} errors found in #{@task}" if @output[:lint_errors].length > 0
176
-
172
+ def summarize
177
173
  success = @task.color(:green)
178
174
  success << ": "
179
175
  success << "[#{@output[:lint_warnings].length}]".color(:yellow)
@@ -183,6 +179,7 @@ module Maximus
183
179
  success << " [#{@output[:lint_refactors].length}]".color(:white)
184
180
  success << " [#{@output[:lint_fatals].length}]".color(:magenta)
185
181
  end
182
+ success << "\n#{'Warning'.color(:red)}: #{@output[:lint_errors].length} errors found in #{@task}" if @output[:lint_errors].length > 0
186
183
 
187
184
  success
188
185
  end
@@ -190,10 +187,10 @@ module Maximus
190
187
  # If there's just too much to handle, through a warning.
191
188
  # @param lint_length [Integer] count of how many lints
192
189
  # @return [String] console message to display
193
- def lint_ceiling
190
+ def ceiling_warning
194
191
  lint_length = (@output[:lint_errors].length + @output[:lint_warnings].length + @output[:lint_conventions].length + @output[:lint_refactors].length + @output[:lint_fatals].length)
195
-
196
192
  return unless lint_length > 100
193
+
197
194
  failed_task = @task.color(:green)
198
195
  errors = "#{lint_length} failures.".color(:red)
199
196
  errormsg = [
@@ -214,24 +211,19 @@ module Maximus
214
211
  # Dev display, executed only when called from command line
215
212
  # @param errors [Hash] data from lint
216
213
  # @return [String] console message to display
217
- def lint_dev_format(errors = @output[:raw_data])
214
+ def dev_format(errors = @output[:raw_data])
218
215
  return if errors.blank?
216
+
219
217
  pretty_output = ''
220
218
  errors.each do |filename, error_list|
221
219
  filename = strip_working_dir(filename)
222
220
  pretty_output << "\n#{filename.color(:cyan).underline} \n"
223
221
  error_list.each do |message|
224
- pretty_output << case message['severity']
225
- when 'warning' then 'W'.color(:yellow)
226
- when 'error' then 'E'.color(:red)
227
- when 'convention' then 'C'.color(:cyan)
228
- when 'refactor' then 'R'.color(:white)
229
- when 'fatal' then 'F'.color(:magenta)
230
- else '?'.color(:blue)
231
- end
222
+ pretty_output << severity_color(message['severity'])
232
223
  pretty_output << " #{message['line'].to_s.color(:blue)} #{message['linter'].color(:green)}: #{message['reason']} \n"
233
224
  end
234
225
  end
226
+ pretty_output << "-----\n\n"
235
227
  pretty_output
236
228
  end
237
229
 
@@ -240,10 +232,10 @@ module Maximus
240
232
  # @param path [String]
241
233
  # @return [String]
242
234
  def strip_working_dir(path)
243
- path.gsub("#{@config.working_dir}/", '')
235
+ path.gsub(@config.working_dir, '')
244
236
  end
245
237
 
246
- # Handle data and generate relevant_lints if appropriate
238
+ # Handle data and generate relevant_output if appropriate
247
239
  # @since 0.1.6
248
240
  # @see #refine
249
241
  # @param data [String, Hash]
@@ -256,10 +248,21 @@ module Maximus
256
248
 
257
249
  data = JSON.parse(data) if data.is_a?(String)
258
250
 
259
- @output[:relevant_lints] = relevant_lints( data, @git_files ) unless @git_files.blank?
260
- data = @output[:relevant_lints] unless @settings[:commit].blank?
251
+ @output[:relevant_output] = relevant_output( data, @git_files ) unless @git_files.blank?
252
+ data = @output[:relevant_output] unless @settings[:commit].blank?
261
253
  data
262
254
  end
263
255
 
256
+ def severity_color(severity)
257
+ case severity
258
+ when 'warning' then 'W'.color(:yellow)
259
+ when 'error' then 'E'.color(:red)
260
+ when 'convention' then 'C'.color(:cyan)
261
+ when 'refactor' then 'R'.color(:white)
262
+ when 'fatal' then 'F'.color(:magenta)
263
+ else '?'.color(:blue)
264
+ end
265
+ end
266
+
264
267
  end
265
268
  end
@@ -1,3 +1,3 @@
1
1
  module Maximus
2
- VERSION = "0.1.6.1"
2
+ VERSION = "0.1.7"
3
3
  end
@@ -1,4 +1,3 @@
1
-
2
1
  module ConfigHelper
3
2
 
4
3
  def create_config(contents = '', location = '.maximus.yml')
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: maximus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6.1
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Shedor
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-02 00:00:00.000000000 Z
11
+ date: 2015-04-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: git
@@ -232,6 +232,7 @@ files:
232
232
  - lib/maximus/config/wraith/nojs.js
233
233
  - lib/maximus/config/wraith/snap.js
234
234
  - lib/maximus/git_control.rb
235
+ - lib/maximus/git_helper.rb
235
236
  - lib/maximus/helper.rb
236
237
  - lib/maximus/lint.rb
237
238
  - lib/maximus/lints/brakeman.rb
@@ -276,7 +277,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
276
277
  version: '0'
277
278
  requirements: []
278
279
  rubyforge_project:
279
- rubygems_version: 2.4.2
280
+ rubygems_version: 2.4.6
280
281
  signing_key:
281
282
  specification_version: 4
282
283
  summary: Make your code spic and <span>