rdoc_rubocop 0.1.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 +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +74 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/rdoc-rubocop +11 -0
- data/lib/rdoc_rubocop/comment/source_code.rb +28 -0
- data/lib/rdoc_rubocop/comment.rb +45 -0
- data/lib/rdoc_rubocop/comment_extractor.rb +33 -0
- data/lib/rdoc_rubocop/comment_token_organizable.rb +17 -0
- data/lib/rdoc_rubocop/file_path.rb +14 -0
- data/lib/rdoc_rubocop/options.rb +37 -0
- data/lib/rdoc_rubocop/rubocop_modifier.rb +69 -0
- data/lib/rdoc_rubocop/rubocop_runner.rb +47 -0
- data/lib/rdoc_rubocop/source_file/corrector.rb +49 -0
- data/lib/rdoc_rubocop/source_file.rb +72 -0
- data/lib/rdoc_rubocop/token/comment_token.rb +34 -0
- data/lib/rdoc_rubocop/token.rb +35 -0
- data/lib/rdoc_rubocop/version.rb +3 -0
- data/lib/rdoc_rubocop.rb +12 -0
- data/rdoc_rubocop.gemspec +44 -0
- metadata +157 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8bde0ed87ddc4498c6a230db6759d21174d1915e2af9c454238979b9e7f2b29d
|
4
|
+
data.tar.gz: e79f99e1b731881249835d5264cfa7998ac33bdc6958238b2e5990ca217c6120
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9210096527aa02b7225a68e188372863bb86fe431cb825e09332d8424eba1037ffce39c624656d3f93d07e39d35af960c46a0d7d689f79d9579069de6cd02f42
|
7
|
+
data.tar.gz: bd30af737512479b43e02eddd27f33f8ddb57afb66e24c66572282c8786ebb5672f86b851dabb870bd322c1c76decbf062aa4d3266bbc6e4f6c868fe9ca13b4f
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Loose Coupling
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# RDocRuboCop
|
2
|
+
|
3
|
+
**RDocRuboCop** is a Ruby static code analyzer and formatter for codes in RDoc.
|
4
|
+
|
5
|
+
### before
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
class Foo
|
9
|
+
# concatenate each elements with ","
|
10
|
+
#
|
11
|
+
# a = [ 1 , 2 , 3 ]
|
12
|
+
# foo=Foo.new
|
13
|
+
# foo.bar( a )
|
14
|
+
#
|
15
|
+
def bar(array)
|
16
|
+
array.join(",")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
```
|
20
|
+
|
21
|
+
### after
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
class Foo
|
25
|
+
# concatenate each elements with ","
|
26
|
+
#
|
27
|
+
# a = [1, 2, 3]
|
28
|
+
# foo = Foo.new
|
29
|
+
# foo.bar(a)
|
30
|
+
#
|
31
|
+
def bar(array)
|
32
|
+
array.join(",")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
```
|
37
|
+
|
38
|
+
## Installation
|
39
|
+
|
40
|
+
Add this line to your application's Gemfile:
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
gem 'rdoc_rubocop'
|
44
|
+
```
|
45
|
+
|
46
|
+
And then execute:
|
47
|
+
|
48
|
+
$ bundle
|
49
|
+
|
50
|
+
Or install it yourself as:
|
51
|
+
|
52
|
+
$ gem install rdoc_rubocop
|
53
|
+
|
54
|
+
## Usage
|
55
|
+
|
56
|
+
# Generate .rdoc_rubocop.yml and .rdoc_rubocop_todo.yml
|
57
|
+
$ rdoc-rubocop --auto-gen-config
|
58
|
+
|
59
|
+
# Correct the code
|
60
|
+
$ rdoc-rubocop -a
|
61
|
+
|
62
|
+
## Development
|
63
|
+
|
64
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
65
|
+
|
66
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
67
|
+
|
68
|
+
## Contributing
|
69
|
+
|
70
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/nowlinuxing/rdoc_rubocop.
|
71
|
+
|
72
|
+
## License
|
73
|
+
|
74
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "rdoc_rubocop"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/exe/rdoc-rubocop
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift("#{__dir__}/../lib")
|
4
|
+
|
5
|
+
require "rdoc_rubocop"
|
6
|
+
|
7
|
+
options, paths = RDocRuboCop::Options.new.parse(ARGV)
|
8
|
+
paths = Dir.glob("**/*.rb") if paths.empty? if paths.empty?
|
9
|
+
|
10
|
+
runner = RDocRuboCop::RuboCopRunner.new(paths, options: options)
|
11
|
+
runner.run
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require "rdoc_rubocop/token/comment_token"
|
2
|
+
|
3
|
+
module RDocRuboCop
|
4
|
+
class Comment
|
5
|
+
class SourceCode
|
6
|
+
include CommentTokenOrganizable
|
7
|
+
|
8
|
+
attr_reader :comment
|
9
|
+
|
10
|
+
def initialize(comment_tokens, comment = nil)
|
11
|
+
@comment_tokens = comment_tokens
|
12
|
+
@comment = comment
|
13
|
+
end
|
14
|
+
|
15
|
+
def text
|
16
|
+
@comment_tokens.map { |comment_token| comment_token.text_without_indent(comment_indent) }.join
|
17
|
+
end
|
18
|
+
|
19
|
+
def lineno
|
20
|
+
@lineno ||= comment_tokens.map(&:lineno).minmax
|
21
|
+
end
|
22
|
+
|
23
|
+
def indent_and_commentchar
|
24
|
+
Token::CommentToken.indent_and_commentchar(comment_tokens[0].column, comment_indent)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require "rdoc_rubocop/comment_token_organizable"
|
2
|
+
require "rdoc_rubocop/comment/source_code"
|
3
|
+
|
4
|
+
module RDocRuboCop
|
5
|
+
class Comment
|
6
|
+
include CommentTokenOrganizable
|
7
|
+
|
8
|
+
attr_reader :source_file
|
9
|
+
|
10
|
+
def initialize(comment_tokens, source_file = nil)
|
11
|
+
@comment_tokens = comment_tokens
|
12
|
+
@source_file = source_file
|
13
|
+
end
|
14
|
+
|
15
|
+
def source_codes
|
16
|
+
code_chunk = []
|
17
|
+
codes = []
|
18
|
+
@comment_tokens.each do |comment_token|
|
19
|
+
if comment_token.comment_indent > comment_indent
|
20
|
+
code_chunk << comment_token
|
21
|
+
elsif comment_token.blank? && code_chunk.any?
|
22
|
+
code_chunk << comment_token
|
23
|
+
elsif code_chunk.any?
|
24
|
+
codes << SourceCode.new(trim(code_chunk))
|
25
|
+
code_chunk = []
|
26
|
+
end
|
27
|
+
end
|
28
|
+
codes << SourceCode.new(trim(code_chunk), self) if code_chunk.any?
|
29
|
+
|
30
|
+
codes
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def trim(code_chunk)
|
36
|
+
i = code_chunk.size - 1
|
37
|
+
while i >= 0 && code_chunk[i].blank? do
|
38
|
+
code_chunk.delete_at(i)
|
39
|
+
i -= 1
|
40
|
+
end
|
41
|
+
|
42
|
+
code_chunk
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'ripper'
|
2
|
+
require 'rdoc_rubocop/token'
|
3
|
+
require 'rdoc_rubocop/comment'
|
4
|
+
|
5
|
+
module RDocRuboCop
|
6
|
+
class CommentExtractor
|
7
|
+
attr_reader :comments
|
8
|
+
|
9
|
+
def initialize(source_file)
|
10
|
+
@source_file = source_file
|
11
|
+
@comments = []
|
12
|
+
end
|
13
|
+
|
14
|
+
def extract
|
15
|
+
@comments =
|
16
|
+
comment_tokens.
|
17
|
+
slice_when { |token_before, token_after| token_after.lineno - token_before.lineno > 1 }.
|
18
|
+
map { |comment_tokens| Comment.new(comment_tokens, @source_file) }
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def comment_tokens
|
24
|
+
tokens.select(&:on_comment?)
|
25
|
+
end
|
26
|
+
|
27
|
+
def tokens
|
28
|
+
Ripper.
|
29
|
+
lex(@source_file.source).
|
30
|
+
map { |token| Token.build(*token) }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module RDocRuboCop
|
2
|
+
module CommentTokenOrganizable
|
3
|
+
def self.included(base)
|
4
|
+
base.include InstanceMethods
|
5
|
+
|
6
|
+
attr_reader :comment_tokens
|
7
|
+
end
|
8
|
+
|
9
|
+
module InstanceMethods
|
10
|
+
private
|
11
|
+
|
12
|
+
def comment_indent
|
13
|
+
@comment_indent ||= @comment_tokens.reject(&:blank?).map(&:comment_indent).min
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require "rdoc_rubocop/comment/source_code"
|
2
|
+
|
3
|
+
module RDocRuboCop
|
4
|
+
class FilePath < String
|
5
|
+
attr_reader :source_code
|
6
|
+
attr_accessor :source
|
7
|
+
|
8
|
+
def initialize(str, source_code)
|
9
|
+
super(str)
|
10
|
+
@source_code = source_code
|
11
|
+
@source = @source_code.text
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require "optparse"
|
2
|
+
|
3
|
+
module RDocRuboCop
|
4
|
+
class Options
|
5
|
+
def initialize
|
6
|
+
@options = {}
|
7
|
+
end
|
8
|
+
|
9
|
+
def parse(args)
|
10
|
+
args = args.dup
|
11
|
+
option_parser.parse!(args)
|
12
|
+
[option_array, args]
|
13
|
+
end
|
14
|
+
|
15
|
+
def option_parser
|
16
|
+
OptionParser.new do |opts|
|
17
|
+
opts.banner = "Usage: rdoc-rubocop [options] [file1, file2, ...]"
|
18
|
+
|
19
|
+
opts.on("-a", "--auto-correct") { |arg| @options["--auto-correct"] = arg }
|
20
|
+
opts.on("--auto-gen-config") { |arg| @options["--auto-gen-config"] = arg }
|
21
|
+
opts.on("-d", "--debug") { |arg| @options["--debug"] = arg }
|
22
|
+
|
23
|
+
opts.on("-c", "--config FILE") { |arg| @options["--config"] = arg }
|
24
|
+
opts.on("--only COP1,COP2,...") { |arg| @options["--only"] = arg }
|
25
|
+
opts.on("--except COP1,COP2,...") { |arg| @options["--except"] = arg }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def option_array
|
32
|
+
@options.
|
33
|
+
to_a.
|
34
|
+
flat_map { |option, arg| arg.is_a?(String) ? [option, arg] : [option] }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require "rdoc_rubocop/file_path"
|
2
|
+
|
3
|
+
module RDocRuboCop
|
4
|
+
module RuboCopModifier
|
5
|
+
module HijackSTDIN
|
6
|
+
def hijack_stdin_opt(filepath)
|
7
|
+
if filepath.respond_to?(:source)
|
8
|
+
stdin_backup = @options[:stdin]
|
9
|
+
|
10
|
+
@options[:stdin] = filepath.source
|
11
|
+
result = yield
|
12
|
+
filepath.source = @options[:stdin]
|
13
|
+
|
14
|
+
@options[:stdin] = stdin_backup
|
15
|
+
|
16
|
+
result
|
17
|
+
else
|
18
|
+
yield
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
module RunnerModifier
|
24
|
+
include HijackSTDIN
|
25
|
+
|
26
|
+
def find_target_files(paths)
|
27
|
+
file_paths, strs = paths.partition { |path| path.respond_to?(:source) }
|
28
|
+
|
29
|
+
if file_paths.empty?
|
30
|
+
super(strs)
|
31
|
+
elsif strs.empty?
|
32
|
+
file_paths
|
33
|
+
else
|
34
|
+
file_paths + super(strs)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def get_processed_source(file)
|
41
|
+
hijack_stdin_opt(file) do
|
42
|
+
super
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def cached_run?
|
47
|
+
false
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
module TeamModifier
|
52
|
+
include HijackSTDIN
|
53
|
+
|
54
|
+
def autocorrect(buffer, cops)
|
55
|
+
hijack_stdin_opt(cops[0].processed_source.path) do
|
56
|
+
super
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
RuboCop::Runner.prepend RDocRuboCop::RuboCopModifier::RunnerModifier
|
64
|
+
RuboCop::Cop::Team.prepend RDocRuboCop::RuboCopModifier::TeamModifier
|
65
|
+
|
66
|
+
RuboCop::ConfigLoader.send(:remove_const, :DOTFILE)
|
67
|
+
RuboCop::ConfigLoader.const_set(:DOTFILE, ".rdoc_rubocop.yml".freeze)
|
68
|
+
RuboCop::ConfigLoader.send(:remove_const, :AUTO_GENERATED_FILE)
|
69
|
+
RuboCop::ConfigLoader.const_set(:AUTO_GENERATED_FILE, ".rdoc_rubocop_todo.yml".freeze)
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require "rdoc_rubocop/source_file"
|
2
|
+
require "rdoc_rubocop/comment_extractor"
|
3
|
+
|
4
|
+
module RDocRuboCop
|
5
|
+
class RuboCopRunner
|
6
|
+
def initialize(paths = [], options: [])
|
7
|
+
@paths = paths
|
8
|
+
@options = options
|
9
|
+
@cli = RuboCop::CLI.new
|
10
|
+
end
|
11
|
+
|
12
|
+
def run
|
13
|
+
if @options.include?("-a") || @options.include?("--auto-correct")
|
14
|
+
format
|
15
|
+
else
|
16
|
+
style_check
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def format
|
23
|
+
targets = source_files
|
24
|
+
|
25
|
+
file_paths = targets.flat_map(&:source_code_file_paths)
|
26
|
+
exit_code = run_cli(file_paths)
|
27
|
+
|
28
|
+
targets.each(&:correct!)
|
29
|
+
|
30
|
+
exit_code
|
31
|
+
end
|
32
|
+
|
33
|
+
def style_check
|
34
|
+
targets = source_files
|
35
|
+
file_paths = targets.flat_map(&:source_code_file_paths)
|
36
|
+
run_cli(file_paths)
|
37
|
+
end
|
38
|
+
|
39
|
+
def run_cli(source_code_file_paths)
|
40
|
+
@cli.run(@options + source_code_file_paths)
|
41
|
+
end
|
42
|
+
|
43
|
+
def source_files
|
44
|
+
@paths.map(&SourceFile.method(:build))
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require "rdoc_rubocop/token/comment_token"
|
2
|
+
|
3
|
+
module RDocRuboCop
|
4
|
+
class SourceFile
|
5
|
+
class Corrector
|
6
|
+
attr_reader :source
|
7
|
+
|
8
|
+
def initialize(source, source_code_file_paths)
|
9
|
+
@source = source
|
10
|
+
@source_code_file_paths = source_code_file_paths
|
11
|
+
end
|
12
|
+
|
13
|
+
def correct
|
14
|
+
source_lines = source.lines
|
15
|
+
|
16
|
+
@source_code_file_paths.reverse_each do |file_path|
|
17
|
+
apply(source_lines, file_path)
|
18
|
+
end
|
19
|
+
|
20
|
+
@source = source_lines.flatten.join
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def apply(source_lines, file_path)
|
26
|
+
lineno = file_path.source_code.lineno
|
27
|
+
|
28
|
+
delete_lines(source_lines, lineno[0] - 1, lineno[1] - 1)
|
29
|
+
insert(source_lines, lineno[0] - 1, file_path)
|
30
|
+
end
|
31
|
+
|
32
|
+
def delete_lines(source_lines, lineno_from, lineno_to)
|
33
|
+
(lineno_to).downto(lineno_from).each do |i|
|
34
|
+
source_lines.delete_at(i)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def insert(source_lines, index, file_path)
|
39
|
+
indent_and_commentchar = file_path.source_code.indent_and_commentchar
|
40
|
+
source_with_indent =
|
41
|
+
file_path.source.
|
42
|
+
gsub(/^/, indent_and_commentchar).
|
43
|
+
gsub(/#{Token::CommentToken::COMMENT_CHAR}\s*$/, "#")
|
44
|
+
|
45
|
+
source_lines.insert(index, source_with_indent)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require "digest"
|
2
|
+
require "rdoc_rubocop/comment_extractor"
|
3
|
+
require "rdoc_rubocop/file_path"
|
4
|
+
require "rdoc_rubocop/source_file/corrector"
|
5
|
+
|
6
|
+
module RDocRuboCop
|
7
|
+
class SourceFile
|
8
|
+
attr_reader :source
|
9
|
+
attr_reader :filename
|
10
|
+
|
11
|
+
def self.build(filename)
|
12
|
+
source = File.open(filename, "r").read
|
13
|
+
new(source, filename)
|
14
|
+
end
|
15
|
+
|
16
|
+
def initialize(source, filename)
|
17
|
+
@source = source
|
18
|
+
@filename = filename
|
19
|
+
|
20
|
+
reset
|
21
|
+
end
|
22
|
+
|
23
|
+
def source_code_file_paths
|
24
|
+
@source_code_file_paths ||=
|
25
|
+
comments.flat_map do |comment|
|
26
|
+
comment.source_codes.map do |source_code|
|
27
|
+
FilePath.new(@filename, source_code)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def comments
|
33
|
+
comment_extractor = CommentExtractor.new(self)
|
34
|
+
comment_extractor.extract
|
35
|
+
comment_extractor.comments
|
36
|
+
end
|
37
|
+
|
38
|
+
def correct!
|
39
|
+
correct
|
40
|
+
save if changed?
|
41
|
+
reset
|
42
|
+
end
|
43
|
+
|
44
|
+
def correct
|
45
|
+
corrector = Corrector.new(@source, @source_code_file_paths)
|
46
|
+
corrector.correct
|
47
|
+
|
48
|
+
@source = corrector.source
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def reset
|
54
|
+
@checksum = compute_digest(@source)
|
55
|
+
@source_code_file_paths = nil
|
56
|
+
end
|
57
|
+
|
58
|
+
def compute_digest(str)
|
59
|
+
Digest::MD5.hexdigest(str)
|
60
|
+
end
|
61
|
+
|
62
|
+
def save
|
63
|
+
File.open(@filename, "w") do |f|
|
64
|
+
f.puts @source
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def changed?
|
69
|
+
compute_digest(@source) != @checksum
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module RDocRuboCop
|
2
|
+
class Token
|
3
|
+
class CommentToken < self
|
4
|
+
COMMENT_CHAR = "#".freeze
|
5
|
+
SPACE_CHAR = " ".freeze
|
6
|
+
|
7
|
+
def self.indent_and_commentchar(indent_before_comment, indent_after_comment)
|
8
|
+
SPACE_CHAR * indent_before_comment +
|
9
|
+
COMMENT_CHAR +
|
10
|
+
SPACE_CHAR * indent_after_comment
|
11
|
+
end
|
12
|
+
|
13
|
+
def on_comment?
|
14
|
+
true
|
15
|
+
end
|
16
|
+
|
17
|
+
def comment_indent
|
18
|
+
text_with_indent[/^#{SPACE_CHAR}*/].length
|
19
|
+
end
|
20
|
+
|
21
|
+
def text_with_indent
|
22
|
+
token.sub(COMMENT_CHAR, "")
|
23
|
+
end
|
24
|
+
|
25
|
+
def text_without_indent(indent)
|
26
|
+
text_with_indent.sub(/^#{SPACE_CHAR}{#{indent}}/, "")
|
27
|
+
end
|
28
|
+
|
29
|
+
def blank?
|
30
|
+
text_with_indent.match?(/^\s*$/)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module RDocRuboCop
|
2
|
+
class Token
|
3
|
+
attr_reader :locate, :type, :token, :state
|
4
|
+
|
5
|
+
def self.build(locate, type, token, state)
|
6
|
+
case type
|
7
|
+
when :on_comment
|
8
|
+
CommentToken.new(locate, type, token, state)
|
9
|
+
else
|
10
|
+
new(locate, type, token, state)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize(locate, type, token, state)
|
15
|
+
@locate = locate
|
16
|
+
@type = type
|
17
|
+
@token = token
|
18
|
+
@state = state
|
19
|
+
end
|
20
|
+
|
21
|
+
def lineno
|
22
|
+
@locate[0]
|
23
|
+
end
|
24
|
+
|
25
|
+
def column
|
26
|
+
@locate[1]
|
27
|
+
end
|
28
|
+
|
29
|
+
def on_comment?
|
30
|
+
false
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
require "rdoc_rubocop/token/comment_token"
|
data/lib/rdoc_rubocop.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require "rubocop"
|
2
|
+
require "rdoc_rubocop/version"
|
3
|
+
require "rdoc_rubocop/comment_extractor"
|
4
|
+
require "rdoc_rubocop/options"
|
5
|
+
require "rdoc_rubocop/source_file"
|
6
|
+
require "rdoc_rubocop/rubocop_modifier"
|
7
|
+
require "rdoc_rubocop/rubocop_runner"
|
8
|
+
|
9
|
+
module RDocRuboCop
|
10
|
+
class Error < StandardError; end
|
11
|
+
# Your code goes here...
|
12
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "rdoc_rubocop/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rdoc_rubocop"
|
8
|
+
spec.version = RDocRuboCop::VERSION
|
9
|
+
spec.authors = ["Loose Coupling"]
|
10
|
+
spec.email = ["loosecpl@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Fix codes in RDoc}
|
13
|
+
spec.description = %q{Fix codes in RDoc}
|
14
|
+
spec.homepage = "https://github.com/nowlinuxing/rdoc_rubocop/"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
21
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
22
|
+
spec.metadata["changelog_uri"] = spec.homepage
|
23
|
+
else
|
24
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
25
|
+
"public gem pushes."
|
26
|
+
end
|
27
|
+
|
28
|
+
# Specify which files should be added to the gem when it is released.
|
29
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
30
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
31
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
32
|
+
end
|
33
|
+
spec.bindir = "exe"
|
34
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
35
|
+
spec.require_paths = ["lib"]
|
36
|
+
|
37
|
+
spec.add_dependency "rubocop"
|
38
|
+
|
39
|
+
spec.add_development_dependency "bundler", "~> 1.17"
|
40
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
41
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
42
|
+
spec.add_development_dependency "pry-byebug"
|
43
|
+
spec.add_development_dependency "pry-doc"
|
44
|
+
end
|
metadata
ADDED
@@ -0,0 +1,157 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rdoc_rubocop
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Loose Coupling
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-12-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rubocop
|
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'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.17'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.17'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry-byebug
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry-doc
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: Fix codes in RDoc
|
98
|
+
email:
|
99
|
+
- loosecpl@gmail.com
|
100
|
+
executables:
|
101
|
+
- rdoc-rubocop
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- ".gitignore"
|
106
|
+
- ".rspec"
|
107
|
+
- ".travis.yml"
|
108
|
+
- Gemfile
|
109
|
+
- LICENSE.txt
|
110
|
+
- README.md
|
111
|
+
- Rakefile
|
112
|
+
- bin/console
|
113
|
+
- bin/setup
|
114
|
+
- exe/rdoc-rubocop
|
115
|
+
- lib/rdoc_rubocop.rb
|
116
|
+
- lib/rdoc_rubocop/comment.rb
|
117
|
+
- lib/rdoc_rubocop/comment/source_code.rb
|
118
|
+
- lib/rdoc_rubocop/comment_extractor.rb
|
119
|
+
- lib/rdoc_rubocop/comment_token_organizable.rb
|
120
|
+
- lib/rdoc_rubocop/file_path.rb
|
121
|
+
- lib/rdoc_rubocop/options.rb
|
122
|
+
- lib/rdoc_rubocop/rubocop_modifier.rb
|
123
|
+
- lib/rdoc_rubocop/rubocop_runner.rb
|
124
|
+
- lib/rdoc_rubocop/source_file.rb
|
125
|
+
- lib/rdoc_rubocop/source_file/corrector.rb
|
126
|
+
- lib/rdoc_rubocop/token.rb
|
127
|
+
- lib/rdoc_rubocop/token/comment_token.rb
|
128
|
+
- lib/rdoc_rubocop/version.rb
|
129
|
+
- rdoc_rubocop.gemspec
|
130
|
+
homepage: https://github.com/nowlinuxing/rdoc_rubocop/
|
131
|
+
licenses:
|
132
|
+
- MIT
|
133
|
+
metadata:
|
134
|
+
homepage_uri: https://github.com/nowlinuxing/rdoc_rubocop/
|
135
|
+
source_code_uri: https://github.com/nowlinuxing/rdoc_rubocop/
|
136
|
+
changelog_uri: https://github.com/nowlinuxing/rdoc_rubocop/
|
137
|
+
post_install_message:
|
138
|
+
rdoc_options: []
|
139
|
+
require_paths:
|
140
|
+
- lib
|
141
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
147
|
+
requirements:
|
148
|
+
- - ">="
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
version: '0'
|
151
|
+
requirements: []
|
152
|
+
rubyforge_project:
|
153
|
+
rubygems_version: 2.7.6
|
154
|
+
signing_key:
|
155
|
+
specification_version: 4
|
156
|
+
summary: Fix codes in RDoc
|
157
|
+
test_files: []
|