rails_review 0.0.1
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 +10 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +57 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/rails_review.rb +15 -0
- data/lib/rails_review/checker.rb +105 -0
- data/lib/rails_review/error.rb +25 -0
- data/lib/rails_review/railtie.rb +9 -0
- data/lib/rails_review/tasks/rails_review.rake +6 -0
- data/lib/rails_review/version.rb +3 -0
- data/rails_review.gemspec +33 -0
- metadata +103 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8081bec27a4fa952c34d15ac85aaa9f7b6cad635
|
4
|
+
data.tar.gz: eefb6dbbb1b28b350b20cd77416bf8a31a1ea6a1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 360cf2c5bfbbd2744160bb916078efa1491f56b051c56677eda8bb34dffc1b9ed2649b14acaff41b2dd605efdaf395df8b48a7d3a36df37cc44be2dd3981c273
|
7
|
+
data.tar.gz: ba1221789081eefa087c3f9d85bbc6433f3fea236c81dc38d3ee36314584e34e5c14bbd5b2311af66a5bcae7b6f892db3ce0548f3cad6807a9bb8fa0647f1aa9
|
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) 2016 RubyEffect Software Solutions Pvt. Ltd.
|
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,57 @@
|
|
1
|
+
# Rails Review
|
2
|
+
|
3
|
+
Rails Review gem checks your rails applications against style guides present at [Rails Style Guide Repository](https://github.com/bbatsov/rails-style-guide) and reports the code snippets where the style guide is not met.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile in the development group:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'rails_review'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install rails_review
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Run the following rake task to start the rails style guide checks on your application.
|
24
|
+
|
25
|
+
$ rake rails_review:start
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
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.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
1. Fork it ( https://github.com/rubyeffect/rails_review/fork )
|
36
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
37
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
38
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
39
|
+
5. Create a new Pull Request
|
40
|
+
|
41
|
+
## Note
|
42
|
+
|
43
|
+
In the current version, 17 [Rails Style Guide](https://github.com/bbatsov/rails-style-guide) points are being checked. Further checks would be added in future commits.
|
44
|
+
|
45
|
+
## License
|
46
|
+
|
47
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
48
|
+
|
49
|
+
## About RubyEffect
|
50
|
+
|
51
|
+

|
52
|
+
|
53
|
+
RubyEffect builds intuitive, live and elegant software that solves real world problems. We love open source and it's community.
|
54
|
+
|
55
|
+
Liked this gem? You may also like the articles we post on our [blog](http://blog.rubyeffect.com). Please do check
|
56
|
+
|
57
|
+
We would love to work on your ideas and see them grow. Say hello @ http://rubyeffect.com/contact
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "rails_review"
|
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
|
data/bin/setup
ADDED
data/lib/rails_review.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require "rails_review/checker"
|
2
|
+
require "rails_review/error"
|
3
|
+
require "rails_review/version"
|
4
|
+
require "rails_review/railtie" if defined?(Rails)
|
5
|
+
|
6
|
+
module RailsReview
|
7
|
+
class << self
|
8
|
+
def start
|
9
|
+
RailsReview::Checker.gemlock_check
|
10
|
+
RailsReview::Checker.timezone_check
|
11
|
+
RailsReview::Checker.custom_validator_directory_check
|
12
|
+
RailsReview::Checker.app_directory_check
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
module RailsReview
|
2
|
+
class Checker
|
3
|
+
@@errors = {}
|
4
|
+
class << self
|
5
|
+
|
6
|
+
# Method to check whether Gemfile.lock is present in .gitignore or not
|
7
|
+
def gemlock_check
|
8
|
+
File.foreach('.gitignore').with_index do |line, index|
|
9
|
+
if line.include? 'Gemfile.lock'
|
10
|
+
@@errors["/.gitignore"] = [{:gemlock => index + 1}]
|
11
|
+
break
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# Method to check if timezone has been configured
|
17
|
+
def timezone_check
|
18
|
+
line_num = 0
|
19
|
+
config_line = ''
|
20
|
+
File.foreach("#{Rails.root}/config/application.rb").with_index do |line, index |
|
21
|
+
if line.include? "config.time_zone"
|
22
|
+
line_num = index + 1
|
23
|
+
config_line = line
|
24
|
+
end
|
25
|
+
break if line_num != 0
|
26
|
+
end
|
27
|
+
formatted_config_line = config_line.gsub(' ', '')
|
28
|
+
if formatted_config_line.first == '#' || formatted_config_line.length == 19
|
29
|
+
@@errors["/config/application.rb"] = [{:timezone => line_num}]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# Method to check if separate directory is being used for custom validators
|
34
|
+
def custom_validator_directory_check
|
35
|
+
if Dir["#{Rails.root}/app/validators"].empty?
|
36
|
+
@@errors["/validators"] = [{:validators => "not found"}]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def app_directory_check
|
41
|
+
files = Dir.glob(File.join(["#{Rails.root}/app", '**', '*'])).reject { |f| File.directory?(f) || f.include?("/assets/") }
|
42
|
+
|
43
|
+
files.each do |file|
|
44
|
+
File.foreach(file).with_index do |line, index|
|
45
|
+
@@errors[file] = [] unless @@errors.has_key?(file)
|
46
|
+
@@errors[file] << {:time_now => index + 1} if line.include? 'Time.now'
|
47
|
+
@@errors[file] << {:time_parse => index + 1} if line.include? 'Time.parse'
|
48
|
+
|
49
|
+
# Controller Specific Checks
|
50
|
+
if file.include?("/controllers/")
|
51
|
+
formatted_line = line.gsub(' ', '')
|
52
|
+
if formatted_line.include?("render:inline") || formatted_line.include?("renderinline:")
|
53
|
+
@@errors[file] << {:render_inline => index + 1}
|
54
|
+
end
|
55
|
+
if formatted_line.include?("render:text") || formatted_line.include?("rendertext:")
|
56
|
+
@@errors[file] << {:render_text => index + 1}
|
57
|
+
end
|
58
|
+
if formatted_line.include?("render:status") || formatted_line.include?("renderstatus:")
|
59
|
+
status = formatted_line.gsub("render:status", '').gsub("renderstatus:", '').first
|
60
|
+
@@errors[file] << {:render_status => index + 1} if status =~ /^[-+]?[1-9]([0-9]*)?$/
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
# Checks for all sub-directories of app except views
|
65
|
+
unless file.include?("/views/")
|
66
|
+
@@errors[file] << {:find_by_sql => index + 1} if line.include?("find_by_sql") && !line.include?("<<")
|
67
|
+
@@errors[file] << {:update_attribute => index + 1} if line.include?("update_attribute(")
|
68
|
+
@@errors[file] << {:dot_all => index + 1} if line.include?(".all")
|
69
|
+
end
|
70
|
+
|
71
|
+
# Models specific checks
|
72
|
+
if file.include?("/models/")
|
73
|
+
@@errors[file] << {:table_name => index + 1} if line.include?("self.table_name")
|
74
|
+
@@errors[file] << {:read_attribute => index + 1} if line.include?("read_attribute")
|
75
|
+
@@errors[file] << {:write_attribute => index + 1} if line.include?("write_attribute")
|
76
|
+
@@errors[file] << {:habtm => index + 1} if line.include?("has_and_belongs_to_many")
|
77
|
+
formatted_line = line.gsub(" ", "")
|
78
|
+
@@errors[file] << {:prepend_true => index + 1} if !(formatted_line.include?("prepend:true") || formatted_line.include?(":prepend=>true")) && line.include?("before_destroy")
|
79
|
+
@@errors[file] << {:dependent_destroy => index + 1} if (line.include?('has_one') || line.include?('has_many')) && !line.include?('dependent')
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
end
|
84
|
+
print
|
85
|
+
end # app_directory_check method end
|
86
|
+
|
87
|
+
# Print errors found
|
88
|
+
def print
|
89
|
+
puts "The following style guide issues have been found:\n"
|
90
|
+
serial_number = 0
|
91
|
+
@@errors.each do |filename, errors_list|
|
92
|
+
next if errors_list.blank?
|
93
|
+
computed_filename = filename.gsub("#{Rails.root}", '')
|
94
|
+
puts "#{serial_number + 1}. #{computed_filename}\n"
|
95
|
+
serial_number += 1
|
96
|
+
errors_list.each_with_index do |error, i|
|
97
|
+
puts "\t#{i+1}. #{RailsReview::Error::MAP[error.keys.first]} - line: #{error.values.first}\n"
|
98
|
+
end
|
99
|
+
puts "\n"
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
end # class self end
|
104
|
+
end # class Checker end
|
105
|
+
end # module RailsReview end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module RailsReview
|
2
|
+
class Error
|
3
|
+
|
4
|
+
# Mapping symbols to respective description of rails style guide.
|
5
|
+
MAP = {
|
6
|
+
:gemlock => "Do not remove the Gemfile.lock from version control. This is not some randomly generated file - it makes sure that all of your team members get the same gem versions when they do a bundle install",
|
7
|
+
:timezone => "Config your timezone accordingly in application.rb",
|
8
|
+
:validators => "Keep custom validators under app/validators",
|
9
|
+
:time_now => "Don't use Time.now. Use Time.zone.now or Time.current instead",
|
10
|
+
:time_parse => "Don't use Time.parse. Use Time.zone.parse instead",
|
11
|
+
:render_inline => "Prefer using a template over inline rendering",
|
12
|
+
:render_text => "Prefer render plain: over render text:",
|
13
|
+
:render_status => "Prefer corresponding symbols to numeric HTTP status codes. They are meaningful and do not look like 'magic' numbers for less known HTTP status codes.",
|
14
|
+
:find_by_sql => "When specifying an explicit query in a method such as find_by_sql, use heredocs with squish. This allows you to legibly format the SQL with line breaks and indentations, while supporting syntax highlighting in many tools (including GitHub, Atom, and RubyMine).",
|
15
|
+
:update_attribute => "Beware of the behavior of the update_attribute method. It doesn't run the model validations (unlike update_attributes) and could easily corrupt the model state.",
|
16
|
+
:dot_all => "Use find_each to iterate over a collection of AR objects. Looping through a collection of records from the database (using the all method, for example) is very inefficient since it will try to instantiate all the objects at once. In that case, batch processing methods allow you to work with the records in batches, thereby greatly reducing memory consumption.",
|
17
|
+
:table_name => "Avoid altering ActiveRecord defaults (table names, primary key, etc) unless you have a very good reason (like a database that's not under your control).",
|
18
|
+
:read_attribute => "Prefer self[:attribute] over read_attribute(:attribute)",
|
19
|
+
:write_attribute => "Prefer self[:attribute] = value over write_attribute(:attribute, value)",
|
20
|
+
:habtm => "Prefer has_many :through to has_and_belongs_to_many. Using has_many :through allows additional attributes and validations on the join model.",
|
21
|
+
:prepend_true => "Since Rails creates callbacks for dependent associations, always call before_destroy callbacks that perform validation with prepend: true",
|
22
|
+
:dependent_destroy => "Define the dependent option to the has_many and has_one associations."
|
23
|
+
}
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rails_review/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rails_review"
|
8
|
+
spec.version = RailsReview::VERSION
|
9
|
+
spec.authors = ["Sanjay Vedula"]
|
10
|
+
spec.email = ["opensource@rubyeffect.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{This gem checks your rails application against the rails style guide.}
|
13
|
+
spec.description = %q{This gem checks your rails application against the rails style guide and highlights the places where the rails style guide points are not met.}
|
14
|
+
spec.homepage = "http://www.rubyeffect.com"
|
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['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
21
|
+
# else
|
22
|
+
# raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
|
+
# end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
spec.add_development_dependency "bundler", "~> 1.12"
|
31
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
32
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rails_review
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sanjay Vedula
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-07-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.12'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.12'
|
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.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
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.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description: This gem checks your rails application against the rails style guide
|
56
|
+
and highlights the places where the rails style guide points are not met.
|
57
|
+
email:
|
58
|
+
- opensource@rubyeffect.com
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- ".rspec"
|
65
|
+
- ".travis.yml"
|
66
|
+
- Gemfile
|
67
|
+
- LICENSE.txt
|
68
|
+
- README.md
|
69
|
+
- Rakefile
|
70
|
+
- bin/console
|
71
|
+
- bin/setup
|
72
|
+
- lib/rails_review.rb
|
73
|
+
- lib/rails_review/checker.rb
|
74
|
+
- lib/rails_review/error.rb
|
75
|
+
- lib/rails_review/railtie.rb
|
76
|
+
- lib/rails_review/tasks/rails_review.rake
|
77
|
+
- lib/rails_review/version.rb
|
78
|
+
- rails_review.gemspec
|
79
|
+
homepage: http://www.rubyeffect.com
|
80
|
+
licenses:
|
81
|
+
- MIT
|
82
|
+
metadata: {}
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options: []
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
requirements: []
|
98
|
+
rubyforge_project:
|
99
|
+
rubygems_version: 2.4.8
|
100
|
+
signing_key:
|
101
|
+
specification_version: 4
|
102
|
+
summary: This gem checks your rails application against the rails style guide.
|
103
|
+
test_files: []
|