ducalis 0.5.5 → 0.5.6
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/.codeclimate.yml +1 -1
- data/DOCUMENTATION.md +250 -198
- data/Gemfile.lock +5 -5
- data/README.md +13 -1
- data/lib/ducalis/cops/callbacks_activerecord.rb +12 -5
- data/lib/ducalis/cops/case_mapping.rb +9 -8
- data/lib/ducalis/cops/controllers_except.rb +6 -6
- data/lib/ducalis/cops/keyword_defaults.rb +4 -5
- data/lib/ducalis/cops/module_like_class.rb +4 -5
- data/lib/ducalis/cops/params_passing.rb +5 -5
- data/lib/ducalis/cops/possible_tap.rb +12 -11
- data/lib/ducalis/cops/preferable_methods.rb +11 -5
- data/lib/ducalis/cops/private_instance_assign.rb +11 -4
- data/lib/ducalis/cops/protected_scope_cop.rb +11 -11
- data/lib/ducalis/cops/raise_withour_error_class.rb +4 -5
- data/lib/ducalis/cops/regex_cop.rb +13 -8
- data/lib/ducalis/cops/rest_only_cop.rb +5 -4
- data/lib/ducalis/cops/rubocop_disable.rb +5 -4
- data/lib/ducalis/cops/strings_in_activerecords.rb +7 -6
- data/lib/ducalis/cops/uncommented_gem.rb +6 -5
- data/lib/ducalis/cops/useless_only.rb +16 -16
- data/lib/ducalis/documentation.rb +16 -7
- data/lib/ducalis/version.rb +1 -1
- metadata +2 -2
@@ -4,24 +4,24 @@ require 'rubocop'
|
|
4
4
|
|
5
5
|
module Ducalis
|
6
6
|
class UselessOnly < RuboCop::Cop::Cop
|
7
|
-
|
7
|
+
OFFENSE = <<-MESSAGE.gsub(/^ +\|/, '').strip
|
8
|
+
| Seems like there is no any reason to keep before filter only for one
|
9
|
+
| action. Maybe it will be better to inline it?
|
10
|
+
|
|
11
|
+
| ```ruby
|
12
|
+
| before_filter :do_something, only: %i[index]
|
13
|
+
| def index; end
|
14
|
+
|
|
15
|
+
| # to
|
16
|
+
|
|
17
|
+
| def index
|
18
|
+
| do_something
|
19
|
+
| end
|
20
|
+
| ```
|
21
|
+
MESSAGE
|
22
|
+
|
8
23
|
FILTERS = %i(before_filter after_filter around_filter
|
9
24
|
before_action after_action around_action).freeze
|
10
|
-
OFFENSE = %(
|
11
|
-
Seems like there is no any reason to keep before filter only for one action. \
|
12
|
-
Maybe it will be better to inline it?
|
13
|
-
|
14
|
-
```ruby
|
15
|
-
before_filter :do_something, only: %i[index]
|
16
|
-
def index; end
|
17
|
-
|
18
|
-
# to
|
19
|
-
|
20
|
-
def index
|
21
|
-
do_something
|
22
|
-
end
|
23
|
-
```
|
24
|
-
).strip
|
25
25
|
|
26
26
|
def on_class(node)
|
27
27
|
_classdef_node, superclass, _body = *node
|
@@ -1,8 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'parser/current'
|
4
|
-
require 'rubocop'
|
5
4
|
|
5
|
+
# This class could be used to dynamically generate documentation from cops spec.
|
6
|
+
# It recognizes bad and good examples by signal words like `raises`. Additional
|
7
|
+
# information for documentation could be passed by setting `DETAILS` constant.
|
6
8
|
class SpecsProcessor < Parser::AST::Processor
|
7
9
|
attr_reader :cases
|
8
10
|
|
@@ -55,6 +57,10 @@ class SpecsProcessor < Parser::AST::Processor
|
|
55
57
|
end
|
56
58
|
|
57
59
|
class Documentation
|
60
|
+
RED_SQUARE = ''
|
61
|
+
GREEN_SQUARE = ''
|
62
|
+
SIGNAL_WORD = 'raises'
|
63
|
+
|
58
64
|
def call
|
59
65
|
Dir['./lib/ducalis/cops/*.rb'].map do |f|
|
60
66
|
present_cop(klass_const_for(f), spec_cases_for(f))
|
@@ -66,7 +72,7 @@ class Documentation
|
|
66
72
|
def present_cop(klass, specs)
|
67
73
|
[
|
68
74
|
"## #{klass}\n", # header
|
69
|
-
klass
|
75
|
+
message(klass) # description
|
70
76
|
] +
|
71
77
|
specs.map do |(it, code)|
|
72
78
|
[
|
@@ -77,11 +83,14 @@ class Documentation
|
|
77
83
|
end
|
78
84
|
|
79
85
|
def color(it)
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
86
|
+
it.include?(SIGNAL_WORD) ? RED_SQUARE : GREEN_SQUARE
|
87
|
+
end
|
88
|
+
|
89
|
+
def message(klass)
|
90
|
+
[
|
91
|
+
klass.const_get(:OFFENSE),
|
92
|
+
*(klass.const_get(:DETAILS) if klass.const_defined?(:DETAILS))
|
93
|
+
].join("\n")
|
85
94
|
end
|
86
95
|
|
87
96
|
def spec_cases_for(f)
|
data/lib/ducalis/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ducalis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ignat Zakrevsky
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-11-
|
11
|
+
date: 2017-11-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: git
|