slimcop 0.7.1 → 0.8.0

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: 7e1bb0dc5266092a4e8b3ce5b80c993eeed1e2f3b2696e7b34c42163c78ee182
4
- data.tar.gz: fdc659581227c0faa8575d00920dc1ddb2e4b2b8fad14780f967aad285ca014c
3
+ metadata.gz: c8ddb3a3a507467e8a94efb06e67729026956faf788fae905c2520ddd2016d4d
4
+ data.tar.gz: 793d36ff3bfffbb5f4979996395f219fe301e5ab6cbd283a75cba389d2ef0b99
5
5
  SHA512:
6
- metadata.gz: 8561d1a374e3cbed80d6970270aa7d4492725b365d0660809ee726b190b4f87dbff240517c534d4770ed170bdbdc55a898adc821e26303f75041e5a5ae9d7b2e
7
- data.tar.gz: dbf457519eefdbb8e1873ba60a0ae1a3109b7c74231c9bbac8b81ee254c581aa320a9c04cb68bbf53e7ff3818f6000e1b52a5ade1b1cf310f2ecf9a18ab54826
6
+ metadata.gz: 80f8d52c2fc2a845ce0f06f58bdf943123e8253dd3834b504ee3dd3da8f30ddb55902ec9e30db041d6eae084617addcefd42b338a720f3300b5c05cf8af34f32
7
+ data.tar.gz: 1eef3d4bc19ad6824e6e70b98da9bb35b88cbf48e748a6bb8e00aa9bed21cedde553518ac7460098ef80ee5ac19ca6183973c89443896a22a4da4fc618ac30fb
data/CHANGELOG.md CHANGED
@@ -2,6 +2,17 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.8.0
6
+
7
+ ### Changed
8
+
9
+ - Use .rubocop.yml by default.
10
+ - Use "**/*.slim" by default.
11
+
12
+ ### Fixed
13
+
14
+ - Fix bug that --no-color was not working.
15
+
5
16
  ## 0.7.1 - 2021-12-29
6
17
 
7
18
  ### Fixed
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- slimcop (0.7.1)
4
+ slimcop (0.8.0)
5
5
  rainbow
6
6
  rubocop (>= 0.87)
7
7
  slimi (>= 0.4)
data/README.md CHANGED
@@ -40,7 +40,7 @@ Usage: slimcop [options] [file1, file2, ...]
40
40
  ### Example
41
41
 
42
42
  ```console
43
- $ slimcop "**/*.slim"
43
+ $ slimcop
44
44
  Inspecting 1 file
45
45
  C
46
46
 
data/lib/slimcop/cli.rb CHANGED
@@ -7,18 +7,17 @@ module Slimcop
7
7
  class Cli
8
8
  def initialize(argv)
9
9
  @argv = argv.dup
10
- @formatter = ::RuboCop::Formatter::ProgressFormatter.new($stdout)
11
10
  end
12
11
 
13
12
  def call
14
13
  options = parse!
15
- Rainbow.enabled = options[:color] if options.key?(:color)
14
+ formatter = ::RuboCop::Formatter::ProgressFormatter.new($stdout, color: options[:color])
16
15
  rubocop_config = RuboCopConfigGenerator.new(additional_config_file_path: options[:additional_config_file_path]).call
17
16
  file_paths = PathFinder.new(patterns: @argv).call
18
17
 
19
- @formatter.started(file_paths)
18
+ formatter.started(file_paths)
20
19
  offenses = file_paths.flat_map do |file_path|
21
- @formatter.file_started(file_path, {})
20
+ formatter.file_started(file_path, {})
22
21
  source = ::File.read(file_path)
23
22
  offenses_ = investigate(
24
23
  auto_correct: options[:auto_correct],
@@ -33,10 +32,10 @@ module Slimcop
33
32
  source: source
34
33
  )
35
34
  end
36
- @formatter.file_finished(file_path, offenses_)
35
+ formatter.file_finished(file_path, offenses_)
37
36
  offenses_
38
37
  end
39
- @formatter.finished(file_paths)
38
+ formatter.finished(file_paths)
40
39
  exit(offenses.empty? ? 0 : 1)
41
40
  end
42
41
 
@@ -76,7 +75,7 @@ module Slimcop
76
75
  parser.on('-a', '--auto-correct', 'Auto-correct offenses.') do
77
76
  options[:auto_correct] = true
78
77
  end
79
- parser.on('-c', '--config=', 'Specify configuration file.') do |file_path|
78
+ parser.on('-c', '--config=', 'Specify configuration file. (default: .rubocop.yml if it exists)') do |file_path|
80
79
  options[:additional_config_file_path] = file_path
81
80
  end
82
81
  parser.on('--[no-]color', 'Force color output on or off.') do |value|
@@ -5,6 +5,10 @@ require 'pathname'
5
5
  module Slimcop
6
6
  # Collect file paths from given path patterns.
7
7
  class PathFinder
8
+ DEFAULT_PATH_PATTERNS = %w[
9
+ **/*.slim
10
+ ].freeze
11
+
8
12
  # @param [Array<String>] patterns Patterns normally given as CLI arguments (e.g. `["app/views/**/*.html.slim"]`).
9
13
  def initialize(patterns:)
10
14
  @patterns = patterns
@@ -12,9 +16,20 @@ module Slimcop
12
16
 
13
17
  # @return [Array<String>]
14
18
  def call
15
- @patterns.flat_map do |pattern|
19
+ patterns.flat_map do |pattern|
16
20
  ::Pathname.glob(pattern).select(&:file?).map(&:to_s)
17
21
  end.uniq.sort
18
22
  end
23
+
24
+ private
25
+
26
+ # @return [Array<String>]
27
+ def patterns
28
+ if @patterns.empty?
29
+ DEFAULT_PATH_PATTERNS
30
+ else
31
+ @patterns
32
+ end
33
+ end
19
34
  end
20
35
  end
@@ -4,6 +4,8 @@ require 'rubocop'
4
4
 
5
5
  module Slimcop
6
6
  class RuboCopConfigGenerator
7
+ DEFAULT_ADDITIONAL_CONFIG_PATH = '.rubocop.yml'
8
+
7
9
  # @param [String] additional_config_file_path
8
10
  def initialize(additional_config_file_path: nil)
9
11
  @additional_config_file_path = additional_config_file_path
@@ -29,13 +31,22 @@ module Slimcop
29
31
  # @return [Hash]
30
32
  def merged_config_hash
31
33
  result = slimcop_default_config
32
- result = ::RuboCop::ConfigLoader.merge(result, additional_config) if @additional_config_file_path
34
+ result = ::RuboCop::ConfigLoader.merge(result, additional_config) if additional_config
33
35
  result
34
36
  end
35
37
 
36
38
  # @return [RuboCop::Config, nil]
37
39
  def additional_config
38
- ::RuboCop::ConfigLoader.load_file(@additional_config_file_path) if @additional_config_file_path
40
+ if instance_variable_defined?(:@additional_config)
41
+ @additional_config
42
+ else
43
+ @additional_config = \
44
+ if @additional_config_file_path
45
+ ::RuboCop::ConfigLoader.load_file(@additional_config_file_path)
46
+ elsif ::File.exist?(DEFAULT_ADDITIONAL_CONFIG_PATH)
47
+ ::RuboCop::ConfigLoader.load_file(DEFAULT_ADDITIONAL_CONFIG_PATH)
48
+ end
49
+ end
39
50
  end
40
51
 
41
52
  # @return [RuboCop::Config]
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Slimcop
4
- VERSION = '0.7.1'
4
+ VERSION = '0.8.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slimcop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryo Nakamura