slimcop 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/Gemfile.lock +1 -1
- data/README.md +12 -3
- data/lib/slimcop/cli.rb +6 -15
- data/lib/slimcop/offense.rb +36 -31
- data/lib/slimcop/version.rb +1 -1
- data/lib/slimcop.rb +0 -1
- metadata +2 -3
- data/lib/slimcop/formatter.rb +0 -72
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 03e13f6191b529e4c4b0ca6bc1fbbd6d1144eb029e62158ae04f43111f4dd96e
|
4
|
+
data.tar.gz: 4eb2dccd29708a5de535d9fb4971eb56084e3d45644fd9ad9f0731416ad22ec7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '09705a482591105427cf3bc97f6ba86ab317d78e845fb0ca91d677730fa7081b5466c54112449127d83dc350431aea1de288bfc67034e10045e47dfcda57a7b3'
|
7
|
+
data.tar.gz: '09384443d865bb4cd1edf7d44e0ee1eb84dcf6729910220b4cad9970eba1dd16b0cb00b26b40f5845223a61488097a5fd9b8c48f25c8e69349ba47d1739cea2c'
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -33,16 +33,25 @@ Use `slimcop` executable to check offenses and auto-correct them.
|
|
33
33
|
$ slimcop --help
|
34
34
|
Usage: slimcop [options] [file1, file2, ...]
|
35
35
|
-a, --auto-correct Auto-correct offenses.
|
36
|
+
-c, --config= Specify configuration file.
|
36
37
|
--[no-]color Force color output on or off.
|
37
38
|
```
|
38
39
|
|
39
40
|
### Example
|
40
41
|
|
41
42
|
```console
|
42
|
-
$ slimcop
|
43
|
+
$ slimcop "**/*.slim"
|
44
|
+
Inspecting 1 file
|
45
|
+
C
|
43
46
|
|
44
47
|
Offenses:
|
45
48
|
|
46
|
-
spec/fixtures/dummy.slim:1:3 C: [Correctable] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
|
47
|
-
|
49
|
+
spec/fixtures/dummy.slim:1:3: C: [Correctable] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
|
50
|
+
- "a"
|
51
|
+
^^^
|
52
|
+
spec/fixtures/dummy.slim:3:5: C: [Correctable] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
|
53
|
+
| #{"c"}
|
54
|
+
^^^
|
55
|
+
|
56
|
+
1 file inspected, 2 offenses detected, 2 offenses auto-correctable
|
48
57
|
```
|
data/lib/slimcop/cli.rb
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'rainbow'
|
4
|
+
require 'rubocop'
|
4
5
|
|
5
6
|
module Slimcop
|
6
7
|
class Cli
|
7
8
|
def initialize(argv)
|
8
9
|
@argv = argv.dup
|
9
|
-
@formatter = Formatter.new
|
10
|
+
@formatter = ::RuboCop::Formatter::ProgressFormatter.new($stdout)
|
10
11
|
end
|
11
12
|
|
12
13
|
def call
|
@@ -15,7 +16,9 @@ module Slimcop
|
|
15
16
|
rubocop_config = RuboCopConfigGenerator.new(additional_config_file_path: options[:additional_config_file_path]).call
|
16
17
|
file_paths = PathFinder.new(patterns: @argv).call
|
17
18
|
|
19
|
+
@formatter.started(file_paths)
|
18
20
|
offenses = file_paths.flat_map do |file_path|
|
21
|
+
@formatter.file_started(file_path, {})
|
19
22
|
source = ::File.read(file_path)
|
20
23
|
offenses_ = investigate(
|
21
24
|
auto_correct: options[:auto_correct],
|
@@ -30,9 +33,10 @@ module Slimcop
|
|
30
33
|
source: source
|
31
34
|
)
|
32
35
|
end
|
36
|
+
@formatter.file_finished(file_path, offenses_)
|
33
37
|
offenses_
|
34
38
|
end
|
35
|
-
|
39
|
+
@formatter.finished(file_paths)
|
36
40
|
exit(offenses.empty? ? 0 : 1)
|
37
41
|
end
|
38
42
|
|
@@ -64,19 +68,6 @@ module Slimcop
|
|
64
68
|
).call
|
65
69
|
end
|
66
70
|
|
67
|
-
# @param [Array<Slimcop::Offense>] offenses
|
68
|
-
def report(offenses)
|
69
|
-
result = +''
|
70
|
-
unless offenses.empty?
|
71
|
-
result << "\nOffenses:\n\n"
|
72
|
-
lines = offenses.map do |offense|
|
73
|
-
@formatter.format_offense(offense)
|
74
|
-
end
|
75
|
-
result << lines.join("\n")
|
76
|
-
end
|
77
|
-
puts(result)
|
78
|
-
end
|
79
|
-
|
80
71
|
# @return [Hash]
|
81
72
|
def parse!
|
82
73
|
options = {}
|
data/lib/slimcop/offense.rb
CHANGED
@@ -1,17 +1,35 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'forwardable'
|
4
|
+
|
3
5
|
require 'parser'
|
6
|
+
require 'rubocop'
|
4
7
|
|
5
8
|
module Slimcop
|
6
9
|
class Offense
|
10
|
+
extend ::Forwardable
|
11
|
+
|
7
12
|
# @return [String]
|
8
13
|
attr_reader :file_path
|
9
14
|
|
10
15
|
# @return [Integer]
|
11
16
|
attr_reader :offset
|
12
17
|
|
13
|
-
|
14
|
-
|
18
|
+
delegate(
|
19
|
+
%i[
|
20
|
+
column
|
21
|
+
column_length
|
22
|
+
correctable?
|
23
|
+
corrected_with_todo?
|
24
|
+
corrected?
|
25
|
+
corrector
|
26
|
+
highlighted_area
|
27
|
+
line
|
28
|
+
message
|
29
|
+
real_column
|
30
|
+
severity
|
31
|
+
] => :rubocop_offense_with_real_location
|
32
|
+
)
|
15
33
|
|
16
34
|
# @param [Integer] offset
|
17
35
|
# @param [RuboCop::Cop::Offense] rubocop_offense
|
@@ -23,29 +41,13 @@ module Slimcop
|
|
23
41
|
@source = source
|
24
42
|
end
|
25
43
|
|
26
|
-
# @return [
|
27
|
-
def
|
28
|
-
@
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
range.line
|
34
|
-
end
|
35
|
-
|
36
|
-
# @return [String]
|
37
|
-
def message
|
38
|
-
@rubocop_offense.message
|
39
|
-
end
|
40
|
-
|
41
|
-
# @return [Integer]
|
42
|
-
def real_column
|
43
|
-
range.column + 1
|
44
|
-
end
|
45
|
-
|
46
|
-
# @return [RuboCop::Cop::Severity]
|
47
|
-
def severity
|
48
|
-
@rubocop_offense.severity
|
44
|
+
# @return [Parser::Source::Range]
|
45
|
+
def location
|
46
|
+
@location ||= ::Parser::Source::Range.new(
|
47
|
+
buffer,
|
48
|
+
@rubocop_offense.location.begin_pos + @offset,
|
49
|
+
@rubocop_offense.location.end_pos + @offset
|
50
|
+
)
|
49
51
|
end
|
50
52
|
|
51
53
|
private
|
@@ -58,12 +60,15 @@ module Slimcop
|
|
58
60
|
)
|
59
61
|
end
|
60
62
|
|
61
|
-
# @return [
|
62
|
-
def
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
@rubocop_offense.
|
63
|
+
# @return [RuboCop::Cop::Offense]
|
64
|
+
def rubocop_offense_with_real_location
|
65
|
+
::RuboCop::Cop::Offense.new(
|
66
|
+
@rubocop_offense.severity.name,
|
67
|
+
location,
|
68
|
+
@rubocop_offense.message,
|
69
|
+
@rubocop_offense.cop_name,
|
70
|
+
@rubocop_offense.status,
|
71
|
+
@rubocop_offense.corrector
|
67
72
|
)
|
68
73
|
end
|
69
74
|
end
|
data/lib/slimcop/version.rb
CHANGED
data/lib/slimcop.rb
CHANGED
@@ -4,7 +4,6 @@ require_relative 'slimcop/version'
|
|
4
4
|
|
5
5
|
module Slimcop
|
6
6
|
autoload :Cli, 'slimcop/cli'
|
7
|
-
autoload :Formatter, 'slimcop/formatter'
|
8
7
|
autoload :Offense, 'slimcop/offense'
|
9
8
|
autoload :PathFinder, 'slimcop/path_finder'
|
10
9
|
autoload :RuboCopConfigGenerator, 'slimcop/rubo_cop_config_generator'
|
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.7.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-
|
11
|
+
date: 2021-12-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rainbow
|
@@ -75,7 +75,6 @@ files:
|
|
75
75
|
- exe/slimcop
|
76
76
|
- lib/slimcop.rb
|
77
77
|
- lib/slimcop/cli.rb
|
78
|
-
- lib/slimcop/formatter.rb
|
79
78
|
- lib/slimcop/offense.rb
|
80
79
|
- lib/slimcop/path_finder.rb
|
81
80
|
- lib/slimcop/rubo_cop_config_generator.rb
|
data/lib/slimcop/formatter.rb
DELETED
@@ -1,72 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'optparse'
|
4
|
-
require 'rainbow'
|
5
|
-
|
6
|
-
module Slimcop
|
7
|
-
# Format String for CLI output.
|
8
|
-
class Formatter
|
9
|
-
COLOR_FOR_SEVERITY_CODE = {
|
10
|
-
convention: :yellow,
|
11
|
-
error: :red,
|
12
|
-
fatal: :red,
|
13
|
-
info: :gray,
|
14
|
-
refactor: :yellow,
|
15
|
-
warning: :magenta
|
16
|
-
}.freeze
|
17
|
-
|
18
|
-
# @param [Slimcop::Offense] offense
|
19
|
-
# @return [String]
|
20
|
-
def format_offense(offense)
|
21
|
-
format(
|
22
|
-
'%<path>s:%<line>d:%<column>d %<severity>s: %<message>s',
|
23
|
-
column: offense.real_column,
|
24
|
-
line: offense.line,
|
25
|
-
message: message(offense),
|
26
|
-
path: file_path(offense),
|
27
|
-
severity: severity(offense)
|
28
|
-
)
|
29
|
-
end
|
30
|
-
|
31
|
-
private
|
32
|
-
|
33
|
-
# @param [String] path e.g. "./spec/fixtures/dummy.slim"
|
34
|
-
# @return [String]
|
35
|
-
# @example "spec/fixtures/dummy.slim"
|
36
|
-
def canonicalize_path(path)
|
37
|
-
::File.expand_path(path).delete_prefix("#{::Dir.pwd}/")
|
38
|
-
end
|
39
|
-
|
40
|
-
# @param [Slimcop::Offense] offense
|
41
|
-
# @return [String]
|
42
|
-
def file_path(offense)
|
43
|
-
Rainbow(canonicalize_path(offense.file_path)).cyan
|
44
|
-
end
|
45
|
-
|
46
|
-
# @param [Slimcop::Offense] offense
|
47
|
-
# @return [String]
|
48
|
-
def message(offense)
|
49
|
-
"#{status(offense)}#{offense.message}"
|
50
|
-
end
|
51
|
-
|
52
|
-
# @param [Slimcop::Offense] offense
|
53
|
-
# @return [String]
|
54
|
-
def severity(offense)
|
55
|
-
Rainbow(offense.severity.code).color(COLOR_FOR_SEVERITY_CODE[offense.severity.name])
|
56
|
-
end
|
57
|
-
|
58
|
-
# @param [Slimcop::Offense] offense
|
59
|
-
# @return [String]
|
60
|
-
def status(offense)
|
61
|
-
if offense.rubocop_offense.corrected_with_todo?
|
62
|
-
Rainbow('[Todo] ').green
|
63
|
-
elsif offense.rubocop_offense.corrected?
|
64
|
-
Rainbow('[Corrected] ').green
|
65
|
-
elsif offense.rubocop_offense.correctable?
|
66
|
-
Rainbow('[Correctable] ').yellow
|
67
|
-
else
|
68
|
-
''
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|