File tree Expand file tree Collapse file tree 4 files changed +85
-0
lines changed Expand file tree Collapse file tree 4 files changed +85
-0
lines changed Original file line number Diff line number Diff line change @@ -78,6 +78,21 @@ Cop/AvoidUsingEnv:
78
78
- lib/gitlab/util.rb
79
79
- spec/lib/gitlab/util_spec.rb
80
80
81
+ Cop/SpecifyDefaultVersion :
82
+ Enabled : true
83
+ Include :
84
+ - config/software/*.rb
85
+ Exclude :
86
+ # These files either use `path` source and doesn't need a default_version
87
+ # or is just a wrapper around other definitions
88
+ - config/software/gitlab-config-template.rb
89
+ - config/software/gitlab-cookbooks.rb
90
+ - config/software/gitlab-ctl-ee.rb
91
+ - config/software/gitlab-ctl.rb
92
+ - config/software/gitlab-scripts.rb
93
+ - config/software/gitlab-selinux.rb
94
+ - config/software/openssl.rb
95
+
81
96
Style/MultilineIfModifier :
82
97
Enabled : false
83
98
Original file line number Diff line number Diff line change
1
+ module Rubocop
2
+ module Cop
3
+ class SpecifyDefaultVersion < RuboCop ::Cop ::Base
4
+ NOTICE_REGEXP = '^ *default_version' . freeze
5
+ MSG = 'Specify default_version for the component.' . freeze
6
+
7
+ def on_new_investigation
8
+ return if notice_found? ( processed_source )
9
+
10
+ add_global_offense ( format ( MSG ) )
11
+ end
12
+
13
+ private
14
+
15
+ def notice_found? ( processed_source )
16
+ notice_regexp = Regexp . new ( NOTICE_REGEXP )
17
+
18
+ notice_found = false
19
+ processed_source . lines . each do |line |
20
+ notice_found = notice_regexp . match? ( line )
21
+ break if notice_found
22
+ end
23
+
24
+ notice_found
25
+ end
26
+ end
27
+ end
28
+ end
Original file line number Diff line number Diff line change 1
1
require_relative 'cop/avoid_using_env'
2
+ require_relative 'cop/specify_default_version'
Original file line number Diff line number Diff line change
1
+ require 'spec_helper'
2
+ require 'rubocop/rspec/cop_helper'
3
+ require 'rubocop/rspec/expect_offense'
4
+
5
+ require 'rubocop/cop/specify_default_version'
6
+
7
+ RSpec . describe Rubocop ::Cop ::SpecifyDefaultVersion do
8
+ include CopHelper
9
+ include RuboCop ::RSpec ::ExpectOffense
10
+
11
+ subject ( :cop ) { described_class . new }
12
+
13
+ it 'flags violation for software definition files without default_version set' do
14
+ expect_offense ( <<~RUBY )
15
+ name 'sample'
16
+ ^{} Specify default_version for the component.
17
+
18
+ license 'MIT'
19
+
20
+ build do
21
+ make
22
+ make install
23
+ end
24
+ RUBY
25
+ end
26
+
27
+ it 'does not flag violation for software definition files with default_version set' do
28
+ expect_no_offenses ( <<~RUBY )
29
+ name 'sample'
30
+
31
+ license 'MIT'
32
+
33
+ default_version '1.0.0'
34
+
35
+ build do
36
+ make
37
+ make install
38
+ end
39
+ RUBY
40
+ end
41
+ end
You can’t perform that action at this time.
0 commit comments