snoot 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 +89 -1
- data/README.md +82 -3
- data/lib/snoot/analyse_run/decision.rb +19 -4
- data/lib/snoot/analyse_run/result.rb +5 -2
- data/lib/snoot/analyse_run.rb +1 -1
- data/lib/snoot/analyser_orchestration/analyser_runs.rb +63 -0
- data/lib/snoot/analyser_orchestration/default.rb +64 -62
- data/lib/snoot/analyser_orchestration/failure_message.rb +26 -0
- data/lib/snoot/analyser_orchestration/result_mapping.rb +61 -17
- data/lib/snoot/analyser_orchestration.rb +2 -1
- data/lib/snoot/cli/argv.rb +18 -0
- data/lib/snoot/cli/internal_error_report.rb +18 -0
- data/lib/snoot/cli/status_line.rb +40 -0
- data/lib/snoot/cli/usage.rb +53 -0
- data/lib/snoot/cli.rb +59 -52
- data/lib/snoot/findings.rb +8 -6
- data/lib/snoot/render_report/complexity_sections.rb +69 -0
- data/lib/snoot/render_report/duplication_sections.rb +58 -0
- data/lib/snoot/render_report/smell_sections.rb +65 -0
- data/lib/snoot/render_report/source_excerpt.rb +66 -0
- data/lib/snoot/render_report.rb +43 -48
- data/lib/snoot/value_types.rb +26 -0
- data/lib/snoot/version.rb +1 -1
- data/lib/snoot.rb +6 -0
- data/snoot.allium +259 -46
- metadata +11 -1
data/lib/snoot/render_report.rb
CHANGED
|
@@ -2,81 +2,76 @@
|
|
|
2
2
|
|
|
3
3
|
module Snoot
|
|
4
4
|
# Given a finding_rendered Run, produces a Report. Smell findings get
|
|
5
|
-
#
|
|
6
|
-
# get
|
|
7
|
-
#
|
|
5
|
+
# header, remaining, instances, tuning and doc; ComplexityHit and
|
|
6
|
+
# DuplicationCluster get header, remaining, finding_context and doc.
|
|
7
|
+
# SmellSections, ComplexitySections and DuplicationSections build their
|
|
8
|
+
# variants' sections; the helpers below build the rest.
|
|
8
9
|
module RenderReport
|
|
9
10
|
# Report is the value returned by RenderReport.invoke: the source
|
|
10
11
|
# Run, the selected Finding it was built from, and the ordered
|
|
11
12
|
# sections hash that CLI joins into stdout output.
|
|
12
13
|
Report = Data.define(:run, :finding, :sections)
|
|
14
|
+
# The doc is always the last section, so the first line equal to this
|
|
15
|
+
# heading marks where it starts, even though reek's docs use ## headings too.
|
|
16
|
+
REFERENCE_HEADING = "## Reference"
|
|
13
17
|
|
|
14
18
|
module_function
|
|
15
19
|
|
|
16
|
-
def invoke(run, smells:, orchestration:)
|
|
20
|
+
def invoke(run, smells:, remaining:, orchestration:)
|
|
17
21
|
finding = run.selected_finding
|
|
18
22
|
sections = if finding.is_a?(Smell)
|
|
19
|
-
|
|
23
|
+
SmellSections.build(smells, finding, orchestration)
|
|
20
24
|
else
|
|
21
25
|
non_smell_sections(finding)
|
|
22
26
|
end
|
|
23
|
-
|
|
27
|
+
header, *rest = sections.merge(doc: reference(sections[:doc])).to_a
|
|
28
|
+
remaining_line = render_remaining(remaining, orchestration.significance_cutoffs)
|
|
29
|
+
Report.new(run: run, finding: finding, sections: [header, [:remaining, remaining_line], *rest].to_h)
|
|
24
30
|
end
|
|
25
31
|
|
|
26
|
-
def
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
def reference(doc) = "#{REFERENCE_HEADING}\n\n#{doc}"
|
|
33
|
+
|
|
34
|
+
def render_remaining(remaining, cutoffs)
|
|
35
|
+
counts = [
|
|
36
|
+
count_of(remaining.smell_types, "smell type"),
|
|
37
|
+
count_of(remaining.duplication_clusters, "duplication cluster"),
|
|
38
|
+
count_of(remaining.complexity_hits, "complexity hit")
|
|
39
|
+
]
|
|
40
|
+
below_cutoff = describe_below_cutoff(remaining.below_cutoff_smell_types)
|
|
41
|
+
"Also significant: #{counts.join(', ')}; #{below_cutoff} (#{describe_cutoffs(cutoffs)})"
|
|
33
42
|
end
|
|
34
43
|
|
|
35
|
-
def
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
when DuplicationCluster then duplication_cluster_sections(finding)
|
|
39
|
-
end
|
|
44
|
+
def describe_below_cutoff(smell_types)
|
|
45
|
+
summary = "#{count_of(smell_types.size, 'smell type')} below cutoff"
|
|
46
|
+
smell_types.empty? ? summary : "#{summary}: #{smell_types.map(&:name).join(', ')}"
|
|
40
47
|
end
|
|
41
48
|
|
|
42
|
-
def
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
doc: "High complexity hits indicate a method or class doing too much. " \
|
|
50
|
-
"Consider extracting helpers, simplifying conditionals, or " \
|
|
51
|
-
"splitting the responsibility across smaller units."
|
|
52
|
-
}
|
|
49
|
+
def describe_cutoffs(cutoffs)
|
|
50
|
+
clauses = [
|
|
51
|
+
cutoff_clause("smell types", cutoffs.smell_type_instances&.then { |floor| "#{floor}+ instances" }),
|
|
52
|
+
cutoff_clause("complexity hits", cutoffs.complexity_score&.then { |floor| "score #{format_score(floor)}+" }),
|
|
53
|
+
cutoff_clause("duplication clusters", cutoffs.duplication_locations&.then { |floor| "#{floor}+ locations" })
|
|
54
|
+
]
|
|
55
|
+
"cutoffs: #{clauses.join('; ')}"
|
|
53
56
|
end
|
|
54
57
|
|
|
55
|
-
def
|
|
56
|
-
|
|
57
|
-
rendered_locations = locations.map(&:description)
|
|
58
|
-
{
|
|
59
|
-
header: "Structural duplication: #{locations.size} locations (signature: #{cluster.signature})",
|
|
60
|
-
finding_context: "Locations:\n#{rendered_locations.join("\n")}",
|
|
61
|
-
doc: "Structural duplication suggests an extracted abstraction is missing. " \
|
|
62
|
-
"Consider whether the duplicated shape belongs to a single helper, " \
|
|
63
|
-
"module, or value type."
|
|
64
|
-
}
|
|
58
|
+
def cutoff_clause(category, requirement)
|
|
59
|
+
requirement ? "#{category} need #{requirement}" : "#{category} have no cutoff"
|
|
65
60
|
end
|
|
66
61
|
|
|
67
|
-
def
|
|
68
|
-
|
|
69
|
-
"## Instances\n\n#{groups.map { |path, group| render_instance_group(path, group) }.join("\n\n")}"
|
|
62
|
+
def format_score(score)
|
|
63
|
+
score.frac.zero? ? score.to_i.to_s : score.to_s("F")
|
|
70
64
|
end
|
|
71
65
|
|
|
72
|
-
def
|
|
73
|
-
|
|
74
|
-
.sort_by { |path, group| [-group.size, path] }
|
|
66
|
+
def count_of(count, noun)
|
|
67
|
+
count == 1 ? "1 #{noun}" : "#{count} #{noun}s"
|
|
75
68
|
end
|
|
76
69
|
|
|
77
|
-
def
|
|
78
|
-
|
|
79
|
-
|
|
70
|
+
def non_smell_sections(finding)
|
|
71
|
+
case finding
|
|
72
|
+
when ComplexityHit then ComplexitySections.build(finding)
|
|
73
|
+
when DuplicationCluster then DuplicationSections.build(finding)
|
|
74
|
+
end
|
|
80
75
|
end
|
|
81
76
|
end
|
|
82
77
|
end
|
data/lib/snoot/value_types.rb
CHANGED
|
@@ -14,7 +14,33 @@ module Snoot
|
|
|
14
14
|
def description = "#{path.raw}:#{line_start}-#{line_end}"
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
+
# One analyser-flagged line and its source text; text is nil when the
|
|
18
|
+
# source file could not be read.
|
|
19
|
+
SourceLine = Data.define(:number, :text)
|
|
20
|
+
|
|
21
|
+
# One operation's share of a flog score: "branch", "assignment", or a
|
|
22
|
+
# called method's name.
|
|
23
|
+
ScoreContribution = Data.define(:operation, :score)
|
|
24
|
+
|
|
25
|
+
# A flog score split into the dimensions its formula combines,
|
|
26
|
+
# score = sqrt(A**2 + B**2 + C**2). Each is a list of ScoreContribution,
|
|
27
|
+
# highest first.
|
|
28
|
+
ComplexityBreakdown = Data.define(:assignments, :branching, :calls)
|
|
29
|
+
|
|
30
|
+
# One copy of a duplicated node: its Location and the SourceLines of
|
|
31
|
+
# its span.
|
|
32
|
+
DuplicateCopy = Data.define(:location, :source_lines)
|
|
33
|
+
|
|
17
34
|
# A Reek smell category, named (e.g. "IrresponsibleModule"). Groups
|
|
18
35
|
# Smells for ranking; keys vendored-doc lookup.
|
|
19
36
|
SmellType = Data.define(:name)
|
|
37
|
+
|
|
38
|
+
# The thresholds an orchestration's significance pre-filters apply. A
|
|
39
|
+
# nil field means that category has no cutoff.
|
|
40
|
+
SignificanceCutoffs = Data.define(:smell_type_instances, :complexity_score, :duplication_locations)
|
|
41
|
+
|
|
42
|
+
# Per-category counts of significant, renderable findings a run left
|
|
43
|
+
# unreported, plus the smell types still below the significance cutoff.
|
|
44
|
+
# Smells count by smell type.
|
|
45
|
+
RemainingFindings = Data.define(:smell_types, :duplication_clusters, :complexity_hits, :below_cutoff_smell_types)
|
|
20
46
|
end
|
data/lib/snoot/version.rb
CHANGED
data/lib/snoot.rb
CHANGED
|
@@ -15,7 +15,13 @@ require "snoot/analyse_run"
|
|
|
15
15
|
require "snoot/analyse_run/result"
|
|
16
16
|
require "snoot/analyse_run/decision"
|
|
17
17
|
require "snoot/render_report"
|
|
18
|
+
require "snoot/render_report/smell_sections"
|
|
19
|
+
require "snoot/render_report/complexity_sections"
|
|
20
|
+
require "snoot/render_report/duplication_sections"
|
|
21
|
+
require "snoot/render_report/source_excerpt"
|
|
18
22
|
require "snoot/analyser_orchestration"
|
|
19
23
|
require "snoot/analyser_orchestration/result_mapping"
|
|
24
|
+
require "snoot/analyser_orchestration/failure_message"
|
|
25
|
+
require "snoot/analyser_orchestration/analyser_runs"
|
|
20
26
|
require "snoot/analyser_orchestration/default"
|
|
21
27
|
require "snoot/cli"
|
data/snoot.allium
CHANGED
|
@@ -52,12 +52,65 @@ value Location {
|
|
|
52
52
|
line_end: Integer
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
+
-- One line an analyser flagged, with that line's source text. text is
|
|
56
|
+
-- null when the source file could not be read.
|
|
57
|
+
value SourceLine {
|
|
58
|
+
number: Integer
|
|
59
|
+
text: String?
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
-- One operation's share of a flog score (e.g. "branch", "assignment",
|
|
63
|
+
-- or a called method's name such as "each").
|
|
64
|
+
value ScoreContribution {
|
|
65
|
+
operation: String
|
|
66
|
+
score: Decimal
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
-- A flog score split into the three dimensions its formula combines:
|
|
70
|
+
-- score = sqrt(A^2 + B^2 + C^2), where A sums the assignments, B the
|
|
71
|
+
-- branching contributions and C every other contribution. Each list is
|
|
72
|
+
-- ordered by descending score.
|
|
73
|
+
value ComplexityBreakdown {
|
|
74
|
+
assignments: List<ScoreContribution>
|
|
75
|
+
branching: List<ScoreContribution>
|
|
76
|
+
calls: List<ScoreContribution>
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
-- One copy of a duplicated node: where it is and the text of each line
|
|
80
|
+
-- in that span.
|
|
81
|
+
value DuplicateCopy {
|
|
82
|
+
location: Location
|
|
83
|
+
source_lines: List<SourceLine>
|
|
84
|
+
}
|
|
85
|
+
|
|
55
86
|
-- A reek smell type identifier (e.g. "FeatureEnvy", "TooManyMethods"). The
|
|
56
87
|
-- set of valid values is owned by reek.
|
|
57
88
|
value SmellType {
|
|
58
89
|
name: String
|
|
59
90
|
}
|
|
60
91
|
|
|
92
|
+
-- The numeric cutoffs an orchestration's significance pre-filters apply,
|
|
93
|
+
-- reported so the report can state them. A null field means that
|
|
94
|
+
-- category has no cutoff: every finding of that kind is significant.
|
|
95
|
+
value SignificanceCutoffs {
|
|
96
|
+
smell_type_instances: Integer?
|
|
97
|
+
complexity_score: Decimal?
|
|
98
|
+
duplication_locations: Integer?
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
-- How many significant, renderable findings a run left unreported,
|
|
102
|
+
-- per category. Smells count by smell type, since one report covers
|
|
103
|
+
-- every instance of its type. below_cutoff_smell_types names, in name
|
|
104
|
+
-- order, every smell type present in the analysed sources with no
|
|
105
|
+
-- instance passing significant_smells, so an agent sees a smell type
|
|
106
|
+
-- accumulating before it reaches the cutoff.
|
|
107
|
+
value RemainingFindings {
|
|
108
|
+
smell_types: Integer
|
|
109
|
+
duplication_clusters: Integer
|
|
110
|
+
complexity_hits: Integer
|
|
111
|
+
below_cutoff_smell_types: List<SmellType>
|
|
112
|
+
}
|
|
113
|
+
|
|
61
114
|
------------------------------------------------------------
|
|
62
115
|
-- Analyser Result
|
|
63
116
|
------------------------------------------------------------
|
|
@@ -83,7 +136,14 @@ variant Sources : AnalyserResult {
|
|
|
83
136
|
-- An analyser failure surfaced to the operator on outcome = analysis_failed.
|
|
84
137
|
-- The analyser field identifies which of the three analysers (Reek, Flog,
|
|
85
138
|
-- Flay) produced the failure; message is the human-readable error detail
|
|
86
|
-
-- carried on stderr.
|
|
139
|
+
-- carried on stderr, on one line. When the analyser's error wraps an
|
|
140
|
+
-- underlying one (a parse error, an unreadable file), message also
|
|
141
|
+
-- carries that error's detail, so a failure on one source file names the
|
|
142
|
+
-- line and reason the analyser reported, not just the file. Only an
|
|
143
|
+
-- error raised while an analyser itself runs is an analyser failure; an
|
|
144
|
+
-- error in snoot's translation of the analyser's output is an internal
|
|
145
|
+
-- error (see InternalErrorExit). Only the
|
|
146
|
+
-- first failed analyser in canonical order
|
|
87
147
|
-- (Reek -> Flog -> Flay) is recorded; the orchestration aborts on first
|
|
88
148
|
-- failure and does not invoke subsequent analysers.
|
|
89
149
|
variant AnalyserFailure : AnalyserResult {
|
|
@@ -128,6 +188,11 @@ contract AnalyserOrchestration {
|
|
|
128
188
|
significant_complexities: (complexities: Set<ComplexityHit>) -> Set<ComplexityHit>
|
|
129
189
|
significant_duplications: (duplications: Set<DuplicationCluster>) -> Set<DuplicationCluster>
|
|
130
190
|
|
|
191
|
+
-- significance_cutoffs reports the thresholds the three pre-filters
|
|
192
|
+
-- above apply. The values remain implementation policy; the contract
|
|
193
|
+
-- requires only that they describe the pre-filters faithfully.
|
|
194
|
+
significance_cutoffs: () -> SignificanceCutoffs
|
|
195
|
+
|
|
131
196
|
-- analyse runs the three analysers in canonical order (Reek -> Flog
|
|
132
197
|
-- -> Flay), capturing each output as it succeeds. On the first
|
|
133
198
|
-- failure it returns an AnalyserFailure tagged with that analyser
|
|
@@ -135,7 +200,22 @@ contract AnalyserOrchestration {
|
|
|
135
200
|
-- returns a Sources bundling the three result sets. This signature
|
|
136
201
|
-- respects @invariant Determinism: for the same path set, the same
|
|
137
202
|
-- outcome (including which analyser fails first, if any, and its
|
|
138
|
-
-- message) is produced within a single CLI invocation.
|
|
203
|
+
-- message) is produced within a single CLI invocation. Each analyser
|
|
204
|
+
-- scopes the path set as its own command does: reek skips what
|
|
205
|
+
-- .reek.yml's exclude_paths names, flay skips files the current
|
|
206
|
+
-- directory's .flayignore matches, and flog analyses every Ruby
|
|
207
|
+
-- file under the path set. Each Smell's
|
|
208
|
+
-- source_lines holds every line reek flagged for it, unique and
|
|
209
|
+
-- ascending, with that line's text from the analysed file. Each
|
|
210
|
+
-- ComplexityHit's location spans the method from its first line to
|
|
211
|
+
-- its last, its source_lines hold every line of that span with the
|
|
212
|
+
-- file's text, and its breakdown groups flog's per-operation scores
|
|
213
|
+
-- the way flog's score formula does. Each DuplicationCluster location
|
|
214
|
+
-- spans the duplicated node from its first line to its last; copies
|
|
215
|
+
-- holds one DuplicateCopy per location, ordered by path then first
|
|
216
|
+
-- line, with each line's text. node_type, identical and mass are
|
|
217
|
+
-- flay's (mass is the cluster total flay reports); copy_mass is the
|
|
218
|
+
-- mass of one copy.
|
|
139
219
|
analyse: (paths: Set<Path>) -> AnalyserResult
|
|
140
220
|
|
|
141
221
|
@invariant Determinism
|
|
@@ -162,17 +242,25 @@ variant Smell : Finding {
|
|
|
162
242
|
smell_type: SmellType
|
|
163
243
|
location: Location
|
|
164
244
|
message: String
|
|
245
|
+
source_lines: List<SourceLine>
|
|
165
246
|
}
|
|
166
247
|
|
|
167
248
|
variant ComplexityHit : Finding {
|
|
168
249
|
location: Location
|
|
169
250
|
method_name: String?
|
|
170
251
|
score: Decimal
|
|
252
|
+
breakdown: ComplexityBreakdown
|
|
253
|
+
source_lines: List<SourceLine>
|
|
171
254
|
}
|
|
172
255
|
|
|
173
256
|
variant DuplicationCluster : Finding {
|
|
174
257
|
signature: String
|
|
258
|
+
node_type: String
|
|
259
|
+
identical: Boolean
|
|
260
|
+
mass: Integer
|
|
261
|
+
copy_mass: Integer
|
|
175
262
|
locations: Set<Location>
|
|
263
|
+
copies: List<DuplicateCopy>
|
|
176
264
|
}
|
|
177
265
|
|
|
178
266
|
-- A Run represents one CLI invocation. Its lifecycle terminates in exactly
|
|
@@ -294,21 +382,41 @@ rule RenderReport {
|
|
|
294
382
|
|
|
295
383
|
-- Section composition is variant-conditional:
|
|
296
384
|
--
|
|
297
|
-
--
|
|
298
|
-
--
|
|
299
|
-
--
|
|
385
|
+
-- Every report's second section is remaining: one line counting the
|
|
386
|
+
-- candidate findings of each category other than the selected one
|
|
387
|
+
-- and naming the below-cutoff smell types (a RemainingFindings),
|
|
388
|
+
-- followed by significance_cutoffs(). It is a count, not a second
|
|
389
|
+
-- finding: candidates are rendered as numbers only, and below-cutoff
|
|
390
|
+
-- smell types by name only.
|
|
391
|
+
--
|
|
392
|
+
-- For Smell findings the report is five sections:
|
|
393
|
+
-- - header: one-line summary naming the smell type and counting its
|
|
394
|
+
-- instances and the files they span
|
|
395
|
+
-- - remaining: as above
|
|
300
396
|
-- - instances: every Smell from the analysed sources whose smell_type
|
|
301
397
|
-- matches the selected_finding's smell_type, grouped by
|
|
302
398
|
-- file, with files ordered by descending instance count
|
|
303
|
-
-- and alphabetical tie-break
|
|
304
|
-
--
|
|
305
|
-
-- is
|
|
306
|
-
--
|
|
399
|
+
-- and alphabetical tie-break
|
|
400
|
+
-- - tuning: fix-first guidance naming where the smell type's
|
|
401
|
+
-- detector is configured (.reek.yml, under detectors:)
|
|
402
|
+
-- - doc: a '## Reference' heading, then vendored_doc(smell_type),
|
|
403
|
+
-- unmodified (always non-null here, per the
|
|
404
|
+
-- SelectedFindingsAreRenderable invariant)
|
|
405
|
+
-- The header and instances lead so a reader that truncates the report
|
|
406
|
+
-- from the top still sees what was found and where; the vendored doc,
|
|
407
|
+
-- often long, follows as reference. Its sample configuration omits
|
|
408
|
+
-- the detectors: key a .reek.yml needs, which the tuning section
|
|
409
|
+
-- supplies; the tuning prose is static implementation policy.
|
|
307
410
|
--
|
|
308
|
-
-- For ComplexityHit and DuplicationCluster findings the report is
|
|
309
|
-
--
|
|
310
|
-
-- - ComplexityHit:
|
|
311
|
-
--
|
|
411
|
+
-- For ComplexityHit and DuplicationCluster findings the report is
|
|
412
|
+
-- a four-section structure (header, remaining, finding_context, doc):
|
|
413
|
+
-- - ComplexityHit: finding_context carries the score breakdown
|
|
414
|
+
-- and the method's code; doc is hand-written
|
|
415
|
+
-- generic prose for high complexity
|
|
416
|
+
-- - DuplicationCluster: finding_context carries every location and
|
|
417
|
+
-- the code of up to three copies; doc is
|
|
418
|
+
-- hand-written generic prose for high duplication
|
|
419
|
+
-- In every variant the doc opens with a '## Reference' heading.
|
|
312
420
|
-- The exact prose is static implementation policy of the gem (one
|
|
313
421
|
-- string per non-Smell variant), not an orchestration-contract
|
|
314
422
|
-- responsibility. This mirrors the threshold-policy delegation in
|
|
@@ -319,47 +427,92 @@ rule RenderReport {
|
|
|
319
427
|
ReportEmitted(
|
|
320
428
|
run: run,
|
|
321
429
|
finding: run.selected_finding,
|
|
322
|
-
sections: {
|
|
430
|
+
sections: { header, remaining, instances, tuning, doc }
|
|
323
431
|
)
|
|
324
432
|
else:
|
|
325
433
|
ReportEmitted(
|
|
326
434
|
run: run,
|
|
327
435
|
finding: run.selected_finding,
|
|
328
|
-
sections: { header, finding_context, doc }
|
|
436
|
+
sections: { header, remaining, finding_context, doc }
|
|
329
437
|
)
|
|
330
438
|
|
|
331
439
|
@guarantee SmellReportShape
|
|
332
440
|
-- For Smell findings, a rendered report contains, in order:
|
|
333
|
-
-- 1.
|
|
334
|
-
--
|
|
441
|
+
-- 1. Header -- one-line summary: the smell type's name in words,
|
|
442
|
+
-- the number of matching instances, and the number
|
|
443
|
+
-- of files they span (analyser-implicit)
|
|
444
|
+
-- 2. Remaining -- 'Also significant: ' then the RemainingFindings
|
|
445
|
+
-- counts by category, then '; N smell types below
|
|
446
|
+
-- cutoff' with ': ' and the comma-separated type
|
|
447
|
+
-- names when N > 0, then the cutoffs in
|
|
448
|
+
-- parentheses, on one line
|
|
449
|
+
-- 3. Instances -- '## Instances' heading followed by per-file
|
|
335
450
|
-- groupings of every Smell from the analysed sources
|
|
336
451
|
-- matching the selected smell_type. Each file group
|
|
337
|
-
-- is the raw path on its own line, then
|
|
338
|
-
-- indented 'Line N: <message>'
|
|
339
|
-
--
|
|
340
|
-
--
|
|
452
|
+
-- is the raw path on its own line, then per Smell a
|
|
453
|
+
-- 2-space-indented 'Line N: <message>' line ('Lines
|
|
454
|
+
-- N, M: <message>' when several lines are flagged),
|
|
455
|
+
-- followed by up to five 4-space-indented
|
|
456
|
+
-- 'N | <code>' lines carrying the flagged lines'
|
|
457
|
+
-- text (stripped, control characters replaced
|
|
458
|
+
-- with U+FFFD, cut to 160 characters) and, past
|
|
459
|
+
-- five, one '… K more: <line numbers>' line. A
|
|
460
|
+
-- line with no readable text has no code line.
|
|
461
|
+
-- File groups are ordered by descending instance
|
|
462
|
+
-- count, with alphabetical path as the tie-break.
|
|
463
|
+
-- 4. Tuning -- fix every instance and rerun; otherwise configure
|
|
464
|
+
-- the detector in .reek.yml as a detectors: block
|
|
465
|
+
-- keyed by the smell type's name
|
|
466
|
+
-- 5. Doc -- '## Reference' heading followed by the vendored
|
|
467
|
+
-- markdown for the selected smell type, unmodified
|
|
341
468
|
|
|
342
469
|
@guarantee NonSmellReportShape
|
|
343
470
|
-- For ComplexityHit and DuplicationCluster findings, a rendered
|
|
344
471
|
-- report contains, in order:
|
|
345
472
|
-- 1. Header -- one-line summary (analyser-implicit, finding
|
|
346
|
-
-- name, location)
|
|
347
|
-
--
|
|
348
|
-
--
|
|
349
|
-
--
|
|
350
|
-
--
|
|
473
|
+
-- name, location). For DuplicationCluster:
|
|
474
|
+
-- 'Identical' or 'Similar', the node type,
|
|
475
|
+
-- the location count, flay's mass and the
|
|
476
|
+
-- mass of one copy
|
|
477
|
+
-- 2. Remaining -- as in SmellReportShape
|
|
478
|
+
-- 3. FindingContext -- file path(s), line range(s), the analyser's
|
|
479
|
+
-- message. For DuplicationCluster: every
|
|
480
|
+
-- location's span, ordered by path then first
|
|
481
|
+
-- line, then the code of the first copy when
|
|
482
|
+
-- the copies are identical, or of the first
|
|
483
|
+
-- three when they are similar: each copy's
|
|
484
|
+
-- span followed by up to twenty 'N | <code>'
|
|
485
|
+
-- lines, formatted as for ComplexityHit. A
|
|
486
|
+
-- copy with unreadable source is left out.
|
|
487
|
+
-- For ComplexityHit:
|
|
488
|
+
-- the span, the method name, the score (two
|
|
489
|
+
-- decimals) with its formula, one line per
|
|
490
|
+
-- breakdown dimension (descending total; the
|
|
491
|
+
-- top four operations by score, then '…'),
|
|
492
|
+
-- then up to fifty 'N | <code>' lines of the
|
|
493
|
+
-- method with common indentation removed,
|
|
494
|
+
-- control characters replaced with U+FFFD and
|
|
495
|
+
-- lines cut to 160 characters, and past fifty
|
|
496
|
+
-- one '… K more lines (N–M)' line. Unreadable
|
|
497
|
+
-- source has no code lines.
|
|
498
|
+
-- 4. Doc -- '## Reference' heading followed by one inlined
|
|
499
|
+
-- hand-written prose constant
|
|
351
500
|
|
|
352
501
|
@guarantee AnalyserProvenanceImplicit
|
|
353
502
|
-- The report does not label the originating analyser. The shape of
|
|
354
|
-
-- the report (
|
|
355
|
-
--
|
|
356
|
-
-- complexity language vs duplication enumeration)
|
|
357
|
-
-- for the agent to infer provenance.
|
|
503
|
+
-- the report (instances for Smell vs finding_context for
|
|
504
|
+
-- non-Smell) and the finding's wording
|
|
505
|
+
-- (smell name vs complexity language vs duplication enumeration)
|
|
506
|
+
-- are sufficient for the agent to infer provenance.
|
|
358
507
|
|
|
359
508
|
@guidance
|
|
360
509
|
-- Section ordering within each variant shape is structural.
|
|
361
510
|
-- Implementations should emit sections in the declared order so an
|
|
362
|
-
-- agent / parser can rely on predictable landmarks
|
|
511
|
+
-- agent / parser can rely on predictable landmarks: the header on
|
|
512
|
+
-- the first line, 'Also significant: ' opening the second section,
|
|
513
|
+
-- and the '## Instances' and '## Reference' headings. The doc is the
|
|
514
|
+
-- last section, so the first '## Reference' line opens it even when
|
|
515
|
+
-- the doc itself carries ## headings. The agent
|
|
363
516
|
-- reading the report should treat the inlined doc as primary
|
|
364
517
|
-- context for acting on the finding. For Smell findings, the
|
|
365
518
|
-- Instances list enumerates every site the agent must consider.
|
|
@@ -373,7 +526,8 @@ rule RenderReport {
|
|
|
373
526
|
------------------------------------------------------------
|
|
374
527
|
|
|
375
528
|
-- A rendered run references exactly one finding. There is no concept of a
|
|
376
|
-
-- top-tier of multiple findings in this spec
|
|
529
|
+
-- top-tier of multiple findings in this spec; the report's remaining
|
|
530
|
+
-- section counts other candidates without rendering them.
|
|
377
531
|
invariant SingleFindingPerRun {
|
|
378
532
|
for r in Runs:
|
|
379
533
|
r.outcome = finding_rendered implies r.selected_finding != null
|
|
@@ -446,16 +600,47 @@ surface CLI {
|
|
|
446
600
|
-- nothing_to_report -> 0
|
|
447
601
|
-- finding_rendered -> 1
|
|
448
602
|
-- analysis_failed -> 2
|
|
603
|
+
-- The exception is an invocation cut short by an unexpected
|
|
604
|
+
-- internal error, which reaches no terminal outcome; see
|
|
605
|
+
-- InternalErrorExit.
|
|
606
|
+
|
|
607
|
+
@guarantee InternalErrorExit
|
|
608
|
+
-- When an accepted invocation is cut short by an unexpected
|
|
609
|
+
-- internal error (anything other than an analyser failure, which
|
|
610
|
+
-- is analysis_failed; an error in translating an analyser's
|
|
611
|
+
-- output is internal), the CLI exits 70 (EX_SOFTWARE). Stderr
|
|
612
|
+
-- carries 'snoot: internal error: <error class>: <message>' and
|
|
613
|
+
-- the backtrace; stdout ends with the internal_error status line
|
|
614
|
+
-- (see StatusLine), after whatever had already been written.
|
|
615
|
+
-- Exit 70 is distinct so a gate can tell a crash from
|
|
616
|
+
-- finding_rendered. An operator interrupt is not an internal
|
|
617
|
+
-- error and keeps the runtime's own exit status.
|
|
449
618
|
|
|
450
619
|
@guarantee UsageErrorExit
|
|
451
|
-
-- An invocation whose argv
|
|
452
|
-
--
|
|
453
|
-
-- does not
|
|
454
|
-
--
|
|
455
|
-
--
|
|
456
|
-
--
|
|
457
|
-
--
|
|
458
|
-
--
|
|
620
|
+
-- An invocation whose argv the CLI rejects is not an accepted
|
|
621
|
+
-- invocation: RunInvoked does not fire, no Run is created, and
|
|
622
|
+
-- TerminatesInOneOutcome does not apply. The CLI exits 64 (POSIX
|
|
623
|
+
-- EX_USAGE). An argument beginning with '-' is an option unless
|
|
624
|
+
-- it follows a '--' argument, which ends options and is itself
|
|
625
|
+
-- consumed. A help or version option anywhere in argv wins: the
|
|
626
|
+
-- CLI prints that banner to stdout and exits 0, ignoring the rest.
|
|
627
|
+
-- Otherwise two kinds of argv are rejected:
|
|
628
|
+
-- - an unknown option: stderr carries one 'snoot: unknown
|
|
629
|
+
-- option: <arg>' line per unknown option;
|
|
630
|
+
-- - a path argument naming nothing on disk: the whole
|
|
631
|
+
-- invocation is rejected even when other paths exist, and
|
|
632
|
+
-- stderr carries one 'snoot: no such file or directory:
|
|
633
|
+
-- <path>' line per missing path. Analysing only the paths
|
|
634
|
+
-- that exist, or some fallback location, would report on a
|
|
635
|
+
-- scope the operator did not ask for.
|
|
636
|
+
-- Every problem is reported in one invocation: the unknown-option
|
|
637
|
+
-- lines, then the missing-path lines, then -- only when an
|
|
638
|
+
-- unknown option was present -- a single "Try 'snoot --help' for
|
|
639
|
+
-- usage." line. Stderr carries nothing else.
|
|
640
|
+
-- Exit code 64 is reserved for this pre-domain failure mode so an
|
|
641
|
+
-- operator (or CI) can distinguish a usage error from
|
|
642
|
+
-- finding_rendered, both of which would otherwise share an exit
|
|
643
|
+
-- code.
|
|
459
644
|
|
|
460
645
|
@guarantee EmptyPathsDefault
|
|
461
646
|
-- An operator invocation that supplies no paths is treated as if
|
|
@@ -466,17 +651,45 @@ surface CLI {
|
|
|
466
651
|
-- empty paths argument.
|
|
467
652
|
|
|
468
653
|
@guarantee StdoutMutuallyExclusive
|
|
469
|
-
-- A run produces stdout content corresponding to its outcome
|
|
654
|
+
-- A run produces stdout content corresponding to its outcome,
|
|
655
|
+
-- always ending with the run's status line (see StatusLine):
|
|
470
656
|
-- finding_rendered -> stdout = formatted report (variant-
|
|
471
657
|
-- specific shape, see the RenderReport
|
|
472
|
-
-- rule's @guarantee blocks)
|
|
473
|
-
--
|
|
474
|
-
--
|
|
475
|
-
--
|
|
476
|
-
--
|
|
658
|
+
-- rule's @guarantee blocks), then the
|
|
659
|
+
-- status line
|
|
660
|
+
-- nothing_to_report -> stdout = single-line acknowledgement:
|
|
661
|
+
-- 'nothing to report -- no findings above
|
|
662
|
+
-- snoot's significance floor', then the
|
|
663
|
+
-- below-cutoff smell types as in the
|
|
664
|
+
-- Remaining section, then
|
|
665
|
+
-- significance_cutoffs() in parentheses;
|
|
666
|
+
-- then the status line
|
|
667
|
+
-- analysis_failed -> stdout = the status line only
|
|
477
668
|
-- Stderr carries warnings (missing vendored docs) at all outcomes.
|
|
478
669
|
-- On outcome = analysis_failed, stderr additionally carries the
|
|
479
670
|
-- failed analyser's message (run.failure.message): one analyser's
|
|
480
671
|
-- error, not aggregated across analysers and not multi-line per
|
|
481
672
|
-- analyser. These stderr contents are independent of stdout.
|
|
673
|
+
-- At any outcome, stderr may also carry the analysers' own
|
|
674
|
+
-- diagnostics, passed through unchanged: files they skipped
|
|
675
|
+
-- (unreadable, unparseable or slow to parse) and their own
|
|
676
|
+
-- advice. snoot neither formats nor suppresses them; for files an
|
|
677
|
+
-- analyser skips without failing, they are the only record of
|
|
678
|
+
-- the skip.
|
|
679
|
+
|
|
680
|
+
@guarantee StatusLine
|
|
681
|
+
-- The last stdout line of every accepted invocation is a status
|
|
682
|
+
-- line for scripts: 'snoot-status: ', the outcome name, then
|
|
683
|
+
-- space-separated key=value fields whose values contain no
|
|
684
|
+
-- spaces:
|
|
685
|
+
-- finding_rendered -> category=smell|duplication|complexity;
|
|
686
|
+
-- type=<smell type name> for a smell; then
|
|
687
|
+
-- remaining=<smell_types +
|
|
688
|
+
-- duplication_clusters + complexity_hits
|
|
689
|
+
-- from RemainingFindings>
|
|
690
|
+
-- nothing_to_report -> no fields
|
|
691
|
+
-- analysis_failed -> analyser=reek|flog|flay
|
|
692
|
+
-- internal_error -> error=<error class name>
|
|
693
|
+
-- A rejected argv (UsageErrorExit) and a help or version banner
|
|
694
|
+
-- start no run and print no status line.
|
|
482
695
|
}
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: snoot
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Benjamin Kudria
|
|
@@ -119,14 +119,24 @@ files:
|
|
|
119
119
|
- lib/snoot/analyse_run/decision.rb
|
|
120
120
|
- lib/snoot/analyse_run/result.rb
|
|
121
121
|
- lib/snoot/analyser_orchestration.rb
|
|
122
|
+
- lib/snoot/analyser_orchestration/analyser_runs.rb
|
|
122
123
|
- lib/snoot/analyser_orchestration/default.rb
|
|
124
|
+
- lib/snoot/analyser_orchestration/failure_message.rb
|
|
123
125
|
- lib/snoot/analyser_orchestration/result_mapping.rb
|
|
124
126
|
- lib/snoot/analyser_result.rb
|
|
125
127
|
- lib/snoot/cli.rb
|
|
128
|
+
- lib/snoot/cli/argv.rb
|
|
126
129
|
- lib/snoot/cli/event.rb
|
|
130
|
+
- lib/snoot/cli/internal_error_report.rb
|
|
127
131
|
- lib/snoot/cli/pipeline.rb
|
|
132
|
+
- lib/snoot/cli/status_line.rb
|
|
133
|
+
- lib/snoot/cli/usage.rb
|
|
128
134
|
- lib/snoot/findings.rb
|
|
129
135
|
- lib/snoot/render_report.rb
|
|
136
|
+
- lib/snoot/render_report/complexity_sections.rb
|
|
137
|
+
- lib/snoot/render_report/duplication_sections.rb
|
|
138
|
+
- lib/snoot/render_report/smell_sections.rb
|
|
139
|
+
- lib/snoot/render_report/source_excerpt.rb
|
|
130
140
|
- lib/snoot/run.rb
|
|
131
141
|
- lib/snoot/state_error.rb
|
|
132
142
|
- lib/snoot/value_types.rb
|