whose-components 0.3.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.
Files changed (104) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +231 -0
  4. data/Rakefile +8 -0
  5. data/app/assets/fonts/whose_components/OFL.txt +93 -0
  6. data/app/assets/fonts/whose_components/leaguespartan-bold.woff2 +0 -0
  7. data/app/assets/tailwind/whose_components/engine.css +139 -0
  8. data/app/components/whose/badge_component/badge_component.html.haml +1 -0
  9. data/app/components/whose/badge_component.rb +23 -0
  10. data/app/components/whose/button_component/button_component.html.haml +6 -0
  11. data/app/components/whose/button_component.rb +40 -0
  12. data/app/components/whose/card_component/card_component.html.haml +6 -0
  13. data/app/components/whose/card_component.rb +24 -0
  14. data/app/components/whose/dialog.rb +21 -0
  15. data/app/components/whose/dialog_header_component/dialog_header_component.en.yml +2 -0
  16. data/app/components/whose/dialog_header_component/dialog_header_component.html.haml +3 -0
  17. data/app/components/whose/dialog_header_component.rb +8 -0
  18. data/app/components/whose/flash_component/flash_component.en.yml +2 -0
  19. data/app/components/whose/flash_component/flash_component.html.haml +14 -0
  20. data/app/components/whose/flash_component.rb +35 -0
  21. data/app/components/whose/form/field_component/field_component.html.haml +16 -0
  22. data/app/components/whose/form/field_component.rb +90 -0
  23. data/app/components/whose/link_component/link_component.html.haml +1 -0
  24. data/app/components/whose/link_component.rb +22 -0
  25. data/app/components/whose/list_component/list_component.html.haml +3 -0
  26. data/app/components/whose/list_component.rb +15 -0
  27. data/app/components/whose/list_row_component/list_row_component.html.haml +12 -0
  28. data/app/components/whose/list_row_component.rb +19 -0
  29. data/app/components/whose/modal_component/modal_component.html.haml +10 -0
  30. data/app/components/whose/modal_component.rb +12 -0
  31. data/app/components/whose/nav/item_component/item_component.html.haml +5 -0
  32. data/app/components/whose/nav/item_component.rb +21 -0
  33. data/app/components/whose/nav_component/nav_component.en.yml +4 -0
  34. data/app/components/whose/nav_component/nav_component.html.haml +22 -0
  35. data/app/components/whose/nav_component.rb +55 -0
  36. data/app/components/whose/offcanvas_component/offcanvas_component.html.haml +8 -0
  37. data/app/components/whose/offcanvas_component.rb +21 -0
  38. data/app/components/whose/page_header_component/page_header_component.html.haml +7 -0
  39. data/app/components/whose/page_header_component.rb +17 -0
  40. data/app/components/whose/pagination_component/pagination_component.html.haml +2 -0
  41. data/app/components/whose/pagination_component.rb +12 -0
  42. data/app/components/whose/tooltip_component/tooltip_component.html.haml +3 -0
  43. data/app/components/whose/tooltip_component.rb +26 -0
  44. data/app/controllers/concerns/whose/authentication.rb +77 -0
  45. data/app/controllers/whose/confirmations_controller.rb +29 -0
  46. data/app/controllers/whose/passwords_controller.rb +38 -0
  47. data/app/controllers/whose/registrations_controller.rb +29 -0
  48. data/app/controllers/whose/sessions_controller.rb +31 -0
  49. data/app/helpers/whose/component_helper.rb +18 -0
  50. data/app/helpers/whose/form_helper.rb +16 -0
  51. data/app/javascript/whose/controllers/whose_dialog_controller.js +3 -0
  52. data/app/javascript/whose/controllers/whose_notification_controller.js +8 -0
  53. data/app/javascript/whose/controllers/whose_password_visibility_controller.js +3 -0
  54. data/app/jobs/.keep +0 -0
  55. data/app/mailers/whose/auth_mailer.rb +17 -0
  56. data/app/models/concerns/whose/authenticatable.rb +31 -0
  57. data/app/models/whose/current.rb +6 -0
  58. data/app/models/whose/session.rb +7 -0
  59. data/app/views/whose/auth_mailer/account_exists.html.haml +6 -0
  60. data/app/views/whose/auth_mailer/account_exists.text.haml +9 -0
  61. data/app/views/whose/auth_mailer/confirmation.html.haml +3 -0
  62. data/app/views/whose/auth_mailer/confirmation.text.haml +5 -0
  63. data/app/views/whose/auth_mailer/password_reset.html.haml +3 -0
  64. data/app/views/whose/auth_mailer/password_reset.text.haml +5 -0
  65. data/app/views/whose/confirmations/new.html.haml +11 -0
  66. data/app/views/whose/confirmations/show.html.haml +6 -0
  67. data/app/views/whose/passwords/edit.html.haml +11 -0
  68. data/app/views/whose/passwords/new.html.haml +11 -0
  69. data/app/views/whose/registrations/new.html.haml +16 -0
  70. data/app/views/whose/sessions/new.html.haml +15 -0
  71. data/config/importmap.rb +7 -0
  72. data/config/locales/whose/auth.en.yml +71 -0
  73. data/config/locales/whose/errors.en.yml +17 -0
  74. data/config/locales/whose/form.en.yml +5 -0
  75. data/config/locales/whose/nav.en.yml +4 -0
  76. data/lib/generators/whose/components/install/install_generator.rb +56 -0
  77. data/lib/generators/whose/components/install/templates/application.html.haml +24 -0
  78. data/lib/generators/whose/components/install/templates/create_users.rb.tt +17 -0
  79. data/lib/generators/whose/components/install/templates/create_whose_sessions.rb.tt +13 -0
  80. data/lib/generators/whose/components/install/templates/user.rb.tt +7 -0
  81. data/lib/generators/whose/components/install/templates/users.rb.tt +15 -0
  82. data/lib/generators/whose/components/views/USAGE +12 -0
  83. data/lib/generators/whose/components/views/views_generator.rb +19 -0
  84. data/lib/templates/app/.claude/skills/asd-ste100/LICENSE +21 -0
  85. data/lib/templates/app/.claude/skills/asd-ste100/README.md +102 -0
  86. data/lib/templates/app/.claude/skills/asd-ste100/SKILL.md +139 -0
  87. data/lib/templates/app/.claude/skills/asd-ste100/examples/before-after.md +92 -0
  88. data/lib/templates/app/.claude/skills/asd-ste100/examples/linter-edge-cases.md +14 -0
  89. data/lib/templates/app/.claude/skills/asd-ste100/references/writing-rules.md +59 -0
  90. data/lib/templates/app/.claude/skills/asd-ste100/scripts/ste-lint.py +486 -0
  91. data/lib/templates/app/CLAUDE.md.tt +181 -0
  92. data/lib/templates/whose_app_template.rb +144 -0
  93. data/lib/whose/components/engine.rb +33 -0
  94. data/lib/whose/components/form_builder.rb +158 -0
  95. data/lib/whose/components/routes.rb +16 -0
  96. data/lib/whose/components/version.rb +7 -0
  97. data/lib/whose/components.rb +16 -0
  98. data/lib/whose/merge_classes.rb +17 -0
  99. data/vendor/javascript/@stimulus-components--dialog.js +4 -0
  100. data/vendor/javascript/@stimulus-components--notification.js +4 -0
  101. data/vendor/javascript/@stimulus-components--password-visibility.js +4 -0
  102. data/vendor/javascript/LICENSES +30 -0
  103. data/vendor/javascript/stimulus-use.js +4 -0
  104. metadata +272 -0
@@ -0,0 +1,486 @@
1
+ #!/usr/bin/env python3
2
+ """Deterministic linter for the structural STE rules in SKILL.md.
3
+
4
+ Checks only rules verifiable without ASD's dictionary. Deliberately never
5
+ flags hedges or modality (may/might/could): the skill treats confidence as
6
+ content, and a linter that pressures hedges out would rewrite claims.
7
+
8
+ Usage:
9
+ ste-lint.py FILE [FILE ...]
10
+ echo "text" | ste-lint.py [--json]
11
+ ste-lint.py --baseline 5 FILE # pass unless hard violations exceed 5
12
+ ste-lint.py --disable passive-voice,present-perfect FILE
13
+ ste-lint.py --selftest
14
+
15
+ Exit 1 when hard ("advisory-free") violations exceed the baseline (default 0).
16
+ Advisory findings (passive voice, compound tenses) never fail the run.
17
+ """
18
+ import json
19
+ import re
20
+ import sys
21
+
22
+ # ponytail: regex heuristics, not a parser. No noun-cluster rule — needs POS
23
+ # tagging to avoid constant false positives; add spaCy-backed rule if ever needed.
24
+ # No ellipsis rule by owner's choice: technical writing sometimes earns one.
25
+ # Irregular past participles used by the present-perfect heuristic.
26
+ IRREGULAR_PARTICIPLES = "given|taken|made|done|found|seen|known|shown|written|built|sent|set|run|read|kept|held|left|put|cut|hit|let|shut|split|spread|begun|become|come|gone|got|gotten|lost|met|paid|said|sold|told|thought|brought|bought|caught|taught|won|worn|torn|born|drawn|grown|thrown|flown|driven|risen|chosen|broken|spoken|frozen|hidden|ridden|forgotten|fallen|eaten|beaten|understood|stood|struck|stuck|swung|hung|led|fed|bled|fled|sped|bound|wound|dug|spun|slid|bit|lit|quit"
27
+
28
+ # Preserve the original passive heuristic; perfects also include intransitive verbs.
29
+ PASSIVE_PARTICIPLES = "given|taken|made|done|found|seen|known|shown|written|built|sent|set|run|read|kept|held|left|put"
30
+ MODAL_PERFECT_PREFIX = re.compile(
31
+ r"\b(?:may|might|could|should|would|must|can|will|shall)"
32
+ r"(?:\s+not|n['’]t)?\s+$", re.I,
33
+ )
34
+
35
+ RULES = [
36
+ ("semicolon", "advisory-free",
37
+ re.compile(r";"),
38
+ "STE bans the semicolon (Rule 8.1). Split into separate sentences."),
39
+ ("phrasal-verb", "advisory-free",
40
+ re.compile(r"\b(spin(?:ning|s)? up|spun up|reach(?:ing|es|ed)? out|div(?:e|es|ing|ed) into|dove into|kick(?:ing|s|ed)? off|circl(?:e|es|ing|ed) back|touch(?:ing|es|ed)? base)\b", re.I),
41
+ "Soft phrasal verb. Use the single plain verb (start, contact, read, begin)."),
42
+ ("marketing-adjective", "advisory-free",
43
+ re.compile(r"\b(seamless(?:ly)?|robust(?:ly)?|cutting-edge|effortless(?:ly)?|blazing[- ]fast|world-class|state-of-the-art|game-chang(?:ing|er))\b", re.I),
44
+ "Marketing adjective. Delete, or replace with the measurement that earns the claim."),
45
+ ("nominalization", "advisory-free",
46
+ re.compile(r"\b(perform|performs|performed|conduct|conducts|conducted|carry out|carries out|carried out)\s+(?:a|an|the)\s+\w+(?:tion|sion|ment|ance|ence|ysis)\b", re.I),
47
+ "Action frozen into a noun. Use the verb (analyze, not perform an analysis of)."),
48
+ ("passive-voice", "advisory",
49
+ re.compile(r"\b(is|are|was|were|been|being)\s+(\w+ed|" + PASSIVE_PARTICIPLES + r")\b(?!\s+(?:to|for|by)\s+\w+ing)", re.I),
50
+ "Possible passive voice. Name the actor and use an active verb, unless the actor is unknown or irrelevant."),
51
+ ("present-perfect", "advisory",
52
+ # modal + perfect infinitive ("may have failed") is a protected hedge, not present perfect
53
+ re.compile(r"(?<!\bmay )(?<!\bmight )(?<!\bcould )(?<!\bshould )(?<!\bwould )(?<!\bmust )\b(has|have|had)\s+(?:been\s+)?(?:\w+(?:ed|en)|" + IRREGULAR_PARTICIPLES + r")\b", re.I),
54
+ "Compound tense. Use simple past/present unless current relevance is the point (then keep and flag)."),
55
+ ]
56
+
57
+ # One word, one meaning: groups of verbs commonly rotated for the same action.
58
+ # Only pairs where the members are genuinely interchangeable — error/fault/failure
59
+ # are distinct concepts and stay out.
60
+ SYNONYM_GROUPS = [
61
+ ("check", "verify", "confirm", "validate"),
62
+ ("delete", "remove", "erase"),
63
+ ("start", "launch", "begin", "initiate"),
64
+ ("stop", "halt", "terminate"),
65
+ ("show", "display"),
66
+ ("use", "utilize", "employ"),
67
+ ("fix", "repair", "correct"),
68
+ ("send", "transmit"),
69
+ ("get", "retrieve", "fetch", "obtain"),
70
+ ("change", "modify", "alter"),
71
+ ]
72
+
73
+ MAX_WORDS = 25 # descriptions cap; instructions cap is 20 but undetectable without context
74
+
75
+ CODE_FENCE = re.compile(r"^(```|~~~)")
76
+ INLINE_CODE = re.compile(r"`[^`]*`")
77
+ LIST_ITEM_START = re.compile(
78
+ r"^(?P<indent> {0,3})(?P<marker>[-*+]|[0-9]+[.)])(?P<gap> +)(?P<body>.*)$"
79
+ )
80
+ CONJUNCTION_END = re.compile(r"\b(?:and|or)\s*$", re.I)
81
+ TABLE_SEPARATOR_CELL = re.compile(r"^:?-{3,}:?$")
82
+
83
+
84
+ def _word_re(base):
85
+ return re.compile(r"\b" + base + r"(?:s|es|ed|d|ing)?\b", re.I)
86
+
87
+
88
+ def _leading_spaces(line):
89
+ return len(line) - len(line.lstrip(" "))
90
+
91
+
92
+ def _is_list_continuation(line, content_indent):
93
+ if not line.strip():
94
+ return True
95
+ if LIST_ITEM_START.match(line):
96
+ return False
97
+ return _leading_spaces(line) >= content_indent
98
+
99
+
100
+ def _split_table_row(line):
101
+ """Return trimmed table cells and their zero-based source columns.
102
+
103
+ A pipe must separate at least two cells. Escaped pipes stay in their cell.
104
+ This deliberately implements only the ordinary Markdown table shape; it is
105
+ enough to distinguish a table from prose that happens to contain a pipe.
106
+ """
107
+ left = len(line) - len(line.lstrip())
108
+ right = len(line.rstrip())
109
+ content = line[left:right]
110
+ if "|" not in content:
111
+ return None
112
+ if content.startswith("|"):
113
+ content = content[1:]
114
+ left += 1
115
+ if content.endswith("|"):
116
+ content = content[:-1]
117
+ raw_cells = re.split(r"(?<!\\)\|", content)
118
+ if len(raw_cells) < 2:
119
+ return None
120
+
121
+ cells = []
122
+ column = left
123
+ for raw_cell in raw_cells:
124
+ leading = len(raw_cell) - len(raw_cell.lstrip())
125
+ cells.append((raw_cell.strip(), column + leading))
126
+ column += len(raw_cell) + 1
127
+ return cells
128
+
129
+
130
+ def _markdown_table_cells(lines):
131
+ """Map ordinary Markdown table rows to their prose cells.
132
+
133
+ The separator row anchors detection, so pipe-containing prose is not
134
+ treated as a table. Both leading-pipe and no-leading-pipe table styles are
135
+ accepted when their header and body use the same number of cells.
136
+ """
137
+ table_cells = {}
138
+ index = 1
139
+ while index < len(lines):
140
+ separator = _split_table_row(lines[index])
141
+ header = _split_table_row(lines[index - 1])
142
+ if (not separator or not header or len(separator) != len(header)
143
+ or not all(TABLE_SEPARATOR_CELL.fullmatch(cell)
144
+ for cell, _ in separator)):
145
+ index += 1
146
+ continue
147
+
148
+ table_cells[index - 1] = header
149
+ table_cells[index] = []
150
+ index += 1
151
+ while index < len(lines):
152
+ row = _split_table_row(lines[index])
153
+ if not row or len(row) != len(separator):
154
+ break
155
+ table_cells[index] = row
156
+ index += 1
157
+ return table_cells
158
+
159
+
160
+ def _dangling_conjunction_findings(text, filename):
161
+ lines = text.splitlines()
162
+ findings = []
163
+ in_fence = False
164
+ index = 0
165
+ while index < len(lines):
166
+ line = lines[index]
167
+ stripped = line.strip()
168
+ if CODE_FENCE.match(stripped):
169
+ in_fence = not in_fence
170
+ index += 1
171
+ continue
172
+ if in_fence:
173
+ index += 1
174
+ continue
175
+ start = LIST_ITEM_START.match(line)
176
+ if not start:
177
+ index += 1
178
+ continue
179
+
180
+ content_indent = (len(start.group("indent"))
181
+ + len(start.group("marker"))
182
+ + len(start.group("gap")))
183
+ item_lines = [(index, start.group("body"))]
184
+ next_index = index + 1
185
+ item_fence = False
186
+ while next_index < len(lines):
187
+ candidate = lines[next_index]
188
+ candidate_stripped = candidate.strip()
189
+ if CODE_FENCE.match(candidate_stripped):
190
+ # Fence delimiters are state markers, not meaningful item lines.
191
+ item_fence = not item_fence
192
+ next_index += 1
193
+ continue
194
+ if item_fence:
195
+ next_index += 1
196
+ continue
197
+ if not _is_list_continuation(candidate, content_indent):
198
+ break
199
+ item_lines.append((next_index, candidate))
200
+ next_index += 1
201
+
202
+ meaningful = []
203
+ for line_index, item_line in item_lines:
204
+ # Preserve code spans as neutral operands while ignoring their contents.
205
+ cleaned = INLINE_CODE.sub(" CODE ", item_line).strip()
206
+ if cleaned:
207
+ meaningful.append((line_index, cleaned))
208
+ if meaningful:
209
+ end_line_index, end_line = meaningful[-1]
210
+ conjunction = CONJUNCTION_END.search(end_line)
211
+ else:
212
+ end_line_index, end_line, conjunction = None, None, None
213
+ if conjunction:
214
+ if end_line_index == index:
215
+ finding_line = index + 1
216
+ finding_col = start.start("marker") + 1
217
+ else:
218
+ raw_end_line = next(
219
+ raw for line_index, raw in item_lines
220
+ if line_index == end_line_index
221
+ )
222
+ masked_end_line = INLINE_CODE.sub(
223
+ lambda match: " " * len(match.group(0)), raw_end_line
224
+ )
225
+ raw_conjunction = CONJUNCTION_END.search(masked_end_line)
226
+ finding_line = end_line_index + 1
227
+ finding_col = raw_conjunction.start() + 1 if raw_conjunction else 1
228
+ findings.append({
229
+ "file": filename,
230
+ "line": finding_line,
231
+ "col": finding_col,
232
+ "rule": "dangling-conjunction",
233
+ "level": "advisory-free",
234
+ "match": end_line,
235
+ "message": "List item ends with a coordinating conjunction. Complete the item or join it with the next item.",
236
+ })
237
+ index = next_index
238
+ return findings
239
+
240
+
241
+ def lint(text, filename="<stdin>"):
242
+ findings = []
243
+ words_total = 0
244
+ in_fence = False
245
+ lines = text.splitlines()
246
+ table_cells = _markdown_table_cells(lines)
247
+ # first occurrence of each synonym-group member: (group_idx, base) -> (line, col, match)
248
+ seen_synonyms = {}
249
+ for lineno, raw_line in enumerate(lines, 1):
250
+ if CODE_FENCE.match(raw_line.strip()):
251
+ in_fence = not in_fence
252
+ continue
253
+ if in_fence:
254
+ continue
255
+ segments = table_cells.get(lineno - 1, [(raw_line, 0)])
256
+ for segment, source_column in segments:
257
+ line = INLINE_CODE.sub("", segment)
258
+ words_total += len(line.split())
259
+ for rule_id, level, pattern, msg in RULES:
260
+ for m in pattern.finditer(line):
261
+ if rule_id == "present-perfect" and MODAL_PERFECT_PREFIX.search(
262
+ line[:m.start()]
263
+ ):
264
+ continue
265
+ findings.append({"file": filename, "line": lineno,
266
+ "col": source_column + m.start() + 1,
267
+ "rule": rule_id, "level": level,
268
+ "match": m.group(0), "message": msg})
269
+ for gi, group in enumerate(SYNONYM_GROUPS):
270
+ for base in group:
271
+ if (gi, base) in seen_synonyms:
272
+ continue
273
+ m = _word_re(base).search(line)
274
+ if m:
275
+ seen_synonyms[(gi, base)] = (
276
+ lineno, source_column + m.start() + 1, m.group(0)
277
+ )
278
+ for sent in re.split(r"(?<=[.!?])\s+", line):
279
+ n = len(sent.split())
280
+ if n > MAX_WORDS:
281
+ findings.append({"file": filename, "line": lineno,
282
+ "col": source_column + 1,
283
+ "rule": "long-sentence", "level": "advisory-free",
284
+ "match": f"{n} words",
285
+ "message": f"Sentence has {n} words (cap {MAX_WORDS}). Split it."})
286
+ # synonym rotation: flag each member after the first, at its first occurrence
287
+ for gi, group in enumerate(SYNONYM_GROUPS):
288
+ present = [(seen_synonyms[(gi, b)], b) for b in group if (gi, b) in seen_synonyms]
289
+ if len(present) > 1:
290
+ present.sort() # document order
291
+ first_base = present[0][1]
292
+ for (lineno, col, match), base in present[1:]:
293
+ findings.append({"file": filename, "line": lineno, "col": col,
294
+ "rule": "synonym-rotation", "level": "advisory-free",
295
+ "match": match,
296
+ "message": f"'{base}' and '{first_base}' name the same action. Pick one and use it every time."})
297
+ findings.extend(_dangling_conjunction_findings(text, filename))
298
+ findings.sort(key=lambda f: (f["line"], f["col"]))
299
+ return findings, words_total
300
+
301
+
302
+ def report(findings, words_total, as_json, hard_count, baseline):
303
+ rate = round(len(findings) * 100 / words_total, 1) if words_total else 0.0
304
+ if as_json:
305
+ print(json.dumps({"violations": findings, "count": len(findings),
306
+ "hard_count": hard_count, "baseline": baseline,
307
+ "words": words_total, "per_100_words": rate}, indent=2))
308
+ return
309
+ for f in findings:
310
+ print(f"{f['file']}:{f['line']}:{f['col']} {f['rule']}: {f['message']} [{f['match']}]")
311
+ print(f"\n{len(findings)} violations ({hard_count} hard, baseline {baseline}), "
312
+ f"{words_total} words, {rate} per 100 words")
313
+ print("Hedges/modality (may, might, could) are never flagged: confidence is content.")
314
+
315
+
316
+ def selftest():
317
+ bad = ("The panel is removed; spin up the job. "
318
+ "Perform an analysis of the seamless log. "
319
+ "We have received the report.")
320
+ findings, _ = lint(bad)
321
+ rules = {f["rule"] for f in findings}
322
+ for expected in ("semicolon", "phrasal-verb", "nominalization",
323
+ "marketing-adjective", "passive-voice", "present-perfect"):
324
+ assert expected in rules, expected
325
+ # hedges must never be flagged, including modal + perfect infinitive
326
+ findings, _ = lint("The request may have failed. It could be a timeout. "
327
+ "The disk might have filled.")
328
+ assert findings == [], findings
329
+ # irregular participles: "has run" is a compound tense as much as "has failed"
330
+ findings, _ = lint("The task has run. The job has set the flag. We have begun.")
331
+ assert sum(1 for f in findings if f["rule"] == "present-perfect") == 3, findings
332
+ findings, _ = lint("The job may have run.")
333
+ assert not any(f["rule"] == "present-perfect" for f in findings), findings
334
+ # Modal perfects remain protected across negation and variable whitespace.
335
+ for modal in ("may", "might", "could", "should", "would", "must"):
336
+ for gap in (" ", " ", "\t", " not "):
337
+ findings, _ = lint(f"The task {modal}{gap}have run.")
338
+ assert not any(f["rule"] == "present-perfect" for f in findings), findings
339
+ findings, _ = lint("The task couldn't have run. The task MAY NOT HAVE RUN.")
340
+ assert not any(f["rule"] == "present-perfect" for f in findings), findings
341
+ findings, _ = lint("The task has run. We have begun. The flag is set.")
342
+ assert sum(f["rule"] == "present-perfect" for f in findings) == 2, findings
343
+ assert any(f["rule"] == "passive-voice" for f in findings), findings
344
+ findings, _ = lint("The task is gone.")
345
+ assert not any(f["rule"] == "passive-voice" for f in findings), findings
346
+ # code blocks skipped
347
+ findings, _ = lint("```\nx = a; y = b\n```")
348
+ assert findings == []
349
+ # all supported list markers, case variants, and trailing whitespace
350
+ findings, _ = lint(
351
+ "- Confirm the target and\n"
352
+ "* Record the result OR \n"
353
+ "+ Close the panel\n"
354
+ "1. Start the task and\n"
355
+ "2) Stop the task OR"
356
+ )
357
+ dangling = [f for f in findings if f["rule"] == "dangling-conjunction"]
358
+ assert len(dangling) == 4, dangling
359
+ assert [f["line"] for f in dangling] == [1, 2, 4, 5], dangling
360
+ assert [f["col"] for f in dangling] == [1, 1, 1, 1], dangling
361
+ assert all(f["level"] == "advisory-free" for f in dangling), dangling
362
+
363
+ # valid continuation lines and standalone four-space code are ignored
364
+ findings, _ = lint(" - Confirm the target and\n record the result.")
365
+ assert not any(f["rule"] == "dangling-conjunction" for f in findings)
366
+ findings, _ = lint("- Confirm the target\n and")
367
+ dangling = [f for f in findings if f["rule"] == "dangling-conjunction"]
368
+ assert len(dangling) == 1 and dangling[0]["line"] == 2, dangling
369
+ assert dangling[0]["col"] == 3, dangling
370
+ findings, _ = lint(" - code and")
371
+ assert not any(f["rule"] == "dangling-conjunction" for f in findings)
372
+ findings, _ = lint("> - Confirm the target and\n> - Record the result or")
373
+ assert not any(f["rule"] == "dangling-conjunction" for f in findings)
374
+ findings, _ = lint("- Do this and\n~~~\ncode and\n~~~")
375
+ dangling = [f for f in findings if f["rule"] == "dangling-conjunction"]
376
+ assert len(dangling) == 1 and dangling[0]["line"] == 1, dangling
377
+ findings, _ = lint("```text\n- code and\n```")
378
+ assert not any(f["rule"] == "dangling-conjunction" for f in findings)
379
+
380
+ # one- and three-space markers and ordered continuation width
381
+ findings, _ = lint(" - Start the task and\n record the result.")
382
+ assert not any(f["rule"] == "dangling-conjunction" for f in findings)
383
+ findings, _ = lint("- Start the task and\n record the result.")
384
+ assert not any(f["rule"] == "dangling-conjunction" for f in findings)
385
+ findings, _ = lint("-\tStart the task and")
386
+ assert not any(f["rule"] == "dangling-conjunction" for f in findings)
387
+ findings, _ = lint(" - Start the task and", filename="fixture.md")
388
+ dangling = [f for f in findings if f["rule"] == "dangling-conjunction"]
389
+ assert len(dangling) == 1 and dangling[0]["col"] == 4, dangling
390
+ assert dangling[0]["file"] == "fixture.md"
391
+ assert dangling[0]["match"].endswith("and")
392
+ assert "Complete the item" in dangling[0]["message"]
393
+ findings, _ = lint("100. Start the task and\n unrelated text")
394
+ dangling = [f for f in findings if f["rule"] == "dangling-conjunction"]
395
+ assert len(dangling) == 1, dangling
396
+ findings, _ = lint("- Start the task and.\n- Stop the task or,")
397
+ assert not any(f["rule"] == "dangling-conjunction" for f in findings)
398
+ findings, _ = lint("- Start the task and\n\n record the result.")
399
+ assert not any(f["rule"] == "dangling-conjunction" for f in findings)
400
+ findings, _ = lint("- Parent item and\n - Nested item or")
401
+ dangling = [f for f in findings if f["rule"] == "dangling-conjunction"]
402
+ assert [f["line"] for f in dangling] == [1, 2], dangling
403
+
404
+ # ordinary prose, inline code, and fenced code are ignored
405
+ findings, _ = lint("The process may include steps and")
406
+ assert not any(f["rule"] == "dangling-conjunction" for f in findings)
407
+ findings, _ = lint("- Use `and` as a label")
408
+ assert not any(f["rule"] == "dangling-conjunction" for f in findings)
409
+ findings, _ = lint("- Combine `left` and `right`")
410
+ assert not any(f["rule"] == "dangling-conjunction" for f in findings), findings
411
+ findings, _ = lint("~~~\n- code and\n~~~")
412
+ assert not any(f["rule"] == "dangling-conjunction" for f in findings)
413
+ findings, _ = lint(("word " * 30).strip() + ".")
414
+ assert any(f["rule"] == "long-sentence" for f in findings)
415
+ # Markdown table syntax is layout, not prose. Each cell stays lintable.
416
+ short_cell = " ".join(f"term{number}" for number in range(1, 25)) + "."
417
+ for table in (
418
+ "| Label | Detail |\n"
419
+ "| --- | --- |\n"
420
+ f"| Clear | {short_cell} |",
421
+ "Label | Detail\n"
422
+ "--- | ---\n"
423
+ f"Clear | {short_cell}"):
424
+ findings, words_total = lint(table)
425
+ assert not any(f["rule"] == "long-sentence" for f in findings), findings
426
+ assert words_total == 27, words_total
427
+ long_cell = " ".join(f"term{number}" for number in range(1, 27)) + "."
428
+ findings, _ = lint(
429
+ "| Label | Detail |\n"
430
+ "| --- | --- |\n"
431
+ f"| Clear | {long_cell} |"
432
+ )
433
+ long_sentences = [f for f in findings if f["rule"] == "long-sentence"]
434
+ assert len(long_sentences) == 1, long_sentences
435
+ assert long_sentences[0]["match"] == "26 words", long_sentences
436
+ # synonym rotation: second member flagged, first named as the keeper
437
+ findings, _ = lint("Check the config file. Then verify the output. Verify twice.")
438
+ rot = [f for f in findings if f["rule"] == "synonym-rotation"]
439
+ assert len(rot) == 1 and "'verify' and 'check'" in rot[0]["message"], rot
440
+ # single consistent term: no flag
441
+ findings, _ = lint("Check the config. Check the output.")
442
+ assert not any(f["rule"] == "synonym-rotation" for f in findings)
443
+ # per-file labels
444
+ findings, _ = lint("a; b", filename="x.md")
445
+ assert findings[0]["file"] == "x.md"
446
+ print("selftest OK")
447
+
448
+
449
+ def main(argv):
450
+ if "--selftest" in argv:
451
+ selftest()
452
+ return 0
453
+ as_json = "--json" in argv
454
+ baseline = 0
455
+ disabled = set()
456
+ paths = []
457
+ i = 0
458
+ while i < len(argv):
459
+ a = argv[i]
460
+ if a == "--baseline":
461
+ i += 1
462
+ baseline = int(argv[i])
463
+ elif a == "--disable":
464
+ i += 1
465
+ disabled = set(argv[i].split(","))
466
+ elif not a.startswith("--"):
467
+ paths.append(a)
468
+ i += 1
469
+
470
+ findings, words_total = [], 0
471
+ if paths:
472
+ for p in paths:
473
+ f, w = lint(open(p, encoding="utf-8").read(), filename=p)
474
+ findings.extend(f)
475
+ words_total += w
476
+ else:
477
+ findings, words_total = lint(sys.stdin.read())
478
+
479
+ findings = [f for f in findings if f["rule"] not in disabled]
480
+ hard_count = sum(1 for f in findings if f["level"] == "advisory-free")
481
+ report(findings, words_total, as_json, hard_count, baseline)
482
+ return 1 if hard_count > baseline else 0
483
+
484
+
485
+ if __name__ == "__main__":
486
+ sys.exit(main(sys.argv[1:]))
@@ -0,0 +1,181 @@
1
+ # <%= app_name.titleize %>
2
+
3
+ ## Commands
4
+
5
+ ```sh
6
+ bin/dev # Start the server, the Tailwind watcher and the jobs
7
+ bin/rails test # Run the unit, controller and integration tests
8
+ bin/rails test:system # Run the system tests
9
+ bin/rails test test/models/user_test.rb:42 # Run one test
10
+ bin/rubocop -A # Fix style. Run it after each change to Ruby files
11
+ bin/brakeman # Scan for security problems
12
+ ```
13
+
14
+ ## Workflow
15
+
16
+ - Before you do work, say how to verify it.
17
+ - After a change, run the related tests and `bin/rubocop`. Run them again just
18
+ before each commit, even when the code did not change since the last run.
19
+ - Never commit to `main`. Work on a feature branch.
20
+ - Never commit unless the owner asks. One commit for each completed task.
21
+ - A commit message is one line: a subject and nothing else.
22
+ - Explain the approach before a large change.
23
+ - Keep pull requests small and about one topic.
24
+
25
+ ## Testing
26
+
27
+ Minitest, `factory_bot` and parallel tests. Factories are in `test/factories/`.
28
+ Use `create` and `build` directly, never `FactoryBot.create`.
29
+
30
+ ### Work test-first
31
+
32
+ Before you change code, run only a new test. This rule wins over any skill that
33
+ runs the full suite first, such as `superpowers:using-git-worktrees`.
34
+
35
+ - **An existing test covers the change, and the behaviour stays the same:**
36
+ do not run it first. Make the change, then run that test.
37
+ - **No test covers the change:** write a new test. Run it and see it fail.
38
+ Make the change. Run it and see it pass.
39
+ - **The change changes behaviour:** do not edit the existing test. Write a new
40
+ test for the new behaviour. Run it and see it fail. Make the change. Run both
41
+ tests. The existing test must now fail and the new test must pass. Then
42
+ update or delete the existing test so that the suite passes. Report each
43
+ existing test that you changed or deleted, and the behaviour that it tested.
44
+ - **A bug fix:** the new test must fail against the code before the fix. If
45
+ that is not practical, say so. Do not assume that the test would have caught
46
+ the bug.
47
+
48
+ ### A failing test is a question
49
+
50
+ - Before you change anything, decide whether the code or the expectation is
51
+ wrong, and say which.
52
+ - Never make a failing test pass by weakening it. Do not loosen a selector,
53
+ widen a matcher, drop an assertion, add a stub, or change the setup until
54
+ the test passes.
55
+ - A changed expectation means the behaviour changed on purpose. Say what now
56
+ behaves differently and why, in the reply and not only in the diff.
57
+
58
+ ### What to test, and how
59
+
60
+ - Every new model, controller, job, service and component needs a test.
61
+ - Do not test a helper that only renders markup from the data that it gets.
62
+ Test a helper that has logic: a calculation, a branch, an ordering rule.
63
+ - Do not write a test that only checks that a factory is valid.
64
+ - Never stub what the test can use for real. Stub only external services:
65
+ HTTP, third-party APIs, clocks that you cannot control. Assert on effects
66
+ that you can see: database rows, enqueued jobs, the response.
67
+ - Controller and integration tests check the status, the redirect, the flash
68
+ and the side effects. They never check the rendered markup. Test markup in a
69
+ component test.
70
+ - System tests check what a user can do: click, navigate, submit, open a menu.
71
+ A test that only checks that content is on the page belongs in a component
72
+ test.
73
+ - In a system test, never select by a Tailwind class, and never assert styling.
74
+ Select by a role, a label, the text, or an `id` or `data-*` attribute that
75
+ the page already needs for its own work, such as an `aria-describedby`
76
+ target or a Stimulus target.
77
+ - Never add an attribute, an `id` or a class to the page only for a test. If a
78
+ test cannot find an element, select it by its role, its label or its text.
79
+
80
+ ### System tests that do not flake
81
+
82
+ A flaky system test is a race between the test and the page. Find the race and
83
+ remove it. Never add `sleep`, a longer wait, or a retry.
84
+
85
+ - After a click, a submit or a `visit` that loads a new page or a Turbo
86
+ response, wait for an element that exists only on the new page:
87
+ `assert_selector "#user_name_error", text: "Enter a value."`. Turbo replaces
88
+ the `body`, and a check that holds a node of the old page fails. The
89
+ selector must match nothing on the old page: `h1` matches on both pages.
90
+ - Never put `assert_text` or `assert_no_text` right after such an action. They
91
+ read the whole `body`, which can be the old one. Scope the text to an
92
+ element with `assert_selector ..., text:`.
93
+ - `assert_current_path` alone does not prove the new page rendered. Turbo can
94
+ change the URL before it replaces the `body`.
95
+ - Use only the matchers that wait: `assert_selector`, `assert_no_selector`,
96
+ `assert_current_path`, `assert_field`, `assert_link`, `assert_button`. Never
97
+ assert on a value that you read once, such as `find(...).text`,
98
+ `all(...).count` or `page.has_text?`.
99
+ - To check that something went away, use `assert_no_selector` on that element.
100
+ - Run each new or changed system test three times before you commit it.
101
+
102
+ ## Conventions
103
+
104
+ - Use the generators from Rails or an installed gem to make files. Write a file
105
+ by hand only when no generator covers it. `bin/rails generate --help` lists
106
+ them.
107
+ - RESTful controllers with the standard actions. Keep controllers thin. Put
108
+ logic in models and services.
109
+ - ActiveRecord scopes over Ruby enumerables. Raw SQL only when necessary: say
110
+ why, and guard against SQL injection.
111
+ - Prevent N+1 queries with `includes`. Add indexes for frequent queries.
112
+ - Order by `id`, not `created_at`.
113
+ - Use `:unprocessable_content` (422), not `:unprocessable_entity`.
114
+ - UI: use the `whose-components` components before you write new markup. Check
115
+ Lookbook (`/lookbook`) for the existing pattern.
116
+ - A new layout for a page never removes a function. Every link, action and
117
+ filter on the old page must exist on the new page.
118
+ - After a UI change, click through it in a browser (Playwright) before you say
119
+ that the task is done.
120
+
121
+ ## Views
122
+
123
+ - HAML.
124
+ - Do not assign local variables at the top of a partial. Move derived values to
125
+ a helper, a presenter or the caller.
126
+ - Never call `render` from a helper to choose a partial. Branch in the view.
127
+ - A component's own text goes in a sidecar locale file next to the component,
128
+ for example `app/components/nav_component/nav_component.en.yml`. Read it with
129
+ `t(".key")`. Text that is not part of a component goes in `config/locales/`.
130
+
131
+ ## Ruby style
132
+
133
+ - Every Ruby file starts with `# frozen_string_literal: true`.
134
+ - Implicit hash values: `foo:`, not `foo: foo`, in hash literals and in keyword
135
+ arguments. Fix the old form on each line that you touch.
136
+ - `filter_map` over `select` and then `map`.
137
+ - Ruby 3.4 `it`: `{ it["key"] }`, not `{ |e| e["key"] }`.
138
+
139
+ ## Comments
140
+
141
+ Write no comments. That is the default, and it is almost always correct.
142
+
143
+ The test for an exception: name the wrong conclusion that the next reader makes
144
+ without the comment. If you cannot name one, write no comment.
145
+
146
+ Two kinds of comment pass the test:
147
+
148
+ - A business rule that the code cannot state.
149
+ - Behaviour that surprises: a hidden constraint, a bug workaround, a reason for
150
+ performance or correctness that is not clear. Give a concrete example with
151
+ real values.
152
+
153
+ Do not write a comment that:
154
+
155
+ - Says what the code does.
156
+ - Explains the change that you just made. That belongs in the commit.
157
+ - Confirms that the code works as written ("as expected", "intentional").
158
+ - Describes the task, the ticket or the pull request.
159
+ - Explains a standard Rails, Minitest or factory_bot idiom.
160
+ - Explains a Tailwind class, a layout or a style choice.
161
+
162
+ ## Writing
163
+
164
+ Use the `asd-ste100` skill (in `.claude/skills/asd-ste100/`) before you write
165
+ or edit English text. Write the text that the skill returns.
166
+
167
+ - **Strict mode** for text that a machine or a user reads and acts on: error
168
+ and flash messages, exception messages, validation messages, tool and job
169
+ descriptions.
170
+ - **STE-flavored mode** for the rest: replies, commit messages, pull request
171
+ titles and bodies, review comments, code comments and docs.
172
+
173
+ Replies:
174
+
175
+ - Give the result in the first sentence. Then bullets, at most four.
176
+ - Under 120 words. Code blocks do not count.
177
+ - Short, complete sentences. Ordinary words. No filler and no hedging.
178
+ - Cite `file:line` for each claim about code. Check before you assert.
179
+ - Report only a problem that you can show is reachable, and name the path.
180
+ - One topic for each reply. One recommendation, not a menu. Label each
181
+ alternative "Option A", "Option B".