slimcop 0.7.1 → 0.10.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: 02e411169bcf03ec8058dab2f6c316188b78cfda2ee5b10839f2bc89e0ffbcb7
4
+ data.tar.gz: 3081e815ee3f7ce7a518ab6a7b384042d4d96eda53bb8c5c776f3cbe21cd90e2
5
5
  SHA512:
6
- metadata.gz: 8561d1a374e3cbed80d6970270aa7d4492725b365d0660809ee726b190b4f87dbff240517c534d4770ed170bdbdc55a898adc821e26303f75041e5a5ae9d7b2e
7
- data.tar.gz: dbf457519eefdbb8e1873ba60a0ae1a3109b7c74231c9bbac8b81ee254c581aa320a9c04cb68bbf53e7ff3818f6000e1b52a5ade1b1cf310f2ecf9a18ab54826
6
+ metadata.gz: adcd201a0fb01c9b40ec857f341bedec643648b463313433558bbc26564b2dc50742d771f68e40d8b9a4a829785e4e49cbbcda2d2ca147b94e8e61a9f5d3f183
7
+ data.tar.gz: 484b00bcf0e97e8980216cb70b0cd4badf5075eaf542f59657ceac2aa8de598c0059a58091210ee69c34bc09fdbe6df9ffc5d666169ccfa3da24a7a81bd10d44
data/CHANGELOG.md CHANGED
@@ -2,6 +2,39 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.10.0 - 2022-01-06
6
+
7
+ ### Added
8
+
9
+ - Use .slimcop.yml as its 1st default config file.
10
+
11
+ ## 0.9.1 - 2022-01-04
12
+
13
+ ### Fixed
14
+
15
+ - Fix $LOAD_PATH at ./exe/slimcop.
16
+
17
+ ## 0.9.0 - 2022-01-02
18
+
19
+ ### Changed
20
+
21
+ - Require slimi >= 0.5.1 to extract Ruby code from Ruby attribute.
22
+
23
+ ### Fixed
24
+
25
+ - Fix -v and --version option.
26
+
27
+ ## 0.8.0 - 2021-12-29
28
+
29
+ ### Changed
30
+
31
+ - Use .rubocop.yml by default.
32
+ - Use "**/*.slim" by default.
33
+
34
+ ### Fixed
35
+
36
+ - Fix bug that --no-color was not working.
37
+
5
38
  ## 0.7.1 - 2021-12-29
6
39
 
7
40
  ### Fixed
data/Gemfile.lock CHANGED
@@ -1,10 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- slimcop (0.7.1)
4
+ slimcop (0.10.0)
5
5
  rainbow
6
6
  rubocop (>= 0.87)
7
- slimi (>= 0.4)
7
+ slimi (>= 0.5.1)
8
8
 
9
9
  GEM
10
10
  remote: https://rubygems.org/
@@ -45,9 +45,13 @@ GEM
45
45
  rubocop-rspec (2.6.0)
46
46
  rubocop (~> 1.19)
47
47
  ruby-progressbar (1.11.0)
48
- slimi (0.4.2)
48
+ slimi (0.7.0)
49
49
  temple
50
+ thor
51
+ tilt
50
52
  temple (0.8.2)
53
+ thor (1.2.1)
54
+ tilt (2.0.10)
51
55
  unicode-display_width (2.1.0)
52
56
 
53
57
  PLATFORMS
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 'spec/fixtures/**/*.slim'
44
44
  Inspecting 1 file
45
45
  C
46
46
 
data/exe/slimcop CHANGED
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
+ $LOAD_PATH.unshift File.expand_path('../lib', __dir__)
4
5
  require 'slimcop'
5
6
 
6
7
  Slimcop::Cli.new(ARGV).call
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
 
@@ -73,10 +72,11 @@ module Slimcop
73
72
  options = {}
74
73
  parser = ::OptionParser.new
75
74
  parser.banner = 'Usage: slimcop [options] [file1, file2, ...]'
75
+ parser.version = VERSION
76
76
  parser.on('-a', '--auto-correct', 'Auto-correct offenses.') do
77
77
  options[:auto_correct] = true
78
78
  end
79
- parser.on('-c', '--config=', 'Specify configuration file.') do |file_path|
79
+ parser.on('-c', '--config=', 'Specify configuration file. (default: .slimcop.yml or .rubocop.yml)') do |file_path|
80
80
  options[:additional_config_file_path] = file_path
81
81
  end
82
82
  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,9 @@ require 'rubocop'
4
4
 
5
5
  module Slimcop
6
6
  class RuboCopConfigGenerator
7
+ DEFAULT_ADDITIONAL_CONFIG_PATH1 = '.slimcop.yml'
8
+ DEFAULT_ADDITIONAL_CONFIG_PATH2 = '.rubocop.yml'
9
+
7
10
  # @param [String] additional_config_file_path
8
11
  def initialize(additional_config_file_path: nil)
9
12
  @additional_config_file_path = additional_config_file_path
@@ -29,13 +32,24 @@ module Slimcop
29
32
  # @return [Hash]
30
33
  def merged_config_hash
31
34
  result = slimcop_default_config
32
- result = ::RuboCop::ConfigLoader.merge(result, additional_config) if @additional_config_file_path
35
+ result = ::RuboCop::ConfigLoader.merge(result, additional_config) if additional_config
33
36
  result
34
37
  end
35
38
 
36
39
  # @return [RuboCop::Config, nil]
37
40
  def additional_config
38
- ::RuboCop::ConfigLoader.load_file(@additional_config_file_path) if @additional_config_file_path
41
+ if instance_variable_defined?(:@additional_config)
42
+ @additional_config
43
+ else
44
+ @additional_config = \
45
+ if @additional_config_file_path
46
+ ::RuboCop::ConfigLoader.load_file(@additional_config_file_path)
47
+ elsif ::File.exist?(DEFAULT_ADDITIONAL_CONFIG_PATH1)
48
+ ::RuboCop::ConfigLoader.load_file(DEFAULT_ADDITIONAL_CONFIG_PATH1)
49
+ elsif ::File.exist?(DEFAULT_ADDITIONAL_CONFIG_PATH2)
50
+ ::RuboCop::ConfigLoader.load_file(DEFAULT_ADDITIONAL_CONFIG_PATH2)
51
+ end
52
+ end
39
53
  end
40
54
 
41
55
  # @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.10.0'
5
5
  end
data/slimcop.gemspec CHANGED
@@ -33,5 +33,5 @@ Gem::Specification.new do |spec|
33
33
 
34
34
  spec.add_dependency 'rainbow'
35
35
  spec.add_dependency 'rubocop', '>= 0.87'
36
- spec.add_dependency 'slimi', '>= 0.4'
36
+ spec.add_dependency 'slimi', '>= 0.5.1'
37
37
  end
metadata CHANGED
@@ -1,14 +1,14 @@
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.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryo Nakamura
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-12-28 00:00:00.000000000 Z
11
+ date: 2022-01-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rainbow
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '0.4'
47
+ version: 0.5.1
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '0.4'
54
+ version: 0.5.1
55
55
  description:
56
56
  email:
57
57
  - r7kamura@gmail.com