rubocop-redmine_wiki_formatter 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8197b1bf6d047289b5e14df36f53564c4572ab7f
4
+ data.tar.gz: 2c1c7f42a9630ddf09d84e8e0c5b358f412cee96
5
+ SHA512:
6
+ metadata.gz: f5c4df7833bb9274cb52eb43400f8e557acbf489876aa3b80f070bbb03a79ffbedf5269f156d98bfd51ac944905ccc0437a58b514e3680185591a8ac9466de65
7
+ data.tar.gz: e9e0eeb80c9728b2ded73094c756a3189f9c665e4ab25d5759295f869978f40aeedcfacdaa6ea678b9206ede2fbbf4c501303ff69718e3e49c1a9ea0653460d6
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ # encoding: utf-8
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gemspec
data/README.md ADDED
@@ -0,0 +1,54 @@
1
+ # RuboCop Redmine Wiki Formatter
2
+
3
+ Redmine Wiki Page Formatter, as an extension to [RuboCop](https://github.com/bbatsov/rubocop).
4
+
5
+
6
+ ## Installation
7
+
8
+ Just install the `rubocop-redmine_wiki_formatter` gem
9
+
10
+ ```bash
11
+ gem install rubocop-redmine_wiki_formatter
12
+ ```
13
+
14
+ or if you use bundler put this in your `Gemfile`
15
+
16
+ ```
17
+ gem 'rubocop-redmine_wiki_formatter', require: false
18
+ ```
19
+
20
+
21
+ ## Usage
22
+
23
+ You need to tell RuboCop to load the RedmineWikiFormatter extension. There are three
24
+ ways to do this:
25
+
26
+ ### RuboCop configuration file
27
+
28
+ Put this into you `.rubocop.yml`.
29
+
30
+ ```
31
+ require: redmine_wiki_formatter
32
+ ```
33
+
34
+ Now you can run `rubocop --format RuboCop::Formatter::RedmineWikiFormatter` and it will automaticly format the output
35
+ to Redmine's Wiki format.
36
+
37
+ ### Command line
38
+
39
+ ```bash
40
+ rubocop --require redmine_wiki_formatter --format RuboCop::Formatter::RedmineWikiFormatter
41
+ ```
42
+
43
+ ### Rake task
44
+
45
+ ```ruby
46
+ RuboCop::RakeTask.new do |task|
47
+ task.requires << 'redmine_wiki_formatter'
48
+ task.options = ['--format', 'RuboCop::Formatter::RedmineWikiFormatter']
49
+ end
50
+ ```
51
+
52
+ ## License
53
+
54
+ `rubocop-redmine_wiki_formatter` is [MIT licensed](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,20 @@
1
+ # encoding: utf-8
2
+
3
+ require 'bundler'
4
+ require 'bundler/setup'
5
+ require 'bundler/gem_tasks'
6
+ begin
7
+ Bundler.setup(:default, :development)
8
+ rescue Bundler::BundlerError => e
9
+ $stderr.puts e.message
10
+ $stderr.puts 'Run `bundle install` to install missing gems'
11
+ exit e.status_code
12
+ end
13
+
14
+ require 'rspec/core'
15
+ require 'rspec/core/rake_task'
16
+ RSpec::Core::RakeTask.new(:spec) do |spec|
17
+ spec.pattern = FileList['spec/**/*_spec.rb']
18
+ end
19
+
20
+ task default: [:spec]
@@ -0,0 +1,6 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubocop'
4
+
5
+ require 'rubocop/formatter/redmine_wiki_formatter'
6
+ require 'rubocop/redmine_wiki_formatter/version'
@@ -0,0 +1,66 @@
1
+ module RuboCop
2
+ module Formatter
3
+ # A Redmine wiki formatter that displays only files with offenses.
4
+ class RedmineWikiFormatter < BaseFormatter
5
+ include PathUtil, TextUtil
6
+
7
+ def started(_target_files)
8
+ @files = []
9
+ @total_offense_file_count = 0
10
+ @total_offense_count = 0
11
+ @total_correction_count = 0
12
+ output.printf("h1. RuboCop (version %s) Inspection Report\r\n\r\n", RuboCop::Version::STRING)
13
+ end
14
+
15
+ def file_finished(file, offenses)
16
+ @files << file
17
+ return if offenses.empty?
18
+ @total_offense_file_count += 1
19
+ count_stats(offenses)
20
+ report_file(file, offenses)
21
+ end
22
+
23
+ def finished(inspected_files)
24
+ output.printf("h2. Summary\r\n\r\n")
25
+ output.printf("* Generated on %s\r\n", DateTime.now)
26
+ output.printf("* %s inspected, %s detected in %s\r\n",
27
+ pluralize(@files.count, 'file'),
28
+ pluralize(@total_offense_count, 'offense', no_for_zero: true),
29
+ pluralize(@total_offense_file_count, 'file'))
30
+ end
31
+
32
+ def report_file(file, offenses)
33
+ output.puts("h2. #{smart_path(file)} - #{pluralize(offenses.count, 'offense')}\r\n\r\n")
34
+
35
+ offenses.each do |o|
36
+ output.printf("h3. Line %d, Column %d\r\n\r\n%s\r\n", o.line, o.real_column, message(o))
37
+ output.printf("<pre><code>%s</code></pre>\r\n\r\n", o.location.source_line)
38
+ end
39
+ output.printf("\r\n")
40
+ end
41
+
42
+ private
43
+
44
+ def count_stats(offenses)
45
+ @total_offense_count += offenses.count
46
+ @total_correction_count += offenses.count(&:corrected?)
47
+ end
48
+
49
+ def smart_path(path)
50
+ # Ideally, we calculate this relative to the project root.
51
+ base_dir = Dir.pwd
52
+
53
+ if path.start_with? base_dir
54
+ relative_path(path, base_dir)
55
+ else
56
+ path
57
+ end
58
+ end
59
+
60
+ def message(offense)
61
+ message = offense.corrected? ? '[Corrected] ' : ''
62
+ message << offense.message
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,8 @@
1
+ module RuboCop
2
+ module RedmineWikiFormatter
3
+ # Version information for the Redmine Wiki Formatter RuboCop plugin.
4
+ module Version
5
+ STRING = '0.1.0'
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,34 @@
1
+ $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
2
+ require 'rubocop/redmine_wiki_formatter/version'
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = 'rubocop-redmine_wiki_formatter'
6
+ spec.summary = 'Formatter for Redmine Wiki page'
7
+ spec.description = <<-end_description
8
+ Formatter for Redmine Wiki page.
9
+ A formatter for the RuboCop tool that outputs in Redmine Wiki markup.
10
+ end_description
11
+ spec.homepage = 'http://github.com/hugoangelo/rubocop-redmine_wiki_formatter'
12
+ spec.authors = ['Hugo Angelo']
13
+ spec.email = ['hugoangelo@gmail.com']
14
+ spec.licenses = ['MIT']
15
+
16
+ spec.version = RuboCop::RedmineWikiFormatter::Version::STRING
17
+ spec.platform = Gem::Platform::RUBY
18
+ spec.required_ruby_version = '>= 1.9.3'
19
+
20
+ spec.require_paths = ['lib']
21
+ spec.files = Dir[
22
+ '{lib,spec}/**/*',
23
+ '*.md',
24
+ '*.gemspec',
25
+ 'Gemfile',
26
+ 'Rakefile'
27
+ ]
28
+ spec.test_files = Dir['{spec}/**/*']
29
+ spec.extra_rdoc_files = ['README.md']
30
+
31
+ spec.add_development_dependency('rubocop', '~> 0.24')
32
+ spec.add_development_dependency('rake', '~> 10.1')
33
+ spec.add_development_dependency('rspec', '~> 3.2')
34
+ end
@@ -0,0 +1,74 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+ require 'stringio'
5
+ require 'fileutils'
6
+
7
+ module RuboCop
8
+ module Formatter
9
+ describe RedmineWikiFormatter do
10
+ subject(:formatter) { described_class.new(output) }
11
+ let(:output) { StringIO.new }
12
+
13
+ describe '#report_file' do
14
+ before do
15
+ formatter.report_file(file, [offense])
16
+ end
17
+
18
+ let(:file) { '/path/to/file' }
19
+
20
+ let(:offense) do
21
+ Cop::Offense.new(:convention, location,
22
+ 'This is a message.', 'CopName', status)
23
+ end
24
+
25
+ let(:location) do
26
+ source_buffer = Parser::Source::Buffer.new('test', 1)
27
+ source_buffer.source = "a\n"
28
+ Parser::Source::Range.new(source_buffer, 0, 1)
29
+ end
30
+
31
+ let(:status) { :uncorrected }
32
+
33
+ context 'the file is under the current working directory' do
34
+ let(:file) { File.expand_path('spec/spec_helper.rb') }
35
+
36
+ it 'prints as relative path' do
37
+ expect(output.string).to include('h2. spec/spec_helper.rb ')
38
+ end
39
+ end
40
+
41
+ context 'the file is outside of the current working directory' do
42
+ let(:file) do
43
+ tempfile = Tempfile.new('')
44
+ tempfile.close
45
+ File.expand_path(tempfile.path)
46
+ end
47
+
48
+ it 'prints as absolute path' do
49
+ expect(output.string).to include("h2. #{file} ")
50
+ end
51
+ end
52
+
53
+ context 'when the offense is not corrected' do
54
+ let(:status) { :uncorrected }
55
+
56
+ it 'prints message as-is' do
57
+ expect(output.string)
58
+ .to include('This is a message.')
59
+ end
60
+ end
61
+
62
+ context 'when the offense is automatically corrected' do
63
+ let(:status) { :corrected }
64
+
65
+ it 'prints [Corrected] along with message' do
66
+ expect(output.string)
67
+ .to include('[Corrected] This is a message.')
68
+ end
69
+ end
70
+ end
71
+
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,7 @@
1
+ # encoding: utf-8
2
+
3
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), *%w{ .. lib }))
4
+
5
+ require 'rspec'
6
+ require 'rubocop'
7
+ require 'rubocop/formatter/redmine_wiki_formatter'
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubocop-redmine_wiki_formatter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Hugo Angelo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-06-18 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.24'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.24'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.1'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.2'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.2'
55
+ description: |2
56
+ Formatter for Redmine Wiki page.
57
+ A formatter for the RuboCop tool that outputs in Redmine Wiki markup.
58
+ email:
59
+ - hugoangelo@gmail.com
60
+ executables: []
61
+ extensions: []
62
+ extra_rdoc_files:
63
+ - README.md
64
+ files:
65
+ - Gemfile
66
+ - README.md
67
+ - Rakefile
68
+ - lib/redmine_wiki_formatter.rb
69
+ - lib/rubocop/formatter/redmine_wiki_formatter.rb
70
+ - lib/rubocop/redmine_wiki_formatter/version.rb
71
+ - rubocop-redmine_wiki_formatter.gemspec
72
+ - spec/rubocop/formatter/redmine_wiki_formatter_spec.rb
73
+ - spec/spec_helper.rb
74
+ homepage: http://github.com/hugoangelo/rubocop-redmine_wiki_formatter
75
+ licenses:
76
+ - MIT
77
+ metadata: {}
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: 1.9.3
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 2.4.6
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: Formatter for Redmine Wiki page
98
+ test_files:
99
+ - spec/rubocop/formatter/redmine_wiki_formatter_spec.rb
100
+ - spec/spec_helper.rb