phare 0.5.2 → 0.6

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: bfcaf74d67d7cc658fd83f8857ea9f261664ec57
4
- data.tar.gz: 916cc9cca2dcbf70d1679ee87b1483c170ad9e90
3
+ metadata.gz: 15b3ee8b4694a9fa9c68c084483509a79b514186
4
+ data.tar.gz: 96bc1409085eb987dc81f520cbc47e44381dfc2b
5
5
  SHA512:
6
- metadata.gz: 8e024596d554770e2eb47bb0578c877cf211643d56ca81aa070826833d06406ef15e2db02799a171d8a52415efae15980549891aa5a5fbf83df1c3cb47d81b34
7
- data.tar.gz: dce0b277a9221a0e4e83b5494eac777322e8e469a7bae8dede1609988e6c609f3f7c871e545c5a71e847f1e0b29c1e13c24ff0b292b3ca5fc7b8bbf91493c837
6
+ metadata.gz: 16c1bf55cf413dfaabce005af9eec64770dfe3eb7640f2f02f7650b60d9dbbfacb3954384f75eec7e77b534bc64207235ad2fefd9fa86cbb3eefdac27bc16e46
7
+ data.tar.gz: fb2e07dff0f5bd49d282039497ac74cf8c9eafb2f41947bea26af8c75585a01eb0998c523caf176f7f31ba58f7a54438c4f58bdb1687ec6fd015e384c575edff
@@ -1,8 +1,6 @@
1
1
  AllCops:
2
- Includes:
3
- - Rakefile
4
- - config.ru
5
- - Gemfile
2
+ Include:
3
+ - phare.gemspec
6
4
 
7
5
  Documentation:
8
6
  Enabled: false
@@ -13,6 +11,9 @@ Encoding:
13
11
  LineLength:
14
12
  Max: 200
15
13
 
14
+ ClassLength:
15
+ Max: 200
16
+
16
17
  AccessModifierIndentation:
17
18
  EnforcedStyle: outdent
18
19
 
@@ -42,8 +43,11 @@ Lambda:
42
43
  RegexpLiteral:
43
44
  Enabled: false
44
45
 
45
- RedundantBegin:
46
+ AssignmentInCondition:
47
+ Enabled: false
48
+
49
+ ClassAndModuleChildren:
46
50
  Enabled: false
47
51
 
48
- AssignmentInCondition:
52
+ GuardClause:
49
53
  Enabled: false
@@ -1,6 +1,7 @@
1
1
  language: ruby
2
2
 
3
3
  rvm:
4
+ - 2.1.1
4
5
  - 2.0.0
5
6
  - 1.9.3
6
7
 
data/README.md CHANGED
@@ -5,8 +5,9 @@
5
5
  <br />
6
6
  Phare looks into your files and check for coding style errors.
7
7
  <br /><br />
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>
8
+ <a href="https://rubygems.org/gems/phare"><img src="http://img.shields.io/gem/v/phare.svg" /></a>
9
+ <a href="https://travis-ci.org/mirego/phare"><img src="http://img.shields.io/travis/mirego/phare.svg" /></a>
10
+ <a href="https://codeclimate.com/github/mirego/phare"><img src="http://img.shields.io/codeclimate/github/mirego/phare.svg" /></a>
10
11
  </p>
11
12
 
12
13
  ## Installation
@@ -37,6 +38,8 @@ Phare provides an executable named `phare`. You can just use it as is:
37
38
  $ phare
38
39
  ```
39
40
 
41
+ ### Version control hook
42
+
40
43
  One of the best ways to use Phare is by hooking it to your version control commit process. For example, with `git`:
41
44
 
42
45
  ```bash
@@ -44,6 +47,28 @@ $ bundle binstubs phare
44
47
  $ ln -s "`pwd`/bin/phare" .git/hooks/pre-commit
45
48
  ```
46
49
 
50
+ ### Options
51
+
52
+ #### Command-line
53
+
54
+ | Option | Description
55
+ |-------------|-------------------------------------------------------------------------------------------------------------------------
56
+ | `directory` | The directory in which to run the checks (default is the current directory
57
+ | `only` | The specific checks to run (e.g. `--only=rubocup,jscs`)
58
+ | `skip` | The checks to skip (e.g. `--skip=scsslint`)
59
+
60
+ #### `.phare.yml`
61
+
62
+ Instead of using command-line arguments when running the `phare` command, you
63
+ can create a `.phare.yml` file at the root of your project and hard-code options
64
+ in that file.
65
+
66
+ ```yaml
67
+ skip:
68
+ - scsslint
69
+ - jshint
70
+ ```
71
+
47
72
  ## Contributors
48
73
 
49
74
  * [@remiprev](https://github.com/remiprev)
data/bin/phare CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- $LOAD_PATH.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
3
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), *%w(.. lib))
4
4
 
5
5
  require 'phare'
6
6
 
@@ -1,5 +1,6 @@
1
1
  require 'English'
2
2
  require 'optparse'
3
+ require 'yaml'
3
4
  require 'phare/version'
4
5
 
5
6
  require 'phare/cli'
@@ -29,4 +30,10 @@ module Phare
29
30
  def self.puts(*args)
30
31
  STDOUT.puts(*args)
31
32
  end
33
+
34
+ def self.banner(string)
35
+ Phare.puts '-' * string.length
36
+ Phare.puts string
37
+ Phare.puts '-' * string.length
38
+ end
32
39
  end
@@ -2,7 +2,7 @@ module Phare
2
2
  class Check
3
3
  attr_reader :status, :command, :tree
4
4
 
5
- def initialize(directory, options = {})
5
+ def initialize(_directory, options = {})
6
6
  @tree = Git.new(@extensions, options)
7
7
  end
8
8
 
@@ -28,11 +28,11 @@ module Phare
28
28
  should_run = binary_exists?
29
29
 
30
30
  [:configuration_exists?, :arguments_exists?].each do |condition|
31
- should_run = should_run && send(condition) if respond_to?(condition, true)
31
+ should_run &&= send(condition) if respond_to?(condition, true)
32
32
  end
33
33
 
34
34
  if @options[:diff]
35
- should_run = should_run && @tree.changed?
35
+ should_run &&= @tree.changed?
36
36
  end
37
37
 
38
38
  should_run
@@ -28,17 +28,15 @@ module Phare
28
28
  end
29
29
 
30
30
  def configuration_exists?
31
- File.exists?(@config)
31
+ File.exist?(@config)
32
32
  end
33
33
 
34
34
  def argument_exists?
35
- @tree.changed? || Dir.exists?(@path)
35
+ @tree.changed? || Dir.exist?(@path)
36
36
  end
37
37
 
38
38
  def print_banner
39
- Phare.puts '---------------------------------------------'
40
- Phare.puts 'Running JSCS to check for JavaScript style…'
41
- Phare.puts '---------------------------------------------'
39
+ Phare.banner 'Running JSCS to check for JavaScript style…'
42
40
  end
43
41
  end
44
42
  end
@@ -29,17 +29,15 @@ module Phare
29
29
  end
30
30
 
31
31
  def configuration_exists?
32
- File.exists?(@config)
32
+ File.exist?(@config)
33
33
  end
34
34
 
35
35
  def arguments_exists?
36
- @tree.changed? || Dir.exists?(@path)
36
+ @tree.changed? || Dir.exist?(@path)
37
37
  end
38
38
 
39
39
  def print_banner
40
- Phare.puts '---------------------------------------------'
41
- Phare.puts 'Running JSHint to check for JavaScript style…'
42
- Phare.puts '---------------------------------------------'
40
+ Phare.banner 'Running JSHint to check for JavaScript style…'
43
41
  end
44
42
  end
45
43
  end
@@ -25,9 +25,7 @@ module Phare
25
25
  end
26
26
 
27
27
  def print_banner
28
- Phare.puts '----------------------------------------'
29
- Phare.puts 'Running Rubocop to check for Ruby style…'
30
- Phare.puts '----------------------------------------'
28
+ Phare.banner 'Running Rubocop to check for Ruby style…'
31
29
  end
32
30
  end
33
31
  end
@@ -6,7 +6,7 @@ module Phare
6
6
 
7
7
  def initialize(directory, options = {})
8
8
  @path = File.expand_path("#{directory}app/assets/stylesheets", __FILE__)
9
- @extensions = %w(.css .scss)
9
+ @extensions = %w(.scss)
10
10
  @options = options
11
11
 
12
12
  super
@@ -27,13 +27,11 @@ module Phare
27
27
  end
28
28
 
29
29
  def arguments_exists?
30
- @tree.changed? || Dir.exists?(@path)
30
+ @tree.changed? || Dir.exist?(@path)
31
31
  end
32
32
 
33
33
  def print_banner
34
- Phare.puts '------------------------------------------'
35
- Phare.puts 'Running SCSS-Lint to check for SCSS style…'
36
- Phare.puts '------------------------------------------'
34
+ Phare.banner 'Running SCSS-Lint to check for SCSS style…'
37
35
  end
38
36
  end
39
37
  end
@@ -23,9 +23,9 @@ module Phare
23
23
  checks = DEFAULT_CHECKS.keys
24
24
 
25
25
  if @options[:only].any?
26
- checks = checks & @options[:only]
26
+ checks &= @options[:only]
27
27
  elsif @options[:skip]
28
- checks = checks - @options[:skip]
28
+ checks -= @options[:skip]
29
29
  else
30
30
  checks
31
31
  end
@@ -5,59 +5,85 @@ module Phare
5
5
 
6
6
  def initialize(env, argv)
7
7
  @env = env
8
- @argv = argv
9
- parse_options
8
+ @options = parsed_options(argv)
10
9
 
11
10
  @suite = Phare::CheckSuite.new(@options)
12
11
  end
13
12
 
14
13
  def run
15
14
  if @env['SKIP_CODE_CHECK']
16
- Phare.puts '--------------------------------------------------------'
17
- Phare.puts 'Skipping code style checking… Really? Well alright then…'
18
- Phare.puts '--------------------------------------------------------'
19
-
15
+ Phare.banner 'Skipping code style checking… Really? Well alright then…'
20
16
  exit 0
21
17
  else
22
18
  if @suite.tap(&:run).status == 0
23
- Phare.puts '------------------------------------------'
24
- Phare.puts 'Everything looks good, keep on committing!'
25
- Phare.puts '------------------------------------------'
26
-
19
+ Phare.banner 'Everything looks good, keep on committing!'
27
20
  exit 0
28
21
  else
29
- Phare.puts '------------------------------------------------------------------------'
30
- Phare.puts 'Something’s wrong with your code style. Please fix it before committing.'
31
- Phare.puts '------------------------------------------------------------------------'
32
-
22
+ Phare.banner 'Something’s wrong with your code style. Please fix it before committing.'
33
23
  exit 1
34
24
  end
35
25
  end
36
26
  end
37
27
 
38
- def parse_options
39
- @options = { directory: Dir.getwd }
28
+ protected
29
+
30
+ def parsed_options(argv)
31
+ options = { directory: Dir.getwd }
32
+ options.merge! parsed_options_from_yaml(File.join(options[:directory], '.phare.yml'))
33
+ options.merge! parsed_options_from_arguments(argv)
34
+ symbolize_options!(options)
35
+
36
+ options
37
+ end
38
+
39
+ def symbolize_options!(options)
40
+ options[:skip].map!(&:to_sym) if options[:skip]
41
+ options[:only].map!(&:to_sym) if options[:only]
42
+
43
+ options
44
+ end
45
+
46
+ def parsed_options_from_arguments(argv)
47
+ options_to_merge = {}
40
48
 
41
49
  OptionParser.new do |opts|
42
50
  opts.banner = 'Usage: phare [options]'
43
51
 
44
52
  opts.on('--directory', 'The directory in which to run the checks (default is the current directory') do |directory|
45
- @options[:directory] = directory
53
+ options_to_merge[:directory] = directory
46
54
  end
47
55
 
48
56
  opts.on('--skip x,y,z', 'Skip checks') do |checks|
49
- @options[:skip] = checks.split(',').map(&:to_sym)
57
+ options_to_merge[:skip] = checks.split(',')
50
58
  end
51
59
 
52
60
  opts.on('--only x,y,z', 'Only run the specified checks') do |checks|
53
- @options[:only] = checks.split(',').map(&:to_sym)
61
+ options_to_merge[:only] = checks.split(',')
54
62
  end
55
63
 
56
64
  opts.on('--diff', 'Only run checks on modified files') do
57
- @options[:diff] = true
65
+ options_to_merge[:diff] = true
58
66
  end
59
67
 
60
- end.parse! @argv
68
+ end.parse! argv
69
+
70
+ options_to_merge
71
+ end
72
+
73
+ def parsed_options_from_yaml(file)
74
+ options_to_merge = {}
75
+
76
+ if File.exist?(file)
77
+ # Load YAML content
78
+ content = YAML.load(File.read(file))
79
+
80
+ # Symbolize keys
81
+ options_to_merge = content.reduce({}) do |memo, (key, value)|
82
+ memo.merge! key.to_sym => value
83
+ end
84
+ end
85
+
86
+ options_to_merge
61
87
  end
62
88
  end
63
89
  end
@@ -10,14 +10,14 @@ module Phare
10
10
  end
11
11
 
12
12
  def changes
13
- @changes ||= Phare.system_output('git status -s').split("\n").reduce([]) do |memo, diff|
13
+ @changes ||= Phare.system_output('git status -s').split("\n").each_with_object([]) do |diff, memo|
14
14
  filename = diff.split(' ').last
15
15
 
16
16
  if diff =~ /^[^D]{2}/ && @extensions.include?(File.extname(filename))
17
17
  memo << filename
18
+ else
19
+ next
18
20
  end
19
-
20
- memo
21
21
  end
22
22
  end
23
23
  end
@@ -1,3 +1,3 @@
1
1
  module Phare
2
- VERSION = '0.5.2'
2
+ VERSION = '0.6'
3
3
  end
@@ -7,18 +7,19 @@ Gem::Specification.new do |spec|
7
7
  spec.name = 'phare'
8
8
  spec.version = Phare::VERSION
9
9
  spec.authors = ['Rémi Prévost']
10
- spec.email = ['remi@exomel.com']
10
+ spec.email = ['rprevost@mirego.com']
11
11
  spec.description = 'Phare looks into your files and check for (Ruby, JavaScript and SCSS) coding style errors.'
12
12
  spec.summary = spec.description
13
13
  spec.homepage = 'https://github.com/mirego/phare'
14
14
  spec.license = 'BSD 3-Clause'
15
15
 
16
- spec.files = `git ls-files`.split($/)
16
+ spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
17
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
19
+ spec.require_paths = ['lib']
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
+ spec.add_development_dependency 'rspec', '~> 3.0.0.rc1'
24
+ spec.add_development_dependency 'rubocop', '0.22'
24
25
  end
@@ -1,12 +1,14 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Phare::Check::JSCS do
4
+ let(:described_class) { Phare::Check::JSCS }
5
+
4
6
  describe :should_run? do
5
7
  let(:check) { described_class.new('.') }
6
8
  before do
7
9
  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
+ allow(File).to receive(:exist?).with(check.config).and_return(config_exists?)
11
+ allow(Dir).to receive(:exist?).with(check.path).and_return(path_exists?)
10
12
  end
11
13
 
12
14
  context 'with found jscs command' do
@@ -1,12 +1,14 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Phare::Check::JSHint do
4
+ let(:described_class) { Phare::Check::JSHint }
5
+
4
6
  describe :should_run? do
5
7
  let(:check) { described_class.new('.') }
6
8
  before do
7
9
  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
+ allow(File).to receive(:exist?).with(check.config).and_return(config_exists?)
11
+ allow(Dir).to receive(:exist?).with(check.path).and_return(path_exists?)
10
12
  end
11
13
 
12
14
  context 'with found jshint command' do
@@ -1,6 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Phare::Check::Rubocop do
4
+ let(:described_class) { Phare::Check::Rubocop }
5
+
4
6
  describe :should_run? do
5
7
  let(:check) { described_class.new('.') }
6
8
  before { expect(Phare).to receive(:system_output).with('which rubocop').and_return(which_output) }
@@ -1,11 +1,13 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Phare::Check::ScssLint do
4
+ let(:described_class) { Phare::Check::ScssLint }
5
+
4
6
  describe :should_run? do
5
7
  let(:check) { described_class.new('.') }
6
8
  before do
7
9
  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?)
10
+ allow(Dir).to receive(:exist?).with(check.path).and_return(path_exists?)
9
11
  end
10
12
 
11
13
  context 'with found scss-lint command' do
@@ -1,6 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Phare::CheckSuite do
4
+ let(:described_class) { Phare::CheckSuite }
5
+
4
6
  describe :run do
5
7
  let(:options) { { directory: '.' } }
6
8
  let(:suite) { described_class.new(options) }
@@ -30,7 +32,7 @@ describe Phare::CheckSuite do
30
32
  end
31
33
 
32
34
  context 'with no failing check' do
33
- let(:exit_status_proc) { proc { |index| 0 } }
35
+ let(:exit_status_proc) { proc { 0 } }
34
36
 
35
37
  it { expect { suite.run }.to change { suite.status }.to(0) }
36
38
  end
@@ -1,11 +1,14 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Phare::CLI do
4
+ let(:described_class) { Phare::CLI }
5
+
4
6
  let(:cli) { described_class.new(env, argv) }
5
7
  let(:argv) { [] }
6
8
  let(:run!) { cli.run }
9
+ let(:env) { {} }
7
10
 
8
- describe :initialize do
11
+ describe :run do
9
12
  context 'with code check skipping' do
10
13
  let(:env) { { 'SKIP_CODE_CHECK' => '1' } }
11
14
  it { expect { run! }.to exit_with_code(0) }
@@ -33,4 +36,16 @@ describe Phare::CLI do
33
36
  end
34
37
  end
35
38
  end
39
+
40
+ describe :parsed_options do
41
+ let(:parsed_options) { cli.send(:parsed_options, argv) }
42
+
43
+ before do
44
+ expect(cli).to receive(:parsed_options_from_yaml).and_return(skip: ['scsslint'])
45
+ expect(cli).to receive(:parsed_options_from_arguments).and_return(skip: ['rubocop'])
46
+ end
47
+
48
+ it { expect(parsed_options[:directory]).to eql Dir.pwd }
49
+ it { expect(parsed_options[:skip]).to eql [:rubocop] }
50
+ end
36
51
  end
@@ -1,6 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Phare::Git do
4
+ let(:described_class) { Phare::Git }
5
+
4
6
  let(:extensions) { ['.rb'] }
5
7
  let(:options) { { diff: true } }
6
8
  let(:git) { described_class.new(extensions, options) }
@@ -39,7 +41,7 @@ describe Phare::Git do
39
41
  end
40
42
 
41
43
  context 'with untracked file' do
42
- let(:tree) { "?? foo.rb" }
44
+ let(:tree) { '?? foo.rb' }
43
45
 
44
46
  it { expect(git.changes).to eq(['foo.rb']) }
45
47
  end
@@ -29,12 +29,16 @@ RSpec::Matchers.define :exit_with_code do |expected_code|
29
29
  actual && actual == expected_code
30
30
  end
31
31
 
32
- failure_message do |block|
32
+ supports_block_expectations do
33
+ true
34
+ end
35
+
36
+ failure_message do
33
37
  "expected block to call exit(#{expected_code}) but exit" +
34
38
  (actual.nil? ? ' not called' : "(#{actual}) was called")
35
39
  end
36
40
 
37
- failure_message_when_negated do |block|
41
+ failure_message_when_negated do
38
42
  "expected block not to call exit(#{expected_code})"
39
43
  end
40
44
 
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.5.2
4
+ version: '0.6'
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-05-12 00:00:00.000000000 Z
11
+ date: 2014-06-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -44,18 +44,32 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 3.0.0.beta2
47
+ version: 3.0.0.rc1
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 3.0.0.beta2
54
+ version: 3.0.0.rc1
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: '0.22'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: '0.22'
55
69
  description: Phare looks into your files and check for (Ruby, JavaScript and SCSS)
56
70
  coding style errors.
57
71
  email:
58
- - remi@exomel.com
72
+ - rprevost@mirego.com
59
73
  executables:
60
74
  - phare
61
75
  extensions: []