phare 0.7.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5d342f532b5c065a64dbc6b1eba2cab4cf1f8b68
4
- data.tar.gz: 171dc0037a16399f7937429fe222624cc53ef57d
3
+ metadata.gz: 32cfbf8d6a2dd16df575bfa14e2428449808a1b7
4
+ data.tar.gz: dc0e226459f1b14eece856393b4a8d66c6ebc06b
5
5
  SHA512:
6
- metadata.gz: ce98e8dfc1bb05d124bd73df59583b20abbc666a4a9c99d2ad4a088394822569eae6185065eaacdf30aeeb7b9bbbcc6fb70cb0f514d21c05676b71e882a2feac
7
- data.tar.gz: 3a14e83a6ef194f4399f44aa0ed6bb348b3694c4faa84544b77a9cf8da2fa98696bccb63ebdd0ba7f63577cec010af8030a8a3eea9cbd7d49bd2ece26a88fbc4
6
+ metadata.gz: f462e483cf50a306ced260ba16750d871af4a7b99662b51ae4301e89314f01a6d337a9acdca5430aebf9c3f441c341b795097c24739c8e2417ce8064c61502a5
7
+ data.tar.gz: 2390db0d20b16ffc98c3d33dc4bfb0912699881015f7e024da7e7876088d2dd65c6ffa3f7a0ba8b53669be9d82e039e744c2362cf17ef5a6efe03f9f0b153d43
data/.travis.yml CHANGED
@@ -3,7 +3,6 @@ language: ruby
3
3
  rvm:
4
4
  - 2.1.1
5
5
  - 2.0.0
6
- - 1.9.3
7
6
 
8
7
  script:
9
8
  - 'echo "Checking code style" && ./bin/phare'
data/LICENSE.md CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014, Mirego
1
+ Copyright (c) 2014-2015, Mirego
2
2
  All rights reserved.
3
3
 
4
4
  Redistribution and use in source and binary forms, with or without
data/README.md CHANGED
@@ -122,7 +122,7 @@ skip:
122
122
 
123
123
  ## License
124
124
 
125
- `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.
125
+ `Phare` is © 2014-2015 [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.
126
126
 
127
127
  The lighthouse logo is based on [this lovely icon](http://thenounproject.com/term/lighthouse/11608/) by [Nick Lacke](http://thenounproject.com/nicklacke), from The Noun Project.
128
128
 
data/lib/phare.rb CHANGED
@@ -8,9 +8,8 @@ require 'phare/git'
8
8
 
9
9
  require 'phare/check'
10
10
  require 'phare/check/rubocop'
11
- require 'phare/check/scss_lint'
12
- require 'phare/check/jshint'
13
- require 'phare/check/jscs'
11
+ require 'phare/check/stylelint'
12
+ require 'phare/check/eslint'
14
13
 
15
14
  require 'phare/check_suite'
16
15
 
@@ -0,0 +1,59 @@
1
+ # encoding: utf-8
2
+ module Phare
3
+ class Check
4
+ class Eslint < Check
5
+ GLOBAL_BINARY = 'eslint'.freeze
6
+ LOCAL_BINARY = 'node_modules/.bin/eslint'.freeze
7
+
8
+ attr_reader :config, :path
9
+
10
+ def initialize(directory, options = {})
11
+ @directory = directory
12
+ @config = File.expand_path("#{directory}.eslintrc", __FILE__)
13
+ @path = File.expand_path("#{directory}app/assets/javascripts", __FILE__)
14
+ @extensions = %w(.js)
15
+ @options = options
16
+
17
+ super
18
+ end
19
+
20
+ def command
21
+ "#{binary} #{input}"
22
+ end
23
+
24
+ protected
25
+
26
+ def configuration_exists?
27
+ File.exist?(@config)
28
+ end
29
+
30
+ def binary
31
+ local_binary_exists? ? @directory + LOCAL_BINARY : GLOBAL_BINARY
32
+ end
33
+
34
+ def binary_exists?
35
+ local_binary_exists? || global_binary_exists?
36
+ end
37
+
38
+ def local_binary_exists?
39
+ !Phare.system_output("which #{@directory}#{LOCAL_BINARY}").empty?
40
+ end
41
+
42
+ def global_binary_exists?
43
+ !Phare.system_output("which #{GLOBAL_BINARY}").empty?
44
+ end
45
+
46
+ def input
47
+ @tree.changed? ? files_to_check.join(' ') : "'#{@path}/**/*#{@extensions.first}'"
48
+ end
49
+
50
+ def arguments_exists?
51
+ @tree.changed? || Dir.exist?(@path)
52
+ end
53
+
54
+ def print_banner
55
+ Phare.banner 'Running ESLint to check for JavaScript style…'
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,59 @@
1
+ # encoding: utf-8
2
+ module Phare
3
+ class Check
4
+ class Stylelint < Check
5
+ GLOBAL_BINARY = 'stylelint'.freeze
6
+ LOCAL_BINARY = 'node_modules/.bin/stylelint'.freeze
7
+
8
+ attr_reader :config, :path
9
+
10
+ def initialize(directory, options = {})
11
+ @directory = directory
12
+ @config = File.expand_path("#{directory}.stylelintrc", __FILE__)
13
+ @path = File.expand_path("#{directory}app/assets/stylesheets", __FILE__)
14
+ @extensions = %w(.scss)
15
+ @options = options
16
+
17
+ super
18
+ end
19
+
20
+ def command
21
+ "#{binary} #{input}"
22
+ end
23
+
24
+ protected
25
+
26
+ def configuration_exists?
27
+ File.exist?(@config)
28
+ end
29
+
30
+ def binary
31
+ local_binary_exists? ? @directory + LOCAL_BINARY : GLOBAL_BINARY
32
+ end
33
+
34
+ def binary_exists?
35
+ local_binary_exists? || global_binary_exists?
36
+ end
37
+
38
+ def local_binary_exists?
39
+ !Phare.system_output("which #{@directory}#{LOCAL_BINARY}").empty?
40
+ end
41
+
42
+ def global_binary_exists?
43
+ !Phare.system_output("which #{GLOBAL_BINARY}").empty?
44
+ end
45
+
46
+ def input
47
+ @tree.changed? ? files_to_check.join(' ') : "'#{@path}/**/*#{@extensions.first}'"
48
+ end
49
+
50
+ def arguments_exists?
51
+ @tree.changed? || Dir.exist?(@path)
52
+ end
53
+
54
+ def print_banner
55
+ Phare.banner 'Running Stylelint to check for SCSS style…'
56
+ end
57
+ end
58
+ end
59
+ end
@@ -4,9 +4,8 @@ module Phare
4
4
 
5
5
  DEFAULT_CHECKS = {
6
6
  rubocop: Check::Rubocop,
7
- scsslint: Check::ScssLint,
8
- jshint: Check::JSHint,
9
- jscs: Check::JSCS
7
+ stylelint: Check::Stylelint,
8
+ eslint: Check::Eslint
10
9
  }
11
10
 
12
11
  def initialize(options = {})
data/lib/phare/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Phare
2
- VERSION = '0.7.1'
2
+ VERSION = '1.0.0'
3
3
  end
@@ -1,23 +1,34 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Phare::Check::JSHint do
4
- let(:described_class) { Phare::Check::JSHint }
3
+ describe Phare::Check::Eslint do
4
+ let(:described_class) { Phare::Check::Eslint }
5
5
 
6
6
  describe :should_run? do
7
7
  let(:check) { described_class.new('.') }
8
+ let(:config_exists?) { true }
9
+ let(:path_exists?) { true }
10
+ let(:local_which_output) { '' }
11
+ let(:global_which_output) { '' }
8
12
  before do
9
- expect(Phare).to receive(:system_output).with('which jshint').and_return(which_output)
13
+ allow(Phare).to receive(:system_output).with('which eslint').and_return(global_which_output)
14
+ allow(Phare).to receive(:system_output).with('which .node_modules/.bin/eslint').and_return(local_which_output)
10
15
  allow(File).to receive(:exist?).with(check.config).and_return(config_exists?)
11
16
  allow(Dir).to receive(:exist?).with(check.path).and_return(path_exists?)
12
17
  end
13
18
 
14
- context 'with found jshint command' do
15
- let(:which_output) { 'jshint' }
16
- let(:config_exists?) { true }
17
- let(:path_exists?) { true }
18
- it { expect(check).to be_able_to_run }
19
+ context 'with found eslint command' do
20
+ context 'for a local eslint' do
21
+ let(:local_which_output) { 'node_modules/.bin/eslint' }
22
+ it { expect(check).to be_able_to_run }
23
+ end
24
+
25
+ context 'for a global eslint' do
26
+ let(:global_which_output) { 'eslint' }
27
+ it { expect(check).to be_able_to_run }
28
+ end
19
29
 
20
30
  context 'with only excluded files and the --diff option' do
31
+ let(:global_which_output) { 'eslint' }
21
32
  let(:check) { described_class.new('.', diff: true) }
22
33
  let(:files) { ['foo.js'] }
23
34
 
@@ -30,8 +41,7 @@ describe Phare::Check::JSHint do
30
41
  end
31
42
  end
32
43
 
33
- context 'with unfound jshint command' do
34
- let(:which_output) { '' }
44
+ context 'with unfound eslint command' do
35
45
  let(:config_exists?) { false }
36
46
  let(:path_exists?) { false }
37
47
  it { expect(check).to_not be_able_to_run }
@@ -42,62 +52,58 @@ describe Phare::Check::JSHint do
42
52
  let(:check) { described_class.new('.') }
43
53
  let(:run!) { check.run }
44
54
 
45
- context 'with available JSHint' do
55
+ context 'with available Eslint' do
46
56
  let(:command) { check.command }
47
- let(:directory) { '.' }
48
- let(:expanded_path) { '.jshintrc' }
49
57
 
50
58
  before do
51
- expect(File).to receive(:expand_path).with("#{directory}app/assets/javascripts", anything).once.and_call_original
52
- expect(File).to receive(:expand_path).with("#{directory}.jshintrc", anything).once.and_return(expanded_path)
53
59
  expect(check).to receive(:should_run?).and_return(true)
54
60
  expect(Phare).to receive(:system).with(command)
55
- expect(Phare).to receive(:last_exit_status).and_return(jshint_exit_status)
61
+ expect(Phare).to receive(:last_exit_status).and_return(eslint_exit_status)
56
62
  expect(check).to receive(:print_banner)
57
63
  end
58
64
 
59
- context 'with check errors' do
60
- let(:jshint_exit_status) { 0 }
65
+ context 'without check errors' do
66
+ let(:eslint_exit_status) { 0 }
61
67
  before { expect(Phare).to receive(:puts).with('Everything looks good from here!') }
62
- it { expect { run! }.to change { check.status }.to(jshint_exit_status) }
68
+ it { expect { run! }.to change { check.status }.to(eslint_exit_status) }
63
69
  end
64
70
 
65
- context 'without check errors' do
66
- let(:jshint_exit_status) { 1337 }
67
- before { expect(Phare).to receive(:puts).with("Something went wrong. Program exited with #{jshint_exit_status}.") }
68
- it { expect { run! }.to change { check.status }.to(jshint_exit_status) }
71
+ context 'with check errors' do
72
+ let(:eslint_exit_status) { 1 }
73
+ before { expect(Phare).to receive(:puts).with("Something went wrong. Program exited with #{eslint_exit_status}.") }
74
+ it { expect { run! }.to change { check.status }.to(eslint_exit_status) }
69
75
  end
70
76
 
71
77
  context 'with --diff option' do
72
- let(:check) { described_class.new(directory, diff: true) }
73
- let(:files) { ['app/foo.js', 'bar.js'] }
74
- let(:jshint_exit_status) { 1337 }
78
+ let(:check) { described_class.new('.', diff: true) }
79
+ let(:files) { ['foo.rb', 'bar.rb'] }
80
+ let(:eslint_exit_status) { 0 }
75
81
 
76
82
  context 'without exclusions' do
77
- let(:command) { "jshint --config #{expanded_path} --extra-ext .js,.es6 #{files.join(' ')}" }
83
+ let(:command) { "eslint #{files.join(' ')}" }
78
84
 
79
85
  before do
80
86
  expect(check.tree).to receive(:changes).and_return(files).at_least(:once)
81
87
  expect(check).to receive(:excluded_files).and_return([]).once
82
88
  end
83
89
 
84
- it { expect { run! }.to change { check.status }.to(jshint_exit_status) }
90
+ it { expect { run! }.to change { check.status }.to(eslint_exit_status) }
85
91
  end
86
92
 
87
93
  context 'with exclusions' do
88
- let(:command) { "jshint --config #{expanded_path} --extra-ext .js,.es6 bar.js" }
94
+ let(:command) { 'eslint bar.rb' }
89
95
 
90
96
  before do
91
- expect(check).to receive(:excluded_files).and_return(['app/foo.js']).once
97
+ expect(check).to receive(:excluded_files).and_return(['foo.rb']).once
92
98
  expect(check.tree).to receive(:changes).and_return(files).at_least(:once)
93
99
  end
94
100
 
95
- it { expect { run! }.to change { check.status }.to(jshint_exit_status) }
101
+ it { expect { run! }.to change { check.status }.to(eslint_exit_status) }
96
102
  end
97
103
  end
98
104
  end
99
105
 
100
- context 'with unavailable JSHint' do
106
+ context 'with unavailable Eslint' do
101
107
  before do
102
108
  expect(check).to receive(:should_run?).and_return(false)
103
109
  expect(Phare).to_not receive(:system).with(check.command)
@@ -1,21 +1,34 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Phare::Check::ScssLint do
4
- let(:described_class) { Phare::Check::ScssLint }
3
+ describe Phare::Check::Stylelint do
4
+ let(:described_class) { Phare::Check::Stylelint }
5
5
 
6
6
  describe :should_run? do
7
7
  let(:check) { described_class.new('.') }
8
+ let(:config_exists?) { true }
9
+ let(:path_exists?) { true }
10
+ let(:local_which_output) { '' }
11
+ let(:global_which_output) { '' }
8
12
  before do
9
- expect(Phare).to receive(:system_output).with('which scss-lint').and_return(which_output)
13
+ allow(Phare).to receive(:system_output).with('which stylelint').and_return(global_which_output)
14
+ allow(Phare).to receive(:system_output).with('which .node_modules/.bin/stylelint').and_return(local_which_output)
15
+ allow(File).to receive(:exist?).with(check.config).and_return(config_exists?)
10
16
  allow(Dir).to receive(:exist?).with(check.path).and_return(path_exists?)
11
17
  end
12
18
 
13
- context 'with found scss-lint command' do
14
- let(:which_output) { 'scss-lint' }
15
- let(:path_exists?) { true }
16
- it { expect(check).to be_able_to_run }
19
+ context 'with found stylelint command' do
20
+ context 'for a local stylelint' do
21
+ let(:local_which_output) { 'node_modules/.bin/stylelint' }
22
+ it { expect(check).to be_able_to_run }
23
+ end
24
+
25
+ context 'for a global stylelint' do
26
+ let(:global_which_output) { 'stylelint' }
27
+ it { expect(check).to be_able_to_run }
28
+ end
17
29
 
18
30
  context 'with only excluded files and the --diff option' do
31
+ let(:global_which_output) { 'stylelint' }
19
32
  let(:check) { described_class.new('.', diff: true) }
20
33
  let(:files) { ['foo.scss'] }
21
34
 
@@ -28,8 +41,8 @@ describe Phare::Check::ScssLint do
28
41
  end
29
42
  end
30
43
 
31
- context 'with unfound scss-lint command' do
32
- let(:which_output) { '' }
44
+ context 'with unfound stylelint command' do
45
+ let(:config_exists?) { false }
33
46
  let(:path_exists?) { false }
34
47
  it { expect(check).to_not be_able_to_run }
35
48
  end
@@ -39,58 +52,58 @@ describe Phare::Check::ScssLint do
39
52
  let(:check) { described_class.new('.') }
40
53
  let(:run!) { check.run }
41
54
 
42
- context 'with available ScssLint' do
55
+ context 'with available Stylelint' do
43
56
  let(:command) { check.command }
44
57
 
45
58
  before do
46
59
  expect(check).to receive(:should_run?).and_return(true)
47
60
  expect(Phare).to receive(:system).with(command)
48
- expect(Phare).to receive(:last_exit_status).and_return(scsslint_exit_status)
61
+ expect(Phare).to receive(:last_exit_status).and_return(stylelint_exit_status)
49
62
  expect(check).to receive(:print_banner)
50
63
  end
51
64
 
52
- context 'with check errors' do
53
- let(:scsslint_exit_status) { 0 }
65
+ context 'without check errors' do
66
+ let(:stylelint_exit_status) { 0 }
54
67
  before { expect(Phare).to receive(:puts).with('Everything looks good from here!') }
55
- it { expect { run! }.to change { check.status }.to(scsslint_exit_status) }
68
+ it { expect { run! }.to change { check.status }.to(stylelint_exit_status) }
56
69
  end
57
70
 
58
- context 'without check errors' do
59
- let(:scsslint_exit_status) { 1337 }
60
- before { expect(Phare).to receive(:puts).with("Something went wrong. Program exited with #{scsslint_exit_status}.") }
61
- it { expect { run! }.to change { check.status }.to(scsslint_exit_status) }
71
+ context 'with check errors' do
72
+ let(:stylelint_exit_status) { 1 }
73
+ before { expect(Phare).to receive(:puts).with("Something went wrong. Program exited with #{stylelint_exit_status}.") }
74
+ it { expect { run! }.to change { check.status }.to(stylelint_exit_status) }
62
75
  end
63
76
 
64
77
  context 'with --diff option' do
65
78
  let(:check) { described_class.new('.', diff: true) }
66
79
  let(:files) { ['foo.rb', 'bar.rb'] }
67
- let(:scsslint_exit_status) { 1337 }
80
+ let(:stylelint_exit_status) { 0 }
68
81
 
69
82
  context 'without exclusions' do
70
- let(:command) { "scss-lint #{files.join(' ')}" }
83
+ let(:command) { "stylelint #{files.join(' ')}" }
71
84
 
72
85
  before do
73
86
  expect(check.tree).to receive(:changes).and_return(files).at_least(:once)
74
87
  expect(check).to receive(:excluded_files).and_return([]).once
75
88
  end
76
89
 
77
- it { expect { run! }.to change { check.status }.to(scsslint_exit_status) }
90
+ it { expect { run! }.to change { check.status }.to(stylelint_exit_status) }
78
91
  end
79
92
 
80
93
  context 'with exclusions' do
81
- let(:command) { 'scss-lint bar.rb' }
94
+ let(:command) { 'stylelint bar.rb' }
82
95
 
83
96
  before do
84
97
  expect(check).to receive(:excluded_files).and_return(['foo.rb']).once
85
98
  expect(check.tree).to receive(:changes).and_return(files).at_least(:once)
86
99
  end
87
100
 
88
- it { expect { run! }.to change { check.status }.to(scsslint_exit_status) }
101
+ it { expect { run! }.to change { check.status }.to(stylelint_exit_status) }
89
102
  end
90
103
  end
91
104
  end
92
105
 
93
- context 'with unavailable ScssLint' do
106
+ context 'with unavailable Stylelint' do
94
107
  before do
95
108
  expect(check).to receive(:should_run?).and_return(false)
96
109
  expect(Phare).to_not receive(:system).with(check.command)
@@ -45,19 +45,19 @@ describe Phare::CheckSuite do
45
45
  let(:only) { [] }
46
46
 
47
47
  context 'with "only" option' do
48
- let(:only) { [:rubocop, :foo, :jshint] }
49
- it { expect(suite.checks).to eql [:rubocop, :jshint] }
48
+ let(:only) { [:rubocop, :foo, :eslint] }
49
+ it { expect(suite.checks).to eql [:rubocop, :eslint] }
50
50
  end
51
51
 
52
52
  context 'with "skip" option' do
53
- let(:skip) { [:scsslint, :foo, :jshint] }
54
- it { expect(suite.checks).to eql [:rubocop, :jscs] }
53
+ let(:skip) { [:stylelint, :foo] }
54
+ it { expect(suite.checks).to eql [:rubocop, :eslint] }
55
55
  end
56
56
 
57
57
  context 'with both "only" and "skip" option' do
58
- let(:skip) { [:scsslint, :rubocop] }
59
- let(:only) { [:scsslint, :foo, :jshint] }
60
- it { expect(suite.checks).to eql [:scsslint, :jshint] }
58
+ let(:skip) { [:stylelint, :rubocop] }
59
+ let(:only) { [:stylelint, :foo, :eslint] }
60
+ it { expect(suite.checks).to eql [:stylelint, :eslint] }
61
61
  end
62
62
 
63
63
  context 'with both "only" and "skip" option' 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.7.1
4
+ version: 1.0.0
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: 2015-04-22 00:00:00.000000000 Z
11
+ date: 2016-09-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -86,19 +86,17 @@ files:
86
86
  - bin/phare
87
87
  - lib/phare.rb
88
88
  - lib/phare/check.rb
89
- - lib/phare/check/jscs.rb
90
- - lib/phare/check/jshint.rb
89
+ - lib/phare/check/eslint.rb
91
90
  - lib/phare/check/rubocop.rb
92
- - lib/phare/check/scss_lint.rb
91
+ - lib/phare/check/stylelint.rb
93
92
  - lib/phare/check_suite.rb
94
93
  - lib/phare/cli.rb
95
94
  - lib/phare/git.rb
96
95
  - lib/phare/version.rb
97
96
  - phare.gemspec
98
- - spec/phare/check/jscs_spec.rb
99
- - spec/phare/check/jshint_spec.rb
97
+ - spec/phare/check/eslint_spec.rb
100
98
  - spec/phare/check/rubocop_spec.rb
101
- - spec/phare/check/scss_lint_spec.rb
99
+ - spec/phare/check/stylelint_spec.rb
102
100
  - spec/phare/check_suite_spec.rb
103
101
  - spec/phare/cli_spec.rb
104
102
  - spec/phare/git_spec.rb
@@ -123,16 +121,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
123
121
  version: '0'
124
122
  requirements: []
125
123
  rubyforge_project:
126
- rubygems_version: 2.4.5
124
+ rubygems_version: 2.5.1
127
125
  signing_key:
128
126
  specification_version: 4
129
127
  summary: Phare looks into your files and check for (Ruby, JavaScript and SCSS) coding
130
128
  style errors.
131
129
  test_files:
132
- - spec/phare/check/jscs_spec.rb
133
- - spec/phare/check/jshint_spec.rb
130
+ - spec/phare/check/eslint_spec.rb
134
131
  - spec/phare/check/rubocop_spec.rb
135
- - spec/phare/check/scss_lint_spec.rb
132
+ - spec/phare/check/stylelint_spec.rb
136
133
  - spec/phare/check_suite_spec.rb
137
134
  - spec/phare/cli_spec.rb
138
135
  - spec/phare/git_spec.rb
@@ -1,54 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'json'
4
-
5
- module Phare
6
- class Check
7
- class JSCS < Check
8
- attr_reader :config, :path
9
-
10
- def initialize(directory, options = {})
11
- @config = File.expand_path("#{directory}.jscs.json", __FILE__)
12
- @path = File.expand_path("#{directory}app/assets", __FILE__)
13
- @extensions = %w(.js)
14
- @options = options
15
-
16
- super
17
- end
18
-
19
- def command
20
- if @tree.changed?
21
- "jscs #{files_to_check.join(' ')}"
22
- else
23
- "jscs #{@path}"
24
- end
25
- end
26
-
27
- protected
28
-
29
- def excluded_list
30
- configuration_file['excludeFiles']
31
- end
32
-
33
- def configuration_file
34
- @configuration_file ||= File.exist?('.jscs.json') ? JSON.parse(File.read('.jscs.json')) : {}
35
- end
36
-
37
- def binary_exists?
38
- !Phare.system_output('which jscs').empty?
39
- end
40
-
41
- def configuration_exists?
42
- File.exist?(@config)
43
- end
44
-
45
- def argument_exists?
46
- @tree.changed? || Dir.exist?(@path)
47
- end
48
-
49
- def print_banner
50
- Phare.banner 'Running JSCS to check for JavaScript style…'
51
- end
52
- end
53
- end
54
- end
@@ -1,52 +0,0 @@
1
- # encoding: utf-8
2
- module Phare
3
- class Check
4
- class JSHint < Check
5
- attr_reader :config, :path
6
-
7
- def initialize(directory, options = {})
8
- @config = File.expand_path("#{directory}.jshintrc", __FILE__)
9
- @path = File.expand_path("#{directory}app/assets/javascripts", __FILE__)
10
- @glob = File.join(@path, '**/*')
11
- @extensions = %w(.js .es6)
12
- @options = options
13
-
14
- super
15
- end
16
-
17
- def command
18
- if @tree.changed?
19
- "jshint --config #{@config} --extra-ext #{@extensions.join(',')} #{files_to_check.join(' ')}"
20
- else
21
- "jshint --config #{@config} --extra-ext #{@extensions.join(',')} #{@glob}"
22
- end
23
- end
24
-
25
- protected
26
-
27
- def excluded_list
28
- configuration_file.split("\n") if configuration_file
29
- end
30
-
31
- def configuration_file
32
- @configuration_file ||= File.exist?('.jshintignore') ? File.read('.jshintignore') : false
33
- end
34
-
35
- def binary_exists?
36
- !Phare.system_output('which jshint').empty?
37
- end
38
-
39
- def configuration_exists?
40
- File.exist?(@config)
41
- end
42
-
43
- def arguments_exists?
44
- @tree.changed? || Dir.exist?(@path)
45
- end
46
-
47
- def print_banner
48
- Phare.banner 'Running JSHint to check for JavaScript style…'
49
- end
50
- end
51
- end
52
- end
@@ -1,46 +0,0 @@
1
- # encoding: utf-8
2
- module Phare
3
- class Check
4
- class ScssLint < Check
5
- attr_reader :path
6
-
7
- def initialize(directory, options = {})
8
- @path = File.expand_path("#{directory}app/assets/stylesheets", __FILE__)
9
- @extensions = %w(.scss)
10
- @options = options
11
-
12
- super
13
- end
14
-
15
- def command
16
- if @tree.changed?
17
- "scss-lint #{files_to_check.join(' ')}"
18
- else
19
- "scss-lint #{@path}"
20
- end
21
- end
22
-
23
- protected
24
-
25
- def excluded_list
26
- configuration_file['exclude']
27
- end
28
-
29
- def configuration_file
30
- @configuration_file ||= File.exist?('.scss-lint.yml') ? YAML::load(File.open('.scss-lint.yml')) : {}
31
- end
32
-
33
- def binary_exists?
34
- !Phare.system_output('which scss-lint').empty?
35
- end
36
-
37
- def arguments_exists?
38
- @tree.changed? || Dir.exist?(@path)
39
- end
40
-
41
- def print_banner
42
- Phare.banner 'Running SCSS-Lint to check for SCSS style…'
43
- end
44
- end
45
- end
46
- end
@@ -1,107 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Phare::Check::JSCS do
4
- let(:described_class) { Phare::Check::JSCS }
5
-
6
- describe :should_run? do
7
- let(:check) { described_class.new('.') }
8
-
9
- before do
10
- expect(Phare).to receive(:system_output).with('which jscs').and_return(which_output)
11
- allow(File).to receive(:exist?).with(check.config).and_return(config_exists?)
12
- allow(Dir).to receive(:exist?).with(check.path).and_return(path_exists?)
13
- end
14
-
15
- context 'with found jscs command' do
16
- let(:which_output) { 'jscs' }
17
- let(:config_exists?) { true }
18
- let(:path_exists?) { true }
19
-
20
- it { expect(check).to be_able_to_run }
21
-
22
- context 'with only excluded files and the --diff option' do
23
- let(:check) { described_class.new('.', diff: true) }
24
- let(:files) { ['foo.js'] }
25
-
26
- before do
27
- expect(check).to receive(:excluded_files).and_return(files).once
28
- expect(check.tree).to receive(:changes).and_return(files).at_least(:once)
29
- end
30
-
31
- it { expect(check.should_run?).to be_falsey }
32
- end
33
- end
34
-
35
- context 'with unfound jscs command' do
36
- let(:which_output) { '' }
37
- let(:config_exists?) { false }
38
- let(:path_exists?) { false }
39
- it { expect(check).to_not be_able_to_run }
40
- end
41
- end
42
-
43
- describe :run do
44
- let(:check) { described_class.new('.') }
45
- let(:run!) { check.run }
46
-
47
- context 'with available JSCS' do
48
- let(:command) { check.command }
49
-
50
- before do
51
- expect(check).to receive(:should_run?).and_return(true)
52
- expect(Phare).to receive(:system).with(command)
53
- expect(Phare).to receive(:last_exit_status).and_return(jscs_exit_status)
54
- expect(check).to receive(:print_banner)
55
- end
56
-
57
- context 'with check errors' do
58
- let(:jscs_exit_status) { 0 }
59
- it { expect { run! }.to change { check.status }.to(jscs_exit_status) }
60
- end
61
-
62
- context 'without check errors' do
63
- let(:jscs_exit_status) { 1337 }
64
- before { expect(Phare).to receive(:puts).with("Something went wrong. Program exited with #{jscs_exit_status}.") }
65
- it { expect { run! }.to change { check.status }.to(jscs_exit_status) }
66
- end
67
-
68
- context 'with --diff option' do
69
- let(:check) { described_class.new('.', diff: true) }
70
- let(:files) { ['app/foo.js', 'bar.js'] }
71
- let(:jscs_exit_status) { 1337 }
72
-
73
- context 'without exclusions' do
74
- let(:command) { "jscs #{files.join(' ')}" }
75
-
76
- before do
77
- expect(check.tree).to receive(:changes).and_return(files).at_least(:once)
78
- expect(check).to receive(:excluded_files).and_return([]).once
79
- end
80
-
81
- it { expect { run! }.to change { check.status }.to(jscs_exit_status) }
82
- end
83
-
84
- context 'with exclusions' do
85
- let(:command) { 'jscs bar.js' }
86
-
87
- before do
88
- expect(check).to receive(:excluded_files).and_return(['app/foo.js']).once
89
- expect(check.tree).to receive(:changes).and_return(files).at_least(:once)
90
- end
91
-
92
- it { expect { run! }.to change { check.status }.to(jscs_exit_status) }
93
- end
94
- end
95
- end
96
-
97
- context 'with unavailable JSCS' do
98
- before do
99
- expect(check).to receive(:should_run?).and_return(false)
100
- expect(Phare).to_not receive(:system).with(check.command)
101
- expect(check).to_not receive(:print_banner)
102
- end
103
-
104
- it { expect { run! }.to change { check.status }.to(0) }
105
- end
106
- end
107
- end