phare 0.3 → 0.4
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/.rspec +1 -0
- data/.travis.yml +17 -0
- data/Rakefile +10 -0
- data/bin/phare +1 -1
- data/lib/phare.rb +25 -4
- data/lib/phare/check.rb +21 -16
- data/lib/phare/check/jscs.rb +29 -0
- data/lib/phare/check/jshint.rb +30 -0
- data/lib/phare/check/rubocop.rb +26 -0
- data/lib/phare/check/scss_lint.rb +28 -0
- data/lib/phare/check_suite.rb +43 -0
- data/lib/phare/cli.rb +44 -12
- data/lib/phare/version.rb +1 -1
- data/phare.gemspec +3 -2
- data/spec/phare/check/jscs_spec.rb +61 -0
- data/spec/phare/check/jshint_spec.rb +62 -0
- data/spec/phare/check/rubocop_spec.rb +53 -0
- data/spec/phare/check/scss_lint_spec.rb +59 -0
- data/spec/phare/check_suite_spec.rb +65 -0
- data/spec/phare/cli_spec.rb +36 -0
- data/spec/spec_helper.rb +44 -0
- metadata +42 -9
- data/lib/phare/checks/javascript_jscs.rb +0 -41
- data/lib/phare/checks/javascript_jshint.rb +0 -44
- data/lib/phare/checks/ruby_rubocop.rb +0 -39
- data/lib/phare/checks/scss_lint.rb +0 -42
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5e4055ee6e95ae9be4856e7031220de6735136a4
|
4
|
+
data.tar.gz: 03a9678f15427a0affb3e76faaeb6694fb2d9775
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 83ee6107f5879b34f1da3a9554d96f2bdaccc982bb12f9d768f359d8b6809dae1f048acd3e76ac56584a4790b50e6b475d76e071d9b6e36ccc3c529bd0ffbafb
|
7
|
+
data.tar.gz: 838988f8a43ba902060c4c4b8036228d946fd80d4337bacbe6879bb6369519c354f47140c7feb0031829cfd3d5797da72e5de932f7fb26b265459231e75a35e8
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/.travis.yml
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
language: ruby
|
2
|
+
|
3
|
+
rvm:
|
4
|
+
- 2.0.0
|
5
|
+
- 1.9.3
|
6
|
+
|
7
|
+
script:
|
8
|
+
- 'echo "Checking code style" && ./bin/phare'
|
9
|
+
- 'echo "Running specs" && bundle exec rake spec'
|
10
|
+
|
11
|
+
notifications:
|
12
|
+
hipchat:
|
13
|
+
rooms:
|
14
|
+
secure: "OjYHtwmsG6bDC8mewX85yulCKxsVpvGiic32e6lDRq2TYmMtot/atOQaZ16YlMMN0CQqiJ8jfpil3HWCSK1iPZxSLHzCEu//bL6uoDJdPc/oXNV2BPAj0CxyHiJPpV3gdgdnZBbYGNdDPtjxo8FuZnM+cWIDl3yW0Y2rQkE7u0k="
|
15
|
+
template:
|
16
|
+
- '%{repository}#%{build_number} (%{branch} - %{commit} : %{author}): %{message} (<a href="%{build_url}">Build</a>/<a href="%{compare_url}">Changes</a>)'
|
17
|
+
format: 'html'
|
data/Rakefile
CHANGED
data/bin/phare
CHANGED
data/lib/phare.rb
CHANGED
@@ -1,10 +1,31 @@
|
|
1
1
|
require 'English'
|
2
|
+
require 'optparse'
|
2
3
|
require 'phare/version'
|
3
4
|
|
4
5
|
require 'phare/cli'
|
6
|
+
|
5
7
|
require 'phare/check'
|
8
|
+
require 'phare/check/rubocop'
|
9
|
+
require 'phare/check/scss_lint'
|
10
|
+
require 'phare/check/jshint'
|
11
|
+
require 'phare/check/jscs'
|
12
|
+
|
13
|
+
require 'phare/check_suite'
|
14
|
+
|
15
|
+
module Phare
|
16
|
+
def self.system(*args)
|
17
|
+
Kernel.system(*args)
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.system_output(args)
|
21
|
+
`#{args}`
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.last_exit_status
|
25
|
+
$CHILD_STATUS.exitstatus
|
26
|
+
end
|
6
27
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
28
|
+
def self.puts(*args)
|
29
|
+
STDOUT.puts(*args)
|
30
|
+
end
|
31
|
+
end
|
data/lib/phare/check.rb
CHANGED
@@ -1,28 +1,33 @@
|
|
1
1
|
module Phare
|
2
2
|
class Check
|
3
|
-
attr_reader :status
|
4
|
-
|
5
|
-
def initialize(directory)
|
6
|
-
@directory = directory
|
7
|
-
@directory << '/' unless @directory.end_with?('/')
|
8
|
-
end
|
3
|
+
attr_reader :status, :command
|
9
4
|
|
10
5
|
def run
|
11
|
-
|
6
|
+
if should_run?
|
7
|
+
print_banner
|
8
|
+
Phare.system(command)
|
9
|
+
@status = Phare.last_exit_status
|
12
10
|
|
13
|
-
|
14
|
-
|
11
|
+
if @status == 0
|
12
|
+
print_success_message
|
13
|
+
else
|
14
|
+
print_error_message
|
15
|
+
end
|
15
16
|
|
16
|
-
|
17
|
-
|
17
|
+
Phare.puts ''
|
18
|
+
else
|
19
|
+
@status = 0
|
20
|
+
end
|
21
|
+
end
|
18
22
|
|
19
|
-
|
20
|
-
jshint.run
|
23
|
+
protected
|
21
24
|
|
22
|
-
|
23
|
-
|
25
|
+
def print_success_message
|
26
|
+
Phare.puts('Everything looks good from here!')
|
27
|
+
end
|
24
28
|
|
25
|
-
|
29
|
+
def print_error_message
|
30
|
+
Phare.puts("Something went wrong. Program exited with #{@status}.")
|
26
31
|
end
|
27
32
|
end
|
28
33
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module Phare
|
3
|
+
class Check
|
4
|
+
class JSCS < Check
|
5
|
+
attr_reader :config, :path
|
6
|
+
|
7
|
+
def initialize(directory)
|
8
|
+
@config = File.expand_path("#{directory}.jscs.json", __FILE__)
|
9
|
+
@path = File.expand_path("#{directory}app/assets", __FILE__)
|
10
|
+
end
|
11
|
+
|
12
|
+
def command
|
13
|
+
"jscs #{@path}"
|
14
|
+
end
|
15
|
+
|
16
|
+
protected
|
17
|
+
|
18
|
+
def should_run?
|
19
|
+
!Phare.system_output('which jscs').empty? && File.exists?(@config) && Dir.exists?(@path)
|
20
|
+
end
|
21
|
+
|
22
|
+
def print_banner
|
23
|
+
Phare.puts '---------------------------------------------'
|
24
|
+
Phare.puts 'Running JSCS to check for JavaScript style…'
|
25
|
+
Phare.puts '---------------------------------------------'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module Phare
|
3
|
+
class Check
|
4
|
+
class JSHint < Check
|
5
|
+
attr_reader :config, :path
|
6
|
+
|
7
|
+
def initialize(directory)
|
8
|
+
@config = File.expand_path("#{directory}.jshintrc", __FILE__)
|
9
|
+
@path = File.expand_path("#{directory}app/assets/javascripts", __FILE__)
|
10
|
+
@glob = File.join(@path, '**/*')
|
11
|
+
end
|
12
|
+
|
13
|
+
def command
|
14
|
+
"jshint --config #{@config} --extra-ext .js,.es6.js #{@glob}"
|
15
|
+
end
|
16
|
+
|
17
|
+
protected
|
18
|
+
|
19
|
+
def should_run?
|
20
|
+
!Phare.system_output('which jshint').empty? && File.exists?(@config) && Dir.exists?(@path)
|
21
|
+
end
|
22
|
+
|
23
|
+
def print_banner
|
24
|
+
Phare.puts '---------------------------------------------'
|
25
|
+
Phare.puts 'Running JSHint to check for JavaScript style…'
|
26
|
+
Phare.puts '---------------------------------------------'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module Phare
|
3
|
+
class Check
|
4
|
+
class Rubocop < Check
|
5
|
+
def initialize(directory)
|
6
|
+
@path = directory
|
7
|
+
end
|
8
|
+
|
9
|
+
def command
|
10
|
+
'rubocop'
|
11
|
+
end
|
12
|
+
|
13
|
+
protected
|
14
|
+
|
15
|
+
def should_run?
|
16
|
+
!Phare.system_output('which rubocop').empty?
|
17
|
+
end
|
18
|
+
|
19
|
+
def print_banner
|
20
|
+
Phare.puts '----------------------------------------'
|
21
|
+
Phare.puts 'Running Rubocop to check for Ruby style…'
|
22
|
+
Phare.puts '----------------------------------------'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module Phare
|
3
|
+
class Check
|
4
|
+
class ScssLint < Check
|
5
|
+
attr_reader :path
|
6
|
+
|
7
|
+
def initialize(directory)
|
8
|
+
@path = File.expand_path("#{directory}app/assets/stylesheets", __FILE__)
|
9
|
+
end
|
10
|
+
|
11
|
+
def command
|
12
|
+
"scss-lint #{@path}"
|
13
|
+
end
|
14
|
+
|
15
|
+
protected
|
16
|
+
|
17
|
+
def should_run?
|
18
|
+
!Phare.system_output('which scss-lint').empty? && Dir.exists?(@path)
|
19
|
+
end
|
20
|
+
|
21
|
+
def print_banner
|
22
|
+
Phare.puts '------------------------------------------'
|
23
|
+
Phare.puts 'Running SCSS-Lint to check for SCSS style…'
|
24
|
+
Phare.puts '------------------------------------------'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Phare
|
2
|
+
class CheckSuite
|
3
|
+
attr_reader :status
|
4
|
+
|
5
|
+
DEFAULT_CHECKS = {
|
6
|
+
rubocop: Check::Rubocop,
|
7
|
+
scsslint: Check::ScssLint,
|
8
|
+
jshint: Check::JSHint,
|
9
|
+
jscs: Check::JSCS
|
10
|
+
}
|
11
|
+
|
12
|
+
def initialize(options = {})
|
13
|
+
@options = options
|
14
|
+
|
15
|
+
@directory = options[:directory]
|
16
|
+
@directory << '/' unless @directory.end_with?('/')
|
17
|
+
|
18
|
+
@options[:skip] ||= []
|
19
|
+
@options[:only] ||= []
|
20
|
+
end
|
21
|
+
|
22
|
+
def checks
|
23
|
+
checks = DEFAULT_CHECKS.keys
|
24
|
+
|
25
|
+
if @options[:only].any?
|
26
|
+
checks = checks & @options[:only]
|
27
|
+
elsif @options[:skip]
|
28
|
+
checks = checks - @options[:skip]
|
29
|
+
else
|
30
|
+
checks
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def run
|
35
|
+
@checks = checks.map do |check|
|
36
|
+
check = DEFAULT_CHECKS[check]
|
37
|
+
check.new(@directory).tap(&:run).status
|
38
|
+
end
|
39
|
+
|
40
|
+
@status = @checks.find { |status| status > 0 } || 0
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/phare/cli.rb
CHANGED
@@ -1,27 +1,59 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
module Phare
|
2
3
|
class CLI
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
attr_reader :suite
|
5
|
+
|
6
|
+
def initialize(env, argv)
|
7
|
+
@env = env
|
8
|
+
@argv = argv
|
9
|
+
parse_options
|
10
|
+
|
11
|
+
@suite = Phare::CheckSuite.new(@options)
|
12
|
+
end
|
13
|
+
|
14
|
+
def run
|
15
|
+
if @env['SKIP_CODE_CHECK']
|
16
|
+
Phare.puts '--------------------------------------------------------'
|
17
|
+
Phare.puts 'Skipping code style checking… Really? Well alright then…'
|
18
|
+
Phare.puts '--------------------------------------------------------'
|
8
19
|
|
9
20
|
exit 0
|
10
21
|
else
|
11
|
-
if
|
12
|
-
puts '------------------------------------------'
|
13
|
-
puts 'Everything looks good, keep on committing!'
|
14
|
-
puts '------------------------------------------'
|
22
|
+
if @suite.tap(&:run).status == 0
|
23
|
+
Phare.puts '------------------------------------------'
|
24
|
+
Phare.puts 'Everything looks good, keep on committing!'
|
25
|
+
Phare.puts '------------------------------------------'
|
15
26
|
|
16
27
|
exit 0
|
17
28
|
else
|
18
|
-
puts '------------------------------------------------------------------------'
|
19
|
-
puts 'Something’s wrong with your code style. Please fix it before committing.'
|
20
|
-
puts '------------------------------------------------------------------------'
|
29
|
+
Phare.puts '------------------------------------------------------------------------'
|
30
|
+
Phare.puts 'Something’s wrong with your code style. Please fix it before committing.'
|
31
|
+
Phare.puts '------------------------------------------------------------------------'
|
21
32
|
|
22
33
|
exit 1
|
23
34
|
end
|
24
35
|
end
|
25
36
|
end
|
37
|
+
|
38
|
+
def parse_options
|
39
|
+
@options = { directory: Dir.getwd }
|
40
|
+
|
41
|
+
OptionParser.new do |opts|
|
42
|
+
opts.banner = 'Usage: phare [options]'
|
43
|
+
|
44
|
+
opts.on('--directory', 'The directory in which to run the checks (default is the current directory') do |directory|
|
45
|
+
@options[:directory] = directory
|
46
|
+
end
|
47
|
+
|
48
|
+
opts.on('--skip x,y,z', 'Skip checks') do |checks|
|
49
|
+
@options[:skip] = checks.split(',').map(&:to_sym)
|
50
|
+
end
|
51
|
+
|
52
|
+
opts.on('--only x,y,z', 'Only run the specified checks') do |checks|
|
53
|
+
@options[:only] = checks.split(',').map(&:to_sym)
|
54
|
+
end
|
55
|
+
|
56
|
+
end.parse! @argv
|
57
|
+
end
|
26
58
|
end
|
27
59
|
end
|
data/lib/phare/version.rb
CHANGED
data/phare.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = Phare::VERSION
|
9
9
|
spec.authors = ['Rémi Prévost']
|
10
10
|
spec.email = ['remi@exomel.com']
|
11
|
-
spec.description = ''
|
12
|
-
spec.summary =
|
11
|
+
spec.description = 'Phare looks into your files and check for (Ruby, JavaScript and SCSS) coding style errors.'
|
12
|
+
spec.summary = spec.description
|
13
13
|
spec.homepage = 'https://github.com/mirego/phare'
|
14
14
|
spec.license = 'BSD 3-Clause'
|
15
15
|
|
@@ -20,4 +20,5 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.add_development_dependency 'bundler', '~> 1.3'
|
22
22
|
spec.add_development_dependency 'rake'
|
23
|
+
spec.add_development_dependency 'rspec', '~> 3.0.0.beta2'
|
23
24
|
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Phare::Check::JSCS do
|
4
|
+
describe :should_run? do
|
5
|
+
let(:check) { described_class.new('.') }
|
6
|
+
before do
|
7
|
+
expect(Phare).to receive(:system_output).with('which jscs').and_return(which_output)
|
8
|
+
allow(File).to receive(:exists?).with(check.config).and_return(config_exists?)
|
9
|
+
allow(Dir).to receive(:exists?).with(check.path).and_return(path_exists?)
|
10
|
+
end
|
11
|
+
|
12
|
+
context 'with found jscs command' do
|
13
|
+
let(:which_output) { 'jscs' }
|
14
|
+
let(:config_exists?) { true }
|
15
|
+
let(:path_exists?) { true }
|
16
|
+
it { expect(check).to be_able_to_run }
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'with unfound jscs command' do
|
20
|
+
let(:which_output) { '' }
|
21
|
+
let(:config_exists?) { false }
|
22
|
+
let(:path_exists?) { false }
|
23
|
+
it { expect(check).to_not be_able_to_run }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe :run do
|
28
|
+
let(:check) { described_class.new('.') }
|
29
|
+
let(:run!) { check.run }
|
30
|
+
|
31
|
+
context 'with available JSCS' do
|
32
|
+
before do
|
33
|
+
expect(check).to receive(:should_run?).and_return(true)
|
34
|
+
expect(Phare).to receive(:system).with(check.command)
|
35
|
+
expect(Phare).to receive(:last_exit_status).and_return(jscs_exit_status)
|
36
|
+
expect(check).to receive(:print_banner)
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'with check errors' do
|
40
|
+
let(:jscs_exit_status) { 0 }
|
41
|
+
it { expect { run! }.to change { check.status }.to(jscs_exit_status) }
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'without check errors' do
|
45
|
+
let(:jscs_exit_status) { 1337 }
|
46
|
+
before { expect(Phare).to receive(:puts).with("Something went wrong. Program exited with #{jscs_exit_status}.") }
|
47
|
+
it { expect { run! }.to change { check.status }.to(jscs_exit_status) }
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'with unavailable JSCS' do
|
52
|
+
before do
|
53
|
+
expect(check).to receive(:should_run?).and_return(false)
|
54
|
+
expect(Phare).to_not receive(:system).with(check.command)
|
55
|
+
expect(check).to_not receive(:print_banner)
|
56
|
+
end
|
57
|
+
|
58
|
+
it { expect { run! }.to change { check.status }.to(0) }
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Phare::Check::JSHint do
|
4
|
+
describe :should_run? do
|
5
|
+
let(:check) { described_class.new('.') }
|
6
|
+
before do
|
7
|
+
expect(Phare).to receive(:system_output).with('which jshint').and_return(which_output)
|
8
|
+
allow(File).to receive(:exists?).with(check.config).and_return(config_exists?)
|
9
|
+
allow(Dir).to receive(:exists?).with(check.path).and_return(path_exists?)
|
10
|
+
end
|
11
|
+
|
12
|
+
context 'with found jshint command' do
|
13
|
+
let(:which_output) { 'jshint' }
|
14
|
+
let(:config_exists?) { true }
|
15
|
+
let(:path_exists?) { true }
|
16
|
+
it { expect(check).to be_able_to_run }
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'with unfound jshint command' do
|
20
|
+
let(:which_output) { '' }
|
21
|
+
let(:config_exists?) { false }
|
22
|
+
let(:path_exists?) { false }
|
23
|
+
it { expect(check).to_not be_able_to_run }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe :run do
|
28
|
+
let(:check) { described_class.new('.') }
|
29
|
+
let(:run!) { check.run }
|
30
|
+
|
31
|
+
context 'with available JSHint' do
|
32
|
+
before do
|
33
|
+
expect(check).to receive(:should_run?).and_return(true)
|
34
|
+
expect(Phare).to receive(:system).with(check.command)
|
35
|
+
expect(Phare).to receive(:last_exit_status).and_return(jshint_exit_status)
|
36
|
+
expect(check).to receive(:print_banner)
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'with check errors' do
|
40
|
+
let(:jshint_exit_status) { 0 }
|
41
|
+
before { expect(Phare).to receive(:puts).with('Everything looks good from here!') }
|
42
|
+
it { expect { run! }.to change { check.status }.to(jshint_exit_status) }
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'without check errors' do
|
46
|
+
let(:jshint_exit_status) { 1337 }
|
47
|
+
before { expect(Phare).to receive(:puts).with("Something went wrong. Program exited with #{jshint_exit_status}.") }
|
48
|
+
it { expect { run! }.to change { check.status }.to(jshint_exit_status) }
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'with unavailable JSHint' do
|
53
|
+
before do
|
54
|
+
expect(check).to receive(:should_run?).and_return(false)
|
55
|
+
expect(Phare).to_not receive(:system).with(check.command)
|
56
|
+
expect(check).to_not receive(:print_banner)
|
57
|
+
end
|
58
|
+
|
59
|
+
it { expect { run! }.to change { check.status }.to(0) }
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Phare::Check::Rubocop do
|
4
|
+
describe :should_run? do
|
5
|
+
let(:check) { described_class.new('.') }
|
6
|
+
before { expect(Phare).to receive(:system_output).with('which rubocop').and_return(which_output) }
|
7
|
+
|
8
|
+
context 'with found rubocop command' do
|
9
|
+
let(:which_output) { 'rubocop' }
|
10
|
+
it { expect(check).to be_able_to_run }
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'with unfound rubocop command' do
|
14
|
+
let(:which_output) { '' }
|
15
|
+
it { expect(check).to_not be_able_to_run }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe :run do
|
20
|
+
let(:check) { described_class.new('.') }
|
21
|
+
let(:run!) { check.run }
|
22
|
+
|
23
|
+
context 'with available Rubocop' do
|
24
|
+
before do
|
25
|
+
expect(check).to receive(:should_run?).and_return(true)
|
26
|
+
expect(Phare).to receive(:system).with(check.command)
|
27
|
+
expect(Phare).to receive(:last_exit_status).and_return(rubocop_exit_status)
|
28
|
+
expect(check).to receive(:print_banner)
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'with check errors' do
|
32
|
+
let(:rubocop_exit_status) { 0 }
|
33
|
+
it { expect { run! }.to change { check.status }.to(0) }
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'without check errors' do
|
37
|
+
let(:rubocop_exit_status) { 1337 }
|
38
|
+
before { expect(Phare).to receive(:puts).with("Something went wrong. Program exited with #{rubocop_exit_status}.") }
|
39
|
+
it { expect { run! }.to change { check.status }.to(rubocop_exit_status) }
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'with unavailable Rubocop' do
|
44
|
+
before do
|
45
|
+
expect(check).to receive(:should_run?).and_return(false)
|
46
|
+
expect(Phare).to_not receive(:system).with(check.command)
|
47
|
+
expect(check).to_not receive(:print_banner)
|
48
|
+
end
|
49
|
+
|
50
|
+
it { expect { run! }.to change { check.status }.to(0) }
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Phare::Check::ScssLint do
|
4
|
+
describe :should_run? do
|
5
|
+
let(:check) { described_class.new('.') }
|
6
|
+
before do
|
7
|
+
expect(Phare).to receive(:system_output).with('which scss-lint').and_return(which_output)
|
8
|
+
allow(Dir).to receive(:exists?).with(check.path).and_return(path_exists?)
|
9
|
+
end
|
10
|
+
|
11
|
+
context 'with found scss-lint command' do
|
12
|
+
let(:which_output) { 'scss-lint' }
|
13
|
+
let(:path_exists?) { true }
|
14
|
+
it { expect(check).to be_able_to_run }
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'with unfound scss-lint command' do
|
18
|
+
let(:which_output) { '' }
|
19
|
+
let(:path_exists?) { false }
|
20
|
+
it { expect(check).to_not be_able_to_run }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe :run do
|
25
|
+
let(:check) { described_class.new('.') }
|
26
|
+
let(:run!) { check.run }
|
27
|
+
|
28
|
+
context 'with available ScssLint' do
|
29
|
+
before do
|
30
|
+
expect(check).to receive(:should_run?).and_return(true)
|
31
|
+
expect(Phare).to receive(:system).with(check.command)
|
32
|
+
expect(Phare).to receive(:last_exit_status).and_return(scsslint_exit_status)
|
33
|
+
expect(check).to receive(:print_banner)
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'with check errors' do
|
37
|
+
let(:scsslint_exit_status) { 0 }
|
38
|
+
before { expect(Phare).to receive(:puts).with('Everything looks good from here!') }
|
39
|
+
it { expect { run! }.to change { check.status }.to(scsslint_exit_status) }
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'without check errors' do
|
43
|
+
let(:scsslint_exit_status) { 1337 }
|
44
|
+
before { expect(Phare).to receive(:puts).with("Something went wrong. Program exited with #{scsslint_exit_status}.") }
|
45
|
+
it { expect { run! }.to change { check.status }.to(scsslint_exit_status) }
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'with unavailable ScssLint' do
|
50
|
+
before do
|
51
|
+
expect(check).to receive(:should_run?).and_return(false)
|
52
|
+
expect(Phare).to_not receive(:system).with(check.command)
|
53
|
+
expect(check).to_not receive(:print_banner)
|
54
|
+
end
|
55
|
+
|
56
|
+
it { expect { run! }.to change { check.status }.to(0) }
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Phare::CheckSuite do
|
4
|
+
describe :run do
|
5
|
+
let(:options) { { directory: '.' } }
|
6
|
+
let(:suite) { described_class.new(options) }
|
7
|
+
|
8
|
+
before do
|
9
|
+
Phare::CheckSuite::DEFAULT_CHECKS.values.each_with_index do |check, index|
|
10
|
+
exit_status = exit_status_proc.call(index)
|
11
|
+
allow_any_instance_of(check).to receive(:run)
|
12
|
+
allow_any_instance_of(check).to receive(:status).and_return(exit_status)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
context 'with a single failing check' do
|
17
|
+
let(:exit_status_proc) do
|
18
|
+
proc { |index| index == 2 ? 1337 : 0 }
|
19
|
+
end
|
20
|
+
|
21
|
+
it { expect { suite.run }.to change { suite.status }.to(1337) }
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'with a multiple failing checks' do
|
25
|
+
let(:exit_status_proc) do
|
26
|
+
proc { |index| (index * 500) + 20 }
|
27
|
+
end
|
28
|
+
|
29
|
+
it { expect { suite.run }.to change { suite.status }.to(20) }
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'with no failing check' do
|
33
|
+
let(:exit_status_proc) { proc { |index| 0 } }
|
34
|
+
|
35
|
+
it { expect { suite.run }.to change { suite.status }.to(0) }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe :checks do
|
40
|
+
let(:options) { { directory: '.', skip: skip, only: only } }
|
41
|
+
let(:suite) { described_class.new(options) }
|
42
|
+
let(:skip) { [] }
|
43
|
+
let(:only) { [] }
|
44
|
+
|
45
|
+
context 'with "only" option' do
|
46
|
+
let(:only) { [:rubocop, :foo, :jshint] }
|
47
|
+
it { expect(suite.checks).to eql [:rubocop, :jshint] }
|
48
|
+
end
|
49
|
+
|
50
|
+
context 'with "skip" option' do
|
51
|
+
let(:skip) { [:scsslint, :foo, :jshint] }
|
52
|
+
it { expect(suite.checks).to eql [:rubocop, :jscs] }
|
53
|
+
end
|
54
|
+
|
55
|
+
context 'with both "only" and "skip" option' do
|
56
|
+
let(:skip) { [:scsslint, :rubocop] }
|
57
|
+
let(:only) { [:scsslint, :foo, :jshint] }
|
58
|
+
it { expect(suite.checks).to eql [:scsslint, :jshint] }
|
59
|
+
end
|
60
|
+
|
61
|
+
context 'with both "only" and "skip" option' do
|
62
|
+
it { expect(suite.checks).to eql Phare::CheckSuite::DEFAULT_CHECKS.keys }
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Phare::CLI do
|
4
|
+
let(:cli) { described_class.new(env, argv) }
|
5
|
+
let(:argv) { [] }
|
6
|
+
let(:run!) { cli.run }
|
7
|
+
|
8
|
+
describe :initialize do
|
9
|
+
context 'with code check skipping' do
|
10
|
+
let(:env) { { 'SKIP_CODE_CHECK' => '1' } }
|
11
|
+
it { expect { run! }.to exit_with_code(0) }
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'without code check skipping' do
|
15
|
+
let(:env) { {} }
|
16
|
+
|
17
|
+
context 'with suite errors' do
|
18
|
+
before do
|
19
|
+
expect(cli.suite).to receive(:run)
|
20
|
+
expect(cli.suite).to receive(:status).and_return(1337)
|
21
|
+
end
|
22
|
+
|
23
|
+
it { expect { run! }.to exit_with_code(1) }
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'without suite errors' do
|
27
|
+
before do
|
28
|
+
expect(cli.suite).to receive(:run)
|
29
|
+
expect(cli.suite).to receive(:status).and_return(0)
|
30
|
+
end
|
31
|
+
|
32
|
+
it { expect { run! }.to exit_with_code(0) }
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
2
|
+
|
3
|
+
require 'rspec'
|
4
|
+
require 'phare'
|
5
|
+
|
6
|
+
RSpec.configure do |config|
|
7
|
+
config.before(:each) do
|
8
|
+
# Disable all logging
|
9
|
+
allow(Phare).to receive(:puts)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
RSpec::Matchers.define :be_able_to_run do
|
14
|
+
match do |actual|
|
15
|
+
actual.send(:should_run?) == true
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
RSpec::Matchers.define :exit_with_code do |expected_code|
|
20
|
+
actual = nil
|
21
|
+
|
22
|
+
match do |block|
|
23
|
+
begin
|
24
|
+
block.call
|
25
|
+
rescue SystemExit => e
|
26
|
+
actual = e.status
|
27
|
+
end
|
28
|
+
|
29
|
+
actual && actual == expected_code
|
30
|
+
end
|
31
|
+
|
32
|
+
failure_message do |block|
|
33
|
+
"expected block to call exit(#{expected_code}) but exit" +
|
34
|
+
(actual.nil? ? ' not called' : "(#{actual}) was called")
|
35
|
+
end
|
36
|
+
|
37
|
+
failure_message_when_negated do |block|
|
38
|
+
"expected block not to call exit(#{expected_code})"
|
39
|
+
end
|
40
|
+
|
41
|
+
description do
|
42
|
+
"expect block to call exit(#{expected_code})"
|
43
|
+
end
|
44
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: phare
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.4'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rémi Prévost
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,7 +38,22 @@ dependencies:
|
|
38
38
|
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
-
|
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.0.beta2
|
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.0.beta2
|
55
|
+
description: Phare looks into your files and check for (Ruby, JavaScript and SCSS)
|
56
|
+
coding style errors.
|
42
57
|
email:
|
43
58
|
- remi@exomel.com
|
44
59
|
executables:
|
@@ -47,7 +62,9 @@ extensions: []
|
|
47
62
|
extra_rdoc_files: []
|
48
63
|
files:
|
49
64
|
- .gitignore
|
65
|
+
- .rspec
|
50
66
|
- .rubocop.yml
|
67
|
+
- .travis.yml
|
51
68
|
- Gemfile
|
52
69
|
- LICENSE.md
|
53
70
|
- README.md
|
@@ -55,13 +72,21 @@ files:
|
|
55
72
|
- bin/phare
|
56
73
|
- lib/phare.rb
|
57
74
|
- lib/phare/check.rb
|
58
|
-
- lib/phare/
|
59
|
-
- lib/phare/
|
60
|
-
- lib/phare/
|
61
|
-
- lib/phare/
|
75
|
+
- lib/phare/check/jscs.rb
|
76
|
+
- lib/phare/check/jshint.rb
|
77
|
+
- lib/phare/check/rubocop.rb
|
78
|
+
- lib/phare/check/scss_lint.rb
|
79
|
+
- lib/phare/check_suite.rb
|
62
80
|
- lib/phare/cli.rb
|
63
81
|
- lib/phare/version.rb
|
64
82
|
- phare.gemspec
|
83
|
+
- spec/phare/check/jscs_spec.rb
|
84
|
+
- spec/phare/check/jshint_spec.rb
|
85
|
+
- spec/phare/check/rubocop_spec.rb
|
86
|
+
- spec/phare/check/scss_lint_spec.rb
|
87
|
+
- spec/phare/check_suite_spec.rb
|
88
|
+
- spec/phare/cli_spec.rb
|
89
|
+
- spec/spec_helper.rb
|
65
90
|
homepage: https://github.com/mirego/phare
|
66
91
|
licenses:
|
67
92
|
- BSD 3-Clause
|
@@ -85,5 +110,13 @@ rubyforge_project:
|
|
85
110
|
rubygems_version: 2.1.0
|
86
111
|
signing_key:
|
87
112
|
specification_version: 4
|
88
|
-
summary:
|
89
|
-
|
113
|
+
summary: Phare looks into your files and check for (Ruby, JavaScript and SCSS) coding
|
114
|
+
style errors.
|
115
|
+
test_files:
|
116
|
+
- spec/phare/check/jscs_spec.rb
|
117
|
+
- spec/phare/check/jshint_spec.rb
|
118
|
+
- spec/phare/check/rubocop_spec.rb
|
119
|
+
- spec/phare/check/scss_lint_spec.rb
|
120
|
+
- spec/phare/check_suite_spec.rb
|
121
|
+
- spec/phare/cli_spec.rb
|
122
|
+
- spec/spec_helper.rb
|
@@ -1,41 +0,0 @@
|
|
1
|
-
module Phare
|
2
|
-
module Checks
|
3
|
-
class JavaScriptJSCS
|
4
|
-
attr_reader :status
|
5
|
-
|
6
|
-
def initialize(directory)
|
7
|
-
@config = File.expand_path("#{directory}.jscs.json", __FILE__)
|
8
|
-
@path = File.expand_path("#{directory}app/assets", __FILE__)
|
9
|
-
@command = "jscs #{@path}"
|
10
|
-
end
|
11
|
-
|
12
|
-
def run
|
13
|
-
if should_run?
|
14
|
-
print_banner
|
15
|
-
system(@command)
|
16
|
-
@status = $CHILD_STATUS.exitstatus
|
17
|
-
|
18
|
-
unless @status == 0
|
19
|
-
puts "Something went wrong. Program exited with #{@status}"
|
20
|
-
end
|
21
|
-
|
22
|
-
puts ''
|
23
|
-
else
|
24
|
-
@status = 0
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
protected
|
29
|
-
|
30
|
-
def should_run?
|
31
|
-
!`which jscs`.empty? && File.exists?(@config) && Dir.exists?(@path)
|
32
|
-
end
|
33
|
-
|
34
|
-
def print_banner
|
35
|
-
puts '---------------------------------------------'
|
36
|
-
puts 'Running JSCS to check for JavaScript style…'
|
37
|
-
puts '---------------------------------------------'
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
@@ -1,44 +0,0 @@
|
|
1
|
-
module Phare
|
2
|
-
module Checks
|
3
|
-
class JavaScriptJSHint
|
4
|
-
attr_reader :status
|
5
|
-
|
6
|
-
def initialize(directory)
|
7
|
-
@config = File.expand_path("#{directory}.jshintrc", __FILE__)
|
8
|
-
@path = File.expand_path("#{directory}app/assets/javascripts", __FILE__)
|
9
|
-
@glob = File.join(@path, '**/*')
|
10
|
-
@command = "jshint --config #{@config} --extra-ext .js,.es6.js #{@glob}"
|
11
|
-
end
|
12
|
-
|
13
|
-
def run
|
14
|
-
if should_run?
|
15
|
-
print_banner
|
16
|
-
system(@command)
|
17
|
-
@status = $CHILD_STATUS.exitstatus
|
18
|
-
|
19
|
-
if @status == 0
|
20
|
-
puts 'No code style errors found.'
|
21
|
-
else
|
22
|
-
puts "Something went wrong. Program exited with #{@status}"
|
23
|
-
end
|
24
|
-
|
25
|
-
puts ''
|
26
|
-
else
|
27
|
-
@status = 0
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
protected
|
32
|
-
|
33
|
-
def should_run?
|
34
|
-
!`which jshint`.empty? && File.exists?(@config) && Dir.exists?(@path)
|
35
|
-
end
|
36
|
-
|
37
|
-
def print_banner
|
38
|
-
puts '---------------------------------------------'
|
39
|
-
puts 'Running JSHint to check for JavaScript style…'
|
40
|
-
puts '---------------------------------------------'
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
module Phare
|
2
|
-
module Checks
|
3
|
-
class RubyRubocop
|
4
|
-
attr_reader :status
|
5
|
-
|
6
|
-
def initialize
|
7
|
-
@command = 'rubocop'
|
8
|
-
end
|
9
|
-
|
10
|
-
def run
|
11
|
-
if should_run?
|
12
|
-
print_banner
|
13
|
-
system(@command)
|
14
|
-
@status = $CHILD_STATUS.exitstatus
|
15
|
-
|
16
|
-
unless @status == 0
|
17
|
-
puts "Something went wrong. Program exited with #{@status}"
|
18
|
-
end
|
19
|
-
|
20
|
-
puts ''
|
21
|
-
else
|
22
|
-
@status = 0
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
protected
|
27
|
-
|
28
|
-
def should_run?
|
29
|
-
!`which rubocop`.empty?
|
30
|
-
end
|
31
|
-
|
32
|
-
def print_banner
|
33
|
-
puts '----------------------------------------'
|
34
|
-
puts 'Running Rubocop to check for Ruby style…'
|
35
|
-
puts '----------------------------------------'
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
@@ -1,42 +0,0 @@
|
|
1
|
-
module Phare
|
2
|
-
module Checks
|
3
|
-
class ScssLint
|
4
|
-
attr_reader :status
|
5
|
-
|
6
|
-
def initialize(directory)
|
7
|
-
@path = File.expand_path("#{directory}app/assets/stylesheets", __FILE__)
|
8
|
-
@command = "scss-lint #{@path}"
|
9
|
-
end
|
10
|
-
|
11
|
-
def run
|
12
|
-
if should_run?
|
13
|
-
print_banner
|
14
|
-
system(@command)
|
15
|
-
@status = $CHILD_STATUS.exitstatus
|
16
|
-
|
17
|
-
if @status == 0
|
18
|
-
puts 'No code style errors found.'
|
19
|
-
else
|
20
|
-
puts "Something went wrong. Program exited with #{@status}"
|
21
|
-
end
|
22
|
-
|
23
|
-
puts ''
|
24
|
-
else
|
25
|
-
@status = 0
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
protected
|
30
|
-
|
31
|
-
def should_run?
|
32
|
-
!`which scss-lint`.empty? && Dir.exists?(@path)
|
33
|
-
end
|
34
|
-
|
35
|
-
def print_banner
|
36
|
-
puts '------------------------------------------'
|
37
|
-
puts 'Running SCSS-Lint to check for SCSS style…'
|
38
|
-
puts '------------------------------------------'
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|