ruumba 0.0.1 → 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 +4 -4
- data/README.md +48 -0
- data/Rakefile +0 -6
- data/bin/ruumba +28 -3
- data/lib/ruumba/analyzer.rb +47 -13
- data/lib/ruumba/rake_task.rb +5 -5
- metadata +9 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4c7ba4f2f438b17471122538d849e61eb25051b6
|
4
|
+
data.tar.gz: efb4b191828bb4e6369ea8d99336c86f70833957
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1fdaa76bbf68eeca255cdcaaa5d8f66ba9e5959a35d241026fa63758f1c787015023b43ccb53e954ada3b14ba5a5d5f2b200e1401d9fa427aa5cfc882ef1779d
|
7
|
+
data.tar.gz: 0c793eb2f6396d70d9cb746e897f8d31a6cbbba808d1d4bb7d601909d9371071b7fcfaa4d826df499cf84bb36a57f76b8678ef89e32b54efe4beb7f7b07d92ed
|
data/README.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
Ruumba
|
2
2
|
======
|
3
|
+
|
4
|
+
[](https://travis-ci.org/ericqweinstein/ruumba)
|
5
|
+
|
3
6
|
> .erb or .rb, you're coming with me.
|
4
7
|
|
5
8
|
> — RuboCop
|
@@ -38,6 +41,51 @@ Then:
|
|
38
41
|
λ bundle exec rake ruumba
|
39
42
|
```
|
40
43
|
|
44
|
+
## Fix paths and unapplicable cops
|
45
|
+
|
46
|
+
By default, Rubocop only scan `.rb` files and so does Ruumba. If you want shown
|
47
|
+
paths to reflect original paths, you can add create a `.ruumba.yml` config file
|
48
|
+
with the following contents:
|
49
|
+
|
50
|
+
```yaml
|
51
|
+
AllCops:
|
52
|
+
Include:
|
53
|
+
- '**/*.erb'
|
54
|
+
```
|
55
|
+
|
56
|
+
You can then disable `.rb` extension auto-append and use your config file:
|
57
|
+
|
58
|
+
```bash
|
59
|
+
λ ruumba -D -e app/views -c .ruumba.yml
|
60
|
+
```
|
61
|
+
|
62
|
+
Since Ruumba rewrites new files form `.erb` files contents, some formatting cops
|
63
|
+
cannot apply, you can disable them in your Ruumba file:
|
64
|
+
|
65
|
+
```yaml
|
66
|
+
Style/FrozenStringLiteralComment:
|
67
|
+
Enabled: false
|
68
|
+
Layout/AlignHash:
|
69
|
+
Enabled: false
|
70
|
+
Layout/AlignParameters:
|
71
|
+
Enabled: false
|
72
|
+
Layout/IndentationWidth:
|
73
|
+
Enabled: false
|
74
|
+
Layout/TrailingBlankLines:
|
75
|
+
Enabled: false
|
76
|
+
```
|
77
|
+
|
78
|
+
You can use `ruumba -a` or `ruumba -D` to look for other cops if this list is
|
79
|
+
missing some.
|
80
|
+
|
81
|
+
You might want to include your existing rubocop config file by appending this in
|
82
|
+
front of your Ruumba config:
|
83
|
+
|
84
|
+
```yaml
|
85
|
+
inherit_from: .rubocop.yml
|
86
|
+
```
|
87
|
+
|
88
|
+
|
41
89
|
## Contributing
|
42
90
|
1. Branch (`git checkout -b fancy-new-feature`)
|
43
91
|
2. Commit (`git commit -m "Fanciness!"`)
|
data/Rakefile
CHANGED
data/bin/ruumba
CHANGED
@@ -4,19 +4,44 @@
|
|
4
4
|
require 'optparse'
|
5
5
|
require_relative '../lib/ruumba'
|
6
6
|
|
7
|
-
|
7
|
+
options = { arguments: [] }
|
8
|
+
opts_parser = OptionParser.new do |opts|
|
8
9
|
opts.banner = 'Usage: ruumba path/to/ERBs/'
|
9
10
|
|
10
11
|
opts.on('-h', '--help', 'Display this screen') do
|
11
12
|
puts opts_parser
|
12
13
|
exit
|
13
14
|
end
|
15
|
+
|
16
|
+
opts.on('-a', '--auto-gen-config', 'Generate a configuration file acting as a TODO list.') do
|
17
|
+
options[:arguments] << '--auto-gen-config'
|
18
|
+
end
|
19
|
+
|
20
|
+
opts.on('-t', '--tmp-folder [TEMP_FOLDER]', 'Use this suffix for the temporary folder') do |f|
|
21
|
+
options[:tmp_folder] = f
|
22
|
+
end
|
23
|
+
|
24
|
+
opts.on('-c', '--config [CONFIG]', 'Use this config for rubocop') do |c|
|
25
|
+
options[:arguments] << "--config #{File.expand_path(c)}"
|
26
|
+
end
|
27
|
+
|
28
|
+
opts.on('-D', '--display-cop-names', 'Display cop names') do ||
|
29
|
+
options[:arguments] << "--display-cop-names"
|
30
|
+
end
|
31
|
+
|
32
|
+
opts.on('-F', '--fail-level [LEVEL]', 'Rubocop fail level') do |l|
|
33
|
+
options[:arguments] << "--fail-level #{l}"
|
34
|
+
end
|
35
|
+
|
36
|
+
opts.on('-e', '--disable-ruby-ext', 'Disable auto-append of .rb extension') do
|
37
|
+
options[:disable_rb_extension] = true
|
38
|
+
end
|
14
39
|
end
|
15
40
|
|
16
|
-
begin
|
41
|
+
begin opts_parser.parse!
|
17
42
|
rescue OptionParser::InvalidOption => e
|
18
43
|
abort "An error occurred: #{e}. Run ruumba -h for help."
|
19
44
|
end
|
20
45
|
|
21
|
-
analyzer = Ruumba::Analyzer.new
|
46
|
+
analyzer = Ruumba::Analyzer.new(options)
|
22
47
|
analyzer.run
|
data/lib/ruumba/analyzer.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# @author Eric Weinstein <eric.q.weinstein@gmail.com>
|
2
2
|
|
3
3
|
require 'securerandom'
|
4
|
+
require 'pathname'
|
5
|
+
require 'tmpdir'
|
4
6
|
|
5
7
|
# Ruumba: RuboCop's sidekick.
|
6
8
|
module Ruumba
|
@@ -8,24 +10,22 @@ module Ruumba
|
|
8
10
|
# to RuboCop for linting (style, correctness, &c).
|
9
11
|
class Analyzer
|
10
12
|
# The regular expression to capture interpolated Ruby.
|
11
|
-
ERB_REGEX =
|
13
|
+
ERB_REGEX = /<%[-=]?(.*?)-?%>/m
|
14
|
+
|
15
|
+
def initialize(opts = nil)
|
16
|
+
@options = opts || {}
|
17
|
+
end
|
12
18
|
|
13
19
|
# Performs static analysis on the provided directory.
|
14
20
|
# @param [Array<String>] dir The directory to analyze.
|
15
21
|
def run(dir = ARGV)
|
16
|
-
fq_dir = File.expand_path
|
17
|
-
|
22
|
+
fq_dir = Pathname.new(File.expand_path(dir.first))
|
23
|
+
pwd = Pathname.new ENV['PWD']
|
24
|
+
target = fq_dir.relative_path_from(pwd)
|
25
|
+
tmp = create_temp_dir
|
18
26
|
|
19
|
-
|
20
|
-
|
21
|
-
code = extract f
|
22
|
-
file.write code
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
system("rubocop #{fq_dir}")
|
27
|
-
|
28
|
-
Dir.glob(Dir["#{fq_dir}/**/*-#{suffix}.rb"]).each { |f| File.delete(f) }
|
27
|
+
copy_erb_files(fq_dir, tmp, pwd)
|
28
|
+
run_rubocop(target, tmp)
|
29
29
|
end
|
30
30
|
|
31
31
|
# Extracts Ruby code from an ERB template.
|
@@ -34,5 +34,39 @@ module Ruumba
|
|
34
34
|
def extract(filename)
|
35
35
|
File.read(filename).scan(ERB_REGEX).map(&:last).map(&:strip).join("\n")
|
36
36
|
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def create_temp_dir
|
41
|
+
if @options[:tmp_folder]
|
42
|
+
Pathname.new(File.expand_path(@options[:tmp_folder]))
|
43
|
+
else
|
44
|
+
Pathname.new(Dir.mktmpdir)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def copy_erb_files(fq_dir, tmp, pwd)
|
49
|
+
extension = '.rb' unless @options[:disable_rb_extension]
|
50
|
+
|
51
|
+
Dir["#{fq_dir}/**/*.erb"].each do |f|
|
52
|
+
n = tmp + Pathname.new(f).relative_path_from(pwd)
|
53
|
+
FileUtils.mkdir_p(File.dirname(n))
|
54
|
+
|
55
|
+
File.open("#{n}#{extension}", 'w+') do |file|
|
56
|
+
code = extract f
|
57
|
+
file.write code
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def run_rubocop(target, tmp)
|
63
|
+
args = (@options[:arguments] || []).join(' ')
|
64
|
+
todo = tmp + '.rubocop_todo.yml'
|
65
|
+
|
66
|
+
system("cd #{tmp} && rubocop #{args} #{target}").tap do
|
67
|
+
FileUtils.cp(todo, ENV['PWD']) if File.exist?(todo)
|
68
|
+
FileUtils.rm_rf(tmp) unless @options[:tmp_folder]
|
69
|
+
end
|
70
|
+
end
|
37
71
|
end
|
38
72
|
end
|
data/lib/ruumba/rake_task.rb
CHANGED
@@ -6,7 +6,7 @@ require 'rake/tasklib'
|
|
6
6
|
module Ruumba
|
7
7
|
# Provides a custom Rake task.
|
8
8
|
class RakeTask < Rake::TaskLib
|
9
|
-
attr_accessor :name, :dir
|
9
|
+
attr_accessor :name, :dir, :options
|
10
10
|
|
11
11
|
# Sets up the custom Rake task.
|
12
12
|
# @param [Array<String>] args Arguments to the Rake task.
|
@@ -15,9 +15,9 @@ module Ruumba
|
|
15
15
|
def initialize(*args, &block)
|
16
16
|
@name = args.shift || :ruumba
|
17
17
|
@dir = []
|
18
|
+
@options = nil
|
18
19
|
|
19
|
-
desc 'Run RuboCop on ERB files'
|
20
|
-
|
20
|
+
desc 'Run RuboCop on ERB files'
|
21
21
|
task(name, *args) do |_, task_args|
|
22
22
|
block.call(*[self, task_args].slice(0, block.arity)) if block
|
23
23
|
run
|
@@ -33,10 +33,10 @@ module Ruumba
|
|
33
33
|
# doesn't substantially impact Rakefile load time.
|
34
34
|
require 'ruumba'
|
35
35
|
|
36
|
-
analyzer = Ruumba::Analyzer.new
|
36
|
+
analyzer = Ruumba::Analyzer.new(@options)
|
37
37
|
puts 'Running Ruumba...'
|
38
38
|
|
39
|
-
analyzer.run
|
39
|
+
analyzer.run(@dir) || exit(1)
|
40
40
|
end
|
41
41
|
end
|
42
42
|
end
|
metadata
CHANGED
@@ -1,29 +1,31 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruumba
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Weinstein
|
8
|
+
- Jan Biniok
|
9
|
+
- Yvan Barthélemy
|
8
10
|
autorequire:
|
9
11
|
bindir: bin
|
10
12
|
cert_chain: []
|
11
|
-
date:
|
13
|
+
date: 2017-07-11 00:00:00.000000000 Z
|
12
14
|
dependencies:
|
13
15
|
- !ruby/object:Gem::Dependency
|
14
16
|
name: rubocop
|
15
17
|
requirement: !ruby/object:Gem::Requirement
|
16
18
|
requirements:
|
17
|
-
- - "
|
19
|
+
- - ">="
|
18
20
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0
|
21
|
+
version: '0'
|
20
22
|
type: :runtime
|
21
23
|
prerelease: false
|
22
24
|
version_requirements: !ruby/object:Gem::Requirement
|
23
25
|
requirements:
|
24
|
-
- - "
|
26
|
+
- - ">="
|
25
27
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0
|
28
|
+
version: '0'
|
27
29
|
description: RuboCop linting for ERB templates.
|
28
30
|
email: eric.q.weinstein@gmail.com
|
29
31
|
executables:
|
@@ -57,10 +59,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
57
59
|
version: '0'
|
58
60
|
requirements: []
|
59
61
|
rubyforge_project:
|
60
|
-
rubygems_version: 2.
|
62
|
+
rubygems_version: 2.5.1
|
61
63
|
signing_key:
|
62
64
|
specification_version: 4
|
63
65
|
summary: Allows users to lint Ruby code in ERB templates the same way they lint source
|
64
66
|
code (using RuboCop).
|
65
67
|
test_files: []
|
66
|
-
has_rdoc:
|