templatecop 0.1.0 → 0.2.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: 7b3638b72df80a798b42389125fa1b67085a6c1ddbae87ac431b9fa2f4088ab7
4
- data.tar.gz: d6c5635d979fe7734f412259fc0dc2761e048de9afe76c271b6ac79452af6ff4
3
+ metadata.gz: 60c625ec4bf026174039c9a815a1baee6e562fff906a0d07bd77b0c4a0d6f96a
4
+ data.tar.gz: 4e08952b06bf388c51a91c12efecfce3642e9c73f8d60df0b64f43f1bc068b87
5
5
  SHA512:
6
- metadata.gz: e4616cc878daf91433567903956aab4f6a96f5a3f33e38284ec1f4d9754632a59a841011eec804e88abb5281a16ac6651cf84cad91e9d33f2d0ff0195120bcbf
7
- data.tar.gz: 8624e290b2f2f42304210ef0a71cf5d15ed57bf01ee1e17a4e131012d52d40f8078f56080d074ebbc668827a91d9095844de42d9be434289bd8a46d34db500dd
6
+ metadata.gz: e3c60ad4fcd3721fe16324fafeca33352b959ac2c6956283b0e62c03a322e7c95931d4bfa8bd03519e5dbbd2d098cf48551d5ee0f253656eddea26637e30e220
7
+ data.tar.gz: 904a14de0c89e399a207a25037db8cfb5b7c42a366fe781aa37caf9b4f9141cac6274f980bfad8a5de4901f4e31699a69c0be243fc29d8dec0d62f848d9f5ad9
data/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.2.0 - 2022-01-22
6
+
7
+ ### Changed
8
+
9
+ - Run in parallel.
10
+
5
11
  ## 0.1.0 - 2022-01-15
6
12
 
7
13
  - Initial release.
data/Gemfile CHANGED
@@ -9,3 +9,4 @@ gem 'rake'
9
9
  gem 'rspec'
10
10
  gem 'rubocop'
11
11
  gem 'rubocop-rspec'
12
+ gem 'slimcop'
data/Gemfile.lock CHANGED
@@ -1,7 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- templatecop (0.1.0)
4
+ templatecop (0.2.0)
5
+ parallel
5
6
  parser
6
7
  rubocop (>= 0.87)
7
8
 
@@ -44,6 +45,16 @@ GEM
44
45
  rubocop-rspec (2.7.0)
45
46
  rubocop (~> 1.19)
46
47
  ruby-progressbar (1.11.0)
48
+ slimcop (0.13.1)
49
+ slimi (>= 0.5.1)
50
+ templatecop
51
+ slimi (0.7.1)
52
+ temple
53
+ thor
54
+ tilt
55
+ temple (0.8.2)
56
+ thor (1.2.1)
57
+ tilt (2.0.10)
47
58
  unicode-display_width (2.1.0)
48
59
 
49
60
  PLATFORMS
@@ -54,6 +65,7 @@ DEPENDENCIES
54
65
  rspec
55
66
  rubocop
56
67
  rubocop-rspec
68
+ slimcop
57
69
  templatecop!
58
70
 
59
71
  BUNDLED WITH
data/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Templatecop
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/templatecop.svg)](https://rubygems.org/gems/templatecop)
4
+ [![test](https://github.com/r7kamura/templatecop/actions/workflows/test.yml/badge.svg)](https://github.com/r7kamura/templatecop/actions/workflows/test.yml)
5
+
3
6
  [RuboCop](https://github.com/rubocop/rubocop) runner framework for template language.
4
7
 
5
8
  ## Installation
@@ -24,4 +27,7 @@ gem install templatecop
24
27
 
25
28
  ## Usage
26
29
 
27
- TBD.
30
+ See these examples:
31
+
32
+ - <https://github.com/r7kamura/erbcop>
33
+ - <https://github.com/r7kamura/slimcop>
@@ -50,6 +50,44 @@ module Templatecop
50
50
  )
51
51
  end
52
52
 
53
+ # @note For Parallel.
54
+ # @return [Hash]
55
+ def marshal_dump
56
+ {
57
+ begin_pos: @rubocop_offense.location.begin_pos,
58
+ cop_name: @rubocop_offense.cop_name,
59
+ end_pos: @rubocop_offense.location.end_pos,
60
+ file_path: @file_path,
61
+ message: @rubocop_offense.message.dup.force_encoding(::Encoding::UTF_8).scrub,
62
+ offset: @offset,
63
+ severity: @rubocop_offense.severity.to_s,
64
+ source: @source,
65
+ status: @rubocop_offense.status
66
+ }
67
+ end
68
+
69
+ # @note For Parallel.
70
+ # @param [Hash] hash
71
+ def marshal_load(hash)
72
+ @file_path = hash[:file_path]
73
+ @offset = hash[:offset]
74
+ @rubocop_offense = ::RuboCop::Cop::Offense.new(
75
+ hash[:severity],
76
+ ::Parser::Source::Range.new(
77
+ ::Parser::Source::Buffer.new(
78
+ @file_path,
79
+ source: @source
80
+ ),
81
+ hash[:begin_pos],
82
+ hash[:end_pos]
83
+ ),
84
+ hash[:message],
85
+ hash[:cop_name],
86
+ hash[:status].to_sym
87
+ )
88
+ @source = hash[:source]
89
+ end
90
+
53
91
  private
54
92
 
55
93
  # @return [Parser::Source::Buffer]
@@ -1,5 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'parallel'
4
+ require 'stringio'
5
+
3
6
  module Templatecop
4
7
  # Run investigation and auto-correcttion.
5
8
  class Runner
@@ -25,9 +28,11 @@ module Templatecop
25
28
  # @return [Array<RuboCop::Cop::Offense>]
26
29
  def call
27
30
  on_started
28
- offenses = investigate_and_correct
29
- on_finished
30
- offenses
31
+ result = run_in_parallel
32
+ on_finished(result)
33
+ result.flat_map do |(_, offenses)|
34
+ offenses
35
+ end
31
36
  end
32
37
 
33
38
  private
@@ -59,9 +64,9 @@ module Templatecop
59
64
  ).call
60
65
  end
61
66
 
62
- # @return [Array<RuboCop::Cop::Offense>]
63
- def investigate_and_correct
64
- @file_paths.flat_map do |file_path|
67
+ # @return [Hash]
68
+ def run_in_parallel
69
+ ::Parallel.map(@file_paths) do |file_path|
65
70
  offenses_per_file = []
66
71
  max_trials_count.times do
67
72
  on_file_started(file_path)
@@ -84,7 +89,7 @@ module Templatecop
84
89
  )
85
90
  end
86
91
  on_file_finished(file_path, offenses_per_file)
87
- offenses_per_file
92
+ [file_path, offenses_per_file]
88
93
  end
89
94
  end
90
95
 
@@ -112,7 +117,18 @@ module Templatecop
112
117
  @formatter.file_finished(file_path, offenses)
113
118
  end
114
119
 
115
- def on_finished
120
+ # We need to adjust @formatter's status (in silently)
121
+ # because @formatter.on_file_* was called in child process, not in this process.
122
+ # @param [Array] result
123
+ def on_finished(result)
124
+ original = @formatter.output
125
+ @formatter.instance_variable_set(:@output, ::StringIO.new)
126
+ result.each do |(file_path, offenses)|
127
+ on_file_started(file_path)
128
+ on_file_finished(file_path, offenses)
129
+ end
130
+ @formatter.instance_variable_set(:@output, original)
131
+
116
132
  @formatter.finished(@file_paths)
117
133
  end
118
134
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Templatecop
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.0'
5
5
  end
data/templatecop.gemspec CHANGED
@@ -29,6 +29,7 @@ Gem::Specification.new do |spec|
29
29
  spec.require_paths = ['lib']
30
30
  spec.metadata['rubygems_mfa_required'] = 'true'
31
31
 
32
+ spec.add_dependency 'parallel'
32
33
  spec.add_dependency 'parser'
33
34
  spec.add_dependency 'rubocop', '>= 0.87'
34
35
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: templatecop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.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: 2022-01-15 00:00:00.000000000 Z
11
+ date: 2022-01-21 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: parallel
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: parser
15
29
  requirement: !ruby/object:Gem::Requirement