rubocop-oneoff_codemod 0.0.3 → 0.0.5
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/README.md +2 -2
- data/lib/rubocop/oneoff_codemod/cops/keep_unique.rb +9 -4
- data/lib/rubocop/oneoff_codemod/cops/rbs_prototype.rb +55 -0
- data/lib/rubocop/oneoff_codemod/version.rb +2 -2
- data/lib/rubocop/oneoff_codemod.rb +1 -0
- data/sig/rubocop/oneoff_codemod.rbs +1 -1
- metadata +16 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f98a73003521d6a8f5aa5811db5db534a45dcfdb5e2ff6bfbca3f28efcb59cd
|
4
|
+
data.tar.gz: 96038200d22d10f9aba5d7ada387359b6912244a18410458d9a71791325962b3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f33f033ec49e89d02c79e4b2b0a7216f487ced3d3471d050b3c26da3e657f5fae5bb6d819062d376c34b50b61de90c49d2c5cb3b711ea277ceb884a654162bbd
|
7
|
+
data.tar.gz: a985602a87cf54e8b50798b1179f311c9835a086b1f7fb58c86d78d2cd3d47f22491cfcdac78086131ddd2e61578577f9835718710edc336cd1f883c7217de20
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# RuboCop::OneoffCodemod
|
2
2
|
|
3
3
|
A RuboCop plugin implementing comment-as-command for one-off codemod, inspired by eslint-plugin-command.
|
4
4
|
|
@@ -32,4 +32,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
32
32
|
|
33
33
|
## Code of Conduct
|
34
34
|
|
35
|
-
Everyone interacting in the
|
35
|
+
Everyone interacting in the RuboCop::OneoffCodemod project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/rubocop-oneoff_codemod/blob/master/CODE_OF_CONDUCT.md).
|
@@ -8,7 +8,8 @@ module RuboCop
|
|
8
8
|
extend AutoCorrector
|
9
9
|
include IgnoredNode
|
10
10
|
|
11
|
-
MSG = "
|
11
|
+
MSG = "Keep array items unique, removing duplicates."
|
12
|
+
COMMAND = "keep-unique"
|
12
13
|
|
13
14
|
def initialize(*args)
|
14
15
|
super
|
@@ -17,9 +18,9 @@ module RuboCop
|
|
17
18
|
|
18
19
|
def on_new_investigation
|
19
20
|
processed_source.comments.each do |comment|
|
20
|
-
next unless comment.text == "#
|
21
|
+
next unless comment.text == "# @#{COMMAND}"
|
21
22
|
|
22
|
-
@commands[comment.location.line] =
|
23
|
+
@commands[comment.location.line] = COMMAND
|
23
24
|
|
24
25
|
add_offense(comment.location.expression) do |corrector|
|
25
26
|
corrector.replace(comment.location.expression, "#")
|
@@ -27,8 +28,12 @@ module RuboCop
|
|
27
28
|
end
|
28
29
|
end
|
29
30
|
|
31
|
+
def command_exists?(node)
|
32
|
+
@commands[node.location.line - 1] == COMMAND
|
33
|
+
end
|
34
|
+
|
30
35
|
def on_array(node)
|
31
|
-
return unless
|
36
|
+
return unless command_exists? node
|
32
37
|
return unless node.loc.begin.source == "[" || node.loc.begin.source.start_with?("%w")
|
33
38
|
|
34
39
|
add_offense(node) do |corrector|
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rbs"
|
4
|
+
|
5
|
+
module RuboCop
|
6
|
+
module Cop
|
7
|
+
module Codemod
|
8
|
+
# KeepUnique
|
9
|
+
class RbsPrototype < Base
|
10
|
+
extend AutoCorrector
|
11
|
+
include IgnoredNode
|
12
|
+
|
13
|
+
MSG = "Run rbs prototype and generates boilerplate signature declaration."
|
14
|
+
COMMAND = "rbs-prototype"
|
15
|
+
|
16
|
+
def initialize(*args)
|
17
|
+
super
|
18
|
+
@commands = {}
|
19
|
+
end
|
20
|
+
|
21
|
+
def find_node_on_line(node, target_line)
|
22
|
+
if node.loc&.line == target_line && node.is_a?(RuboCop::AST::DefNode)
|
23
|
+
node
|
24
|
+
else
|
25
|
+
node.child_nodes.find do |child_node|
|
26
|
+
find_node_on_line child_node, target_line
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def on_new_investigation
|
32
|
+
processed_source.comments.each do |comment|
|
33
|
+
next unless comment.text == "# @#{COMMAND}"
|
34
|
+
|
35
|
+
target_node = find_node_on_line(processed_source.ast, comment.location.line + 1)
|
36
|
+
target_method = target_node.method_name
|
37
|
+
|
38
|
+
add_offense(comment.location.expression) do |corrector|
|
39
|
+
parser = RBS::Prototype::RB.new
|
40
|
+
parser.parse processed_source.raw_source
|
41
|
+
string = []
|
42
|
+
parser.decls.each do |decl|
|
43
|
+
decl.members.each do |member|
|
44
|
+
string << member.overloads.map(&:method_type).join(" | ") if target_method == member.name
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
corrector.replace(comment.location.expression, "# #{string.join}")
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop-oneoff_codemod
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Koji NAKAMURA
|
@@ -23,6 +23,20 @@ dependencies:
|
|
23
23
|
- - "~>"
|
24
24
|
- !ruby/object:Gem::Version
|
25
25
|
version: '1.1'
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: rbs
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
26
40
|
- !ruby/object:Gem::Dependency
|
27
41
|
name: rubocop
|
28
42
|
requirement: !ruby/object:Gem::Requirement
|
@@ -61,6 +75,7 @@ files:
|
|
61
75
|
- config/default.yml
|
62
76
|
- lib/rubocop/oneoff_codemod.rb
|
63
77
|
- lib/rubocop/oneoff_codemod/cops/keep_unique.rb
|
78
|
+
- lib/rubocop/oneoff_codemod/cops/rbs_prototype.rb
|
64
79
|
- lib/rubocop/oneoff_codemod/plugin.rb
|
65
80
|
- lib/rubocop/oneoff_codemod/version.rb
|
66
81
|
- sig/rubocop/oneoff_codemod.rbs
|