misogi 0.1.0 → 0.2.0
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/CHANGELOG.md +4 -0
- data/README.md +3 -0
- data/lib/misogi/cli.rb +18 -7
- data/lib/misogi/rule/base.rb +3 -2
- data/lib/misogi/rule/rails.rb +2 -1
- data/lib/misogi/rule/rspec.rb +2 -1
- data/lib/misogi/rule/ruby_standard.rb +2 -1
- data/lib/misogi/version.rb +1 -1
- data/lib/misogi/violation.rb +15 -2
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 82aebf0fd073991337784a716bffd744a392fc39130dbb4df28ab09250f68503
|
|
4
|
+
data.tar.gz: 37ffc3498476d27b0bae291100add371815788e66fa0ecb8eaa222937cb70236
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e5ba3450b633aa7e0f43e1a151f2046ae226d9660a3a17e07cfc23064ff12a6b4941a25a4b04f77d52f935875fd88b353637cb00ab9757288ae18d3abbae642f
|
|
7
|
+
data.tar.gz: 2236cbf2ac2e708f56dfd9255314a9abd6da0252aec67089e2cdebccb526baea611889c1ec7521150bfae834cccaa58a6e2447f8f1ad27d5a81d1b2e3a77f072
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
data/lib/misogi/cli.rb
CHANGED
|
@@ -13,7 +13,8 @@ module Misogi
|
|
|
13
13
|
rules: nil, # nilの場合は設定ファイルを使用
|
|
14
14
|
base_path: nil,
|
|
15
15
|
pattern: nil,
|
|
16
|
-
config_path: ".misogi.yml"
|
|
16
|
+
config_path: ".misogi.yml",
|
|
17
|
+
format: "text"
|
|
17
18
|
}
|
|
18
19
|
end
|
|
19
20
|
|
|
@@ -107,6 +108,10 @@ module Misogi
|
|
|
107
108
|
@options[:config_path] = path
|
|
108
109
|
end
|
|
109
110
|
|
|
111
|
+
opts.on("-f", "--format FORMAT", "出力フォーマット(text|json)") do |format|
|
|
112
|
+
@options[:format] = format
|
|
113
|
+
end
|
|
114
|
+
|
|
110
115
|
opts.on("-h", "--help", "ヘルプを表示") do
|
|
111
116
|
puts opts
|
|
112
117
|
exit 0
|
|
@@ -235,12 +240,18 @@ module Misogi
|
|
|
235
240
|
# 違反を表示
|
|
236
241
|
# @param violations [Array<Violation>] 違反のリスト
|
|
237
242
|
def display_violations(violations)
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
puts
|
|
242
|
-
|
|
243
|
-
|
|
243
|
+
case @options[:format]
|
|
244
|
+
when "json"
|
|
245
|
+
require "json"
|
|
246
|
+
puts JSON.pretty_generate(violations.map(&:to_h))
|
|
247
|
+
when "text"
|
|
248
|
+
if violations.empty?
|
|
249
|
+
puts "✓ 違反は見つかりませんでした"
|
|
250
|
+
else
|
|
251
|
+
puts "✗ #{violations.size}件の違反が見つかりました:\n\n"
|
|
252
|
+
violations.each do |violation|
|
|
253
|
+
puts violation
|
|
254
|
+
end
|
|
244
255
|
end
|
|
245
256
|
end
|
|
246
257
|
end
|
data/lib/misogi/rule/base.rb
CHANGED
|
@@ -24,9 +24,10 @@ module Misogi
|
|
|
24
24
|
# 違反を作成するヘルパーメソッド
|
|
25
25
|
# @param file_path [String] ファイルパス
|
|
26
26
|
# @param message [String] 違反メッセージ
|
|
27
|
+
# @param suggest_path [String|nil] 修正案のパス
|
|
27
28
|
# @return [Violation]
|
|
28
|
-
def violation(file_path:, message:)
|
|
29
|
-
Violation.new(file_path: file_path, message: message, rule_name: name)
|
|
29
|
+
def violation(file_path:, message:, suggest_path: nil)
|
|
30
|
+
Violation.new(file_path: file_path, message: message, rule_name: name, suggest_path:)
|
|
30
31
|
end
|
|
31
32
|
end
|
|
32
33
|
end
|
data/lib/misogi/rule/rails.rb
CHANGED
|
@@ -66,7 +66,8 @@ module Misogi
|
|
|
66
66
|
defined_namespaces = parsed_content.namespaces.join(", ")
|
|
67
67
|
violations << violation(
|
|
68
68
|
file_path: file_path,
|
|
69
|
-
message: "名前空間 '#{defined_namespaces}' は #{expected_paths_str} に配置すべきです"
|
|
69
|
+
message: "名前空間 '#{defined_namespaces}' は #{expected_paths_str} に配置すべきです",
|
|
70
|
+
suggest_path: expected_paths_str
|
|
70
71
|
)
|
|
71
72
|
end
|
|
72
73
|
|
data/lib/misogi/rule/rspec.rb
CHANGED
|
@@ -64,7 +64,8 @@ module Misogi
|
|
|
64
64
|
described_str = described_namespaces.join(", ")
|
|
65
65
|
violations << violation(
|
|
66
66
|
file_path: file_path,
|
|
67
|
-
message: "テスト対象 '#{described_str}' のspecファイルは #{expected_paths_str} に配置すべきです"
|
|
67
|
+
message: "テスト対象 '#{described_str}' のspecファイルは #{expected_paths_str} に配置すべきです",
|
|
68
|
+
suggest_path: expected_paths_str
|
|
68
69
|
)
|
|
69
70
|
end
|
|
70
71
|
|
|
@@ -40,7 +40,8 @@ module Misogi
|
|
|
40
40
|
defined_namespaces = parsed_content.namespaces.join(", ")
|
|
41
41
|
violations << violation(
|
|
42
42
|
file_path: file_path,
|
|
43
|
-
message: "名前空間 '#{defined_namespaces}' は #{expected_paths_str} に配置すべきです"
|
|
43
|
+
message: "名前空間 '#{defined_namespaces}' は #{expected_paths_str} に配置すべきです",
|
|
44
|
+
suggest_path: expected_paths_str
|
|
44
45
|
)
|
|
45
46
|
end
|
|
46
47
|
|
data/lib/misogi/version.rb
CHANGED
data/lib/misogi/violation.rb
CHANGED
|
@@ -3,15 +3,17 @@
|
|
|
3
3
|
module Misogi
|
|
4
4
|
# ファイルパスとコンテンツの検証違反を表すクラス
|
|
5
5
|
class Violation
|
|
6
|
-
attr_reader :file_path, :message, :rule_name
|
|
6
|
+
attr_reader :file_path, :message, :rule_name, :suggest_path
|
|
7
7
|
|
|
8
8
|
# @param file_path [String] 違反が見つかったファイルパス
|
|
9
9
|
# @param message [String] 違反の詳細メッセージ
|
|
10
10
|
# @param rule_name [String] 違反を検出したルール名
|
|
11
|
-
|
|
11
|
+
# @param suggest_path [String|] 修正案のパス
|
|
12
|
+
def initialize(file_path:, message:, rule_name:, suggest_path: nil)
|
|
12
13
|
@file_path = file_path
|
|
13
14
|
@message = message
|
|
14
15
|
@rule_name = rule_name
|
|
16
|
+
@suggest_path = suggest_path
|
|
15
17
|
end
|
|
16
18
|
|
|
17
19
|
# 違反情報を文字列として表現
|
|
@@ -19,5 +21,16 @@ module Misogi
|
|
|
19
21
|
def to_s
|
|
20
22
|
"#{file_path}: [#{rule_name}] #{message}"
|
|
21
23
|
end
|
|
24
|
+
|
|
25
|
+
# 違反情報をハッシュとして表現
|
|
26
|
+
# @return [Hash]
|
|
27
|
+
def to_h
|
|
28
|
+
{
|
|
29
|
+
file_path:,
|
|
30
|
+
message:,
|
|
31
|
+
rule_name:,
|
|
32
|
+
suggest_path:
|
|
33
|
+
}
|
|
34
|
+
end
|
|
22
35
|
end
|
|
23
36
|
end
|