rubocop-amagi 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/cops/logger_format_cop.rb +67 -0
- data/lib/cops/readme.md +21 -0
- data/rubocop.yml +4 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5c511ba9414de4bf9b7fd8b9c22fd449642e137c4a6dc91ddb72ce1ba5d25843
|
4
|
+
data.tar.gz: dcc3756aeb88a3145b592ef21d2a1fdc1e401fd7de614454b0887c9f0a042b5d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b3009a45fb0297181f2d0aeabb9e6d6db74b486f6de675dab5a13a778e5e0fd7331df2308a6a4a27463302e73dfc52eea7a3f6ed4b2bf079074bec972895992a
|
7
|
+
data.tar.gz: 6e61fe1738eda19e5b6578c61c25ea0bebdcdddadcf837dd459bc3abd130f93529543260525db4865097d55ba0d55c8f700054120553d01bb52dd68809a4cb22
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module RuboCop
|
2
|
+
module Cop
|
3
|
+
module CustomCops
|
4
|
+
class PutLoggerFormatCop < Cop
|
5
|
+
# Constant required for Rubocop
|
6
|
+
MSG = 'Log Format should be <module/class>#method_name:<space><message>'.freeze
|
7
|
+
def get_classname(node)
|
8
|
+
# for getting complete names of controllers
|
9
|
+
@name = ""
|
10
|
+
if node.children[0] == nil
|
11
|
+
@name += node.children[1].to_s + "::"
|
12
|
+
else
|
13
|
+
get_classname(node.children[0])
|
14
|
+
@name += node.children[1].to_s + "::"
|
15
|
+
end
|
16
|
+
return @name[0...-2]
|
17
|
+
end
|
18
|
+
|
19
|
+
def on_module(node)
|
20
|
+
# gives module name for a particular node
|
21
|
+
@class_name = node.children[0].children[1]
|
22
|
+
end
|
23
|
+
|
24
|
+
def on_class(node)
|
25
|
+
# gives class name for a particular node
|
26
|
+
@class_name = get_classname(node.children[0])
|
27
|
+
end
|
28
|
+
|
29
|
+
def on_def(node)
|
30
|
+
# gives method_name for each node
|
31
|
+
@method_name = node.children[0]
|
32
|
+
end
|
33
|
+
|
34
|
+
def on_defs(node)
|
35
|
+
# gives method_name for class methods
|
36
|
+
@method_name = node.children[1]
|
37
|
+
end
|
38
|
+
|
39
|
+
def on_block(node)
|
40
|
+
# give name of a block defined without any method
|
41
|
+
@method_name = node.children[0].children[1].to_s if node.parent&.parent && node.parent.parent&.class_type?
|
42
|
+
end
|
43
|
+
|
44
|
+
def on_send(node)
|
45
|
+
if node.children[1] == :puts
|
46
|
+
str = get_string(node.children[2])
|
47
|
+
if str != "#{@class_name}##{@method_name}:"
|
48
|
+
# add offense if format not correct
|
49
|
+
add_offense(node, location: :expression)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def get_string(node)
|
55
|
+
string = if node&.str_type?
|
56
|
+
node.children[0].to_s
|
57
|
+
elsif node&.dstr_type?
|
58
|
+
node.children[0].children[0].to_s
|
59
|
+
else
|
60
|
+
'false_string'
|
61
|
+
end
|
62
|
+
string.partition(' ').first
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
data/lib/cops/readme.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# Amagi Rubocop CustomCop Rules
|
2
|
+
|
3
|
+
## How to use CustomCops?
|
4
|
+
***
|
5
|
+
**Using any cop**
|
6
|
+
---
|
7
|
+
Open .rubocop.yml in your working directory and set the enabled option as true.
|
8
|
+
~~~ruby
|
9
|
+
CustomCop/Copname:
|
10
|
+
Enabled: true
|
11
|
+
~~~
|
12
|
+
### About PutLoggerFormatCop
|
13
|
+
PutLoggerFormatCop ensures that the message format received on encountering **puts** is of the standard format
|
14
|
+
~~~ruby
|
15
|
+
"<module/class>#method_name:<space><message>".
|
16
|
+
~~~
|
17
|
+
Enabling the cop inside .rubocop.yml :
|
18
|
+
~~~ruby
|
19
|
+
CustomCop/PutLoggerFormatCop:
|
20
|
+
Enabled: true
|
21
|
+
~~~
|
data/rubocop.yml
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop-amagi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cloudport Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-07-08 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: amagi rubocop rules
|
14
14
|
email: cloudport.team@amagi.com
|
@@ -16,6 +16,8 @@ executables: []
|
|
16
16
|
extensions: []
|
17
17
|
extra_rdoc_files: []
|
18
18
|
files:
|
19
|
+
- lib/cops/logger_format_cop.rb
|
20
|
+
- lib/cops/readme.md
|
19
21
|
- rubocop.yml
|
20
22
|
homepage: https://github.com/amagimedia/rubocop-amagi
|
21
23
|
licenses:
|
@@ -36,7 +38,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
36
38
|
- !ruby/object:Gem::Version
|
37
39
|
version: '0'
|
38
40
|
requirements: []
|
39
|
-
rubygems_version: 3.
|
41
|
+
rubygems_version: 3.3.7
|
40
42
|
signing_key:
|
41
43
|
specification_version: 4
|
42
44
|
summary: amagi rubocop rules
|