slimcop 0.7.0 → 0.9.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: 03e13f6191b529e4c4b0ca6bc1fbbd6d1144eb029e62158ae04f43111f4dd96e
4
- data.tar.gz: 4eb2dccd29708a5de535d9fb4971eb56084e3d45644fd9ad9f0731416ad22ec7
3
+ metadata.gz: 75b0d9431db2adbba5b1b238af9c11bdbf95528541136714f1d09acdb226048c
4
+ data.tar.gz: 1bdfd90997739807a9ca4e38ad37bd29ae2d9f736fbaf0d74824aa367bbd5dd4
5
5
  SHA512:
6
- metadata.gz: '09705a482591105427cf3bc97f6ba86ab317d78e845fb0ca91d677730fa7081b5466c54112449127d83dc350431aea1de288bfc67034e10045e47dfcda57a7b3'
7
- data.tar.gz: '09384443d865bb4cd1edf7d44e0ee1eb84dcf6729910220b4cad9970eba1dd16b0cb00b26b40f5845223a61488097a5fd9b8c48f25c8e69349ba47d1739cea2c'
6
+ metadata.gz: a8bb9144ee99b9745fa1f6ae1c136ed7e438e6d433c22963ade6cb25120d4fb81780ee03f4051ed393b4d37ee7f33b5a74c603229a88f487f6646e094d13ea5f
7
+ data.tar.gz: 1af01925da76e7116394f222ec7b9630e842e9be4d4d3dd71ff0a2e4480d0160e5e408c4675ef28dbbcbb04dc541a162d602341b9002098829eb24ced4946519
data/CHANGELOG.md CHANGED
@@ -2,7 +2,41 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
- ### 0.7.0 - 2021-12-28
5
+ ## 0.9.1 - 2022-01-04
6
+
7
+ ### Fixed
8
+
9
+ - Fix $LOAD_PATH at ./exe/slimcop.
10
+
11
+ ## 0.9.0 - 2022-01-02
12
+
13
+ ### Changed
14
+
15
+ - Require slimi >= 0.5.1 to extract Ruby code from Ruby attribute.
16
+
17
+ ### Fixed
18
+
19
+ - Fix -v and --version option.
20
+
21
+ ## 0.8.0 - 2021-12-29
22
+
23
+ ### Changed
24
+
25
+ - Use .rubocop.yml by default.
26
+ - Use "**/*.slim" by default.
27
+
28
+ ### Fixed
29
+
30
+ - Fix bug that --no-color was not working.
31
+
32
+ ## 0.7.1 - 2021-12-29
33
+
34
+ ### Fixed
35
+
36
+ - Exclude disabled offenses.
37
+ - Uniq paths at PathFinder.
38
+
39
+ ## 0.7.0 - 2021-12-28
6
40
 
7
41
  ### Changed
8
42
 
data/Gemfile.lock CHANGED
@@ -1,10 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- slimcop (0.7.0)
4
+ slimcop (0.9.1)
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,11 @@ 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.6.0)
49
49
  temple
50
+ tilt
50
51
  temple (0.8.2)
52
+ tilt (2.0.10)
51
53
  unicode-display_width (2.1.0)
52
54
 
53
55
  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
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: .rubocop.yml if it exists)') 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
- end.sort
21
+ end.uniq.sort
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
18
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]
@@ -21,7 +21,7 @@ module Slimcop
21
21
  # Skip if invalid syntax Ruby code is given. (e.g. "- if a?")
22
22
  return [] unless rubocop_processed_source.valid_syntax?
23
23
 
24
- rubocop_team.investigate(rubocop_processed_source).offenses
24
+ rubocop_team.investigate(rubocop_processed_source).offenses.reject(&:disabled?)
25
25
  end
26
26
 
27
27
  private
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Slimcop
4
- VERSION = '0.7.0'
4
+ VERSION = '0.9.1'
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.0
4
+ version: 0.9.1
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-03 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