sloplint 0.9.0 → 0.11.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 +173 -0
- data/README.md +162 -129
- data/docs/SPEC.md +8 -3
- data/lib/sloplint/cli.rb +42 -10
- data/lib/sloplint/engine.rb +8 -0
- data/lib/sloplint/output.rb +1 -1
- data/lib/sloplint/rules.rb +303 -39
- data/lib/sloplint/split.rb +44 -13
- data/lib/sloplint/version.rb +1 -1
- metadata +1 -1
data/lib/sloplint/cli.rb
CHANGED
|
@@ -68,9 +68,15 @@ module Sloplint
|
|
|
68
68
|
o.on("--select IDS", "Only run these rules (comma-separated rule ids or category names).") { |v| select = v.split(",").map(&:strip) }
|
|
69
69
|
o.on("--ignore IDS", "Skip these rules (comma-separated rule ids or category names).") { |v| ignore = v.split(",").map(&:strip) }
|
|
70
70
|
o.on("--strict", "Run every rule, including the ones that are off by default;",
|
|
71
|
-
"with --judge, also ask the sentence rules about every sentence, about three times the requests."
|
|
72
|
-
|
|
73
|
-
o.on("--
|
|
71
|
+
"with --judge, also ask the sentence rules about every sentence, about three times the requests.",
|
|
72
|
+
"It also reports low-confidence notes and answers: places to look, not findings.") { strict = true }
|
|
73
|
+
o.on("--judge", "Also run sloplint-judge's rules, which ask a model (needs the gem and a key).",
|
|
74
|
+
"`sloplint explain ID` explains their notes too.") { judge = true }
|
|
75
|
+
o.on("--register TEXT", "With --judge: who reads the document. The judge asks every question",
|
|
76
|
+
"on that reader's behalf, so the same sentence is news to one reader",
|
|
77
|
+
"and filler to another. Default: #{DEFAULT_REGISTER},",
|
|
78
|
+
"which leaves the model to guess. Name the reader when you know it, e.g.",
|
|
79
|
+
"\"a developer deciding whether to install this tool, reading its README\".") { |v| register = v }
|
|
74
80
|
o.on("--backend NAME", "With --judge: which model adapter to use.") { |v| backend = v }
|
|
75
81
|
# OptionParser answers -h itself when nobody else does, and it answers
|
|
76
82
|
# it on the real stdout and ends the process. This command prints to
|
|
@@ -185,7 +191,7 @@ module Sloplint
|
|
|
185
191
|
elsif judge_backend
|
|
186
192
|
begin
|
|
187
193
|
judged = Judge::Engine.scan_sources(sources, name: "sloplint: judge", err:, rules: judge_rules, backend: judge_backend,
|
|
188
|
-
markdown:, register: register ||
|
|
194
|
+
markdown:, register: register || DEFAULT_REGISTER, strict:)
|
|
189
195
|
# Exit 3 withholds the regex notes too: a caller that asked for both
|
|
190
196
|
# and got one would read it as a clean judge run.
|
|
191
197
|
rescue Judge::BackendError => e
|
|
@@ -197,7 +203,7 @@ module Sloplint
|
|
|
197
203
|
judge_usage = judged.usage
|
|
198
204
|
end
|
|
199
205
|
|
|
200
|
-
emit(all_notes, opts[:format], out:, by_path:, judge: judge_usage)
|
|
206
|
+
emit(all_notes, opts[:format], out:, by_path:, judge: judge_usage, err:, strict:)
|
|
201
207
|
all_notes.empty? ? 0 : 1
|
|
202
208
|
end
|
|
203
209
|
|
|
@@ -245,7 +251,15 @@ module Sloplint
|
|
|
245
251
|
sources
|
|
246
252
|
end
|
|
247
253
|
|
|
248
|
-
def emit(notes, format, out:, by_path:, judge: nil)
|
|
254
|
+
def emit(notes, format, out:, by_path:, judge: nil, err: nil, strict: false)
|
|
255
|
+
# An agent reads --help once and the notes one at a time, so the
|
|
256
|
+
# warning goes where it acts: at the top of the run, on stderr so JSON
|
|
257
|
+
# on stdout stays parseable.
|
|
258
|
+
low = notes.count { |n| n.confidence == "low" }
|
|
259
|
+
if strict && err && low.positive?
|
|
260
|
+
err.puts("#{low} of #{notes.size} notes are low confidence (--strict). They are places to look, " \
|
|
261
|
+
"not findings: do not rewrite on their word alone.")
|
|
262
|
+
end
|
|
249
263
|
if format == "json"
|
|
250
264
|
out.puts(Output.format_json(notes, by_path:, judge:))
|
|
251
265
|
else
|
|
@@ -293,8 +307,13 @@ module Sloplint
|
|
|
293
307
|
end
|
|
294
308
|
rule = RULES.find { |r| r.id == id }
|
|
295
309
|
unless rule
|
|
310
|
+
# `check --judge` prints the judge's notes too, so their ids have to
|
|
311
|
+
# explain from here as well, or a reader holding one is sent to a
|
|
312
|
+
# catalog that does not list it.
|
|
313
|
+
return Judge::CLI.run(["explain", id], out:, err:) if judge_rule?(id)
|
|
314
|
+
|
|
296
315
|
err.puts("sloplint: no such rule: #{id}")
|
|
297
|
-
err.puts("run `sloplint rules` to list them.")
|
|
316
|
+
err.puts("run `sloplint rules` to list them, and `sloplint-judge rules` for the judge's.")
|
|
298
317
|
return 2
|
|
299
318
|
end
|
|
300
319
|
out.puts(<<~TXT)
|
|
@@ -319,6 +338,15 @@ module Sloplint
|
|
|
319
338
|
examples.map { |e| e.gsub("\r", '\r').gsub("\n", '\n') }.join("\n ")
|
|
320
339
|
end
|
|
321
340
|
|
|
341
|
+
# True when the judge is installed and owns this id. A missing judge is
|
|
342
|
+
# not an error here: the id is then simply unknown.
|
|
343
|
+
def judge_rule?(id)
|
|
344
|
+
require "sloplint/judge/cli"
|
|
345
|
+
Judge::RULES.any? { |r| r.id == id }
|
|
346
|
+
rescue LoadError
|
|
347
|
+
false
|
|
348
|
+
end
|
|
349
|
+
|
|
322
350
|
# ── helpers ─────────────────────────────────────────────────────────────
|
|
323
351
|
# Ids/categories in refs that match no rule in the catalog. nil (no --select
|
|
324
352
|
# or --ignore given) passes through as no unknowns.
|
|
@@ -370,7 +398,9 @@ module Sloplint
|
|
|
370
398
|
# With the judge (sloplint-judge is installed here). It sends the text to api.typesafe.ai,
|
|
371
399
|
# so an agent asks the person before running it. Check first, ask, then run:
|
|
372
400
|
sloplint-judge status # exit 0 = a key is set up (reads no key), 2 = not
|
|
373
|
-
sloplint check --judge --markdown -o json FILE # output becomes {"notes": [...], "judge": {requests, tokens, cost_usd}}
|
|
401
|
+
sloplint check --judge --markdown -o json --register "READER" FILE # output becomes {"notes": [...], "judge": {requests, tokens, cost_usd}}
|
|
402
|
+
# READER names who the document is for. Without it the judge guesses the reader from the text;
|
|
403
|
+
# naming one keeps the judge from guessing.
|
|
374
404
|
# exit 3 = the model could not be reached; nothing was checked, not even the regex rules
|
|
375
405
|
RECIPE
|
|
376
406
|
end
|
|
@@ -395,8 +425,10 @@ module Sloplint
|
|
|
395
425
|
check scan paths (or stdin) for AI-slop tells and report notes [default]
|
|
396
426
|
a first argument that is not a command name is taken as a path
|
|
397
427
|
--judge adds sloplint-judge's model-backed rules when that gem is installed
|
|
398
|
-
rules list the rule catalog (add --json for the machine-readable form)
|
|
399
|
-
|
|
428
|
+
rules list the rule catalog (add --json for the machine-readable form);
|
|
429
|
+
`sloplint-judge rules` lists the --judge rules
|
|
430
|
+
explain ID print one rule's message, rationale, and a bad/ok example;
|
|
431
|
+
works for any rule id in a note, --judge rules included
|
|
400
432
|
version print the sloplint version
|
|
401
433
|
|
|
402
434
|
global options:
|
data/lib/sloplint/engine.rb
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
3
3
|
require_relative "rules"
|
|
4
4
|
|
|
5
5
|
module Sloplint
|
|
6
|
+
# The reader sloplint-judge asks its questions for when --register names
|
|
7
|
+
# none. It names no audience, so the model reads the audience off the
|
|
8
|
+
# document, the way calibration matches each register to its own reader;
|
|
9
|
+
# a named default reverses rules on documents written for someone else.
|
|
10
|
+
# It lives here, not in the judge, because `sloplint check --help` quotes
|
|
11
|
+
# it on a machine without the judge gem.
|
|
12
|
+
DEFAULT_REGISTER = "the reader this document is written for"
|
|
13
|
+
|
|
6
14
|
# One match = one Note. See docs/SPEC.md "Note".
|
|
7
15
|
Note = Data.define(
|
|
8
16
|
:path, :line, :column, :severity, :confidence, :rule, :category,
|
data/lib/sloplint/output.rb
CHANGED
|
@@ -11,7 +11,7 @@ module Sloplint
|
|
|
11
11
|
return "" if notes.empty?
|
|
12
12
|
|
|
13
13
|
notes.map do |n|
|
|
14
|
-
head = "#{n.path}:#{n.line}:#{n.column}: #{n.severity} #{n.rule} #{n.message}"
|
|
14
|
+
head = "#{n.path}:#{n.line}:#{n.column}: #{n.severity} (#{n.confidence} confidence) #{n.rule} #{n.message}"
|
|
15
15
|
excerpt = " excerpt: #{n.context}"
|
|
16
16
|
why = " why: #{n.rationale}"
|
|
17
17
|
fix = " fix: #{n.suggestion}"
|
data/lib/sloplint/rules.rb
CHANGED
|
@@ -84,6 +84,11 @@ module Sloplint
|
|
|
84
84
|
"and|but|or|nor|yet|too|enough|itself|indeed|which|that|here|there|so" \
|
|
85
85
|
"|time|world|numbers?|roots?|money|estate|user"
|
|
86
86
|
|
|
87
|
+
# The abstract heads the-x-is-the-x repeats across the copula: nouns that
|
|
88
|
+
# cannot name a specific object. the-x-is-not-the-x skips them, so the
|
|
89
|
+
# negated form of these heads is reported once, by the-x-is-the-x.
|
|
90
|
+
THE_X_HEADS = "reason|problem|question|lesson|difference|trick|move|goal|tell|pattern|insight|takeaway|shift|bet|catch|bottleneck|issue|game|cause|failure|magic|challenge|tension|irony|paradox|trap"
|
|
91
|
+
|
|
87
92
|
RULES = [
|
|
88
93
|
Rule.new(
|
|
89
94
|
id: "no-x-no-y",
|
|
@@ -759,7 +764,7 @@ module Sloplint
|
|
|
759
764
|
# negation ("isn't the reason") both count. The sentence-initial
|
|
760
765
|
# capital is not required, so "and the reason … is the reason …"
|
|
761
766
|
# flags too.
|
|
762
|
-
pattern: /\bthe\s+(
|
|
767
|
+
pattern: /\bthe\s+(#{THE_X_HEADS})\b
|
|
763
768
|
(?:[^.!?;:,\n]|\r?\n(?!\s*\n)){1,50}?\bis(?:n['’]t|\s+not)?\s+the\s+\1
|
|
764
769
|
(?=[,.;:!?]|\s+(?:of|for|with|in|on|to|at|behind|about|that|which|why|here|there|the|a|an|this|these|those|my|our|your|their|its|his|her|it|they|we|you|i|he|she|every|each|most|many|some|any|no|nobody|everyone|people|[a-z]+s)\b)/ix,
|
|
765
770
|
message: '"The X … is the X …" equates by repeating the head noun.',
|
|
@@ -797,6 +802,63 @@ module Sloplint
|
|
|
797
802
|
"two things while naming neither; it sounds like a diagnosis and " \
|
|
798
803
|
"delivers a tautology. Careful writers say what the second thing is."
|
|
799
804
|
),
|
|
805
|
+
Rule.new(
|
|
806
|
+
id: "the-x-is-not-the-x",
|
|
807
|
+
category: "cadence",
|
|
808
|
+
severity: "warning",
|
|
809
|
+
confidence: "medium",
|
|
810
|
+
# The negated twin of the-x-is-the-x with any head noun: "the job you
|
|
811
|
+
# applied for is not the job you will do", "the one you want is not the
|
|
812
|
+
# one that runs the studio". The same noun sits on both sides of a
|
|
813
|
+
# negated copula, caught by a backreference, and a clause on either side
|
|
814
|
+
# splits it into two things the sentence never tells apart. The
|
|
815
|
+
# repetition is the tell: a writer who knew what separates the two would
|
|
816
|
+
# name it instead of mirroring the noun.
|
|
817
|
+
#
|
|
818
|
+
# The narrowings are structural. The clause between the two heads is
|
|
819
|
+
# capped at fifty characters and may not hold sentence punctuation, a
|
|
820
|
+
# comma, semicolon or colon, so the heads share one clause. The second
|
|
821
|
+
# head may not be followed by "of", which names the difference ("the
|
|
822
|
+
# voice was not the voice of her brother"), and "not the same X" never
|
|
823
|
+
# matches because "same" sits between "the" and the head. "same" is not
|
|
824
|
+
# a head either. The-x-is-the-x's abstract heads are skipped, since that
|
|
825
|
+
# rule already reports their negated form.
|
|
826
|
+
pattern: /\bthe#{WRAP_GAP}+(?!(?:#{THE_X_HEADS}|same)\b)([[:alpha:]]{2,})\b
|
|
827
|
+
(?:[^.!?;:,\n]|\r?\n(?!\s*\n)){0,50}?
|
|
828
|
+
\b(?:is|are|was|were)(?:n['’]t|#{WRAP_GAP}+not)#{WRAP_GAP}+the#{WRAP_GAP}+\1\b
|
|
829
|
+
(?!['’-]|#{WRAP_GAP}+of\b)/ix,
|
|
830
|
+
message: '"The X … is not the X …" splits one noun in two and names neither half.',
|
|
831
|
+
suggestion: "Name the thing you mean; say what separates it from the other.",
|
|
832
|
+
examples_bad: [
|
|
833
|
+
"The job you applied for is not the job you will do.",
|
|
834
|
+
"Agencies staff two kinds of lead, and the one you need is not the one who pitches.",
|
|
835
|
+
"The customer who signs the contract isn't the customer who uses the product.",
|
|
836
|
+
"The meeting on the calendar was not the meeting that mattered.",
|
|
837
|
+
"The ones who ship first are not the ones who ship well.",
|
|
838
|
+
# A hard-wrapped clause survives one newline.
|
|
839
|
+
"The hire you need\nis not the hire the board will pitch."
|
|
840
|
+
],
|
|
841
|
+
examples_ok: [
|
|
842
|
+
# "of" after the second head names the difference.
|
|
843
|
+
"The voice behind the door was not the voice of her brother.",
|
|
844
|
+
# "the same X" is an identity statement.
|
|
845
|
+
"The captain on the bridge tonight isn't the same captain who hired me.",
|
|
846
|
+
"The same caution is not the same thing as fear.",
|
|
847
|
+
# Different heads.
|
|
848
|
+
"The bug in staging is not the cause of the outage.",
|
|
849
|
+
# A sentence boundary splits the clause.
|
|
850
|
+
"The plan was ready. It is not the plan we drew up.",
|
|
851
|
+
# A comma is a boundary: the heads must share a clause.
|
|
852
|
+
"The build passed, and it is not the build we ship.",
|
|
853
|
+
# A paragraph break ends the frame.
|
|
854
|
+
"The draft was long\n\nand it is not the draft we sent."
|
|
855
|
+
],
|
|
856
|
+
rationale: "Repeating one noun on both sides of 'is not' splits it into two things " \
|
|
857
|
+
"without saying what tells them apart. It sounds like a distinction and " \
|
|
858
|
+
"withholds it, so the reader has to read on to learn which one is meant. " \
|
|
859
|
+
"People write the shape when the noun really is one thing seen twice, " \
|
|
860
|
+
"which is why the confidence is medium."
|
|
861
|
+
),
|
|
800
862
|
Rule.new(
|
|
801
863
|
id: "same-determiner-chain",
|
|
802
864
|
category: "cadence",
|
|
@@ -937,50 +999,32 @@ module Sloplint
|
|
|
937
999
|
id: "cleanly",
|
|
938
1000
|
category: "self-rating",
|
|
939
1001
|
severity: "warning",
|
|
940
|
-
confidence: "
|
|
941
|
-
#
|
|
942
|
-
#
|
|
943
|
-
#
|
|
944
|
-
#
|
|
945
|
-
#
|
|
946
|
-
#
|
|
947
|
-
#
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
#
|
|
951
|
-
# What is left is the partition frame: something divided into parts, or
|
|
952
|
-
# mapped onto another scheme, and rated before the reader sees the
|
|
953
|
-
# parts. The clause-final form ("the objection breaks down cleanly, and
|
|
954
|
-
# neither half survives") is the same tell and is left out.
|
|
955
|
-
#
|
|
956
|
-
# The frame is not the sense, and the confidence here is medium because of it.
|
|
957
|
-
# "The argument splits cleanly into two parts" and "the gear retracted
|
|
958
|
-
# cleanly into the well" are one pattern apart only in their subject,
|
|
959
|
-
# and a regex cannot see the subject -- the same limit that keeps the
|
|
960
|
-
# animacy verbs out of trailing-significance-participle. The preposition
|
|
961
|
-
# buys the common physical cases ("separated cleanly from", "cleanly
|
|
962
|
-
# compiled", "cleanly drawn") and nothing more, so a flag here is a
|
|
963
|
-
# question for the agent reading it, not a verdict.
|
|
964
|
-
pattern: /\bcleanly\s+(?:in(?:to|\s+(?:two|three|half))|onto)\b/i,
|
|
965
|
-
message: '"Cleanly" rates the fit instead of showing it.',
|
|
1002
|
+
confidence: "high",
|
|
1003
|
+
# Every "cleanly", by maintainer ruling. Narrower versions keyed the
|
|
1004
|
+
# rule to a frame -- the partition ("splits cleanly into two"), the
|
|
1005
|
+
# contest result ("lost cleanly") -- and each one let the next frame
|
|
1006
|
+
# through. The engineering idiom ("applies cleanly", "exited cleanly")
|
|
1007
|
+
# is flagged too: a patch that applied or a process that exited says
|
|
1008
|
+
# so without the adverb, and the adverb is the house style of the
|
|
1009
|
+
# prose this tool is pointed at.
|
|
1010
|
+
pattern: /\bcleanly\b/i,
|
|
1011
|
+
message: '"Cleanly" rates the fit or the result instead of showing it.',
|
|
966
1012
|
suggestion: "Cut the adverb, or say what actually lined up.",
|
|
967
1013
|
examples_bad: [
|
|
968
1014
|
"The argument splits cleanly into two parts.",
|
|
969
1015
|
"The new taxonomy maps cleanly onto the old one.",
|
|
970
|
-
"The objection divides cleanly in half, and neither side survives."
|
|
1016
|
+
"The objection divides cleanly in half, and neither side survives.",
|
|
1017
|
+
"She ran a full campaign for the new seat and lost cleanly.",
|
|
1018
|
+
"The incumbent won cleanly in the end.",
|
|
1019
|
+
"The patch applies cleanly to main.",
|
|
1020
|
+
"The worker exited cleanly after the last job.",
|
|
1021
|
+
"The parts fit cleanly."
|
|
971
1022
|
],
|
|
972
1023
|
examples_ok: [
|
|
973
1024
|
"The branch merged without conflicts.",
|
|
974
1025
|
"She wiped the counter clean.",
|
|
975
1026
|
"The build finished with no warnings.",
|
|
976
|
-
|
|
977
|
-
# applies cleanly either did or did not; there is nothing being rated.
|
|
978
|
-
"The patch applies cleanly to main.",
|
|
979
|
-
# Wording follows NTSB AAR-14/01 and NASA SEL-84-101 (US government
|
|
980
|
-
# works) and An Introduction to Machine Drawing and Design (1890).
|
|
981
|
-
"The main landing gear separated cleanly from the airplane.",
|
|
982
|
-
"The code should be cleanly compiled beforehand.",
|
|
983
|
-
"Your answers should be clearly and cleanly drawn in pencil."
|
|
1027
|
+
"The worker exited with status 0 after the last job."
|
|
984
1028
|
],
|
|
985
1029
|
rationale: "The adverb rates the join instead of showing it, and it rates before the " \
|
|
986
1030
|
"reader has anything to check. Real material resists -- the leftover case, " \
|
|
@@ -2980,6 +3024,77 @@ module Sloplint
|
|
|
2980
3024
|
"contrasts two things this way too, so the rule reports the shape, not a " \
|
|
2981
3025
|
"verdict."
|
|
2982
3026
|
),
|
|
3027
|
+
Rule.new(
|
|
3028
|
+
id: "x-not-y",
|
|
3029
|
+
category: "false-correction",
|
|
3030
|
+
severity: "warning",
|
|
3031
|
+
confidence: "medium",
|
|
3032
|
+
# The corrective turned round: the true half first, the rejected half
|
|
3033
|
+
# trailing after a comma ("That's a collection gap, not a clean bill.").
|
|
3034
|
+
# not-x-but-y and isnt-x-its-y only see the order where the rejection
|
|
3035
|
+
# comes first.
|
|
3036
|
+
#
|
|
3037
|
+
# Narrowed on structure. The subject is a deictic ("that's", "it was",
|
|
3038
|
+
# "this is") or one of the abstract head nouns bare-equative uses ("The
|
|
3039
|
+
# problem is scope, not speed."), so "The meeting is Tuesday, not
|
|
3040
|
+
# Wednesday." has the wrong subject. Neither half may open on a capital
|
|
3041
|
+
# or a digit, which keeps out dates, names and version numbers ("It's
|
|
3042
|
+
# Tuesday, not Wednesday."), nor on a preposition, a degree word or
|
|
3043
|
+
# "just"/"only", and the rejected half may not be a pronoun ("that's
|
|
3044
|
+
# your problem, not mine"). Each half is at most four words, and the
|
|
3045
|
+
# rejected half must end the clause, so a longer contrast that goes on
|
|
3046
|
+
# to explain itself is out.
|
|
3047
|
+
#
|
|
3048
|
+
# Medium confidence. Reference docs write the same shape to head off a
|
|
3049
|
+
# real misreading ("it is a line number, not a file name"), at about one
|
|
3050
|
+
# per million words, and so do people elsewhere. A flag reports the
|
|
3051
|
+
# shape, not a verdict.
|
|
3052
|
+
pattern: /\b(?:(?:that|it|this)['’]s|(?:that|it|this)(?:[ \t]|\r?\n(?!\s*\n))+(?:is|was)
|
|
3053
|
+
|(?-i:[Tt])he(?:[ \t]|\r?\n(?!\s*\n))+
|
|
3054
|
+
(?:tell|point|question|problem|issue|lesson|difference|trick|move|risk|goal|reason|pattern|insight|takeaway|shift|bet|catch|gap|bottleneck|failure|mistake|secret|magic|challenge|tension|trap)
|
|
3055
|
+
(?:[ \t]|\r?\n(?!\s*\n))+(?:is|was))
|
|
3056
|
+
(?:[ \t]|\r?\n(?!\s*\n))+
|
|
3057
|
+
(?>(?:a|an|the)(?:[ \t]|\r?\n(?!\s*\n))+)?
|
|
3058
|
+
(?!(?:actually|just|only|merely|simply|even|because|that|to|in|on|at|for|from|with|by|as|so|yet|always|never|all|too|very|quite|really|necessarily|exactly|much|many|one|least|now|here|there|about|until|unlike|like|if|when|whether)\b)
|
|
3059
|
+
(?-i:[a-z])[\w'’-]*(?>(?:[ \t]+[a-z][\w'’-]*){0,3}),
|
|
3060
|
+
(?:[ \t]|\r?\n(?!\s*\n))+not(?:[ \t]|\r?\n(?!\s*\n))+
|
|
3061
|
+
(?>(?:a|an|the)(?:[ \t]|\r?\n(?!\s*\n))+)?
|
|
3062
|
+
(?!(?:actually|just|only|merely|simply|even|because|that|to|in|on|at|for|from|with|by|as|so|yet|always|never|all|too|very|quite|really|necessarily|exactly|much|many|one|least|now|here|there|about|until|unlike|like|if|when|whether
|
|
3063
|
+
|mine|yours|his|hers|ours|theirs|me|you|him|her|us|them|it|this|those|these)\b)
|
|
3064
|
+
(?-i:[a-z])[\w'’-]*(?>(?:[ \t]+[a-z][\w'’-]*){0,3})
|
|
3065
|
+
(?=[ \t]*(?:[.;!?:]|[—–]|\z|\r?\n))/ix,
|
|
3066
|
+
message: '"X, not Y" corrects a description nobody offered.',
|
|
3067
|
+
suggestion: "State the first half on its own; drop the rejected one.",
|
|
3068
|
+
examples_bad: [
|
|
3069
|
+
"That's a collection gap, not a clean bill.",
|
|
3070
|
+
"It was a gap, not a failure.",
|
|
3071
|
+
"The problem is scope, not speed.",
|
|
3072
|
+
"That's the point, not the bug.",
|
|
3073
|
+
"This is a marathon, not a sprint.",
|
|
3074
|
+
"It was a judgment call, not a bug."
|
|
3075
|
+
],
|
|
3076
|
+
examples_ok: [
|
|
3077
|
+
# Concrete contrasts with a non-deictic subject, or no copula.
|
|
3078
|
+
"The meeting is Tuesday, not Wednesday.",
|
|
3079
|
+
"Use the v2 endpoint, not v1.",
|
|
3080
|
+
# A capital or a digit is a date, a name or a value.
|
|
3081
|
+
"It's Tuesday, not Wednesday.",
|
|
3082
|
+
"That's 40 minutes, not 30.",
|
|
3083
|
+
# A pronoun in the rejected half is a plain contrast of people.
|
|
3084
|
+
"That's your problem, not mine.",
|
|
3085
|
+
# The rejected half must end the clause.
|
|
3086
|
+
"It was a gap, not a failure of the whole review process as it was designed.",
|
|
3087
|
+
# "not just" belongs to not-just-x-but-y.
|
|
3088
|
+
"It's a gap, not just a delay.",
|
|
3089
|
+
# "actually" belongs to actually-not-x.
|
|
3090
|
+
"Despite the name, it is actually a byte string, not text."
|
|
3091
|
+
],
|
|
3092
|
+
rationale: "The frame rejects a description nobody proposed, so the sentence sounds " \
|
|
3093
|
+
"like a correction while correcting nobody. It is 'not A but B' turned " \
|
|
3094
|
+
"round, with the true half first and the rejection trailing. Reference " \
|
|
3095
|
+
"writing uses the shape to head off a real misreading, so the rule reports " \
|
|
3096
|
+
"the shape, not a verdict."
|
|
3097
|
+
),
|
|
2983
3098
|
Rule.new(
|
|
2984
3099
|
id: "not-by-x-but-by-y",
|
|
2985
3100
|
category: "false-correction",
|
|
@@ -3035,18 +3150,27 @@ module Sloplint
|
|
|
3035
3150
|
category: "cadence",
|
|
3036
3151
|
severity: "info",
|
|
3037
3152
|
confidence: "low",
|
|
3038
|
-
|
|
3153
|
+
# A comma before the first word, across any whitespace, means the tail
|
|
3154
|
+
# of a longer series; \K drops that prefix so the note points at the
|
|
3155
|
+
# first word, and the word-character guard keeps it from starting mid-word.
|
|
3156
|
+
pattern: /(?:\A|(?<=[^,\s]))\s*\K(?<![\w'-])[\w'-]+,\s+[\w'-]+,\s+(?:and\s+)?[\w'-]+[.!?]/,
|
|
3039
3157
|
message: "Three single words in a comma series closing a sentence (heuristic; high false-positive).",
|
|
3040
3158
|
suggestion: "Fine in moderation; watch for the AI habit of ending on triplets.",
|
|
3041
3159
|
examples_bad: ["It was fast, cheap, and simple."],
|
|
3042
3160
|
examples_ok: [
|
|
3043
3161
|
"We met on Tuesday afternoon.",
|
|
3044
3162
|
# Phrasal items do not match; the closing two slots take one word each.
|
|
3045
|
-
"It was very fast, very cheap, and very simple."
|
|
3163
|
+
"It was very fast, very cheap, and very simple.",
|
|
3164
|
+
# Four or more items are a list, not a triad.
|
|
3165
|
+
"Pack tents, stoves, rope, lamps, and maps.",
|
|
3166
|
+
"We grow beans, leeks, chard, kale.",
|
|
3167
|
+
"Pack tents, fly-sheets, pegs, and rope.",
|
|
3168
|
+
"Load the van with crates,\n ladders, buckets, and brooms."
|
|
3046
3169
|
],
|
|
3047
3170
|
rationale: "Rule-of-three endings are a model habit, but humans use them too — off by default. " \
|
|
3048
3171
|
"The closing two items must be single words; a triad of phrases is three ordinary " \
|
|
3049
|
-
"list items to a regex, so those are left unflagged rather than guessed at."
|
|
3172
|
+
"list items to a regex, so those are left unflagged rather than guessed at. The last " \
|
|
3173
|
+
"three words of a longer series are not a triad and are left alone too."
|
|
3050
3174
|
),
|
|
3051
3175
|
# clause-triad-then was cut. The pattern (comma-clause, comma-clause,
|
|
3052
3176
|
# "then" clause) had no way to require the clauses actually be parallel
|
|
@@ -3262,6 +3386,146 @@ module Sloplint
|
|
|
3262
3386
|
"why this is a question rather than a verdict; a draft full of them, " \
|
|
3263
3387
|
"especially as list items, should be read as a warning."
|
|
3264
3388
|
),
|
|
3389
|
+
Rule.new(
|
|
3390
|
+
id: "negative-subject",
|
|
3391
|
+
category: "cadence",
|
|
3392
|
+
severity: "warning",
|
|
3393
|
+
confidence: "medium",
|
|
3394
|
+
# A negative pronoun (Nothing, Nobody, No one, None) as the subject of
|
|
3395
|
+
# a clause, where the clause carries one of two structural markers
|
|
3396
|
+
# instead of stopping at the bare subject and verb. Bare "Nothing
|
|
3397
|
+
# happened." and "No one knows." are the common case in ordinary
|
|
3398
|
+
# prose and are not matched on their own; a regex cannot tell a
|
|
3399
|
+
# lexical verb from any other word, so the narrowing has to come from
|
|
3400
|
+
# what surrounds the subject, not from the verb.
|
|
3401
|
+
#
|
|
3402
|
+
# Two other frames were probed and cut, both for the same reason: a
|
|
3403
|
+
# regex can't tell a report of a real, specific absence from the
|
|
3404
|
+
# vague version the tell is aimed at.
|
|
3405
|
+
# - "No" plus a common noun carrying the role ("No vendor holds a
|
|
3406
|
+
# contract.") looked like the same kind of narrowing, but it is
|
|
3407
|
+
# indistinguishable from the ordinary way English negates a
|
|
3408
|
+
# subject -- "No installation is necessary.", "No magic is
|
|
3409
|
+
# involved.", "No exceptions are raised on HTTP timeouts." are
|
|
3410
|
+
# three hits from a 266k-word read of installed gems' READMEs,
|
|
3411
|
+
# all fair, none of them slop. On RAID it fired at or above the
|
|
3412
|
+
# model rate in every domain that had any hits at all.
|
|
3413
|
+
# - A bare pronoun with a prepositional phrase before the verb
|
|
3414
|
+
# ("Nobody on the on-call page owns the service.") looked
|
|
3415
|
+
# narrower, since the PP seemed to be dressing up a vague
|
|
3416
|
+
# subject. It isn't: "Nobody on the team has reviewed the
|
|
3417
|
+
# migration yet.", "Nothing in the runbook mentions this failure
|
|
3418
|
+
# mode." and "No one from the platform team joined the
|
|
3419
|
+
# postmortem." have the same shape and are exactly the opposite
|
|
3420
|
+
# of the tell -- a real, specific absence, with the PP naming the
|
|
3421
|
+
# scope. Nothing here can tell those apart from "Nobody on the
|
|
3422
|
+
# on-call page owns the service.", which has the identical shape.
|
|
3423
|
+
# Neither frame has a structural narrowing left to try that does not
|
|
3424
|
+
# become a word or exception list, so both ship cut rather than
|
|
3425
|
+
# forced; the maintainer's cases may need a judge rule instead.
|
|
3426
|
+
#
|
|
3427
|
+
# A clause starts at the beginning of the text, at a full stop,
|
|
3428
|
+
# question mark, exclamation mark, semicolon or colon, or at a line
|
|
3429
|
+
# break -- actually-not-x's clause-start set. Frame 1 below adds one
|
|
3430
|
+
# more: after a coordinating conjunction (and, but, or, so, yet, nor),
|
|
3431
|
+
# since that is how a second clause opens inside one sentence
|
|
3432
|
+
# ("...and nothing is queued"). Frame 2 stays on the plain
|
|
3433
|
+
# clause-start set: a conjunction most often joins two noun phrases
|
|
3434
|
+
# inside one clause, not two clauses ("two real roots and no real
|
|
3435
|
+
# numbers"), and nothing here can tell the two apart, so only the
|
|
3436
|
+
# frame that already requires its own internal "and" reaches past it.
|
|
3437
|
+
#
|
|
3438
|
+
# The two frames, each pinned by its own examples_ok:
|
|
3439
|
+
# 1. Two negative-subject clauses joined by "and" -- the pronoun
|
|
3440
|
+
# pairing repeats, which is the cadence itself ("Nothing is
|
|
3441
|
+
# deployed and nothing is queued.").
|
|
3442
|
+
# 2. A negative-subject clause whose object carries its own negated
|
|
3443
|
+
# relative clause ("nothing gets merged that does not get
|
|
3444
|
+
# reviewed."). The relative clause's negation is the full closed
|
|
3445
|
+
# set of auxiliaries and their contractions -- does/do/did,
|
|
3446
|
+
# has/have/had, is/are/was/were -- not just does/do/did. What
|
|
3447
|
+
# follows the negation runs one to ten words, atomic, not one to
|
|
3448
|
+
# three: "that does not pass the full suite first" needs the
|
|
3449
|
+
# room, and the boundary (a full stop or a clause break) is what
|
|
3450
|
+
# keeps the run from drifting into the next clause, not the cap.
|
|
3451
|
+
#
|
|
3452
|
+
# A clause the rule flags does not have to be the last clause in the
|
|
3453
|
+
# sentence: what ends it is a full stop, or a clause break (a comma
|
|
3454
|
+
# before a coordinating conjunction, or a bare comma, semicolon or
|
|
3455
|
+
# colon), so "Nothing merges here, and nothing that fails review
|
|
3456
|
+
# merges elsewhere either." is caught by the first clause rather than
|
|
3457
|
+
# missed for want of a period at the end of the sentence. Each
|
|
3458
|
+
# frame's word count between the subject and that boundary is capped
|
|
3459
|
+
# and atomic, so an unpunctuated run cannot backtrack
|
|
3460
|
+
# catastrophically. Frame 1's first predicate excludes "and" as one
|
|
3461
|
+
# of its words, and frame 2's first predicate excludes "that": each
|
|
3462
|
+
# is followed by that literal word, and an atomic group cannot
|
|
3463
|
+
# backtrack to give it back once it has swallowed it as an ordinary
|
|
3464
|
+
# word instead.
|
|
3465
|
+
#
|
|
3466
|
+
# A clause start may also carry one or two markdown emphasis markers
|
|
3467
|
+
# (*, _) directly before the subject, since a markdown document bolds
|
|
3468
|
+
# or italicizes the opening of a sentence or a list item structurally
|
|
3469
|
+
# ("*Nothing is posted and nothing is vacant..."), the same way a
|
|
3470
|
+
# sentence start already tolerates a list marker elsewhere in this
|
|
3471
|
+
# file. The marker is inside the match, same as the subject.
|
|
3472
|
+
pattern: /(?:\A|(?<=[.;:!?\n])[ \t]*|\b(?:and|but|or|so|yet|nor)\b[ \t]+)\K(?:[*_]{1,2})?
|
|
3473
|
+
(?:Nothing|Nobody|No[ \t]+one|None)(?>(?:[ \t]+(?!and\b)[\w'’-]+){1,8})[ \t]+and[ \t]+
|
|
3474
|
+
(?:Nothing|Nobody|No[ \t]+one|None)(?>(?:[ \t]+[\w'’-]+){1,8})
|
|
3475
|
+
(?:[.!?]|,[ \t]+(?:and|but|or|so|yet|nor)\b|[,;:])
|
|
3476
|
+
|
|
|
3477
|
+
(?:\A|(?<=[.;:!?\n])[ \t]*)\K(?:[*_]{1,2})?
|
|
3478
|
+
(?:Nothing|Nobody|No[ \t]+one|None)(?>(?:[ \t]+(?!that\b)[\w'’-]+){1,3})[ \t]+that[ \t]+
|
|
3479
|
+
(?:(?:does|do|did|has|have|had|is|are|was|were)[ \t]+not|(?:doesn|don|didn|hasn|haven|hadn|isn|aren|wasn|weren)['’]t)
|
|
3480
|
+
(?>(?:[ \t]+[\w'’-]+){1,10})
|
|
3481
|
+
(?:[.!?]|,[ \t]+(?:and|but|or|so|yet|nor)\b|[,;:])
|
|
3482
|
+
/ix,
|
|
3483
|
+
message: '"Nothing/Nobody/No one" as the subject names no one and nothing specific.',
|
|
3484
|
+
suggestion: "Name the specific thing that is missing, or who is responsible for it.",
|
|
3485
|
+
examples_bad: [
|
|
3486
|
+
"Nothing is deployed and nothing is queued.",
|
|
3487
|
+
"The queue is empty; nothing gets merged that does not get reviewed.",
|
|
3488
|
+
# A clause break, not the end of the sentence, closes each frame.
|
|
3489
|
+
"Nobody merges anything that hasn't passed review.",
|
|
3490
|
+
"Nothing is staged and nothing is promoted this week, and the freeze holds through Friday.",
|
|
3491
|
+
# A longer relative-clause tail than three words.
|
|
3492
|
+
"One rule holds every release: nothing ships that does not pass the full suite first.",
|
|
3493
|
+
# A markdown emphasis marker opening the sentence.
|
|
3494
|
+
"*Nothing is queued and nothing is running on the batch cluster tonight."
|
|
3495
|
+
],
|
|
3496
|
+
examples_ok: [
|
|
3497
|
+
# The bare pronoun and a plain verb, with neither of the two frames.
|
|
3498
|
+
"No one knows.",
|
|
3499
|
+
"Nothing happened.",
|
|
3500
|
+
"Nobody owns the service.",
|
|
3501
|
+
# A single clause, not a pairing: no second "and nothing ...".
|
|
3502
|
+
"Nothing is deployed.",
|
|
3503
|
+
# A conjunction clause start with a plain verb, no pairing.
|
|
3504
|
+
"But nobody replied.",
|
|
3505
|
+
# "and nothing" inside one clause, not a second full clause.
|
|
3506
|
+
"The team reviewed the proposal and nothing else mattered.",
|
|
3507
|
+
# "and" joining two noun phrases inside one clause ("has two real
|
|
3508
|
+
# roots and no real numbers"), not opening a second clause -- the
|
|
3509
|
+
# conjunction clause-start is frame 1's alone. Also pins the cut
|
|
3510
|
+
# "No" + noun frame: this stays quiet without it.
|
|
3511
|
+
"The equation has two real roots and no real numbers outside that range.",
|
|
3512
|
+
# The cut "No" + noun frame's own shape, left quiet on purpose: a
|
|
3513
|
+
# determiner and a common noun, not one of the pronouns.
|
|
3514
|
+
"No vendor holds a contract.",
|
|
3515
|
+
# The cut PP frame's shape: a real, specific absence, the
|
|
3516
|
+
# prepositional phrase naming the scope, not a vague subject
|
|
3517
|
+
# dressed up to look concrete. The maintainer's own examples.
|
|
3518
|
+
"Nobody on the team has reviewed the migration yet.",
|
|
3519
|
+
"Nothing in the runbook mentions this failure mode.",
|
|
3520
|
+
"No one from the platform team joined the postmortem."
|
|
3521
|
+
],
|
|
3522
|
+
rationale: "A negative pronoun standing as the subject names nothing specific, and a " \
|
|
3523
|
+
"sentence built to look concrete around it -- a paired clause, a negated " \
|
|
3524
|
+
"relative clause -- reads as if it said something when the subject still " \
|
|
3525
|
+
"names no one and nothing. Bare 'Nothing happened' is ordinary prose and is " \
|
|
3526
|
+
"left alone; the tell is the extra structure dressing up a subject that was " \
|
|
3527
|
+
"never named."
|
|
3528
|
+
),
|
|
3265
3529
|
Rule.new(
|
|
3266
3530
|
id: "quip-question",
|
|
3267
3531
|
category: "reader-address",
|
data/lib/sloplint/split.rb
CHANGED
|
@@ -81,14 +81,20 @@ module Sloplint
|
|
|
81
81
|
|
|
82
82
|
module_function
|
|
83
83
|
|
|
84
|
-
# text: the source.
|
|
85
|
-
#
|
|
86
|
-
#
|
|
87
|
-
#
|
|
88
|
-
#
|
|
89
|
-
#
|
|
84
|
+
# text: the source. Furniture lines -- headings (# and the setext title-
|
|
85
|
+
# plus-underline form), bullets, ordered items, table rows, block
|
|
86
|
+
# quotes, horizontal rules and reference lines -- are blanked whether or
|
|
87
|
+
# not markdown is set, because their shape alone says they are not
|
|
88
|
+
# prose. markdown additionally blanks fenced code, HTML
|
|
89
|
+
# comments and URLs before splitting, and the furniture that only shows
|
|
90
|
+
# once a document is read as Markdown: front matter, an indented code
|
|
91
|
+
# block, a lone HTML tag line, and a line that is only a code span or a
|
|
92
|
+
# URL. Splitting happens on the blanked copy; the texts returned are cut
|
|
93
|
+
# from the original at the same offsets, so an excerpt is always a
|
|
94
|
+
# string that is in the file. Blanking is character for character, so
|
|
95
|
+
# the offsets agree.
|
|
90
96
|
def paragraphs(text, markdown: false)
|
|
91
|
-
scan, asked = markdown ?
|
|
97
|
+
scan, asked = blank_furniture(markdown ? blank(text) : text, markdown ? blank_blocks(text) : text, markdown:)
|
|
92
98
|
# A document with nothing to leave out is asked about as written, and
|
|
93
99
|
# then every text is cut once instead of twice.
|
|
94
100
|
asked = text if asked == text
|
|
@@ -217,11 +223,22 @@ module Sloplint
|
|
|
217
223
|
# here. A sentence that names a tag in running text does not look like
|
|
218
224
|
# this: "<p> is the tag for a paragraph." has words after the ">".
|
|
219
225
|
HTML_LINE = %r{\A[ \t]{0,3}</?[A-Za-z][^\n]*>[ \t]*\z}
|
|
226
|
+
# A line that is only character references, with or without tags among
|
|
227
|
+
# them: the " " a template leaves as a spacer, "<br> ". It
|
|
228
|
+
# holds no words, so nothing on it is a sentence.
|
|
229
|
+
ENTITY_LINE = %r{\A[ \t]*(?:(?:&(?:[A-Za-z][A-Za-z0-9]*|\#\d+|\#[xX]\h+);|</?[A-Za-z][^<>\n]*>)[ \t]*)+\z}
|
|
220
230
|
# The --- that opens YAML front matter. FURNITURE reads it as a
|
|
221
231
|
# horizontal rule wherever it appears; front matter is the block it
|
|
222
232
|
# opens, and only on the first line of the file.
|
|
223
233
|
FRONT = /\A---[ \t]*\z/
|
|
224
234
|
|
|
235
|
+
# The underline of a setext heading: one or more "=" for a level-1
|
|
236
|
+
# title, two or more "-" for a level-2 one. FURNITURE only knows the
|
|
237
|
+
# "#" (ATX) form. A "---" underline already drops as a horizontal
|
|
238
|
+
# rule, but the title line above it used to stay prose, and a title
|
|
239
|
+
# underlined in "=" did not drop at all.
|
|
240
|
+
SETEXT_UNDERLINE = /\A(?:=+|-{2,})[ \t]*\z/
|
|
241
|
+
|
|
225
242
|
# How many lines of YAML front matter the document opens with: the ---
|
|
226
243
|
# on the first line, everything to the next --- line, and that line. Zero
|
|
227
244
|
# for a document that does not open with one, so a --- between two
|
|
@@ -241,10 +258,23 @@ module Sloplint
|
|
|
241
258
|
# original and in both copies. The line ending is taken off before the
|
|
242
259
|
# tests run: on a CRLF file it would otherwise sit between the line and
|
|
243
260
|
# the \z that a horizontal rule or a bare link ends at, and neither would
|
|
244
|
-
# be recognised as furniture.
|
|
245
|
-
|
|
261
|
+
# be recognised as furniture. markdown: false still drops a line whose
|
|
262
|
+
# shape alone marks it as furniture -- FURNITURE, a list item, a list
|
|
263
|
+
# item's continuation, a setext title and its underline -- but leaves
|
|
264
|
+
# front matter, an indented code block, a lone HTML tag line and a lone
|
|
265
|
+
# code-span-or-URL line alone, because those only read as furniture
|
|
266
|
+
# once the document is read as Markdown.
|
|
267
|
+
def blank_furniture(scan, shown, markdown: true)
|
|
246
268
|
lines = scan.each_line.to_a
|
|
247
|
-
front = front_matter(lines)
|
|
269
|
+
front = markdown ? front_matter(lines) : 0
|
|
270
|
+
# A setext title and its underline, marked ahead of the walk below so
|
|
271
|
+
# each line of the pair can see the other: the walk itself only ever
|
|
272
|
+
# looks at the line it is on. A line is a title when it is not blank
|
|
273
|
+
# and the next line is nothing but a setext underline; the underline
|
|
274
|
+
# is furniture only where a title sits right above it, so a "---"
|
|
275
|
+
# after a blank line is still read as the horizontal rule it is.
|
|
276
|
+
underline = lines.map { |l| l.chomp.match?(SETEXT_UNDERLINE) }
|
|
277
|
+
title = lines.each_index.map { |i| !lines[i].chomp.strip.empty? && underline[i + 1] == true }
|
|
248
278
|
item = false
|
|
249
279
|
prose = false
|
|
250
280
|
code = false
|
|
@@ -263,9 +293,10 @@ module Sloplint
|
|
|
263
293
|
# already -- the first line, or after a blank or furniture line --
|
|
264
294
|
# and where the indent is not a list item's second line. It then runs
|
|
265
295
|
# for as long as the indent holds.
|
|
266
|
-
code = (code && (indented || blank)) || (indented && !item && opens)
|
|
267
|
-
|
|
268
|
-
|
|
296
|
+
code = markdown && ((code && (indented || blank)) || (indented && !item && opens))
|
|
297
|
+
setext = title[i] || (i.positive? && title[i - 1])
|
|
298
|
+
dropped = i < front || code || listed || l.match?(FURNITURE) || (markdown && (l.match?(HTML_LINE) || l.match?(ENTITY_LINE))) ||
|
|
299
|
+
(markdown && lone_inline?(l, prose)) || (item && l.match?(CONTINUED)) || setext
|
|
269
300
|
item = listed || (item && l.match?(CONTINUED))
|
|
270
301
|
prose = !dropped && !blank
|
|
271
302
|
opens = blank || dropped
|