rubocop-amagi 0.0.2 → 0.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aa00724d1111fb9879f9f7c1e1dce30fdeb71f09d7f2c48eaf204a5046583782
4
- data.tar.gz: 8e516fab6964c59a4cbffecb2fad4207b01738ab0e1f99648b64d5454e5d9517
3
+ metadata.gz: 5c511ba9414de4bf9b7fd8b9c22fd449642e137c4a6dc91ddb72ce1ba5d25843
4
+ data.tar.gz: dcc3756aeb88a3145b592ef21d2a1fdc1e401fd7de614454b0887c9f0a042b5d
5
5
  SHA512:
6
- metadata.gz: edc06cd08d7c1b94cd6c88a42a21ab97b8043488cb3d4eb041671cf22afe47eba4ac2a07695225c007c4dbfe7ea4730646234b227b79149482ae790662a7650c
7
- data.tar.gz: 57a5b9215454f2578d2fc8220cb1992bf02442be41bdfe11592b77b60d572487ad1f88e28bea791046608aefc17316a06d02fd5a712f246c7c185b8b022d6513
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
@@ -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
@@ -8,7 +8,11 @@ AllCops:
8
8
  - 'node_modules/**/*'
9
9
 
10
10
  require:
11
+ - './lib/cops/logger_format_cop.rb'
11
12
  - 'rubocop-rails'
13
+
14
+ CustomCops/PutLoggerFormatCop:
15
+ Enabled: false
12
16
 
13
17
  Bundler/DuplicatedGem:
14
18
  Enabled: true
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.2
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: 2021-10-18 00:00:00.000000000 Z
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.2.26
41
+ rubygems_version: 3.3.7
40
42
  signing_key:
41
43
  specification_version: 4
42
44
  summary: amagi rubocop rules