Skip to content

Migrate orga from v2 to v4#837

Open
fenril058 wants to merge 25 commits into
kijimad:mainfrom
fenril058:pr/orga-v4
Open

Migrate orga from v2 to v4#837
fenril058 wants to merge 25 commits into
kijimad:mainfrom
fenril058:pr/orga-v4

Conversation

@fenril058
Copy link
Copy Markdown

Summary

  • Upgrade orga parser from v2 to v4, which now produces a unist-compatible AST
    (https://github.com/syntax-tree/unist)
  • Replace the traverse library with unist-util-visit for tree traversal, removing a legacy dependency
  • Flatten orga v4 section wrapper nodes into their parent nodes so the output matches the flat structure expected by textlint rules
    (Document > [Header, Paragraph, Header, Paragraph, ...])
  • Rewrite the test suite:
    • Remove mocha and power-assert
    • Switch to tsx and Node.js built-in assert
  • Update ESLint configuration from .eslintrc.js to flat config (eslint.config.mjs)
  • Update various dependencies:
    • TypeScript v6
    • textlint
    • @types/node
    • diff
    • semver

Background

orga v4 wraps each headline and its body in a section node:

document > section > [headline, paragraph, ...]

TxtAST has no equivalent section node, so this PR promotes section children into the parent node before returning the AST.

This preserves the flat structure expected by existing textlint rules.

Test plan

  • npm test passes
  • Existing .org files parse correctly with textlint rules (no regressions)

fenril058 and others added 25 commits May 13, 2026 10:09
Use an `interface` instead of a `type`
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
…ne/newline nodes

traverse.remove() misses the last element when multiple consecutive removals occur
(its index adjustment compensates by only one step per removal). Strip emptyLine and
newline tokens with a recursive children filter after the traversal loop instead.

Also restores correct orga v4 type mapping: inline text nodes use type "text" with a
style property, not "text.plain"/"text.bold" etc., and link URLs live in node.path.value.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
orga v4 produces a unist-compatible AST, so use the standard unist-util-visit
for tree traversal instead of the generic traverse library. This removes the
this.notLeaf guard (unist-util-visit only descends into children arrays, never
into data objects or other non-node properties) and eliminates the traverse
dependency entirely.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
orga v4 wraps each headline and its content in a section node
(document > section > [headline, paragraph, section, ...]).
TxtAST has no equivalent for section, so promote section children
directly into the parent, giving the flat structure that textlint
rules expect (document > [header, paragraph, header, paragraph]).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…nd headings

Covers the case where newline nodes were left with range=undefined due to
traverse.remove() missing the last consecutive removal, which caused
TypeError in rules using sentence-splitter (e.g. textlint-rule-sentence-length).
Uses @textlint/ast-tester to assert every node has valid range/loc/raw.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…, and AST validity

Add mapping for strikeThrough → Delete (orga v4 style property).

New unit tests (OrgProcessor-test.ts):
- italic, verbatim, strikeThrough inline styles
- inline footnote reference ([fn:1] inside paragraph)
- nested list structure (outer/inner List and ListItem nodes)
- Str node range, loc, and raw values against source text

New AST validity tests (ast-test.ts, using @textlint/ast-tester):
- all inline styles in one paragraph
- nested list
- link with description
- inline footnote reference

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ation

OrgProcessor unit tests:
- availableExtensions returns ['.org']
- postProcess passes through messages and filePath
- postProcess defaults filePath to '<org>' when not provided

Edge cases:
- empty string parses to empty Document without crashing
- link without description extracts url correctly
- ordered list produces List and ListItem nodes

Header range after section flattening:
- raw, range, and loc are correct for a heading preceded by section wrapper
- sibling paragraph follows directly with no UNKNOWN section node between them

Also adds empty string and ordered list to ast-tester validity suite.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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