rubocop-oneoff_codemod 0.0.1 → 0.0.2
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/.rubocop.yml +13 -0
- data/lib/rubocop/oneoff_codemod/cops/keep_unique.rb +31 -12
- data/lib/rubocop/oneoff_codemod/plugin.rb +30 -0
- data/lib/rubocop/oneoff_codemod/version.rb +1 -1
- data/lib/rubocop/oneoff_codemod.rb +1 -0
- metadata +25 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0acba39d923070ad04e1a5a509bcf45995e7cdf9ac8e526892e82311ccff5f0e
|
4
|
+
data.tar.gz: 73b28c183ad3afc838a76d2caacf2954b4b84063cf415a346305c8ddb439bac2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 43ac80bb778c09d227cccdb64334f152851f6e5525b411145aef070833b7e2ea21afd0712b0b9cb6066dcf0045857067a158fb564857825f34e75834a04f3153
|
7
|
+
data.tar.gz: 16b1eecbe7d1deda97c5d76a90950b334221d42813bdda9602aad811295e87775f252f631b9dc277ee7503dbeb5060ec1730b550efed2ee07589364bb967e247
|
data/.rubocop.yml
CHANGED
@@ -1,9 +1,22 @@
|
|
1
1
|
AllCops:
|
2
2
|
TargetRubyVersion: 3.1
|
3
3
|
NewCops: enable
|
4
|
+
SuggestExtensions: false
|
4
5
|
|
5
6
|
Style/StringLiterals:
|
6
7
|
EnforcedStyle: double_quotes
|
7
8
|
|
8
9
|
Style/StringLiteralsInInterpolation:
|
9
10
|
EnforcedStyle: double_quotes
|
11
|
+
|
12
|
+
Metrics/AbcSize:
|
13
|
+
Enabled: false
|
14
|
+
|
15
|
+
Metrics/CyclomaticComplexity:
|
16
|
+
Enabled: false
|
17
|
+
|
18
|
+
Metrics/MethodLength:
|
19
|
+
Enabled: false
|
20
|
+
|
21
|
+
Metrics/PerceivedComplexity:
|
22
|
+
Enabled: false
|
@@ -3,8 +3,8 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Codemod
|
6
|
-
#
|
7
|
-
class
|
6
|
+
# KeepUnique
|
7
|
+
class KeepUnique < Base
|
8
8
|
extend AutoCorrector
|
9
9
|
include IgnoredNode
|
10
10
|
|
@@ -17,7 +17,7 @@ module RuboCop
|
|
17
17
|
|
18
18
|
def on_new_investigation
|
19
19
|
processed_source.comments.each do |comment|
|
20
|
-
next unless comment.text
|
20
|
+
next unless comment.text == "# @keep-unique"
|
21
21
|
|
22
22
|
@commands[comment.location.line] = :keep_unique
|
23
23
|
|
@@ -28,16 +28,35 @@ module RuboCop
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def on_array(node)
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
31
|
+
return unless @commands[node.location.line - 1] == :keep_unique
|
32
|
+
return unless node.loc.begin.source == "[" || node.loc.begin.source.start_with?("%w")
|
33
|
+
|
34
|
+
add_offense(node) do |corrector|
|
35
|
+
next if part_of_ignored_node?(node)
|
36
|
+
|
37
|
+
indent = " " * node.values.first.loc.column
|
38
|
+
if node.loc.begin.source == "["
|
39
|
+
separator = ", "
|
40
|
+
line_separator = ",\n#{indent}"
|
41
|
+
else
|
42
|
+
separator = " "
|
43
|
+
line_separator = "\n#{indent}"
|
40
44
|
end
|
45
|
+
|
46
|
+
content = []
|
47
|
+
content << node.loc.begin.source
|
48
|
+
content << processed_source.raw_source[node.loc.begin.end_pos..(node.values.first.loc.expression.begin_pos - 1)] # rubocop:disable Layout/LineLength
|
49
|
+
|
50
|
+
acc = node.values.uniq(&:source).each_with_object([]) do |v_node, acc|
|
51
|
+
acc << [] if acc.last&.last&.loc&.line != v_node.loc.line # rubocop:disable Style/SafeNavigationChainLength
|
52
|
+
acc.last << v_node
|
53
|
+
end
|
54
|
+
content << acc.map { |a| a.map(&:source).join(separator) }.join(line_separator)
|
55
|
+
|
56
|
+
content << processed_source.raw_source[node.values.last.loc.expression.end_pos..(node.loc.end.begin_pos - 1)] # rubocop:disable Layout/LineLength
|
57
|
+
content << node.loc.end.source
|
58
|
+
|
59
|
+
corrector.replace(node, content)
|
41
60
|
end
|
42
61
|
|
43
62
|
ignore_node(node)
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "lint_roller"
|
4
|
+
|
5
|
+
module RuboCop
|
6
|
+
module OneoffCodemod
|
7
|
+
# A plugin that integrates RuboCop Oneoff Codemod with RuboCop's plugin system.
|
8
|
+
class Plugin < LintRoller::Plugin
|
9
|
+
def about
|
10
|
+
LintRoller::About.new(
|
11
|
+
name: "rubocop-oneoff_codemod",
|
12
|
+
version: RuboCop::OneoffCodemod::VERSION,
|
13
|
+
homepage: "https://github.com/kozy4324/rubocop-oneoff_codemod",
|
14
|
+
description: "A RuboCop plugin implementing comment-as-command for one-off codemod, inspired " \
|
15
|
+
"by eslint-plugin-command."
|
16
|
+
)
|
17
|
+
end
|
18
|
+
|
19
|
+
def supported?(context)
|
20
|
+
context.engine == :rubocop
|
21
|
+
end
|
22
|
+
|
23
|
+
def rules(_context)
|
24
|
+
project_root = Pathname.new(__dir__).join("../../../") # steep:ignore
|
25
|
+
|
26
|
+
LintRoller::Rules.new(type: :path, config_format: :rubocop, value: project_root.join("config", "default.yml"))
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Koji NAKAMURA
|
@@ -9,20 +9,40 @@ bindir: exe
|
|
9
9
|
cert_chain: []
|
10
10
|
date: 1980-01-02 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
|
+
- !ruby/object:Gem::Dependency
|
13
|
+
name: lint_roller
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - "~>"
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: '1.1'
|
19
|
+
type: :runtime
|
20
|
+
prerelease: false
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
requirements:
|
23
|
+
- - "~>"
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: '1.1'
|
12
26
|
- !ruby/object:Gem::Dependency
|
13
27
|
name: rubocop
|
14
28
|
requirement: !ruby/object:Gem::Requirement
|
15
29
|
requirements:
|
16
30
|
- - ">="
|
17
31
|
- !ruby/object:Gem::Version
|
18
|
-
version:
|
32
|
+
version: 1.72.1
|
33
|
+
- - "<"
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '2.0'
|
19
36
|
type: :runtime
|
20
37
|
prerelease: false
|
21
38
|
version_requirements: !ruby/object:Gem::Requirement
|
22
39
|
requirements:
|
23
40
|
- - ">="
|
24
41
|
- !ruby/object:Gem::Version
|
25
|
-
version:
|
42
|
+
version: 1.72.1
|
43
|
+
- - "<"
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '2.0'
|
26
46
|
description: A RuboCop plugin implementing comment-as-command for one-off codemod,
|
27
47
|
inspired by eslint-plugin-command.
|
28
48
|
email:
|
@@ -40,6 +60,7 @@ files:
|
|
40
60
|
- Rakefile
|
41
61
|
- lib/rubocop/oneoff_codemod.rb
|
42
62
|
- lib/rubocop/oneoff_codemod/cops/keep_unique.rb
|
63
|
+
- lib/rubocop/oneoff_codemod/plugin.rb
|
43
64
|
- lib/rubocop/oneoff_codemod/version.rb
|
44
65
|
- sig/rubocop/oneoff_codemod.rbs
|
45
66
|
homepage: https://github.com/kozy4324/rubocop-oneoff_codemod
|
@@ -50,6 +71,7 @@ metadata:
|
|
50
71
|
homepage_uri: https://github.com/kozy4324/rubocop-oneoff_codemod
|
51
72
|
source_code_uri: https://github.com/kozy4324/rubocop-oneoff_codemod
|
52
73
|
changelog_uri: https://github.com/kozy4324/rubocop-oneoff_codemod/releases
|
74
|
+
default_lint_roller_plugin: RuboCop::OneoffCodemod::Plugin
|
53
75
|
rdoc_options: []
|
54
76
|
require_paths:
|
55
77
|
- lib
|