slimcop 0.8.0 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +30 -1
- data/Gemfile.lock +7 -3
- data/README.md +1 -1
- data/exe/slimcop +1 -0
- data/lib/slimcop/cli.rb +2 -1
- data/lib/slimcop/rubo_cop_config_generator.rb +6 -3
- data/lib/slimcop/ruby_clipper.rb +93 -0
- data/lib/slimcop/ruby_extractor.rb +4 -4
- data/lib/slimcop/slim_offense_collector.rb +1 -1
- data/lib/slimcop/version.rb +1 -1
- data/lib/slimcop.rb +1 -0
- data/slimcop.gemspec +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4b967da47ab7a5721d082f4d1a4e9bb84006431c5acb5992a27f8246bdcfd904
|
4
|
+
data.tar.gz: 6e260866461bc31ddef835279d647905f17f87890b63af229bd98557699e0d8f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 62cbf9db3a9f0fc741714afdd4f886b61efb4bed1e3f4ca54e6e7caa03b3cf2e8f3141aec2456b3b13f7fe0999e5a7ab9a7578a6700225a220db08200f9b2f96
|
7
|
+
data.tar.gz: c6742245998d9fbd23dca47dbf55be3e8717722daa7515df5afab77baca05d1c2ddc26d80a62bbbc97a7cfa06332a5c6fb3bc078a7d3853479598f7cb86c36ea
|
data/CHANGELOG.md
CHANGED
@@ -2,7 +2,36 @@
|
|
2
2
|
|
3
3
|
## Unreleased
|
4
4
|
|
5
|
-
## 0.
|
5
|
+
## 0.11.0 - 2022-01-10
|
6
|
+
|
7
|
+
### Changed
|
8
|
+
|
9
|
+
- Use :offset instead of :begin_ at RubyExtractor.
|
10
|
+
- Detect offenses from code that containing `if`, `unless`, `do`, etc.
|
11
|
+
|
12
|
+
## 0.10.0 - 2022-01-06
|
13
|
+
|
14
|
+
### Added
|
15
|
+
|
16
|
+
- Use .slimcop.yml as its 1st default config file.
|
17
|
+
|
18
|
+
## 0.9.1 - 2022-01-04
|
19
|
+
|
20
|
+
### Fixed
|
21
|
+
|
22
|
+
- Fix $LOAD_PATH at ./exe/slimcop.
|
23
|
+
|
24
|
+
## 0.9.0 - 2022-01-02
|
25
|
+
|
26
|
+
### Changed
|
27
|
+
|
28
|
+
- Require slimi >= 0.5.1 to extract Ruby code from Ruby attribute.
|
29
|
+
|
30
|
+
### Fixed
|
31
|
+
|
32
|
+
- Fix -v and --version option.
|
33
|
+
|
34
|
+
## 0.8.0 - 2021-12-29
|
6
35
|
|
7
36
|
### Changed
|
8
37
|
|
data/Gemfile.lock
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
slimcop (0.
|
4
|
+
slimcop (0.11.0)
|
5
5
|
rainbow
|
6
6
|
rubocop (>= 0.87)
|
7
|
-
slimi (>= 0.
|
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.
|
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
data/exe/slimcop
CHANGED
data/lib/slimcop/cli.rb
CHANGED
@@ -72,10 +72,11 @@ module Slimcop
|
|
72
72
|
options = {}
|
73
73
|
parser = ::OptionParser.new
|
74
74
|
parser.banner = 'Usage: slimcop [options] [file1, file2, ...]'
|
75
|
+
parser.version = VERSION
|
75
76
|
parser.on('-a', '--auto-correct', 'Auto-correct offenses.') do
|
76
77
|
options[:auto_correct] = true
|
77
78
|
end
|
78
|
-
parser.on('-c', '--config=', 'Specify configuration file. (default: .
|
79
|
+
parser.on('-c', '--config=', 'Specify configuration file. (default: .slimcop.yml or .rubocop.yml)') do |file_path|
|
79
80
|
options[:additional_config_file_path] = file_path
|
80
81
|
end
|
81
82
|
parser.on('--[no-]color', 'Force color output on or off.') do |value|
|
@@ -4,7 +4,8 @@ require 'rubocop'
|
|
4
4
|
|
5
5
|
module Slimcop
|
6
6
|
class RuboCopConfigGenerator
|
7
|
-
|
7
|
+
DEFAULT_ADDITIONAL_CONFIG_PATH1 = '.slimcop.yml'
|
8
|
+
DEFAULT_ADDITIONAL_CONFIG_PATH2 = '.rubocop.yml'
|
8
9
|
|
9
10
|
# @param [String] additional_config_file_path
|
10
11
|
def initialize(additional_config_file_path: nil)
|
@@ -43,8 +44,10 @@ module Slimcop
|
|
43
44
|
@additional_config = \
|
44
45
|
if @additional_config_file_path
|
45
46
|
::RuboCop::ConfigLoader.load_file(@additional_config_file_path)
|
46
|
-
elsif ::File.exist?(
|
47
|
-
::RuboCop::ConfigLoader.load_file(
|
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)
|
48
51
|
end
|
49
52
|
end
|
50
53
|
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Slimcop
|
4
|
+
# Remove unnecessary part (e.g. `if`, `unless`, `do`, ...) from Ruby code.
|
5
|
+
class RubyClipper
|
6
|
+
# @param [String] code
|
7
|
+
def initialize(code)
|
8
|
+
@code = code
|
9
|
+
end
|
10
|
+
|
11
|
+
# @return [Hash]
|
12
|
+
def call
|
13
|
+
[
|
14
|
+
PrecedingKeywordRemover,
|
15
|
+
TrailingDoRemover
|
16
|
+
].each_with_object(
|
17
|
+
code: @code,
|
18
|
+
offset: 0
|
19
|
+
) do |klass, object|
|
20
|
+
result = klass.new(object[:code]).call
|
21
|
+
object[:code] = result[:code]
|
22
|
+
object[:offset] += result[:offset]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class PrecedingKeywordRemover
|
27
|
+
REGEXP = /
|
28
|
+
\A
|
29
|
+
(?:
|
30
|
+
begin
|
31
|
+
| case
|
32
|
+
| else
|
33
|
+
| elsif
|
34
|
+
| ensure
|
35
|
+
| if
|
36
|
+
| rescue
|
37
|
+
| unless
|
38
|
+
| until
|
39
|
+
| when
|
40
|
+
| while
|
41
|
+
| for[ \t]+\w+[ \t]+in
|
42
|
+
)
|
43
|
+
[ \t]
|
44
|
+
/x.freeze
|
45
|
+
|
46
|
+
# @param [String] code
|
47
|
+
def initialize(code)
|
48
|
+
@code = code
|
49
|
+
end
|
50
|
+
|
51
|
+
# @return [Hash]
|
52
|
+
def call
|
53
|
+
data = @code.match(REGEXP)
|
54
|
+
if data
|
55
|
+
offset = data[0].length
|
56
|
+
{
|
57
|
+
code: @code[offset..],
|
58
|
+
offset: offset
|
59
|
+
}
|
60
|
+
else
|
61
|
+
{
|
62
|
+
code: @code,
|
63
|
+
offset: 0
|
64
|
+
}
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
class TrailingDoRemover
|
70
|
+
REGEXP = /
|
71
|
+
[ \t]
|
72
|
+
do
|
73
|
+
[ \t]*
|
74
|
+
(\|[^|]*\|)?
|
75
|
+
[ \t]*
|
76
|
+
\Z
|
77
|
+
/x.freeze
|
78
|
+
|
79
|
+
# @param [String] code
|
80
|
+
def initialize(code)
|
81
|
+
@code = code
|
82
|
+
end
|
83
|
+
|
84
|
+
# @return [Hash]
|
85
|
+
def call
|
86
|
+
{
|
87
|
+
code: @code.sub(REGEXP, ''),
|
88
|
+
offset: 0
|
89
|
+
}
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
require 'slimi'
|
4
4
|
|
5
5
|
module Slimcop
|
6
|
-
# Extract codes from Slim source.
|
6
|
+
# Extract Ruby codes from Slim source.
|
7
7
|
class RubyExtractor
|
8
8
|
# @param [String, nil] file_path
|
9
9
|
# @param [String] source
|
@@ -15,10 +15,10 @@ module Slimcop
|
|
15
15
|
# @return [Array<Hash>]
|
16
16
|
def call
|
17
17
|
ranges.map do |(begin_, end_)|
|
18
|
+
clipped = RubyClipper.new(@source[begin_...end_]).call
|
18
19
|
{
|
19
|
-
|
20
|
-
|
21
|
-
end_: end_
|
20
|
+
code: clipped[:code],
|
21
|
+
offset: begin_ + clipped[:offset]
|
22
22
|
}
|
23
23
|
end
|
24
24
|
end
|
data/lib/slimcop/version.rb
CHANGED
data/lib/slimcop.rb
CHANGED
@@ -7,6 +7,7 @@ module Slimcop
|
|
7
7
|
autoload :Offense, 'slimcop/offense'
|
8
8
|
autoload :PathFinder, 'slimcop/path_finder'
|
9
9
|
autoload :RuboCopConfigGenerator, 'slimcop/rubo_cop_config_generator'
|
10
|
+
autoload :RubyClipper, 'slimcop/ruby_clipper'
|
10
11
|
autoload :RubyExtractor, 'slimcop/ruby_extractor'
|
11
12
|
autoload :RubyOffenseCollector, 'slimcop/ruby_offense_collector'
|
12
13
|
autoload :SlimCorrector, 'slimcop/slim_corrector'
|
data/slimcop.gemspec
CHANGED
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.
|
4
|
+
version: 0.11.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:
|
11
|
+
date: 2022-01-10 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:
|
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:
|
54
|
+
version: 0.5.1
|
55
55
|
description:
|
56
56
|
email:
|
57
57
|
- r7kamura@gmail.com
|
@@ -78,6 +78,7 @@ files:
|
|
78
78
|
- lib/slimcop/offense.rb
|
79
79
|
- lib/slimcop/path_finder.rb
|
80
80
|
- lib/slimcop/rubo_cop_config_generator.rb
|
81
|
+
- lib/slimcop/ruby_clipper.rb
|
81
82
|
- lib/slimcop/ruby_extractor.rb
|
82
83
|
- lib/slimcop/ruby_offense_collector.rb
|
83
84
|
- lib/slimcop/slim_corrector.rb
|