phare 0.4 → 0.5
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 +8 -2
- data/lib/phare/check.rb +27 -0
- data/lib/phare/check/jscs.rb +18 -4
- data/lib/phare/check/jshint.rb +18 -4
- data/lib/phare/check/rubocop.rb +9 -3
- data/lib/phare/check/scss_lint.rb +14 -4
- data/lib/phare/check_suite.rb +1 -1
- data/lib/phare/cli.rb +4 -0
- data/lib/phare/version.rb +1 -1
- data/spec/phare/check/jscs_spec.rb +15 -1
- data/spec/phare/check/jshint_spec.rb +3 -1
- data/spec/phare/check/rubocop_spec.rb +14 -1
- data/spec/phare/check/scss_lint_spec.rb +14 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b1d1e596a5d40fef1d29fa89cd662336f7fd45e7
|
4
|
+
data.tar.gz: 81dddc44763f470efd54222f21b72f48251be8fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ce38e47371b89624a02538c0cca7a08ab1b15874f6fc566f2450f8e992a2e5ca3943b883a4771f60f4d8dbf6a36479fa1cc86e4790b59afe2ff2298912958b18
|
7
|
+
data.tar.gz: 073eeb502d9612627efedf47a559ded08803378b3c72235819d0fce5e2e245afa6ff89cedf8768db12219a9413b76ccdcc21d95938b50286790e57dac88e5ad1
|
data/README.md
CHANGED
@@ -3,9 +3,10 @@
|
|
3
3
|
<img src="http://i.imgur.com/9Pa2RgE.png" alt="Phare" />
|
4
4
|
</a>
|
5
5
|
<br />
|
6
|
-
Phare looks into your files and check for coding style errors.
|
6
|
+
Phare looks into your files and check for coding style errors.
|
7
7
|
<br /><br />
|
8
8
|
<a href="https://rubygems.org/gems/phare"><img src="https://badge.fury.io/rb/phare.png" /></a>
|
9
|
+
<a href="https://travis-ci.org/mirego/phare"><img src="https://travis-ci.org/mirego/phare.png?branch=master" /></a>
|
9
10
|
</p>
|
10
11
|
|
11
12
|
## Installation
|
@@ -36,13 +37,18 @@ Phare provides an executable named `phare`. You can just use it as is:
|
|
36
37
|
$ phare
|
37
38
|
```
|
38
39
|
|
39
|
-
One of the best
|
40
|
+
One of the best ways to use Phare is by hooking it to your version control commit process. For example, with `git`:
|
40
41
|
|
41
42
|
```bash
|
42
43
|
$ bundle binstubs phare
|
43
44
|
$ ln -s "`pwd`/bin/phare" .git/hooks/pre-commit
|
44
45
|
```
|
45
46
|
|
47
|
+
## Contributors
|
48
|
+
|
49
|
+
* [@remiprev](https://github.com/remiprev)
|
50
|
+
* [@garno](https://github.com/garno)
|
51
|
+
|
46
52
|
## License
|
47
53
|
|
48
54
|
`Phare` is © 2014 [Mirego](http://www.mirego.com) and may be freely distributed under the [New BSD license](http://opensource.org/licenses/BSD-3-Clause). See the [`LICENSE.md`](https://github.com/mirego/phare/blob/master/LICENSE.md) file.
|
data/lib/phare/check.rb
CHANGED
@@ -20,6 +20,33 @@ module Phare
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
+
def tree_changed?
|
24
|
+
@options[:diff] && tree_changes && tree_changes.any?
|
25
|
+
end
|
26
|
+
|
27
|
+
def tree_changes
|
28
|
+
@modified_files ||= Phare.system_output('git status -s').split("\n").reduce([]) do |memo, diff|
|
29
|
+
filename = diff.split(' ').last
|
30
|
+
|
31
|
+
memo << filename if @extensions.include?(File.extname(filename))
|
32
|
+
memo
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def should_run?
|
37
|
+
should_run = binary_exists?
|
38
|
+
|
39
|
+
[:configuration_exists?, :arguments_exists?].each do |condition|
|
40
|
+
should_run = should_run && send(condition) if respond_to?(condition, true)
|
41
|
+
end
|
42
|
+
|
43
|
+
if @options[:diff]
|
44
|
+
should_run = should_run && tree_changed?
|
45
|
+
end
|
46
|
+
|
47
|
+
should_run
|
48
|
+
end
|
49
|
+
|
23
50
|
protected
|
24
51
|
|
25
52
|
def print_success_message
|
data/lib/phare/check/jscs.rb
CHANGED
@@ -4,19 +4,33 @@ module Phare
|
|
4
4
|
class JSCS < Check
|
5
5
|
attr_reader :config, :path
|
6
6
|
|
7
|
-
def initialize(directory)
|
7
|
+
def initialize(directory, options = {})
|
8
8
|
@config = File.expand_path("#{directory}.jscs.json", __FILE__)
|
9
9
|
@path = File.expand_path("#{directory}app/assets", __FILE__)
|
10
|
+
@extensions = %w(.js)
|
11
|
+
@options = options
|
10
12
|
end
|
11
13
|
|
12
14
|
def command
|
13
|
-
|
15
|
+
if tree_changed?
|
16
|
+
"jscs #{tree_changes.join(' ')}"
|
17
|
+
else
|
18
|
+
"jscs #{@path}"
|
19
|
+
end
|
14
20
|
end
|
15
21
|
|
16
22
|
protected
|
17
23
|
|
18
|
-
def
|
19
|
-
!Phare.system_output('which jscs').empty?
|
24
|
+
def binary_exists?
|
25
|
+
!Phare.system_output('which jscs').empty?
|
26
|
+
end
|
27
|
+
|
28
|
+
def configuration_exists?
|
29
|
+
File.exists?(@config)
|
30
|
+
end
|
31
|
+
|
32
|
+
def argument_exists?
|
33
|
+
tree_changed? || Dir.exists?(@path)
|
20
34
|
end
|
21
35
|
|
22
36
|
def print_banner
|
data/lib/phare/check/jshint.rb
CHANGED
@@ -4,20 +4,34 @@ module Phare
|
|
4
4
|
class JSHint < Check
|
5
5
|
attr_reader :config, :path
|
6
6
|
|
7
|
-
def initialize(directory)
|
7
|
+
def initialize(directory, options = {})
|
8
8
|
@config = File.expand_path("#{directory}.jshintrc", __FILE__)
|
9
9
|
@path = File.expand_path("#{directory}app/assets/javascripts", __FILE__)
|
10
10
|
@glob = File.join(@path, '**/*')
|
11
|
+
@extensions = %w(.js .es6.js)
|
12
|
+
@options = options
|
11
13
|
end
|
12
14
|
|
13
15
|
def command
|
14
|
-
|
16
|
+
if tree_changed?
|
17
|
+
"jshint --config #{@config} --extra-ext #{@extensions.join(',')} #{tree_changes.join(' ')}"
|
18
|
+
else
|
19
|
+
"jshint --config #{@config} --extra-ext #{@extensions.join(',')} #{@glob}"
|
20
|
+
end
|
15
21
|
end
|
16
22
|
|
17
23
|
protected
|
18
24
|
|
19
|
-
def
|
20
|
-
!Phare.system_output('which jshint').empty?
|
25
|
+
def binary_exists?
|
26
|
+
!Phare.system_output('which jshint').empty?
|
27
|
+
end
|
28
|
+
|
29
|
+
def configuration_exists?
|
30
|
+
File.exists?(@config)
|
31
|
+
end
|
32
|
+
|
33
|
+
def arguments_exists?
|
34
|
+
tree_changed? || Dir.exists?(@path)
|
21
35
|
end
|
22
36
|
|
23
37
|
def print_banner
|
data/lib/phare/check/rubocop.rb
CHANGED
@@ -2,17 +2,23 @@
|
|
2
2
|
module Phare
|
3
3
|
class Check
|
4
4
|
class Rubocop < Check
|
5
|
-
def initialize(directory)
|
5
|
+
def initialize(directory, options = {})
|
6
6
|
@path = directory
|
7
|
+
@extensions = %w(.rb)
|
8
|
+
@options = options
|
7
9
|
end
|
8
10
|
|
9
11
|
def command
|
10
|
-
|
12
|
+
if tree_changed?
|
13
|
+
"rubocop #{tree_changes.join(' ')}"
|
14
|
+
else
|
15
|
+
'rubocop'
|
16
|
+
end
|
11
17
|
end
|
12
18
|
|
13
19
|
protected
|
14
20
|
|
15
|
-
def
|
21
|
+
def binary_exists?
|
16
22
|
!Phare.system_output('which rubocop').empty?
|
17
23
|
end
|
18
24
|
|
@@ -4,18 +4,28 @@ module Phare
|
|
4
4
|
class ScssLint < Check
|
5
5
|
attr_reader :path
|
6
6
|
|
7
|
-
def initialize(directory)
|
7
|
+
def initialize(directory, options = {})
|
8
8
|
@path = File.expand_path("#{directory}app/assets/stylesheets", __FILE__)
|
9
|
+
@extensions = %w(.css .scss)
|
10
|
+
@options = options
|
9
11
|
end
|
10
12
|
|
11
13
|
def command
|
12
|
-
|
14
|
+
if tree_changed?
|
15
|
+
"scss-lint #{tree_changes.join(' ')}"
|
16
|
+
else
|
17
|
+
"scss-lint #{@path}"
|
18
|
+
end
|
13
19
|
end
|
14
20
|
|
15
21
|
protected
|
16
22
|
|
17
|
-
def
|
18
|
-
!Phare.system_output('which scss-lint').empty?
|
23
|
+
def binary_exists?
|
24
|
+
!Phare.system_output('which scss-lint').empty?
|
25
|
+
end
|
26
|
+
|
27
|
+
def arguments_exists?
|
28
|
+
tree_changed? || Dir.exists?(@path)
|
19
29
|
end
|
20
30
|
|
21
31
|
def print_banner
|
data/lib/phare/check_suite.rb
CHANGED
data/lib/phare/cli.rb
CHANGED
data/lib/phare/version.rb
CHANGED
@@ -22,6 +22,7 @@ describe Phare::Check::JSCS do
|
|
22
22
|
let(:path_exists?) { false }
|
23
23
|
it { expect(check).to_not be_able_to_run }
|
24
24
|
end
|
25
|
+
|
25
26
|
end
|
26
27
|
|
27
28
|
describe :run do
|
@@ -29,9 +30,11 @@ describe Phare::Check::JSCS do
|
|
29
30
|
let(:run!) { check.run }
|
30
31
|
|
31
32
|
context 'with available JSCS' do
|
33
|
+
let(:command) { check.command }
|
34
|
+
|
32
35
|
before do
|
33
36
|
expect(check).to receive(:should_run?).and_return(true)
|
34
|
-
expect(Phare).to receive(:system).with(
|
37
|
+
expect(Phare).to receive(:system).with(command)
|
35
38
|
expect(Phare).to receive(:last_exit_status).and_return(jscs_exit_status)
|
36
39
|
expect(check).to receive(:print_banner)
|
37
40
|
end
|
@@ -46,6 +49,17 @@ describe Phare::Check::JSCS do
|
|
46
49
|
before { expect(Phare).to receive(:puts).with("Something went wrong. Program exited with #{jscs_exit_status}.") }
|
47
50
|
it { expect { run! }.to change { check.status }.to(jscs_exit_status) }
|
48
51
|
end
|
52
|
+
|
53
|
+
context 'with --diff option' do
|
54
|
+
let(:check) { described_class.new('.', diff: true) }
|
55
|
+
let(:files) { ['foo.js', 'bar.js'] }
|
56
|
+
let(:command) { "jscs #{files.join(' ')}" }
|
57
|
+
let(:jscs_exit_status) { 1337 }
|
58
|
+
|
59
|
+
before { expect(check).to receive(:tree_changes).and_return(files).at_least(:once) }
|
60
|
+
|
61
|
+
it { expect { run! }.to change { check.status }.to(jscs_exit_status) }
|
62
|
+
end
|
49
63
|
end
|
50
64
|
|
51
65
|
context 'with unavailable JSCS' do
|
@@ -29,9 +29,11 @@ describe Phare::Check::JSHint do
|
|
29
29
|
let(:run!) { check.run }
|
30
30
|
|
31
31
|
context 'with available JSHint' do
|
32
|
+
let(:command) { check.command }
|
33
|
+
|
32
34
|
before do
|
33
35
|
expect(check).to receive(:should_run?).and_return(true)
|
34
|
-
expect(Phare).to receive(:system).with(
|
36
|
+
expect(Phare).to receive(:system).with(command)
|
35
37
|
expect(Phare).to receive(:last_exit_status).and_return(jshint_exit_status)
|
36
38
|
expect(check).to receive(:print_banner)
|
37
39
|
end
|
@@ -21,9 +21,11 @@ describe Phare::Check::Rubocop do
|
|
21
21
|
let(:run!) { check.run }
|
22
22
|
|
23
23
|
context 'with available Rubocop' do
|
24
|
+
let(:command) { check.command }
|
25
|
+
|
24
26
|
before do
|
25
27
|
expect(check).to receive(:should_run?).and_return(true)
|
26
|
-
expect(Phare).to receive(:system).with(
|
28
|
+
expect(Phare).to receive(:system).with(command)
|
27
29
|
expect(Phare).to receive(:last_exit_status).and_return(rubocop_exit_status)
|
28
30
|
expect(check).to receive(:print_banner)
|
29
31
|
end
|
@@ -38,6 +40,17 @@ describe Phare::Check::Rubocop do
|
|
38
40
|
before { expect(Phare).to receive(:puts).with("Something went wrong. Program exited with #{rubocop_exit_status}.") }
|
39
41
|
it { expect { run! }.to change { check.status }.to(rubocop_exit_status) }
|
40
42
|
end
|
43
|
+
|
44
|
+
context 'with --diff option' do
|
45
|
+
let(:check) { described_class.new('.', diff: true) }
|
46
|
+
let(:files) { ['foo.rb', 'bar.rb'] }
|
47
|
+
let(:command) { "rubocop #{files.join(' ')}" }
|
48
|
+
let(:rubocop_exit_status) { 1337 }
|
49
|
+
|
50
|
+
before { expect(check).to receive(:tree_changes).and_return(files).at_least(:once) }
|
51
|
+
|
52
|
+
it { expect { run! }.to change { check.status }.to(rubocop_exit_status) }
|
53
|
+
end
|
41
54
|
end
|
42
55
|
|
43
56
|
context 'with unavailable Rubocop' do
|
@@ -26,9 +26,11 @@ describe Phare::Check::ScssLint do
|
|
26
26
|
let(:run!) { check.run }
|
27
27
|
|
28
28
|
context 'with available ScssLint' do
|
29
|
+
let(:command) { check.command }
|
30
|
+
|
29
31
|
before do
|
30
32
|
expect(check).to receive(:should_run?).and_return(true)
|
31
|
-
expect(Phare).to receive(:system).with(
|
33
|
+
expect(Phare).to receive(:system).with(command)
|
32
34
|
expect(Phare).to receive(:last_exit_status).and_return(scsslint_exit_status)
|
33
35
|
expect(check).to receive(:print_banner)
|
34
36
|
end
|
@@ -44,6 +46,17 @@ describe Phare::Check::ScssLint do
|
|
44
46
|
before { expect(Phare).to receive(:puts).with("Something went wrong. Program exited with #{scsslint_exit_status}.") }
|
45
47
|
it { expect { run! }.to change { check.status }.to(scsslint_exit_status) }
|
46
48
|
end
|
49
|
+
|
50
|
+
context 'with --diff option' do
|
51
|
+
let(:check) { described_class.new('.', diff: true) }
|
52
|
+
let(:files) { ['foo.css', 'bar.css.scss'] }
|
53
|
+
let(:command) { "scss-lint #{files.join(' ')}" }
|
54
|
+
let(:scsslint_exit_status) { 1337 }
|
55
|
+
|
56
|
+
before { expect(check).to receive(:tree_changes).and_return(files).at_least(:once) }
|
57
|
+
|
58
|
+
it { expect { run! }.to change { check.status }.to(scsslint_exit_status) }
|
59
|
+
end
|
47
60
|
end
|
48
61
|
|
49
62
|
context 'with unavailable ScssLint' do
|
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.5'
|
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-04-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|