@cffnpwr/textlint-rule-no-chained-continuative 0.0.0 → 1.0.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.
package/dist/index.mjs ADDED
@@ -0,0 +1,2 @@
1
+ import{createBlockQuoteDepth as e,toMaskedStringSource as t,validateOptions as n}from"@cffnpwr/textlint-rule-preset-ja-writing-extras-shared";import{type as r}from"arktype";import{tokenize as i}from"kuromojin";import{SentenceSplitterSyntax as a,splitAST as o}from"sentence-splitter";const s=r({"+":`reject`,"max?":`number.integer >= 0`,"skipBlockQuote?":`boolean`,"severity?":`unknown`}),c=e=>o(e),l=e=>e.pos!==`動詞`&&e.pos!==`助動詞`?!1:e.conjugated_form===`連用形`||e.pos===`助動詞`&&e.basic_form===`ぬ`&&e.conjugated_form===`連用ニ接続`,u=e=>{let t=[],n=0;return e.forEach((r,i)=>{let a=n;n+=r.surface_form.length,l(r)&&e[i+1]?.surface_form===`、`&&t.push({start:a,end:n})}),t},d=(r,o={})=>{n(s,o);let{Syntax:l,RuleError:d,report:f,locator:p}=r,m=o.max??1,h=o.skipBlockQuote??!0,g=e(),_=async e=>{if(h&&g.isInside())return;let n=e.range[0],r=c(e).children.filter(e=>e.type===a.Sentence);for(let a of r){let r=t(a),o=u(await i(r.toString())),s=o[m];if(s===void 0)continue;let c=r.originalIndexFromIndex(s.start),l=r.originalIndexFromIndex(s.end-1);if(c===void 0||l===void 0)continue;let h=a.range[0]-n;f(e,new d(`1文の中で連用中止(動詞・助動詞の連用形+読点)が${o.length}回使われています。${m}回までにしてください。文を分けるか、接続助詞・接続詞を使って節の関係を示してください。`,{padding:p.range([h+c,h+l+1])}))}};return{[l.BlockQuote]:g.enter,[l.BlockQuoteExit]:g.exit,[l.Paragraph]:_}};export{d as default};
2
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":["optionsSchema","type","splitParagraph","splitAST","node","isContinuativeForm","token","findContinuatives","found","index","tokens","start","tokenIndex","rule","validateOptions","options","context","max","skipBlockQuote","blockQuote","createBlockQuoteDepth","checkParagraph","base","sentences","child","SentenceSplitterSyntax","sentence","source","toMaskedStringSource","continuatives","tokenize","target","last","sentenceOffset","report","RuleError","locator","Syntax"],"sources":["../src/index.ts"],"sourcesContent":["import type { TxtParagraphNode } from \"@textlint/ast-node-types\";\nimport type { TextlintRuleModule } from \"@textlint/types\";\nimport type { KuromojiToken } from \"kuromojin\";\n\nimport { createBlockQuoteDepth, toMaskedStringSource, validateOptions } from \"@cffnpwr/textlint-rule-preset-ja-writing-extras-shared\";\nimport { type } from \"arktype\";\nimport { tokenize } from \"kuromojin\";\nimport { SentenceSplitterSyntax, splitAST } from \"sentence-splitter\";\n\nconst optionsSchema = type({\n \"+\": \"reject\",\n \"max?\": \"number.integer >= 0\",\n \"skipBlockQuote?\": \"boolean\",\n \"severity?\": \"unknown\",\n});\n\nexport type Options = {\n max?: number;\n skipBlockQuote?: boolean;\n};\n\n// optionsSchema(実行時バリデータ)と公開型Optionsの同期をコンパイル時の保証対象とするための型\ntype Expect<T extends true> = T;\ntype Equals<A, B> = (<T>() => T extends A ? 1 : 2) extends (<T>() => T extends B ? 1 : 2) ? true : false;\ntype _AssertOptions = Expect<Equals<Options, Omit<typeof optionsSchema.infer, \"severity\">>>;\n\nconst defaultMax = 1;\n\n// sentence-splitter 5.1.0がtextlint 15系と異なる型定義(@textlint/ast-node-types@13)を要求するための変換(構造は互換)\nconst splitParagraph = (node: TxtParagraphNode) => splitAST(node as unknown as Parameters<typeof splitAST>[0]);\n\n// IPAdicが「〜ず」(助動詞「ぬ」)の活用形を「連用形」ではなく「連用ニ接続」とするための個別判定\nconst isContinuativeForm = (token: KuromojiToken): boolean => {\n if (token.pos !== \"動詞\" && token.pos !== \"助動詞\") {\n return false;\n }\n if (token.conjugated_form === \"連用形\") {\n return true;\n }\n return token.pos === \"助動詞\" && token.basic_form === \"ぬ\" && token.conjugated_form === \"連用ニ接続\";\n};\n\ntype TokenRange = { start: number; end: number; };\n\n// 連用中止(動詞・助動詞の連用形の直後が読点)のトークンの範囲の一覧\nconst findContinuatives = (tokens: readonly KuromojiToken[]): TokenRange[] => {\n const found: TokenRange[] = [];\n // kuromojinのword_positionがサロゲートペアを1文字と数えるため、表層形の長さの累積をUTF-16単位の位置として使用\n let index = 0;\n tokens.forEach((token, tokenIndex) => {\n const start = index;\n index += token.surface_form.length;\n if (isContinuativeForm(token) && tokens[tokenIndex + 1]?.surface_form === \"、\") {\n found.push({ start, end: index });\n }\n });\n return found;\n};\n\nconst rule: TextlintRuleModule<Options> = (context, options = {}) => {\n validateOptions(optionsSchema, options);\n const { Syntax, RuleError, report, locator } = context;\n const max = options.max ?? defaultMax;\n const skipBlockQuote = options.skipBlockQuote ?? true;\n const blockQuote = createBlockQuoteDepth();\n\n const checkParagraph = async (node: TxtParagraphNode): Promise<void> => {\n // 形態素解析の待機中に走査が進むため、引用配下の判定を待機の前に実施\n if (skipBlockQuote && blockQuote.isInside()) {\n return;\n }\n const base = node.range[0];\n const sentences = splitParagraph(node).children.filter(\n (child) => child.type === SentenceSplitterSyntax.Sentence,\n );\n for (const sentence of sentences) {\n const source = toMaskedStringSource(sentence);\n const continuatives = findContinuatives(await tokenize(source.toString()));\n const target = continuatives[max];\n if (target === undefined) {\n continue;\n }\n const start = source.originalIndexFromIndex(target.start);\n // 終端の位置はマークアップの境界でずれるため、末尾の文字の位置から算出\n const last = source.originalIndexFromIndex(target.end - 1);\n if (start === undefined || last === undefined) {\n continue;\n }\n const sentenceOffset = sentence.range[0] - base;\n report(\n node,\n new RuleError(\n `1文の中で連用中止(動詞・助動詞の連用形+読点)が${continuatives.length}回使われています。${max}回までにしてください。文を分けるか、接続助詞・接続詞を使って節の関係を示してください。`,\n { padding: locator.range([sentenceOffset + start, sentenceOffset + last + 1]) },\n ),\n );\n }\n };\n\n return {\n [Syntax.BlockQuote]: blockQuote.enter,\n [Syntax.BlockQuoteExit]: blockQuote.ex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AAK,EAElDC,EAAOL,EAAO,uBAAuBI,EAAO,IAAM,CAAC,EACzD,GAAIpB,IAAU,IAAA,IAAaqB,IAAS,IAAA,GAClC,SAEF,IAAMC,EAAiBP,EAAS,MAAM,GAAKJ,EAC3CY,EACE9B,EACA,IAAI+B,EACF,4BAA4BN,EAAc,OAAO,WAAWZ,EAAI,6CAChE,CAAE,QAASmB,EAAQ,MAAM,CAACH,EAAiBtB,EAAOsB,EAAiBD,EAAO,CAAC,CAAC,CAAE,CAChF,CACF,CACF,CACF,EAEA,MAAO,EACJK,EAAO,YAAalB,EAAW,OAC/BkB,EAAO,gBAAiBlB,EAAW,MACnCkB,EAAO,WAAYhB,CACtB,CACF,E"}
package/package.json CHANGED
@@ -1,10 +1,51 @@
1
1
  {
2
2
  "name": "@cffnpwr/textlint-rule-no-chained-continuative",
3
- "version": "0.0.0",
4
- "description": "OIDC trusted publishing setup package for @cffnpwr/textlint-rule-no-chained-continuative",
3
+ "version": "1.0.0",
4
+ "description": "1文の中で連用中止が連続する状態を検出するtextlintルール",
5
+ "homepage": "https://github.com/cffnpwr/textlint-rule-preset-ja-writing-extras",
6
+ "bugs": "https://github.com/cffnpwr/textlint-rule-preset-ja-writing-extras/issues",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/cffnpwr/textlint-rule-preset-ja-writing-extras.git",
10
+ "directory": "packages/no-chained-continuative"
11
+ },
12
+ "license": "MIT",
13
+ "author": "cffnpwr",
14
+ "type": "module",
5
15
  "keywords": [
6
- "oidc",
7
- "trusted-publishing",
8
- "setup"
9
- ]
16
+ "textlintrule"
17
+ ],
18
+ "exports": {
19
+ ".": {
20
+ "import": "./dist/index.mjs",
21
+ "require": "./dist/index.cjs"
22
+ },
23
+ "./package.json": "./package.json"
24
+ },
25
+ "types": "./dist/index.d.cts",
26
+ "files": [
27
+ "dist",
28
+ "LICENSE"
29
+ ],
30
+ "scripts": {
31
+ "test": "bun test src",
32
+ "typecheck": "tsc --noEmit"
33
+ },
34
+ "dependencies": {
35
+ "@cffnpwr/textlint-rule-preset-ja-writing-extras-shared": "1.4.0",
36
+ "arktype": "2.2.10",
37
+ "kuromojin": "3.1.0",
38
+ "sentence-splitter": "5.1.0"
39
+ },
40
+ "devDependencies": {
41
+ "@textlint/ast-node-types": "15.8.0",
42
+ "@textlint/types": "15.8.0"
43
+ },
44
+ "peerDependencies": {
45
+ "textlint": ">=15.0.0"
46
+ },
47
+ "inlinedDependencies": {
48
+ "@textlint/ast-node-types": "15.8.0",
49
+ "@textlint/types": "15.8.0"
50
+ }
10
51
  }