k_builder 0.0.61 → 0.0.62

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: c78906798abec61e633a8e6447baed740f5618025e6ec1733655c5173ee62b43
4
- data.tar.gz: fd412c1aab0fa24ea34c2394c43ae77bba5588d4d25c50e890f1dc4a14f84f7e
3
+ metadata.gz: c3544040b2994f74c65d824516980a5ca980d441c53e97629920c23513cf76a2
4
+ data.tar.gz: e0c8e494f82a58e1564f59cfb66f960f6a99561a3cc28bfab81c17a77a3b4f8d
5
5
  SHA512:
6
- metadata.gz: bbf46357650901ba2a5af3ba6c9371d6ca4752c281a57f88edcbb9b9264b75fa83afab90d679642dfe0475b4b48d5291fe936f83e70bc61cff193bdc96978105
7
- data.tar.gz: a41800fce5dfe7297995317eed2441f1bd27d52e3af4def56558dcad53e1390c75cf4a699cd4f9fa2b90b76087d86c011b7204ff14a161be0b490edef09e3de9
6
+ metadata.gz: 8a27d1f32b26b8878260c11f15a0285b64a65769d9b17631cb05f9c772deab1ddf97bb3f7db9ab392efd9d9b257344bb85272827de19228905b9fe4493d6a485
7
+ data.tar.gz: f1a237017caff54b821d750dc9e467ec659a7127abae3d9640afe4a997c83afd9347c0113c99eb60d78c849875d26c34305983dbfc478d9e33a6be229ad8149f
data/lib/k_builder.rb CHANGED
@@ -10,6 +10,8 @@ require 'k_builder/base_builder'
10
10
  require 'k_builder/base_configuration'
11
11
  require 'k_builder/configuration'
12
12
  require 'k_builder/file_segments'
13
+ require 'k_builder/commands/base_command'
14
+ require 'k_builder/commands/rubo_cop_command'
13
15
 
14
16
  require 'handlebars/helpers/template'
15
17
 
@@ -320,13 +320,11 @@ module KBuilder
320
320
  Handlebars::Helpers::Template.render(template_content, opts) unless template_content.nil?
321
321
  end
322
322
 
323
- def run_cop(file, auto_safe: false, auto_all: false)
324
- cli = RuboCop::CLI.new
325
- opts = ['--format', 'simple', file]
326
- opts.prepend('-a') if auto_safe
327
- opts.prepend('-A') if auto_all
323
+ def run_cop(file, **opts)
324
+ command = Commands::RuboCopCommand.new(file, builder: self, **opts)
325
+ command.execute
328
326
 
329
- cli.run(opts)
327
+ self
330
328
  end
331
329
 
332
330
  # Need to handle absolute files, see
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KBuilder
4
+ module Commands
5
+ # Base command for single responsibility actions that can be fired
6
+ # from methods in the builder.
7
+ #
8
+ # Uses the command pattern
9
+ class BaseCommand
10
+ include KLog::Logging
11
+
12
+ attr_accessor :builder
13
+ attr_accessor :valid
14
+
15
+ def initialize(**opts)
16
+ @builder = opts[:builder]
17
+ @valid = true
18
+ end
19
+
20
+ def guard(message)
21
+ # THIS SHOULD ONLY LOG IF DEBUGGING IS TURNED ON
22
+ log.error(message)
23
+ @valid = false
24
+ end
25
+
26
+ def valid?
27
+ @valid
28
+ end
29
+
30
+ def debug(title: nil)
31
+ log.section_heading(title) if title
32
+ debug_values if respond_to?(:debug_values)
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,112 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KBuilder
4
+ module Commands
5
+ # Run RuboCop against a file
6
+ class RuboCopCommand < BaseCommand
7
+ attr_reader :file_pattern
8
+ attr_reader :fix_safe
9
+ attr_reader :fix_unsafe
10
+ attr_reader :rubo_config_file
11
+ attr_reader :show_console
12
+
13
+ attr_reader :cop_options
14
+ attr_reader :cop_opt_values
15
+
16
+ # Initialize RuboCop command
17
+ #
18
+ # @param [String] file_pattern File name or file pattern
19
+ # @param [Hash] **opts The options
20
+ # @option opts [Boolean] :fix_safe RuboCop -a option will fix simple and safe issues
21
+ # @option opts [Boolean] :fix_unsafe RuboCop -A option will fix simple but potentially unsafe issues
22
+ # @option opts [Boolean] :show_console This will show in console, or if false set --out ~/last_cop.txt so that console is redirected to file
23
+ # @option opts [String] :rubo_config_file YAML file with RuboCop configuration options
24
+ #
25
+ # @example Cop for single file with auto fix turned on for simple issues
26
+ #
27
+ # RubCopCommand.new('abc.rb', fix_safe: true)
28
+ #
29
+ # @example Cop for all spec files to auto simple and unsafe issues
30
+ #
31
+ # RubCopCommand.new('spec/**/*.rb', fix_unsafe: true)
32
+ def initialize(file_pattern, **opts)
33
+ super(**opts)
34
+
35
+ @valid = true
36
+
37
+ self.file_pattern = file_pattern
38
+
39
+ self.fix_safe = opts[:fix_safe]
40
+ self.fix_unsafe = opts[:fix_unsafe]
41
+ self.show_console = opts[:show_console]
42
+ self.rubo_config_file = opts[:rubo_config_file]
43
+ end
44
+
45
+ def execute
46
+ return unless valid?
47
+
48
+ cop_run
49
+ end
50
+
51
+ def cli_options
52
+ cli_options = []
53
+ # quite is the same as simple, except you will see nothing if no offenses
54
+ cli_options << '--format' << 'quiet' # 'simple'
55
+ cli_options << '-a' if fix_safe
56
+ cli_options << '-A' if fix_unsafe
57
+ cli_options << '--config' << rubo_config_file if rubo_config_file
58
+ cli_options << '--out' << '~/last_cop.txt' unless show_console
59
+ cli_options << file_pattern
60
+ cli_options
61
+ end
62
+
63
+ def debug_values
64
+ log.kv 'rubocop target', file_pattern
65
+ log.kv '-a', 'automatic fix for safe issues' if fix_safe
66
+ log.kv '-A', 'automatic fix for potentially unsafe issues' if fix_unsafe
67
+ log.kv '-config', rubo_config_file if rubo_config_file
68
+ end
69
+
70
+ private
71
+
72
+ def file_pattern=(value)
73
+ @file_pattern = value
74
+
75
+ if value.nil? || value.empty?
76
+ guard 'file_pattern is required'
77
+ elsif Pathname.glob(value).length.zero?
78
+ guard 'file_pattern does not reference an existing file'
79
+ end
80
+ end
81
+
82
+ def fix_safe=(value)
83
+ @fix_safe = value || false
84
+ end
85
+
86
+ def fix_unsafe=(value)
87
+ @fix_unsafe = value || false
88
+ end
89
+
90
+ def show_console=(value)
91
+ @show_console = value || false
92
+ end
93
+
94
+ def rubo_config_file=(value)
95
+ @rubo_config_file = value
96
+
97
+ return if value.nil? || value.empty?
98
+
99
+ guard("Unknown RuboCop config file: #{value}") unless File.exist?(value)
100
+ end
101
+
102
+ def cop_run
103
+ cli = RuboCop::CLI.new
104
+
105
+ # log.section_heading('CLI OPTIONS')
106
+ # log.block cli_options
107
+
108
+ cli.run(cli_options)
109
+ end
110
+ end
111
+ end
112
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module KBuilder
4
- VERSION = '0.0.61'
4
+ VERSION = '0.0.62'
5
5
  end
data/~/last_cop.txt ADDED
@@ -0,0 +1,19 @@
1
+ == /var/folders/jh/nffr8l5j4rzgc7s386gj770r0000gn/T/rspec-20210701-95573-12q1az6/make-pretty.rb ==
2
+ C: 1: 1: Naming/FileName: The name of this source file (make-pretty.rb) should use snake_case.
3
+ C: 1: 1: [Corrected] Style/FrozenStringLiteralComment: Missing frozen string literal comment.
4
+ C: 2: 1: [Corrected] Layout/EmptyLineAfterMagicComment: Add an empty line after magic comments.
5
+ C: 2: 1: [Corrected] Layout/IndentationWidth: Use 2 (not 0) spaces for indentation.
6
+ C: 2: 1: [Corrected] Style/SingleLineMethods: Avoid single-line method definitions.
7
+ C: 2: 19: [Corrected] Layout/SpaceAfterComma: Space missing after comma.
8
+ W: 2: 20: [Corrected] Lint/UnusedMethodArgument: Unused method argument - xyz. If it's necessary, use _ or _xyz as an argument name to indicate that it won't be used.
9
+ C: 2: 30: [Corrected] Layout/SpaceAroundOperators: Surrounding space missing for operator =.
10
+ C: 3: 1: Style/Documentation: Missing top-level class documentation comment.
11
+ C: 3: 4: [Corrected] Layout/TrailingEmptyLines: Final newline missing.
12
+ C: 3: 28: [Corrected] Style/Semicolon: Do not use semicolons to terminate expressions.
13
+ C: 3: 29: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
14
+ C: 4: 3: [Corrected] Layout/IndentationWidth: Use 2 (not 0) spaces for indentation.
15
+ C: 4: 13: [Corrected] Style/Semicolon: Do not use semicolons to terminate expressions.
16
+ C: 4: 14: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
17
+ W: 5: 1: [Corrected] Layout/DefEndAlignment: end at 5, 0 is not aligned with def at 3, 2.
18
+
19
+ 1 file inspected, 16 offenses detected, 14 offenses corrected
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: k_builder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.61
4
+ version: 0.0.62
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Cruwys
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-06-30 00:00:00.000000000 Z
11
+ date: 2021-07-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: handlebars-helpers
@@ -111,6 +111,8 @@ files:
111
111
  - lib/k_builder.rb
112
112
  - lib/k_builder/base_builder.rb
113
113
  - lib/k_builder/base_configuration.rb
114
+ - lib/k_builder/commands/base_command.rb
115
+ - lib/k_builder/commands/rubo_cop_command.rb
114
116
  - lib/k_builder/configuration.rb
115
117
  - lib/k_builder/file_segments.rb
116
118
  - lib/k_builder/version.rb
@@ -121,6 +123,7 @@ files:
121
123
  - usage/_out5.png
122
124
  - usage/_usage_folder_after.png
123
125
  - usage/_usage_folder_before.png
126
+ - "~/last_cop.txt"
124
127
  homepage: http://appydave.com
125
128
  licenses:
126
129
  - MIT