armitage-rubocop 0.1.0 → 0.2.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
  SHA256:
3
- metadata.gz: c79f9dd2133384170f52d8e63f6d5c790aa676af7316f2041d701c253538834a
4
- data.tar.gz: 28b428ec1ccd0a6cfadf9ec77d373c37576d0119ba63d466223badb614db103b
3
+ metadata.gz: bf9988be221ab5c4cfdf372e5086ecdde56e6bf917948d630641d297244cbee0
4
+ data.tar.gz: b24b32fc84e143eb9452083a917649ad7ff58581e9e3c6264f2803d993d8547a
5
5
  SHA512:
6
- metadata.gz: bf13240014c78d087c4fb12bd73126594f438838133e31fbdc01360a34bdf4aad09f53519438a75ffa2c1bd28f41adf4ee6dc863b33335c56f4f50a69d441849
7
- data.tar.gz: c41e32a20625100abaf14c9a4f6e7259eb79ce16e20bc2ebe0c4348d82faaab9051e46b4f0d593e9156cce5b5198ab2b094f1ed28a908e5decf8ce6876f797d6
6
+ metadata.gz: f75a43f8b08530f675a164f25e209af5e35f864238b5ca8f12f925c6a1502c6321206fb7be336afb819ed95fe864e48fba910132bd32b71653de6add6ec79178
7
+ data.tar.gz: a86dbe13e40123aa55bc2cfd41fd234118904392ccdfc10c66836d39f98adc67d0bd05fe3a73a85409f944edd1a6ffe60941208befd8a85fe7ac90215d5764c0
data/README.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # armitage-rubocop
2
2
 
3
+ - [Installation](#installation)
4
+ - [Usage](#usage)
5
+ - [Build](#build)
6
+
7
+ ---
8
+
3
9
  ### Installation
4
10
  ```ruby
5
11
  gem 'armitage-rubocop'
@@ -15,6 +21,8 @@ $ gem install 'armitage-rubocop'
15
21
  require 'armitage-rubocop'
16
22
  ```
17
23
 
24
+ ---
25
+
18
26
  ### Usage
19
27
 
20
28
  - edit your `.rubocop.yml` file:
@@ -33,3 +41,21 @@ inheit_gem:
33
41
  # rails-specific cops + general + rspec
34
42
  armitage-rubocop: lib/rubocop.rails.yml
35
43
  ```
44
+
45
+ ---
46
+
47
+ ### Build
48
+
49
+ ```ruby
50
+ # --- full build ---
51
+ bundle exec rake armitage_rubocop:build
52
+
53
+ # --- validate code style ---
54
+ bundle exec rake rubocop
55
+
56
+ # --- validate yaml files ---
57
+ bundle exec rake armitage_rubocop:validation:valid_yamls
58
+
59
+ # --- validate rubocop cops (existence and params) ---
60
+ bundle exec rake armitage_rubocop:validation:recognizable_cops
61
+ ```
data/Rakefile CHANGED
@@ -2,12 +2,14 @@
2
2
 
3
3
  require 'bundler/gem_tasks'
4
4
  require 'rubocop/rake_task'
5
+ require 'open3'
5
6
  require 'yaml'
6
7
  require 'rubocop'
7
- require 'open3'
8
+ require 'rubocop-rspec'
8
9
 
9
10
  RuboCop::RakeTask.new(:rubocop) do |t|
10
11
  t.options = %w[--config ./lib/rubocop.general.yml]
12
+ t.requires << 'rubocop-rspec'
11
13
  end
12
14
 
13
15
  namespace :armitage_rubocop do
@@ -26,7 +28,7 @@ namespace :armitage_rubocop do
26
28
  # NOTE: results structure { type => exit_code }
27
29
  results = {}.tap do |result_data|
28
30
  build_processes.each_pair do |build_type, build_process|
29
- # NOTE: build_process => [stdin, stdout, stderr, whtr]
31
+ # NOTE: build_process => [stdin, stdout, stderr, wtr]
30
32
  build_result = build_process[3].value.exitstatus
31
33
  result_data[build_type] = build_result
32
34
  end
@@ -53,13 +55,7 @@ namespace :armitage_rubocop do
53
55
 
54
56
  # NOTE: try to load without Psych exceptions
55
57
  invalid_yamls = yamls.each_with_object([]) do |file_name, invalid_files|
56
- # rubocop:disable Style/RedundantBegin
57
- begin
58
- YAML.load(File.read(file_name))
59
- rescue StandardError
60
- invalid_files << "- \e[33m#{file_name}\e[0m"
61
- end
62
- # rubocop:enable Style/RedundantBegin
58
+ YAML.load(File.read(file_name)) rescue (invalid_files << "- \e[33m#{file_name}\e[0m")
63
59
  end
64
60
 
65
61
  if invalid_yamls.empty?
@@ -74,7 +70,7 @@ namespace :armitage_rubocop do
74
70
  desc 'Checks that all defined cops can be used'
75
71
  task :recognizable_cops do
76
72
  yamls = Dir[Pathname.new(__FILE__).join('../lib/**/*.yml')]
77
- invalid_cops = Set.new
73
+ invalid_cops = Hash.new { |h, k| h[k] = +'' }
78
74
 
79
75
  # NOTE: strongly rubocop-related realization
80
76
  # - see https://github.com/rubocop-hq/rubocop/blob/master/lib/rubocop/config.rb
@@ -86,19 +82,38 @@ namespace :armitage_rubocop do
86
82
  yamls.each do |yaml_file|
87
83
  rubocop_config = RuboCop::ConfigLoader.load_file(yaml_file)
88
84
 
89
- rubocop_config.keys.each_with_object([]) do |cop, acc|
85
+ # NOTE: validate cop existence
86
+ rubocop_config.keys.each do |cop|
90
87
  next if RuboCop::ConfigLoader.default_configuration.key?(cop)
91
88
  next if RuboCop::Cop::Cop.registry.contains_cop_matching?([cop])
92
89
  next if cop == 'inherit_mode'
93
- invalid_cops << "- \e[33m#{cop}\e[0m"
90
+ invalid_cops[cop] << "\e[31mBAD COP\e[0m"
91
+ end
92
+
93
+ # NOTE: validate cop params
94
+ rubocop_config.keys.each do |cop|
95
+ next if invalid_cops.key?(cop)
96
+ invalid_params = []
97
+
98
+ rubocop_config[cop].each_key do |cop_param|
99
+ next if RuboCop::Config::COMMON_PARAMS.include?(cop_param)
100
+ next if RuboCop::ConfigLoader.default_configuration[cop].key?(cop_param)
101
+ invalid_params << "\e[35m#{cop_param}\e[0m"
102
+ end
103
+
104
+ next if invalid_params.empty?
105
+ invalid_cops[cop] = "\e[31mBAD PARAMS\e[0m: #{invalid_params.join(', ')}"
94
106
  end
95
107
  end
96
108
 
97
109
  if invalid_cops.empty?
98
110
  puts "[\e[32mCOP RECOGNITION CHECK\e[0m] => \e[1;33mall cops are recognizable!\e[0m"
99
111
  else
100
- invalid_cops_message = invalid_cops.to_a.join("\n")
101
- abort "[\e[31mCOP RECOGNITION CHECK\e[0m] => some cops can not be recognized:\n" \
112
+ invalid_cops_message = invalid_cops.each_pair.map do |cop, message|
113
+ "[\e[32m#{cop}\e[0m]\t- #{message}"
114
+ end.join("\n")
115
+
116
+ abort "[\e[31mCOP RECOGNITION CHECK\e[0m] => some cops can not be fully recognized:\n" \
102
117
  "#{invalid_cops_message}"
103
118
  end
104
119
  end
@@ -6,7 +6,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
6
 
7
7
  Gem::Specification.new do |spec|
8
8
  spec.name = 'armitage-rubocop'
9
- spec.version = '0.1.0'
9
+ spec.version = '0.2.0'
10
10
  spec.license = 'MIT'
11
11
  spec.authors = ['Rustam Ibragimov']
12
12
  spec.email = ['iamdaiver@icloud.com']
@@ -73,8 +73,8 @@ Layout/ElseAlignment:
73
73
 
74
74
  Layout/EmptyComment:
75
75
  Enabled: true
76
- AllowBorderComment: false
77
- AllowMarginComment: false
76
+ AllowBorderComment: true
77
+ AllowMarginComment: true
78
78
 
79
79
  Layout/EmptyLineAfterGuardClause:
80
80
  Enabled: false
@@ -9,6 +9,7 @@ Metrics/BlockLength:
9
9
  ExcludedMethods: []
10
10
  Exclude:
11
11
  - Rakefile
12
+ - spec/**/*
12
13
 
13
14
  Metrics/BlockNesting:
14
15
  Enabled: true
@@ -44,7 +44,7 @@ Naming/UncommunicativeBlockParamName:
44
44
 
45
45
  Naming/UncommunicativeMethodParamName:
46
46
  Enabled: true
47
- MinNameLength: 3
47
+ MinNameLength: 1
48
48
  AllowNamesEndingInNumbers: true
49
49
 
50
50
  Naming/VariableName:
@@ -416,6 +416,8 @@ Style/SingleLineBlockParams:
416
416
  Style/SingleLineMethods:
417
417
  Enabled: true
418
418
  AllowIfMethodIsEmpty: true
419
+ Exclude:
420
+ - spec/**/*
419
421
 
420
422
  Style/SpecialGlobalVars:
421
423
  Enabled: true
@@ -81,8 +81,7 @@ RSpec/Focus:
81
81
  Enabled: true
82
82
 
83
83
  RSpec/HookArgument:
84
- Enabled: true
85
- EnforcedStyle: implicit
84
+ Enabled: false
86
85
 
87
86
  RSpec/ImplicitExpect:
88
87
  Enabled: true
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: armitage-rubocop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rustam Ibragimov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-23 00:00:00.000000000 Z
11
+ date: 2018-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop