digivizer-style 1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ff91b9e9b0fbd2c9bd6b59bd45623694d7361848
4
+ data.tar.gz: fee81c5288b0ac66ab0619f76e82dc0aad431b88
5
+ SHA512:
6
+ metadata.gz: c0f86d8bec2f6cadc2563f4c33f97ac47895b323aabf84b091ff136b4e41a1cc578d531ce11a16410de5ab37af03687d78a7f1aadada480b205cefc0532b7fff
7
+ data.tar.gz: f383c5b85230efa6fda87918c8467df67a9c0a28d03ef78def381b643b5f23f4e4c3ea2d50501c06bbf9710df07a7d8a9a5d36237a46d9b08b847fc628652994
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+ source 'https://gems.dgvz.net'
3
+
4
+ gemspec
@@ -0,0 +1,50 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ digibits (1.5)
5
+ rubocop (~> 0.42.1.pre)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ remote: https://gems.dgvz.net/
10
+ specs:
11
+ ast (2.3.0)
12
+ diff-lcs (1.2.5)
13
+ parser (2.3.1.2)
14
+ ast (~> 2.2)
15
+ powerpack (0.1.1)
16
+ rainbow (2.1.0)
17
+ rake (11.2.2)
18
+ rspec (3.5.0)
19
+ rspec-core (~> 3.5.0)
20
+ rspec-expectations (~> 3.5.0)
21
+ rspec-mocks (~> 3.5.0)
22
+ rspec-core (3.5.1)
23
+ rspec-support (~> 3.5.0)
24
+ rspec-expectations (3.5.0)
25
+ diff-lcs (>= 1.2.0, < 2.0)
26
+ rspec-support (~> 3.5.0)
27
+ rspec-mocks (3.5.0)
28
+ diff-lcs (>= 1.2.0, < 2.0)
29
+ rspec-support (~> 3.5.0)
30
+ rspec-support (3.5.0)
31
+ rubocop (0.42.1.pre)
32
+ parser (>= 2.3.1.1, < 3.0)
33
+ powerpack (~> 0.1)
34
+ rainbow (>= 1.99.1, < 3.0)
35
+ ruby-progressbar (~> 1.7)
36
+ unicode-display_width (~> 1.0, >= 1.0.1)
37
+ ruby-progressbar (1.8.1)
38
+ unicode-display_width (1.1.0)
39
+
40
+ PLATFORMS
41
+ ruby
42
+
43
+ DEPENDENCIES
44
+ bundler (~> 1.3)
45
+ digibits!
46
+ rake
47
+ rspec
48
+
49
+ BUNDLED WITH
50
+ 1.11.2
@@ -0,0 +1,26 @@
1
+ # encoding: utf-8
2
+
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'digivizer-style'
8
+ spec.version = '1.1'
9
+ spec.authors = ['Digivizer Developer']
10
+ spec.email = ['dev-accounts@digivizer.com']
11
+ spec.description = 'The Digivizer Manual of Style'
12
+ spec.summary = 'This gem contains a rubocop configuration for Digivizer'
13
+ spec.homepage = ''
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'rubocop', '~> 0.45'
22
+
23
+ spec.add_development_dependency 'bundler', '~> 1.3'
24
+ spec.add_development_dependency 'rake', '~> 11.2'
25
+ spec.add_development_dependency 'rspec', '~> 3.5'
26
+ end
@@ -0,0 +1,44 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ module RuboCop
5
+ module Cop
6
+ module Metrics
7
+ # This cop checks if the length a method exceeds some maximum value.
8
+ # Comment lines can optionally be ignored.
9
+ # The maximum allowed length is configurable.
10
+ class DGVZMethodLength < Cop
11
+ include OnMethodDef
12
+ include CodeLength
13
+
14
+ private
15
+
16
+ def on_method_def(node, _method_name, _args, _body)
17
+ check_code_length(node)
18
+ end
19
+
20
+ def message(length, max_length)
21
+ format('Method has far too many lines. [%d/%d]', length, max_length)
22
+ end
23
+
24
+ def code_length(node)
25
+ lines = node.source.lines.to_a[1..-2] || []
26
+
27
+ lines.count { |line| !dgvz_irrelevant_line(line) }
28
+ end
29
+
30
+ def blacklist
31
+ cop_config['Blacklist']
32
+ end
33
+
34
+ def logger_line?(source_line)
35
+ blacklist.find { |o| source_line.include?(o) }
36
+ end
37
+
38
+ def dgvz_irrelevant_line(source_line)
39
+ source_line.blank? || (!count_comments? && comment_line?(source_line)) || logger_line?(source_line)
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,32 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+ # author: Harry Lee
4
+
5
+ module RuboCop
6
+ module Cop
7
+ module Style
8
+ # This cop checks for uses of `raise e`.
9
+ # @example
10
+ # case e
11
+ # when condition
12
+ # statement
13
+ # else
14
+ # raise e
15
+ # end
16
+ class RaiseException < Cop
17
+ MSG = 'Raise strings or constants, not variables.'.freeze
18
+
19
+ ALLOWED_TYPES = [:const, :str]
20
+
21
+ def on_send(node)
22
+ return unless node.command?(:raise)
23
+
24
+ # args will contain the type of arguments ex) (send nil :e)
25
+ _receiver, _selector, args = *node
26
+
27
+ add_offense(node, :expression, MSG) unless ALLOWED_TYPES.include?(args.type)
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,142 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.3
3
+
4
+ AccessorMethodName:
5
+ Enabled: false
6
+
7
+ GuardClause:
8
+ Enabled: false
9
+
10
+ StringLiterals:
11
+ Enabled: false
12
+
13
+ BracesAroundHashParameters:
14
+ Enabled: false
15
+
16
+ SpaceInsideHashLiteralBraces:
17
+ EnforcedStyle: no_space
18
+
19
+ SpaceAroundEqualsInParameterDefault:
20
+ EnforcedStyle: no_space
21
+
22
+ SpaceInsideHashLiteralBraces:
23
+ Enabled: false
24
+
25
+ SpaceBeforeFirstArg:
26
+ Enabled: false
27
+
28
+ HashSyntax:
29
+ EnforcedStyle: hash_rockets
30
+
31
+ ClassLength:
32
+ Max: 180
33
+
34
+ ColonMethodCall:
35
+ Enabled: false
36
+
37
+ Documentation:
38
+ Enabled: false
39
+
40
+ IfUnlessModifier:
41
+ Enabled: false
42
+
43
+ Metrics/LineLength:
44
+ Max: 160
45
+
46
+ Loop:
47
+ Enabled: true
48
+
49
+ Style/MethodCallWithoutArgsParentheses:
50
+ Enabled: false
51
+
52
+ # DGVZMethodLength:
53
+ # Enabled: true
54
+ # Max: 23
55
+ # Blacklist:
56
+ # - .error
57
+ # - .info
58
+ # - .debug
59
+ # - .fatal
60
+ # - .trace
61
+
62
+ MethodLength:
63
+ Max: 23
64
+ Enabled: false
65
+
66
+ NilComparison:
67
+ Enabled: false
68
+
69
+ ParenthesesAroundCondition:
70
+ Enabled: false
71
+
72
+ Style/TernaryParentheses:
73
+ Enabled: true
74
+ EnforcedStyle: require_parentheses
75
+
76
+ RedundantSelf:
77
+ Enabled: false
78
+
79
+ TrivialAccessors:
80
+ Enabled: false
81
+
82
+ Void:
83
+ Enabled: false
84
+
85
+ WordArray:
86
+ Enabled: false
87
+
88
+ AsciiIdentifiers:
89
+ Enabled: false
90
+
91
+ AsciiComments:
92
+ Enabled: false
93
+
94
+ Style/CollectionMethods:
95
+ Enabled: false
96
+
97
+ Style/ClassAndModuleChildren:
98
+ Enabled: false
99
+
100
+ Style/CommentAnnotation:
101
+ Enabled: true
102
+
103
+ Style/DocumentationMethod:
104
+ Enabled: true
105
+
106
+ Style/Lambda:
107
+ Enabled: false
108
+
109
+ Style/SignalException:
110
+ Enabled: false
111
+
112
+ Layout/EmptyLinesAroundClassBody:
113
+ Enabled: true
114
+ EnforcedStyle: empty_lines
115
+
116
+ Layout/EmptyLinesAroundModuleBody:
117
+ Enabled: true
118
+ EnforcedStyle: empty_lines
119
+
120
+ Metrics/AbcSize:
121
+ Enabled: false
122
+
123
+ Style/MultilineBlockChain:
124
+ Enabled: false
125
+
126
+ Style/RescueModifier:
127
+ Enabled: false
128
+
129
+ Style/NegatedIf:
130
+ Enabled: false
131
+
132
+ Performance/RedundantBlockCall:
133
+ Enabled: false
134
+
135
+ Style/SignalException:
136
+ Enabled: false
137
+
138
+ Style/EmptyLiteral:
139
+ Enabled: false
140
+
141
+ Style/MutableConstant:
142
+ Enabled: false
@@ -0,0 +1,122 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ require 'spec_helper'
5
+ require './lib/dgvz_method_length'
6
+
7
+ describe RuboCop::Cop::Metrics::DGVZMethodLength, :config do
8
+ subject(:cop) { described_class.new(config) }
9
+ let(:cop_config) { { 'Max' => 5, 'Blacklist' => ['.error', '.info', '.debug', '.fatal', '.trace'] } }
10
+
11
+
12
+ it 'accept a method with .error' do
13
+ inspect_source(cop, ['def m',
14
+ 'logger.error{"abc"}',
15
+ 'logger.error{"abc"}',
16
+ 'logger.error{"abc"}',
17
+ 'logger.error{"abc"}',
18
+ 'logger.error{"abc"}',
19
+ 'logger.error{"abc"}',
20
+ 'logger.error{"abc"}',
21
+ 'logger.error{"abc"}',
22
+ 'end'])
23
+ expect(cop.offenses).to be_empty
24
+ end
25
+
26
+ it 'accept a method with .info' do
27
+ inspect_source(cop, ['def m',
28
+ 'logger.info{"abc"}',
29
+ 'logger.info{"abc"}',
30
+ 'logger.info{"abc"}',
31
+ 'logger.info{"abc"}',
32
+ 'logger.info{"abc"}',
33
+ 'logger.info{"abc"}',
34
+ 'logger.info{"abc"}',
35
+ 'logger.info{"abc"}',
36
+ 'end'])
37
+ expect(cop.offenses).to be_empty
38
+ end
39
+
40
+ it 'accept a method with .debug' do
41
+ inspect_source(cop, ['def m',
42
+ 'logger.debug{"abc"}',
43
+ 'logger.debug{"abc"}',
44
+ 'logger.debug{"abc"}',
45
+ 'logger.debug{"abc"}',
46
+ 'logger.debug{"abc"}',
47
+ 'logger.debug{"abc"}',
48
+ 'logger.debug{"abc"}',
49
+ 'logger.debug{"abc"}',
50
+ 'end'])
51
+ expect(cop.offenses).to be_empty
52
+ end
53
+
54
+ it 'accept a method with .fatal' do
55
+ inspect_source(cop, ['def m',
56
+ 'logger.fatal{"abc"}',
57
+ 'logger.fatal{"abc"}',
58
+ 'logger.fatal{"abc"}',
59
+ 'logger.fatal{"abc"}',
60
+ 'logger.fatal{"abc"}',
61
+ 'logger.fatal{"abc"}',
62
+ 'logger.fatal{"abc"}',
63
+ 'logger.fatal{"abc"}',
64
+ 'end'])
65
+ expect(cop.offenses).to be_empty
66
+ end
67
+
68
+ it 'accept a method with .trace' do
69
+ inspect_source(cop, ['def m',
70
+ 'logger.trace{"abc"}',
71
+ 'logger.trace{"abc"}',
72
+ 'logger.trace{"abc"}',
73
+ 'logger.trace{"abc"}',
74
+ 'logger.trace{"abc"}',
75
+ 'logger.trace{"abc"}',
76
+ 'logger.trace{"abc"}',
77
+ 'logger.trace{"abc"}',
78
+ 'end'])
79
+ expect(cop.offenses).to be_empty
80
+ end
81
+
82
+ it 'accepts a method with less than 5 lines' do
83
+ inspect_source(cop, ['def m()',
84
+ ' a = 1',
85
+ ' a = 2',
86
+ ' a = 3',
87
+ ' a = 4',
88
+ 'end'])
89
+ expect(cop.offenses).to be_empty
90
+ end
91
+
92
+ it 'rejects a method with more than 5 lines' do
93
+ inspect_source(cop, ['def m()',
94
+ ' a = 1',
95
+ ' a = 2',
96
+ ' a = 3',
97
+ ' a = 4',
98
+ ' a = 5',
99
+ ' a = 6',
100
+ 'end'])
101
+ expect(cop.offenses.size).to eq(1)
102
+ end
103
+
104
+ it 'does not count blank lines' do
105
+ inspect_source(cop, ['def m()',
106
+ ' a = 1',
107
+ ' a = 2',
108
+ ' a = 3',
109
+ ' a = 4',
110
+ '',
111
+ '',
112
+ ' a = 7',
113
+ 'end'])
114
+ expect(cop.offenses).to be_empty
115
+ end
116
+
117
+ it 'accepts empty methods' do
118
+ inspect_source(cop, ['def m()',
119
+ 'end'])
120
+ expect(cop.offenses).to be_empty
121
+ end
122
+ end
@@ -0,0 +1,24 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ require 'spec_helper'
5
+ require './lib/raise_exception.rb'
6
+
7
+ describe RuboCop::Cop::Style::RaiseException do
8
+ subject(:cop) { described_class.new }
9
+
10
+ it 'reports an offense for a raise with variables' do
11
+ inspect_source(cop, 'raise e, msg')
12
+ expect(cop.offenses.size).to eq(1)
13
+ end
14
+
15
+ it 'reports an offense for a raise with variables' do
16
+ inspect_source(cop, 'raise Error, msg')
17
+ expect(cop.offenses.size).to eq(0)
18
+ end
19
+
20
+ it 'reports an offense for a raise with variables' do
21
+ inspect_source(cop, 'raise "my error", msg')
22
+ expect(cop.offenses.size).to eq(0)
23
+ end
24
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: digivizer-style
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.1'
5
+ platform: ruby
6
+ authors:
7
+ - Digivizer Developer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-07-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rubocop
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.45'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.45'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '11.2'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '11.2'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.5'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.5'
69
+ description: The Digivizer Manual of Style
70
+ email:
71
+ - dev-accounts@digivizer.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - Gemfile
77
+ - Gemfile.lock
78
+ - digivizer-style.gemspec
79
+ - lib/dgvz_method_length.rb
80
+ - lib/raise_exception.rb
81
+ - rubocop.yml
82
+ - spec/dgvz_method_length_spec.rb
83
+ - spec/raise_exception_spec.rb
84
+ homepage: ''
85
+ licenses:
86
+ - MIT
87
+ metadata: {}
88
+ post_install_message:
89
+ rdoc_options: []
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ requirements: []
103
+ rubyforge_project:
104
+ rubygems_version: 2.5.1
105
+ signing_key:
106
+ specification_version: 4
107
+ summary: This gem contains a rubocop configuration for Digivizer
108
+ test_files:
109
+ - spec/dgvz_method_length_spec.rb
110
+ - spec/raise_exception_spec.rb