Skip to content

refactor: split importcheck.go and share the --when rules with import - #438

Merged
ryanlewis merged 3 commits into
mainfrom
refactor/import-split
Oct 9, 2026
Merged

ryanlewis merged 3 commits into
mainfrom
refactor/import-split

Conversation

@ryanlewis

Copy link
Copy Markdown
Owner

Two steps, one commit each (plus a review commit).

Split importcheck.go (pure move). The 1,900-line file is now split by job:

  • importvalidate.go: the pre-write checks (prepareImport, the badImport* and futureImportDates checks) and the refusal error
  • importdest.go: destination resolution (resolveImportDests, importCreates, importTo)
  • importreadback.go: the read-back (readBackCreates, unconfirmShared, checkClosedAt, checkWhens) and its error
  • importcheck.go: the shared types and the payload walk

createdDest.fits stays in verify.go because add uses it too. A sorted-line comparison shows the old and new files differ only in their import blocks.

Import uses the shared --when rules. ImpossibleWhenError now carries a Reason, so import words its own message from NormalizeWhen's verdict. That removes import's copied clock regexes (importClock24/importClock12), realClock, importTimedWhens and the anytime/someday branch. The timed-keyword check is exported as things.TimedWhenKeyword. Import keeps its own narrower payload rules: a when or deadline starting with a digit must be a two-digit YYYY-MM-DD, only today, tomorrow, evening or a date may come before an @, and a bare time or ISO date-time is refused. A new payloadType helper maps a payload item's type to a task type in prepareImport, importCreates, badImportSchedule and badImportTypes.

A new 50-row table test in importvalidate_test.go covers import's when and deadline rules and their exact refusal messages. I wrote it before the switch, and it passes unchanged after it.

Behaviour change. add --when (and edit --when) now refuse a 12-hour time with two or more spaces before am/pm, such as today@6 pm, today@9:30 pm or a bare 9:30 pm. Import already refused these, while add passed them to Things. Neither form has been tested in Things, so both now refuse it. One space (6 pm, 9:30 PM) is still accepted. The docs only show times with no space (9:30PM, 6pm), so they need no change.

make test and make lint pass.

…-back

A pure move: importvalidate.go holds the pre-write checks and the
refusal error, importdest.go the destination resolution, and
importreadback.go the read-back and its error. importcheck.go keeps
the shared types and the payload walk.
ImpossibleWhenError now carries a reason, so import words its own
message from NormalizeWhen's verdict instead of keeping its own clock
regexes, timed keywords and anytime/someday branch. The timed-keyword
check is exported as things.TimedWhenKeyword, and payloadType maps a
payload's type to a TaskType for prepareImport and importCreates.

The two grammars differed on one input: a 12-hour time with two or
more spaces before am/pm, which import refused and add sent. add now
refuses it too, since neither form was measured in Things.
@ryanlewis
ryanlewis force-pushed the refactor/import-split branch from 2560ce6 to 8a77af4 Compare October 9, 2026 23:34
@ryanlewis
ryanlewis merged commit 76ca76a into main Oct 9, 2026
8 checks passed
@ryanlewis
ryanlewis deleted the refactor/import-split branch October 9, 2026 23:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant