salsify_rubocop 0.41.0 → 0.42.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: 958e634bf861eaef7ab87caefdd93c5b2231a845
4
- data.tar.gz: eca6466c32044673f76c67d22641cc9c2ed62b59
3
+ metadata.gz: d574fdef745a9e334e55b58c449deb2cb1807cc9
4
+ data.tar.gz: dffcaa9c8811f95ee57d170e5724cdbf8543ee46
5
5
  SHA512:
6
- metadata.gz: f1deff4fab86c200b20a6cef653d558efa08b453797e51a56aa6a88fcd75ac6cb3f1cab039fcb17276a143e90299e303f627a3cf45cddd907eea615f06e43f3f
7
- data.tar.gz: b9872d4adce997972c1ca05247ea85b7b6285dd6386cbf193dfa9e413852122d1d86beb1a1876ae90f0c36e4ebfa38abb91c6d347c088872e176ca8f208503c4
6
+ metadata.gz: 159db8ad25a634d544070cac994477049711ac2409dbd339b04b8cf86942976df9892a2785bf8ef0a6a0bd13777ab386c6422e0cdbee23fe81f7ae7bc76fb6f3
7
+ data.tar.gz: 4cab967d8390bb8bced638ea4e9b9e7b42ef6ddc6532e48555fb14d067b04a59d7e4b15c58fd09202968f29c0e6b902a2035d77b4157c82108c20af16bf965e7
data/.rspec CHANGED
@@ -1,2 +1,4 @@
1
+ --order rand
1
2
  --format documentation
2
3
  --color
4
+ --require spec_helper
data/.rubocop.yml CHANGED
@@ -1,3 +1,6 @@
1
+ inherit_from:
2
+ - conf/rubocop.yml
3
+
1
4
  Metrics/LineLength:
2
5
  Exclude:
3
6
  - '*.gemspec'
data/.travis.yml CHANGED
@@ -1,5 +1,7 @@
1
1
  language: ruby
2
2
  rvm:
3
+ - 2.2.4
3
4
  - 2.3.1
4
- before_install: gem install bundler -v 1.12.4
5
-
5
+ script:
6
+ - bundle exec rubocop
7
+ - bundle exec rspec
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # salsify_rubocop
2
2
 
3
+ ## v0.42.0
4
+ - Update to RuboCop v0.42.
5
+ - Add `Salsify/RspecDocString` cop to check quoting for examples/example groups.
6
+
3
7
  ## v0.41.0
4
8
  - `.ruby-version` can be used to determine TargetRubyVersion in RuboCop v0.41
5
9
  - Change to `rubocop_rails` configuration:
data/conf/rubocop.yml CHANGED
@@ -1,7 +1,12 @@
1
1
  inherit_from:
2
2
  - ../conf/rubocop_without_rspec.yml
3
3
 
4
- require: rubocop-rspec
4
+ require: salsify_rubocop
5
+
6
+ # See https://github.com/bbatsov/rubocop/pull/3343
7
+ Style/NumericPredicate:
8
+ Exclude:
9
+ - 'spec/**/*'
5
10
 
6
11
  RSpec/DescribeClass:
7
12
  Enabled: false
@@ -0,0 +1,9 @@
1
+ Salsify/RspecDocString:
2
+ Description: 'Check that RSpec doc strings use the correct quoting.'
3
+ Enabled: true
4
+ EnforcedStyle: double_quotes
5
+ SupportedStyles:
6
+ - single_quotes
7
+ - double_quotes
8
+ Include:
9
+ - 'spec/**/*'
@@ -0,0 +1,84 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ module RuboCop
5
+ module Cop
6
+ module Salsify
7
+ # Check that doc strings for example groups and examples use either
8
+ # single-quoted or double-quoted strings based on the enforced style.
9
+ #
10
+ # This cop is disabled by default.
11
+ #
12
+ # @example
13
+ #
14
+ # # When EnforcedStyle is double_quotes
15
+ # # Good
16
+ # it "does something" do
17
+ # ...
18
+ # end
19
+ #
20
+ # # When EnforcedStyle is single_quotes
21
+ # # Good
22
+ # it 'does something' do
23
+ # ...
24
+ # end
25
+ class RspecDocString < Cop
26
+ include ConfigurableEnforcedStyle
27
+
28
+ SINGLE_QUOTE_MSG =
29
+ 'Example Group/Example doc strings must be single-quoted.'.freeze
30
+ DOUBLE_QUOTE_MSG =
31
+ 'Example Group/Example doc strings must be double-quoted.'.freeze
32
+
33
+ DOCUMENTED_METHODS = [
34
+ :example_group, :describe, :context, :xdescribe, :xcontext,
35
+ :it, :example, :specify, :xit, :xexample, :xspecify,
36
+ :feature, :scenario, :xfeature, :xscenario,
37
+ :fdescribe, :fcontext, :focus, :fexample, :fit, :fspecify,
38
+ :ffeature, :fscenario
39
+ ].to_set.freeze
40
+
41
+ def on_send(node)
42
+ _receiver, method_name, *args = *node
43
+ return unless DOCUMENTED_METHODS.include?(method_name) &&
44
+ !args.empty? && args.first.str_type?
45
+
46
+ check_quotes(args.first)
47
+ end
48
+
49
+ private
50
+
51
+ def check_quotes(doc_node)
52
+ if wrong_quotes?(doc_node)
53
+ if style == :single_quotes
54
+ add_offense(doc_node, :expression, SINGLE_QUOTE_MSG)
55
+ else
56
+ add_offense(doc_node, :expression, DOUBLE_QUOTE_MSG)
57
+ end
58
+ end
59
+ end
60
+
61
+ def wrong_quotes?(node)
62
+ src = node.source
63
+ return false if src.start_with?('%', '?')
64
+ if style == :single_quotes
65
+ src !~ /^'/ && !double_quotes_acceptable?(node.str_content)
66
+ else
67
+ src !~ /^" | \\ | \#/x
68
+ end
69
+ end
70
+
71
+ def autocorrect(node)
72
+ lambda do |corrector|
73
+ str = node.str_content
74
+ if style == :single_quotes
75
+ corrector.replace(node.source_range, to_string_literal(str))
76
+ else
77
+ corrector.replace(node.source_range, str.inspect)
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
@@ -1,5 +1,16 @@
1
1
  require 'salsify_rubocop/version'
2
+ require 'rubocop-rspec'
2
3
 
3
- # Top-level gem module
4
- module SalsifyRubocop
5
- end
4
+ # Because RuboCop doesn't yet support plugins, we have to monkey patch in a
5
+ # bit of our configuration. Based on approach from rubocop-rspec:
6
+ DEFAULT_FILES = File.expand_path('../../config/default.yml', __FILE__)
7
+
8
+ path = File.absolute_path(DEFAULT_FILES)
9
+ hash = RuboCop::ConfigLoader.send(:load_yaml_configuration, path)
10
+ config = RuboCop::Config.new(hash, path)
11
+ puts "configuration from #{DEFAULT_FILES}" if RuboCop::ConfigLoader.debug?
12
+ config = RuboCop::ConfigLoader.merge_with_default(config, path)
13
+ RuboCop::ConfigLoader.instance_variable_set(:@default_configuration, config)
14
+
15
+ # cops
16
+ require 'rubocop/cop/salsify/rspec_doc_string'
@@ -1,3 +1,3 @@
1
1
  module SalsifyRubocop
2
- VERSION = '0.41.0'.freeze
2
+ VERSION = '0.42.0'.freeze
3
3
  end
@@ -33,6 +33,6 @@ Gem::Specification.new do |spec|
33
33
  spec.add_development_dependency 'rake', '~> 10.0'
34
34
  spec.add_development_dependency 'rspec', '~> 3.0'
35
35
 
36
- spec.add_runtime_dependency 'rubocop', '~> 0.41.2'
37
- spec.add_runtime_dependency 'rubocop-rspec', '~> 1.5.0'
36
+ spec.add_runtime_dependency 'rubocop', '~> 0.42.0'
37
+ spec.add_runtime_dependency 'rubocop-rspec', '~> 1.5.1'
38
38
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: salsify_rubocop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.41.0
4
+ version: 0.42.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Salsify, Inc
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-07-07 00:00:00.000000000 Z
11
+ date: 2016-07-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -58,28 +58,28 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 0.41.2
61
+ version: 0.42.0
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 0.41.2
68
+ version: 0.42.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rubocop-rspec
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 1.5.0
75
+ version: 1.5.1
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 1.5.0
82
+ version: 1.5.1
83
83
  description: Shared shared RuboCop configuration
84
84
  email:
85
85
  - engineering@salsify.com
@@ -101,6 +101,8 @@ files:
101
101
  - conf/rubocop.yml
102
102
  - conf/rubocop_rails.yml
103
103
  - conf/rubocop_without_rspec.yml
104
+ - config/default.yml
105
+ - lib/rubocop/cop/salsify/rspec_doc_string.rb
104
106
  - lib/salsify_rubocop.rb
105
107
  - lib/salsify_rubocop/version.rb
106
108
  - salsify_rubocop.gemspec