rubycritic 4.0.0 → 4.0.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
  SHA256:
3
- metadata.gz: db2b8e076626a6a29d140f9f6552b6f5829e0f8d258b9cc47afa4fc1f21acbcc
4
- data.tar.gz: 6ef348632806a7a388aebadb6d53eec20870f0efc93459433debeda020126f00
3
+ metadata.gz: d3132430741ac30bdaa6f20f560ede65e01b93acf76b7153ae19775aeb968ee4
4
+ data.tar.gz: 51263545f9e96e3e17e04c2e3c43c1afe5832e112bc0f75ece347491625dc691
5
5
  SHA512:
6
- metadata.gz: b081e071ffad334bb27a1e469f5debe08bd2b3cc563cf1c5196c745539c237eb640297df2936461913a1b1fc4a714a8365786191bbe016725c94a96f80b7dd74
7
- data.tar.gz: a937c6a4142b87a414b513492517d4defccdf06d182b1a846fea149142d6bf10d06c42dcf62fad5edd8746d7eb7236d427d12109f0e3b13573577dc6902848c7
6
+ metadata.gz: 9889018dec050aeb9ec6bb29674ae687847e94dd86cf916826af7f7f3a07946ef9885341f6c9b205ebe3c62e6f22404eeab507ef58c6936dcf738a2a3200231b
7
+ data.tar.gz: e9de8a1897ca29f08a99fe912ffb78f7244305da7c63d0552f0ce0d702a0397247c91d27e25eef7937ccdd1bd13080fde8ab6b6f60ebb26d3d97999c8801b7ff
data/CHANGELOG.md CHANGED
@@ -1,4 +1,9 @@
1
- # master [(unreleased)](https://github.com/whitesmith/rubycritic/compare/v4.0.0...master)
1
+ # master [(unreleased)](https://github.com/whitesmith/rubycritic/compare/v4.0.1...master)
2
+
3
+ # 4.0.1 / 2019-03-12 [(commits)](https://github.com/whitesmith/rubycritic/compare/v4.0.0...v4.0.1)
4
+
5
+ * [FEATUE] Allow passing formatters from the outside (by [@marcgrimme][] and [@onumis][])
6
+ * [CHANGE] Fix aruba deprecation warning
2
7
 
3
8
  # 4.0.0 / 2019-02-27 [(commits)](https://github.com/whitesmith/rubycritic/compare/v3.5.1...v4.0.0)
4
9
 
data/README.md CHANGED
@@ -112,23 +112,33 @@ For a full list of the command-line options run:
112
112
  $ rubycritic --help
113
113
  ```
114
114
 
115
- | Command flag | Description |
116
- |-----------------------------|------------------------------------------------------------------------------------------------|
117
- | `-v` / `--version` | Displays the current version and exits |
118
- | `-p` / `--path` | Set path where report will be saved (tmp/rubycritic by default) |
119
- | `-f` / `--format` | Report smells in the given format: `html` (default; will open in a browser), `json`, `console` |
120
- | `-s` / `--minimum-score` | Set a minimum score (FLOAT: ex: 96.28), default: 0 |
121
- | `-m` / `--mode-ci` | Use CI mode. Faster, analyses diffs w.r.t base_branch (default: master), see -b |
122
- | `-b` / `--branch` | Set branch to compare |
123
- | `-t` / `--maximum-decrease` | Set a threshold for score difference between two branches (works only with -b), default: 0 |
124
- | `--deduplicate-symlinks` | De-duplicate symlinks based on their final target |
125
- | `--suppress-ratings` | Suppress letter ratings |
126
- | `--no-browser` | Do not open html report with browser |
115
+ | Command flag | Description |
116
+ |-------------------------------------|-----------------------------------------------------------------|
117
+ | `-v` / `--version` | Displays the current version and exits |
118
+ | `-p` / `--path` | Set path where report will be saved (tmp/rubycritic by default) |
119
+ | `-f` / `--format` | Report smells in the given format(s)<sup>1</sup> |
120
+ | `--custom-format path:classname` | Load and instantiate custom formatter(s)<sup>2</sup> |
121
+ | `-s` / `--minimum-score` | Set a minimum score (FLOAT: ex: 96.28), default: 0 |
122
+ | `-m` / `--mode-ci` | Use CI mode<sup>3</sup> |
123
+ | `-b` / `--branch` | Set branch to compare |
124
+ | `-t` / `--maximum-decrease` | Threshold for score difference between two branches<sup>4</sup> |
125
+ | `--deduplicate-symlinks` | De-duplicate symlinks based on their final target |
126
+ | `--suppress-ratings` | Suppress letter ratings |
127
+ | `--no-browser` | Do not open html report with browser |
128
+
129
+ 1. Available output formats:
130
+ - `html` (default; will open in a browser)
131
+ - `json`
132
+ - `console`
133
+ - `lint`
134
+ 2. See [custom formatters docs](/docs/formatters.md)
135
+ 3. Faster, analyses diffs w.r.t base_branch (default: master), see `-b`
136
+ 4. Works only with `-b`, default: 0
127
137
 
128
138
  You also can use a config file. Just create a `.rubycritic.yml` on your project root path.
129
139
 
130
140
  Here are one example:
131
- ```
141
+ ```yml
132
142
  mode_ci:
133
143
  enabled: true # default is false
134
144
  branch: 'production' # default is master
@@ -202,16 +212,18 @@ RubyCritic::RakeTask.new do |task|
202
212
  end
203
213
  ```
204
214
 
215
+ ## Formatters
216
+
217
+ See [formatters](docs/formatters.md)
205
218
 
206
219
  ## Compatibility
207
220
 
208
221
  RubyCritic is supporting Ruby versions:
209
222
 
210
- * 2.1
211
- * 2.2
212
223
  * 2.3
213
224
  * 2.4
214
225
  * 2.5
226
+ * 2.6
215
227
 
216
228
 
217
229
  ## Improving RubyCritic
@@ -16,7 +16,6 @@ module RubyCritic
16
16
  def parse
17
17
  argv_options.parse
18
18
  file_options.parse
19
-
20
19
  self
21
20
  end
22
21
 
@@ -5,13 +5,14 @@ require 'optparse'
5
5
  module RubyCritic
6
6
  module Cli
7
7
  class Options
8
+ # rubocop:disable Metrics/ClassLength
8
9
  class Argv
9
10
  def initialize(argv)
10
11
  @argv = argv
11
12
  self.parser = OptionParser.new
12
13
  end
13
14
 
14
- # rubocop:disable Metrics/MethodLength
15
+ # rubocop:disable Metrics/MethodLength,Metrics/AbcSize
15
16
  def parse
16
17
  parser.new do |opts|
17
18
  opts.banner = 'Usage: rubycritic [options] [paths]'
@@ -43,11 +44,28 @@ module RubyCritic
43
44
  ' html (default; will open in a browser)',
44
45
  ' json',
45
46
  ' console',
46
- ' lint'
47
+ ' lint',
48
+ 'Multiple formats are supported.'
47
49
  ) do |format|
48
50
  formats << format
49
51
  end
50
52
 
53
+ formatters = []
54
+ self.formatters = formatters
55
+ opts.on(
56
+ '--custom-format [REQUIREPATH]:[CLASSNAME]|[CLASSNAME]',
57
+ 'Instantiate a given class as formatter and call report for reporting.',
58
+ 'Two ways are possible to load the formatter.',
59
+ 'If the class is not autorequired the REQUIREPATH can be given together',
60
+ 'with the CLASSNAME to be loaded seperated by a :.',
61
+ 'Example: rubycritic/markdown/reporter.rb:RubyCritic::MarkDown::Reporter',
62
+ 'or if the file is already required the CLASSNAME is enough',
63
+ 'Example: RubyCritic::MarkDown::Reporter',
64
+ 'Multiple formatters are supported.'
65
+ ) do |formatter|
66
+ formatters << formatter
67
+ end
68
+
51
69
  opts.on('-s', '--minimum-score [MIN_SCORE]', 'Set a minimum score') do |min_score|
52
70
  self.minimum_score = Float(min_score)
53
71
  end
@@ -86,6 +104,7 @@ module RubyCritic
86
104
  mode: mode,
87
105
  root: root,
88
106
  formats: formats,
107
+ formatters: formatters,
89
108
  deduplicate_symlinks: deduplicate_symlinks,
90
109
  paths: paths,
91
110
  suppress_ratings: suppress_ratings,
@@ -97,11 +116,11 @@ module RubyCritic
97
116
  threshold_score: threshold_score
98
117
  }
99
118
  end
100
- # rubocop:enable Metrics/MethodLength
119
+ # rubocop:enable Metrics/MethodLength,Metrics/AbcSize
101
120
 
102
121
  private
103
122
 
104
- attr_accessor :mode, :root, :formats, :deduplicate_symlinks,
123
+ attr_accessor :mode, :root, :formats, :formatters, :deduplicate_symlinks,
105
124
  :suppress_ratings, :minimum_score, :no_browser,
106
125
  :parser, :base_branch, :feature_branch, :threshold_score
107
126
  def paths
@@ -112,6 +131,7 @@ module RubyCritic
112
131
  self.feature_branch = SourceControlSystem::Git.current_branch
113
132
  end
114
133
  end
134
+ # rubocop:enable Metrics/ClassLength
115
135
  end
116
136
  end
117
137
  end
@@ -5,7 +5,7 @@ require 'rubycritic/source_control_systems/base'
5
5
  module RubyCritic
6
6
  class Configuration
7
7
  attr_reader :root
8
- attr_accessor :source_control_system, :mode, :formats, :deduplicate_symlinks,
8
+ attr_accessor :source_control_system, :mode, :formats, :formatters, :deduplicate_symlinks,
9
9
  :suppress_ratings, :open_with, :no_browser, :base_branch,
10
10
  :feature_branch, :base_branch_score, :feature_branch_score,
11
11
  :base_root_directory, :feature_root_directory,
@@ -15,7 +15,6 @@ module RubyCritic
15
15
  def set(options)
16
16
  self.mode = options[:mode] || :default
17
17
  self.root = options[:root] || 'tmp/rubycritic'
18
- self.formats = options[:formats] || [:html]
19
18
  self.deduplicate_symlinks = options[:deduplicate_symlinks]
20
19
  self.suppress_ratings = options[:suppress_ratings]
21
20
  self.open_with = options[:open_with]
@@ -23,6 +22,12 @@ module RubyCritic
23
22
  self.base_branch = options[:base_branch]
24
23
  self.feature_branch = options[:feature_branch]
25
24
  self.threshold_score = options[:threshold_score].to_i
25
+ setup_formats(options)
26
+ end
27
+
28
+ def setup_formats(options)
29
+ self.formats = options[:formats] || [:html]
30
+ self.formatters = options[:formatters] || []
26
31
  end
27
32
 
28
33
  def root=(path)
@@ -5,9 +5,12 @@ module RubyCritic
5
5
  REPORT_GENERATOR_CLASS_FORMATS = %i[json console lint].freeze
6
6
 
7
7
  def self.generate_report(analysed_modules)
8
- Config.formats.uniq.each do |format|
8
+ RubyCritic::Config.formats.uniq.each do |format|
9
9
  report_generator_class(format).new(analysed_modules).generate_report
10
10
  end
11
+ RubyCritic::Config.formatters.each do |formatter|
12
+ report_generator_class_from_formatter(formatter).new(analysed_modules).generate_report
13
+ end
11
14
  end
12
15
 
13
16
  def self.report_generator_class(config_format)
@@ -19,5 +22,18 @@ module RubyCritic
19
22
  Generator::HtmlReport
20
23
  end
21
24
  end
25
+
26
+ def self.report_generator_class_from_formatter(formatter)
27
+ require_path, class_name = formatter.sub(/([^:]):([^:])/, '\1\;\2').split('\;', 2)
28
+ class_name ||= require_path
29
+ require require_path unless require_path == class_name
30
+ class_from_path(class_name)
31
+ end
32
+
33
+ def self.class_from_path(path)
34
+ path.split('::').inject(Object) { |obj, klass| obj.const_get klass }
35
+ rescue NameError => error
36
+ raise "Could not create reporter for class #{path}. Error: #{error}!"
37
+ end
22
38
  end
23
39
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RubyCritic
4
- VERSION = '4.0.0'.freeze
4
+ VERSION = '4.0.1'.freeze
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubycritic
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0
4
+ version: 4.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Guilherme Simoes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-02-27 00:00:00.000000000 Z
11
+ date: 2019-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: flay