best_practice_project 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -2
- data/Gemfile +2 -0
- data/Gemfile.lock +5 -1
- data/VERSION +1 -1
- data/best_practice_project.gemspec +12 -3
- data/lib/best_practice_project.rb +31 -91
- data/lib/best_practice_project/base_handler.rb +21 -0
- data/lib/best_practice_project/coffee_lint_handler.rb +45 -0
- data/lib/best_practice_project/config/haml-lint.yml +6 -0
- data/lib/best_practice_project/config/rubocop.yml +4 -2
- data/lib/best_practice_project/haml_lint_handler.rb +31 -0
- data/lib/best_practice_project/rails_best_practices_handler.rb +22 -0
- data/lib/best_practice_project/rubocop_handler.rb +17 -112
- data/lib/best_practice_project/scss_lint_handler.rb +36 -0
- data/lib/tasks/best_practice_project.rake +9 -17
- metadata +22 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3e683826592449afebee264ce6045ec6646483e7
|
4
|
+
data.tar.gz: bb6557d292562498e89d917591b13f2b2960b3af
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec018b7d4fd6fe91c2df959f24765a8f6916ec3172a722c4420a850d3e659ef05724a56f4a0d2a831b5b0208a7f5671cc4ab9088108561ff4453fff8c661eab9
|
7
|
+
data.tar.gz: 2bab2d409b34ba1635af884484c7d8d2360817d5863af18f2417716c81cb68184dbe8bfea98c7ce7facf07cdaf1a50838dd12eb5faf2cdcc5b3ac422d2c08c51
|
data/.rubocop.yml
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
AllCops:
|
2
|
+
DisplayCopNames: true
|
3
|
+
DisplayStyleGuide: true
|
2
4
|
Exclude:
|
3
5
|
- db/schema.rb
|
4
6
|
- spec/dummy/db/schema.rb
|
@@ -31,10 +33,10 @@ Style/Documentation:
|
|
31
33
|
Style/EmptyLines:
|
32
34
|
Enabled: false
|
33
35
|
|
34
|
-
StringLiterals:
|
36
|
+
Style/StringLiterals:
|
35
37
|
EnforcedStyle: double_quotes
|
36
38
|
|
37
|
-
StringLiteralsInInterpolation:
|
39
|
+
Style/StringLiteralsInInterpolation:
|
38
40
|
Enabled: false
|
39
41
|
|
40
42
|
Style/NilComparison:
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -2,6 +2,8 @@ GEM
|
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
4
|
addressable (2.3.8)
|
5
|
+
auto_autoloader (0.0.1)
|
6
|
+
string-cases
|
5
7
|
builder (3.2.2)
|
6
8
|
descendants_tracker (0.0.4)
|
7
9
|
thread_safe (~> 0.3, >= 0.3.1)
|
@@ -60,12 +62,14 @@ GEM
|
|
60
62
|
json (~> 1.8)
|
61
63
|
simplecov-html (~> 0.10.0)
|
62
64
|
simplecov-html (0.10.0)
|
65
|
+
string-cases (0.0.2)
|
63
66
|
thread_safe (0.3.5)
|
64
67
|
|
65
68
|
PLATFORMS
|
66
69
|
ruby
|
67
70
|
|
68
71
|
DEPENDENCIES
|
72
|
+
auto_autoloader
|
69
73
|
bundler (~> 1.0)
|
70
74
|
jeweler (~> 2.0.1)
|
71
75
|
rdoc (~> 3.12)
|
@@ -73,4 +77,4 @@ DEPENDENCIES
|
|
73
77
|
simplecov
|
74
78
|
|
75
79
|
BUNDLED WITH
|
76
|
-
1.
|
80
|
+
1.11.2
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.8
|
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: best_practice_project 0.0.
|
5
|
+
# stub: best_practice_project 0.0.8 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "best_practice_project"
|
9
|
-
s.version = "0.0.
|
9
|
+
s.version = "0.0.8"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.authors = ["kaspernj"]
|
14
|
-
s.date = "2016-01-
|
14
|
+
s.date = "2016-01-07"
|
15
15
|
s.description = "A bundle of various linters and code inspection tools"
|
16
16
|
s.email = "k@spernj.org"
|
17
17
|
s.extra_rdoc_files = [
|
@@ -30,8 +30,14 @@ Gem::Specification.new do |s|
|
|
30
30
|
"VERSION",
|
31
31
|
"best_practice_project.gemspec",
|
32
32
|
"lib/best_practice_project.rb",
|
33
|
+
"lib/best_practice_project/base_handler.rb",
|
34
|
+
"lib/best_practice_project/coffee_lint_handler.rb",
|
35
|
+
"lib/best_practice_project/config/haml-lint.yml",
|
33
36
|
"lib/best_practice_project/config/rubocop.yml",
|
37
|
+
"lib/best_practice_project/haml_lint_handler.rb",
|
38
|
+
"lib/best_practice_project/rails_best_practices_handler.rb",
|
34
39
|
"lib/best_practice_project/rubocop_handler.rb",
|
40
|
+
"lib/best_practice_project/scss_lint_handler.rb",
|
35
41
|
"lib/tasks/best_practice_project.rake",
|
36
42
|
"shippable.yml",
|
37
43
|
"spec/best_practice_project_spec.rb",
|
@@ -46,12 +52,14 @@ Gem::Specification.new do |s|
|
|
46
52
|
s.specification_version = 4
|
47
53
|
|
48
54
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
55
|
+
s.add_runtime_dependency(%q<auto_autoloader>, [">= 0"])
|
49
56
|
s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
|
50
57
|
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
51
58
|
s.add_development_dependency(%q<bundler>, ["~> 1.0"])
|
52
59
|
s.add_development_dependency(%q<jeweler>, ["~> 2.0.1"])
|
53
60
|
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
54
61
|
else
|
62
|
+
s.add_dependency(%q<auto_autoloader>, [">= 0"])
|
55
63
|
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
56
64
|
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
57
65
|
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
@@ -59,6 +67,7 @@ Gem::Specification.new do |s|
|
|
59
67
|
s.add_dependency(%q<simplecov>, [">= 0"])
|
60
68
|
end
|
61
69
|
else
|
70
|
+
s.add_dependency(%q<auto_autoloader>, [">= 0"])
|
62
71
|
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
63
72
|
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
64
73
|
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
@@ -1,11 +1,11 @@
|
|
1
1
|
require "yaml"
|
2
|
+
require "fileutils"
|
3
|
+
require "auto_autoloader"
|
2
4
|
|
3
5
|
class BestPracticeProject
|
4
|
-
|
6
|
+
AutoAutoloader.autoload_sub_classes(self, __FILE__)
|
5
7
|
|
6
|
-
|
7
|
-
|
8
|
-
attr_reader :rails, :rubocop_handler
|
8
|
+
attr_reader :rails, :rubocop_handler, :haml_lint_handler, :scss_lint_handler, :coffee_lint_handler, :rails_best_practices_handler
|
9
9
|
alias_method :rails?, :rails
|
10
10
|
|
11
11
|
def self.load_tasks
|
@@ -13,25 +13,19 @@ class BestPracticeProject
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def initialize
|
16
|
-
@rubocop_handler = BestPracticeProject::RubocopHandler.new(best_practice_project: self)
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
@
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
@commands << scss_lint_command if scss_lint_installed?
|
30
|
-
@commands << coffee_lint_command if coffee_lint_installed?
|
31
|
-
@commands << rails_best_practices_command if rails_best_practices_installed?
|
32
|
-
end
|
33
|
-
|
34
|
-
@commands << proc { @rubocop_handler.execute }
|
16
|
+
@rubocop_handler = BestPracticeProject::RubocopHandler.new(best_practice_project: self)
|
17
|
+
@haml_lint_handler = BestPracticeProject::HamlLintHandler.new(best_practice_project: self)
|
18
|
+
@scss_lint_handler = BestPracticeProject::ScssLintHandler.new(best_practice_project: self)
|
19
|
+
@coffee_lint_handler = BestPracticeProject::CoffeeLintHandler.new(best_practice_project: self)
|
20
|
+
@rails_best_practices_handler = BestPracticeProject::RailsBestPracticesHandler.new(best_practice_project: self)
|
21
|
+
|
22
|
+
@handlers = [
|
23
|
+
@rubocop_handler,
|
24
|
+
@haml_lint_handler,
|
25
|
+
@scss_lint_handler,
|
26
|
+
@coffee_lint_handler,
|
27
|
+
@rails_best_practices_handler
|
28
|
+
]
|
35
29
|
end
|
36
30
|
|
37
31
|
def rails?
|
@@ -42,88 +36,34 @@ class BestPracticeProject
|
|
42
36
|
def execute
|
43
37
|
process_status = true
|
44
38
|
|
45
|
-
@
|
46
|
-
|
47
|
-
|
48
|
-
status = command.call unless status
|
49
|
-
else
|
50
|
-
puts "Executing: #{command}"
|
51
|
-
status = system(command)
|
52
|
-
end
|
53
|
-
|
54
|
-
process_status = status unless status
|
39
|
+
@handlers.select(&:installed?).each do |handler|
|
40
|
+
handler_result = handler.execute
|
41
|
+
process_status = false unless handler_result
|
55
42
|
end
|
56
43
|
|
57
44
|
process_status
|
58
45
|
end
|
59
46
|
|
60
47
|
def generate_configs
|
61
|
-
|
62
|
-
|
63
|
-
@rubocop_handler.generate_config if rubocop_installed?
|
64
|
-
generate_scss_config if scss_lint_installed?
|
65
|
-
generate_coffee_lint_config if coffee_lint_installed?
|
66
|
-
end
|
67
|
-
|
68
|
-
def scss_lint_command
|
69
|
-
"bundle exec scss-lint --config config/scss-lint.yml app/assets/stylesheets/" if rails?
|
70
|
-
end
|
71
|
-
|
72
|
-
def coffee_lint_command
|
73
|
-
"bundle exec coffeelint.rb -f config/coffeelint.json -r app/assets/javascripts/" if rails?
|
74
|
-
end
|
48
|
+
puts "Handlers: #{@handlers.select(&:installed?).map(&:class).map(&:name)}"
|
75
49
|
|
76
|
-
|
77
|
-
"bundle exec rails_best_practices" if rails?
|
50
|
+
@handlers.select(&:installed?).map(&:generate_config)
|
78
51
|
end
|
79
52
|
|
80
53
|
private
|
81
54
|
|
82
|
-
def
|
83
|
-
|
84
|
-
|
85
|
-
rescue LoadError
|
86
|
-
false
|
87
|
-
end
|
88
|
-
|
89
|
-
def scss_lint_installed?
|
90
|
-
require "scss_lint"
|
91
|
-
true
|
92
|
-
rescue LoadError
|
93
|
-
false
|
94
|
-
end
|
55
|
+
def commands
|
56
|
+
unless @commands
|
57
|
+
@commands = []
|
95
58
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
false
|
101
|
-
end
|
102
|
-
|
103
|
-
def rails_best_practices_installed?
|
104
|
-
require "rails_best_practices"
|
105
|
-
true
|
106
|
-
rescue LoadError
|
107
|
-
false
|
108
|
-
end
|
109
|
-
|
110
|
-
def generate_coffee_lint_config
|
111
|
-
return unless @coffee_lint_config_path
|
112
|
-
return puts "Coffee-Lint config already exists in #{@coffee_lint_config_path}" if File.exist?(@coffee_lint_config_path)
|
113
|
-
|
114
|
-
puts "FIXME: Generate Coffee-Lint configuration!"
|
115
|
-
end
|
116
|
-
|
117
|
-
def generate_scss_config
|
118
|
-
return unless @scss_config_path
|
119
|
-
return puts "SCSS-Lint config already exists in #{@scss_config_path}" if File.exist?(@scss_config_path)
|
120
|
-
|
121
|
-
config = `bundle exec scss-lint --format=Config`
|
59
|
+
if rails?
|
60
|
+
@commands << @scss_lint_handler.command if @scss_lint_handler.installed?
|
61
|
+
@commands << @rails_best_practices_handler.command if @rails_best_practices_handler.installed?
|
62
|
+
end
|
122
63
|
|
123
|
-
|
124
|
-
fp.write(config)
|
64
|
+
@commands << proc { @rubocop_handler.execute }
|
125
65
|
end
|
126
66
|
|
127
|
-
|
67
|
+
@commands
|
128
68
|
end
|
129
69
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class BestPracticeProject::BaseHandler
|
2
|
+
def initialize(args)
|
3
|
+
@bpp = args.fetch(:best_practice_project)
|
4
|
+
end
|
5
|
+
|
6
|
+
def rails?
|
7
|
+
@bpp.rails?
|
8
|
+
end
|
9
|
+
|
10
|
+
def installed?
|
11
|
+
raise "stub!"
|
12
|
+
end
|
13
|
+
|
14
|
+
def generate_config
|
15
|
+
raise "stub!"
|
16
|
+
end
|
17
|
+
|
18
|
+
def execute
|
19
|
+
raise "stub!"
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
class BestPracticeProject::CoffeeLintHandler < BestPracticeProject::BaseHandler
|
2
|
+
def command
|
3
|
+
"bundle exec coffeelint.rb -f coffeelint.json -r app/assets/javascripts/" if rails?
|
4
|
+
end
|
5
|
+
|
6
|
+
def execute
|
7
|
+
require "coffeelint"
|
8
|
+
|
9
|
+
dirs = ENV["DIRS"].split(":").map(&:strip) if ENV["DIRS"]
|
10
|
+
dirs ||= ["app/assets/javascripts"]
|
11
|
+
status = true
|
12
|
+
|
13
|
+
dirs.each do |dir|
|
14
|
+
dir = dir.strip
|
15
|
+
|
16
|
+
puts "Running CoffeeLint on: #{dir}"
|
17
|
+
result = Coffeelint.run_test_suite(dir)
|
18
|
+
|
19
|
+
puts "Result: #{result}"
|
20
|
+
status = false if result > 0
|
21
|
+
end
|
22
|
+
|
23
|
+
status
|
24
|
+
end
|
25
|
+
|
26
|
+
def installed?
|
27
|
+
require "coffeelint"
|
28
|
+
true
|
29
|
+
rescue LoadError
|
30
|
+
false
|
31
|
+
end
|
32
|
+
|
33
|
+
def generate_config
|
34
|
+
return unless @coffee_lint_config_path
|
35
|
+
return puts "Coffee-Lint config already exists in #{@coffee_lint_config_path}" if File.exist?(@coffee_lint_config_path)
|
36
|
+
|
37
|
+
puts "CoffeeLintHandler: FIXME: Generate Coffee-Lint configuration!"
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def config_path
|
43
|
+
@config_path ||= "coffeelint.json"
|
44
|
+
end
|
45
|
+
end
|
@@ -1,4 +1,6 @@
|
|
1
1
|
AllCops:
|
2
|
+
DisplayCopNames: true
|
3
|
+
DisplayStyleGuide: true
|
2
4
|
Exclude:
|
3
5
|
- db/schema.rb
|
4
6
|
- spec/dummy/db/schema.rb
|
@@ -31,10 +33,10 @@ Style/Documentation:
|
|
31
33
|
Style/EmptyLines:
|
32
34
|
Enabled: false
|
33
35
|
|
34
|
-
StringLiterals:
|
36
|
+
Style/StringLiterals:
|
35
37
|
EnforcedStyle: double_quotes
|
36
38
|
|
37
|
-
StringLiteralsInInterpolation:
|
39
|
+
Style/StringLiteralsInInterpolation:
|
38
40
|
Enabled: false
|
39
41
|
|
40
42
|
Style/NilComparison:
|
@@ -0,0 +1,31 @@
|
|
1
|
+
class BestPracticeProject::HamlLintHandler < BestPracticeProject::BaseHandler
|
2
|
+
def installed?
|
3
|
+
require "haml_lint"
|
4
|
+
true
|
5
|
+
rescue LoadError
|
6
|
+
false
|
7
|
+
end
|
8
|
+
|
9
|
+
def generate_config
|
10
|
+
puts "HamlLintHandler: Copying standard config"
|
11
|
+
FileUtils.copy(bpp_config_path, config_path)
|
12
|
+
end
|
13
|
+
|
14
|
+
def command
|
15
|
+
@command ||= "bundle exec haml-lint app"
|
16
|
+
end
|
17
|
+
|
18
|
+
def execute
|
19
|
+
system(command)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def bpp_config_path
|
25
|
+
@bpp_config_path ||= File.realpath("#{File.dirname(__FILE__)}/config/haml-lint.yml")
|
26
|
+
end
|
27
|
+
|
28
|
+
def config_path
|
29
|
+
@config_path ||= Rails.root.join(".haml-lint.yml").to_s
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class BestPracticeProject::RailsBestPracticesHandler < BestPracticeProject::BaseHandler
|
2
|
+
def command
|
3
|
+
"bundle exec rails_best_practices"
|
4
|
+
end
|
5
|
+
|
6
|
+
def generate_config
|
7
|
+
system("bundle exec rails_best_practices -g")
|
8
|
+
end
|
9
|
+
|
10
|
+
def execute
|
11
|
+
system(command)
|
12
|
+
end
|
13
|
+
|
14
|
+
def installed?
|
15
|
+
return false unless rails?
|
16
|
+
|
17
|
+
require "rails_best_practices"
|
18
|
+
true
|
19
|
+
rescue LoadError
|
20
|
+
false
|
21
|
+
end
|
22
|
+
end
|
@@ -1,145 +1,50 @@
|
|
1
|
-
class BestPracticeProject::RubocopHandler
|
1
|
+
class BestPracticeProject::RubocopHandler < BestPracticeProject::BaseHandler
|
2
2
|
def initialize(args)
|
3
|
-
|
3
|
+
super
|
4
|
+
|
4
5
|
@actual_config_path = File.realpath("#{File.dirname(__FILE__)}/config/rubocop.yml")
|
5
6
|
|
6
7
|
if rails?
|
7
|
-
@config_path = Rails.root.join("
|
8
|
-
@todo_path = Rails.root.join("
|
9
|
-
@default_path = Rails.root.join(".rubocop.yml")
|
10
|
-
@default_todo_path = Rails.root.join(".rubocop_todo.yml")
|
8
|
+
@config_path = Rails.root.join(".rubocop.yml").to_s
|
9
|
+
@todo_path = Rails.root.join(".rubocop_todo.yml").to_s
|
11
10
|
else
|
12
|
-
@config_path = "
|
13
|
-
@todo_path = "
|
14
|
-
@default_path = ".rubocop.yml"
|
15
|
-
@default_todo_path = ".rubocop_todo.yml"
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def rails?
|
20
|
-
@bpp.rails?
|
21
|
-
end
|
22
|
-
|
23
|
-
def remove_best_practice_path
|
24
|
-
self.inherit_from_to = nil
|
25
|
-
end
|
26
|
-
|
27
|
-
def update_best_practice_path
|
28
|
-
self.inherit_from_to = @actual_config_path
|
29
|
-
end
|
30
|
-
|
31
|
-
def reset_best_practice_path
|
32
|
-
self.inherit_from_to = "$$$best_practice_project_config_path$$$"
|
33
|
-
end
|
34
|
-
|
35
|
-
# Make default ".rubocop.yml" and ".rubocop_todo" to support Sublime Text plugins and likewise
|
36
|
-
def update_default_configs
|
37
|
-
remove_best_practice_path
|
38
|
-
File.symlink(@todo_path, @default_todo_path)
|
39
|
-
# FileUtils.cp(@todo_path, @default_todo_path)
|
40
|
-
|
41
|
-
# Make default ".rubocop.yml" and ".rubocop_todo" to support Sublime Text plugins and likewise
|
42
|
-
generated_config = {"inherit_from" => [@actual_config_path, ".rubocop_todo.yml"]}
|
43
|
-
File.open(@default_path, "w") do |fp|
|
44
|
-
fp.write(YAML.dump(generated_config))
|
11
|
+
@config_path = ".rubocop.yml"
|
12
|
+
@todo_path = ".rubocop_todo.yml"
|
45
13
|
end
|
46
14
|
end
|
47
15
|
|
48
16
|
def command
|
49
17
|
command = "bundle exec rubocop --display-cop-names"
|
50
18
|
command << " --rails" if rails?
|
51
|
-
command << " \"--config=#{@config_path}\"" if File.exist?(@config_path)
|
52
19
|
command << " --auto-correct" if ARGV.include?("auto-correct")
|
53
20
|
|
54
21
|
command
|
55
22
|
end
|
56
23
|
|
57
24
|
def generate_config
|
58
|
-
|
25
|
+
FileUtils.copy(@actual_config_path, @config_path)
|
59
26
|
|
60
|
-
|
61
|
-
fp.write(generate_todo_config)
|
62
|
-
end
|
27
|
+
generate_todo_config
|
63
28
|
|
64
29
|
puts "Generated Rubocop todo config in #{@todo_path}"
|
65
|
-
|
66
|
-
generated_config = {}
|
67
|
-
generated_config["inherit_from"] = "best_project_practice_rubocop_todo.yml"
|
68
|
-
|
69
|
-
File.open(@config_path, "w") do |fp|
|
70
|
-
fp.write(YAML.dump(generated_config))
|
71
|
-
end
|
72
|
-
|
73
|
-
update_default_configs
|
74
|
-
|
75
30
|
puts "Generated Rubocop config in #{@config_path}"
|
76
31
|
end
|
77
32
|
|
78
33
|
def generate_todo_config
|
79
|
-
|
80
|
-
|
81
|
-
todo_backup_file_path = Rails.root.join(".rubocop_todo_backup.yml").to_s
|
82
|
-
else
|
83
|
-
todo_file_path = ".rubocop_todo.yml"
|
84
|
-
todo_backup_file_path = ".rubocop_todo_backup.yml"
|
85
|
-
end
|
86
|
-
|
87
|
-
if File.exist?(todo_file_path)
|
88
|
-
File.rename(todo_file_path, todo_backup_file_path)
|
89
|
-
end
|
90
|
-
|
91
|
-
rubocop_command = "rubocop --display-cop-names --auto-gen-config --config=#{@actual_config_path}"
|
92
|
-
rubocop_command << " --rails" if @bpp.rails?
|
34
|
+
rubocop_command = "rubocop --display-cop-names --auto-gen-config --config=#{@config_path}"
|
35
|
+
rubocop_command << " --rails" if rails?
|
93
36
|
|
94
37
|
system(rubocop_command)
|
95
|
-
|
96
|
-
raise "Todo-file was not generated" unless File.exist?(todo_file_path)
|
97
|
-
|
98
|
-
todo_config = File.read(todo_file_path)
|
99
|
-
File.unlink(todo_file_path)
|
100
|
-
File.rename(todo_backup_file_path, todo_file_path) if File.exist?(todo_backup_file_path)
|
101
|
-
|
102
|
-
todo_config
|
103
38
|
end
|
104
39
|
|
105
40
|
def execute
|
106
|
-
|
107
|
-
|
108
|
-
begin
|
109
|
-
system(command)
|
110
|
-
ensure
|
111
|
-
remove_best_practice_path
|
112
|
-
end
|
41
|
+
system(command)
|
113
42
|
end
|
114
43
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
if new_inherit_from
|
121
|
-
replace_with = "inherit_from: \"#{new_inherit_from}\""
|
122
|
-
else
|
123
|
-
replace_with = ""
|
124
|
-
end
|
125
|
-
|
126
|
-
if todo_config.include?("inherit_from:")
|
127
|
-
replace_what = /^inherit_from: (.+)$/
|
128
|
-
elsif todo_config.start_with?("---\n")
|
129
|
-
replace_what = /\A---\n/
|
130
|
-
replace_with.prepend("---\n")
|
131
|
-
replace_with << "\n\n" if replace_with.length > 0
|
132
|
-
else
|
133
|
-
replace_what = /\A/
|
134
|
-
replace_with << "\n\n" if replace_with.length > 0
|
135
|
-
end
|
136
|
-
|
137
|
-
todo_config.gsub!(replace_what, replace_with)
|
138
|
-
|
139
|
-
raise "Couldn't insert dynamic config" unless todo_config.include?(replace_with)
|
140
|
-
|
141
|
-
File.open(@todo_path, "w") do |fp|
|
142
|
-
fp.write(todo_config)
|
143
|
-
end
|
44
|
+
def installed?
|
45
|
+
require "rubocop"
|
46
|
+
true
|
47
|
+
rescue LoadError
|
48
|
+
false
|
144
49
|
end
|
145
50
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
class BestPracticeProject::ScssLintHandler < BestPracticeProject::BaseHandler
|
2
|
+
def installed?
|
3
|
+
return false unless rails?
|
4
|
+
require "scss_lint"
|
5
|
+
true
|
6
|
+
rescue LoadError
|
7
|
+
false
|
8
|
+
end
|
9
|
+
|
10
|
+
def generate_config
|
11
|
+
return unless @scss_config_path
|
12
|
+
return puts "SCSS-Lint config already exists in #{@scss_config_path}" if File.exist?(@scss_config_path)
|
13
|
+
|
14
|
+
config = `bundle exec scss-lint --format=Config`
|
15
|
+
|
16
|
+
File.open(config_path, "w") do |fp|
|
17
|
+
fp.write(config)
|
18
|
+
end
|
19
|
+
|
20
|
+
puts "ScssLintHandler: Generated SCSS-Lint config in #{@scss_config_path}"
|
21
|
+
end
|
22
|
+
|
23
|
+
def command
|
24
|
+
"bundle exec scss-lint --config .scss-lint.yml app/assets/stylesheets/"
|
25
|
+
end
|
26
|
+
|
27
|
+
def execute
|
28
|
+
system(command)
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def config_path
|
34
|
+
@config_path ||= ".scss-lint.yml"
|
35
|
+
end
|
36
|
+
end
|
@@ -1,34 +1,26 @@
|
|
1
1
|
namespace "best_practice_project" do
|
2
|
-
task "run" do |
|
2
|
+
task "run" do |_t, _args|
|
3
3
|
exit BestPracticeProject.new.execute
|
4
4
|
end
|
5
5
|
|
6
|
-
task "
|
7
|
-
|
6
|
+
task "run_haml_lint "do
|
7
|
+
exit BestPracticeProject.new.haml_lint_handler.execute
|
8
|
+
end
|
8
9
|
|
9
|
-
|
10
|
-
|
10
|
+
task "run_rubocop" do
|
11
|
+
exit BestPracticeProject.new.rubocop_handler.execute
|
11
12
|
end
|
12
13
|
|
13
14
|
task "run_scss_lint" do
|
14
|
-
|
15
|
-
|
16
|
-
puts "Executing: #{best_practice_project.scss_lint_command}"
|
17
|
-
exit system(best_practice_project.scss_lint_command)
|
15
|
+
exit BestPracticeProject.new.scss_lint_handler.execute
|
18
16
|
end
|
19
17
|
|
20
18
|
task "run_coffee_lint" do
|
21
|
-
|
22
|
-
|
23
|
-
puts "Executing: #{best_practice_project.coffee_lint_command}"
|
24
|
-
exit system(best_practice_project.coffee_lint_command)
|
19
|
+
exit BestPracticeProject.new.coffee_lint_handler.execute
|
25
20
|
end
|
26
21
|
|
27
22
|
task "run_rails_best_practices" do
|
28
|
-
|
29
|
-
|
30
|
-
puts "Executing: #{best_practice_project.rails_best_practices_command}"
|
31
|
-
exit system(best_practice_project.rails_best_practices_command)
|
23
|
+
exit BestPracticeProject.new.rails_best_practices_handler.execute
|
32
24
|
end
|
33
25
|
|
34
26
|
task "generate_configs" do
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: best_practice_project
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kaspernj
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-01-
|
11
|
+
date: 2016-01-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: auto_autoloader
|
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'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: rspec
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -99,8 +113,14 @@ files:
|
|
99
113
|
- VERSION
|
100
114
|
- best_practice_project.gemspec
|
101
115
|
- lib/best_practice_project.rb
|
116
|
+
- lib/best_practice_project/base_handler.rb
|
117
|
+
- lib/best_practice_project/coffee_lint_handler.rb
|
118
|
+
- lib/best_practice_project/config/haml-lint.yml
|
102
119
|
- lib/best_practice_project/config/rubocop.yml
|
120
|
+
- lib/best_practice_project/haml_lint_handler.rb
|
121
|
+
- lib/best_practice_project/rails_best_practices_handler.rb
|
103
122
|
- lib/best_practice_project/rubocop_handler.rb
|
123
|
+
- lib/best_practice_project/scss_lint_handler.rb
|
104
124
|
- lib/tasks/best_practice_project.rake
|
105
125
|
- shippable.yml
|
106
126
|
- spec/best_practice_project_spec.rb
|