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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7c8728a15051d8b738eefad002020f1d547e1f16
4
- data.tar.gz: b8d749c81d4719fc52f68a23d6243ac022ac7625
3
+ metadata.gz: 4c7ba4f2f438b17471122538d849e61eb25051b6
4
+ data.tar.gz: efb4b191828bb4e6369ea8d99336c86f70833957
5
5
  SHA512:
6
- metadata.gz: ccc655259643fda1b72c3ea786088641be4da80fc240a92ce2a5495cd9839a7c8156277a517c374fb850027536d297ad4c2ab5c3ecf6b328d438fd0246db78ac
7
- data.tar.gz: 2672a943fb32fc126d459eb5c47d6355fa6d5b612c5befefa325c02beff3af90997e9b5d39d276c43a5cd04d770e3ede0a3df38f3ba900d36b26b05351e0a845
6
+ metadata.gz: 1fdaa76bbf68eeca255cdcaaa5d8f66ba9e5959a35d241026fa63758f1c787015023b43ccb53e954ada3b14ba5a5d5f2b200e1401d9fa427aa5cfc882ef1779d
7
+ data.tar.gz: 0c793eb2f6396d70d9cb746e897f8d31a6cbbba808d1d4bb7d601909d9371071b7fcfaa4d826df499cf84bb36a57f76b8678ef89e32b54efe4beb7f7b07d92ed
data/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  Ruumba
2
2
  ======
3
+
4
+ [![Build Status](https://travis-ci.org/ericqweinstein/ruumba.svg?branch=master)](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
@@ -29,9 +29,3 @@ desc 'Run all the tests, lint all the things'
29
29
  namespace :test do
30
30
  task all: %i(spec rubocop)
31
31
  end
32
-
33
- desc 'Generate Ruby documentation'
34
- YARD::Rake::YardocTask.new do |t|
35
- t.files = %w(lib/**/*.rb)
36
- t.options = %w(--protected --private)
37
- end
data/bin/ruumba CHANGED
@@ -4,19 +4,44 @@
4
4
  require 'optparse'
5
5
  require_relative '../lib/ruumba'
6
6
 
7
- opt_parser = OptionParser.new do |opts|
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 opt_parser.parse!
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
@@ -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 dir.first
17
- suffix = SecureRandom.hex
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
- Dir["#{fq_dir}/**/*.erb"].each do |f|
20
- File.open("#{f}-#{suffix}.rb", 'w+') do |file|
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
@@ -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' unless ::Rake.application.last_comment
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 @dir
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.1
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: 2015-01-09 00:00:00.000000000 Z
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.28.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.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.4.5
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: