salsify_rubocop 0.41.0 → 0.42.0
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 +2 -0
- data/.rubocop.yml +3 -0
- data/.travis.yml +4 -2
- data/CHANGELOG.md +4 -0
- data/conf/rubocop.yml +6 -1
- data/config/default.yml +9 -0
- data/lib/rubocop/cop/salsify/rspec_doc_string.rb +84 -0
- data/lib/salsify_rubocop.rb +14 -3
- data/lib/salsify_rubocop/version.rb +1 -1
- data/salsify_rubocop.gemspec +2 -2
- metadata +8 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d574fdef745a9e334e55b58c449deb2cb1807cc9
|
4
|
+
data.tar.gz: dffcaa9c8811f95ee57d170e5724cdbf8543ee46
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 159db8ad25a634d544070cac994477049711ac2409dbd339b04b8cf86942976df9892a2785bf8ef0a6a0bd13777ab386c6422e0cdbee23fe81f7ae7bc76fb6f3
|
7
|
+
data.tar.gz: 4cab967d8390bb8bced638ea4e9b9e7b42ef6ddc6532e48555fb14d067b04a59d7e4b15c58fd09202968f29c0e6b902a2035d77b4157c82108c20af16bf965e7
|
data/.rspec
CHANGED
data/.rubocop.yml
CHANGED
data/.travis.yml
CHANGED
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:
|
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
|
data/config/default.yml
ADDED
@@ -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
|
data/lib/salsify_rubocop.rb
CHANGED
@@ -1,5 +1,16 @@
|
|
1
1
|
require 'salsify_rubocop/version'
|
2
|
+
require 'rubocop-rspec'
|
2
3
|
|
3
|
-
#
|
4
|
-
|
5
|
-
|
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'
|
data/salsify_rubocop.gemspec
CHANGED
@@ -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.
|
37
|
-
spec.add_runtime_dependency 'rubocop-rspec', '~> 1.5.
|
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.
|
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-
|
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.
|
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.
|
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.
|
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.
|
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
|