From 0748a35b5abdb0c4206858b29afd7f97b8183d37 Mon Sep 17 00:00:00 2001 From: azu Date: Sat, 25 Nov 2023 14:19:59 +0900 Subject: [PATCH] fix: fix `isIgnored` work (#23) Previously, it does not work correctly. --- package.json | 14 ++-- src/IgnoreNodeManager.ts | 3 +- test/IgnoreNodeManager-test.ts | 47 ++++++++++- yarn.lock | 145 +++++++++++++++++---------------- 4 files changed, 129 insertions(+), 80 deletions(-) diff --git a/package.json b/package.json index f6608b8..d01e4fd 100644 --- a/package.json +++ b/package.json @@ -25,20 +25,20 @@ "watch": "tsc -p . --watch" }, "dependencies": { - "@textlint/ast-node-types": "^13.2.0", + "@textlint/ast-node-types": "^13.4.1", "structured-source": "^4.0.0", "unist-util-visit": "^2.0.3" }, "devDependencies": { - "@textlint/kernel": "^13.2.0", - "@textlint/textlint-plugin-markdown": "^13.2.0", - "@textlint/types": "^13.2.0", - "@types/mocha": "^10.0.1", - "@types/node": "^18.13.0", + "@textlint/kernel": "^13.4.1", + "@textlint/textlint-plugin-markdown": "^13.4.1", + "@textlint/types": "^13.4.1", + "@types/mocha": "^10.0.6", + "@types/node": "^20.10.0", "markdown-to-ast": "^6.0.3", "mocha": "^10.2.0", "ts-node": "^10.9.1", "ts-node-test-register": "^10.0.0", - "typescript": "^4.9.5" + "typescript": "^5.3.2" } } diff --git a/src/IgnoreNodeManager.ts b/src/IgnoreNodeManager.ts index 126b336..eb4dced 100644 --- a/src/IgnoreNodeManager.ts +++ b/src/IgnoreNodeManager.ts @@ -57,8 +57,7 @@ export default class IgnoreNodeManager { * @returns {boolean} */ isIgnored(node: TxtNode | TxtParentNode) { - const index = node.index; - return this.isIgnoredIndex(index); + return this.isIgnoredRange(node.range); } /** diff --git a/test/IgnoreNodeManager-test.ts b/test/IgnoreNodeManager-test.ts index fc6a357..40c36ef 100644 --- a/test/IgnoreNodeManager-test.ts +++ b/test/IgnoreNodeManager-test.ts @@ -1,11 +1,53 @@ // LICENSE : MIT import assert from 'assert' import { IgnoreNodeManager } from "../src/index"; -import { TxtNodeType, TxtParentNode } from "@textlint/ast-node-types"; +import { TxtNode, TxtNodeType, TxtParentNode } from "@textlint/ast-node-types"; import { TextlintKernel, TextlintRuleModule } from "@textlint/kernel" import { builtInPlugins } from "./textlint-helper"; describe("IgnoreNodeManager", function () { + describe("#isIgnored()", () => { + it("should ignore multiple nodes", () => { + const ignoreManager = new IgnoreNodeManager(); + const outerNode: TxtNode = { + type: "Str", + range: [0, 1], + loc: { + start: { + line: 1, + column: 1 + }, + end: { + line: 1, + column: 2 + } + }, + raw: "t", + } + const testNode: TxtNode = { + type: "Str", + range: [2, 5], + loc: { + start: { + line: 1, + column: 3 + }, + end: { + line: 1, + column: 6 + } + }, + raw: "test", + } + // 0 1 2 3 4 5 6 7 8 9 + // ^ ^ ^ + // 5(endIndex) is not included + ignoreManager.ignoreRange(testNode.range); + // Should ignore: + assert.ok(ignoreManager.isIgnored(testNode)); + assert.ok(ignoreManager.isIgnored(outerNode) === false); + }); + }); describe("#isIgnoredRange()", () => { it("should ignore multiple nodes", () => { const ignoreManager = new IgnoreNodeManager(); @@ -130,4 +172,5 @@ This is **ignored**. }); }); }); -}); +}) +; diff --git a/yarn.lock b/yarn.lock index 4eba4b5..0455f1a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -48,58 +48,58 @@ "@jridgewell/resolve-uri" "^3.0.3" "@jridgewell/sourcemap-codec" "^1.4.10" -"@textlint/ast-node-types@^13.2.0": - version "13.2.0" - resolved "https://registry.yarnpkg.com/@textlint/ast-node-types/-/ast-node-types-13.2.0.tgz#9210439c88bc61664f8534a19cb7794dcc2061ed" - integrity sha512-P76rGK9SoN/f40yVW2Dep3QkXQOkAYTzEZjV0yBf/W9N0c81HUDJPS//aRbS3ml0Yb7TNgkXYm/ChTsL79RcAg== +"@textlint/ast-node-types@^13.4.1": + version "13.4.1" + resolved "https://registry.yarnpkg.com/@textlint/ast-node-types/-/ast-node-types-13.4.1.tgz#00424f7b9bc6fe15cf6a78468ffe1e5d1adce5b2" + integrity sha512-qrZyhCh8Ekk6nwArx3BROybm9BnX6vF7VcZbijetV/OM3yfS4rTYhoMWISmhVEP2H2re0CtWEyMl/XF+WdvVLQ== "@textlint/ast-node-types@^4.0.0": version "4.4.3" resolved "https://registry.yarnpkg.com/@textlint/ast-node-types/-/ast-node-types-4.4.3.tgz#fdba16e8126cddc50f45433ce7f6c55e7829566c" integrity sha512-qi2jjgO6Tn3KNPGnm6B7p6QTEPvY95NFsIAaJuwbulur8iJUEenp1OnoUfiDaC/g2WPPEFkcfXpmnu8XEMFo2A== -"@textlint/ast-tester@^13.2.0": - version "13.2.0" - resolved "https://registry.yarnpkg.com/@textlint/ast-tester/-/ast-tester-13.2.0.tgz#6938b1c4ccf59df4fe278dd898fe0c7e1bcb8c8c" - integrity sha512-4UHmeT1J2FGm1rfTAIjWw3LWEZPMuHCA2hdAiXVZXZbIOQYE/kmMvUgUeFAxEj0Wg7ozCoOMsTr7T0VF/8CZlA== +"@textlint/ast-tester@^13.4.1": + version "13.4.1" + resolved "https://registry.yarnpkg.com/@textlint/ast-tester/-/ast-tester-13.4.1.tgz#74a704b582fe7cd3caf1d3ae1c65fa0d7f1f6fec" + integrity sha512-YSHUR1qDgMPGF5+nvrquEhif6zRJ667xUnfP/9rTNtThIhoTQINvczr5/7xa43F1PDWplL6Curw+2jrE1qHwGQ== dependencies: - "@textlint/ast-node-types" "^13.2.0" + "@textlint/ast-node-types" "^13.4.1" debug "^4.3.4" -"@textlint/ast-traverse@^13.2.0": - version "13.2.0" - resolved "https://registry.yarnpkg.com/@textlint/ast-traverse/-/ast-traverse-13.2.0.tgz#a607aee37d297b46f255ea36b3461bd43fd17316" - integrity sha512-aqGLu8Yiex/CJGkKXF2p7k3OfzqGBjUp4Of3hPFWb/oARQsUKIeMfQB0bNi5rqcIeOVQhMVTcMzHiW2LPOjDSw== - dependencies: - "@textlint/ast-node-types" "^13.2.0" - -"@textlint/feature-flag@^13.2.0": - version "13.2.0" - resolved "https://registry.yarnpkg.com/@textlint/feature-flag/-/feature-flag-13.2.0.tgz#0b702bb5dde83b04fabbf02696296371e387ddbd" - integrity sha512-HJaz2wT4DDywn5s5r+9N3rEw6GhOB5/IVVVO4HfgALAIrO4K9cSlR1lTFFYgr15uWf0wMnGE8lu43RR9LtDXHw== - -"@textlint/kernel@^13.2.0": - version "13.2.0" - resolved "https://registry.yarnpkg.com/@textlint/kernel/-/kernel-13.2.0.tgz#d374c1c3da239b5e728eec56c71c42a719779d65" - integrity sha512-RUKRax9EhRQDLr9YLv6qxnCnTIre3NouZHyjXR2jB1F6zdOPU+mhI3IC1c7k+iOQVajTi6wWq63POU+ffbpvzA== - dependencies: - "@textlint/ast-node-types" "^13.2.0" - "@textlint/ast-tester" "^13.2.0" - "@textlint/ast-traverse" "^13.2.0" - "@textlint/feature-flag" "^13.2.0" - "@textlint/source-code-fixer" "^13.2.0" - "@textlint/types" "^13.2.0" - "@textlint/utils" "^13.2.0" +"@textlint/ast-traverse@^13.4.1": + version "13.4.1" + resolved "https://registry.yarnpkg.com/@textlint/ast-traverse/-/ast-traverse-13.4.1.tgz#1f35f15a54542c76aef71ce1e4f4a83723016d45" + integrity sha512-uucuC7+NHWkXx2TX5vuyreuHeb+GFiA83V65I+FnYP5EC4dAMOQ86rTSPrZmCwLz+qIWgfDgihGzPccpj3EZGg== + dependencies: + "@textlint/ast-node-types" "^13.4.1" + +"@textlint/feature-flag@^13.4.1": + version "13.4.1" + resolved "https://registry.yarnpkg.com/@textlint/feature-flag/-/feature-flag-13.4.1.tgz#79d27b099baa54166ca4cdd1da80336e7b08192d" + integrity sha512-qY8gKUf30XtzWMTkwYeKytCo6KPx6milpz8YZhuRsEPjT/5iNdakJp5USWDQWDrwbQf7RbRncQdU+LX5JbM9YA== + +"@textlint/kernel@^13.4.1": + version "13.4.1" + resolved "https://registry.yarnpkg.com/@textlint/kernel/-/kernel-13.4.1.tgz#b98f6c501b73db8b8ec46cd1aac70937ee73efa8" + integrity sha512-r2sUhjPysFjl2Ax37x9AfWkJM8jgKN0bL4SX3xRzOukdcj69Dst5On5qBZtULaVMX1LDkwkdxA6ZEADmq27qQA== + dependencies: + "@textlint/ast-node-types" "^13.4.1" + "@textlint/ast-tester" "^13.4.1" + "@textlint/ast-traverse" "^13.4.1" + "@textlint/feature-flag" "^13.4.1" + "@textlint/source-code-fixer" "^13.4.1" + "@textlint/types" "^13.4.1" + "@textlint/utils" "^13.4.1" debug "^4.3.4" fast-equals "^4.0.3" structured-source "^4.0.0" -"@textlint/markdown-to-ast@^13.2.0": - version "13.2.0" - resolved "https://registry.yarnpkg.com/@textlint/markdown-to-ast/-/markdown-to-ast-13.2.0.tgz#301d032b36c87418c6518a7c58b5092c3c733223" - integrity sha512-eYd1XgbzirQk/fDKnNAsT3QKTtEz+CSpBiGIzvaD1kYEzA1aSWtWEJoyZU6DwFJgFs+6scAdcYT2O264IVDRyg== +"@textlint/markdown-to-ast@^13.4.1": + version "13.4.1" + resolved "https://registry.yarnpkg.com/@textlint/markdown-to-ast/-/markdown-to-ast-13.4.1.tgz#63f1f87fb059c083c13a434f7117aca786867835" + integrity sha512-jUa5bTNmxjEgfCXW4xfn7eSJqzUXyNKiIDWLKtI4MUKRNhT3adEaa/NuQl0Mii3Hu3HraZR7hYhRHLh+eeM43w== dependencies: - "@textlint/ast-node-types" "^13.2.0" + "@textlint/ast-node-types" "^13.4.1" debug "^4.3.4" mdast-util-gfm-autolink-literal "^0.1.3" remark-footnotes "^3.0.0" @@ -109,32 +109,32 @@ traverse "^0.6.7" unified "^9.2.2" -"@textlint/source-code-fixer@^13.2.0": - version "13.2.0" - resolved "https://registry.yarnpkg.com/@textlint/source-code-fixer/-/source-code-fixer-13.2.0.tgz#fe9a7235ad431ce916b99857e3eaf163f340befd" - integrity sha512-t8J4kgVQp+G/s5c4DcmAuE8WR2+7Ovf++SQgeRaUoEGoZP+trrF/JaIzlNaH+5MDk6vQ2Z1+WZc2VL+oM5uNnA== +"@textlint/source-code-fixer@^13.4.1": + version "13.4.1" + resolved "https://registry.yarnpkg.com/@textlint/source-code-fixer/-/source-code-fixer-13.4.1.tgz#2408e6209be0290c58b92750375cff4e976f415a" + integrity sha512-Sl29f3Tpimp0uVE3ysyJBjxaFTVYLOXiJX14eWCQ/kC5ZhIXGosEbStzkP1n8Urso1rs1W4p/2UemVAm3NH2ng== dependencies: - "@textlint/types" "^13.2.0" + "@textlint/types" "^13.4.1" debug "^4.3.4" -"@textlint/textlint-plugin-markdown@^13.2.0": - version "13.2.0" - resolved "https://registry.yarnpkg.com/@textlint/textlint-plugin-markdown/-/textlint-plugin-markdown-13.2.0.tgz#1bed77e177fdff0db651f248c18048b242df03e1" - integrity sha512-oLvCp9RqydnfxUacBienhsliTLIsH5zXHeQpQyaDrQtL3syweBgtYFyOoZq1X6jZOU0QLnCCkn1RofMumRBfxA== +"@textlint/textlint-plugin-markdown@^13.4.1": + version "13.4.1" + resolved "https://registry.yarnpkg.com/@textlint/textlint-plugin-markdown/-/textlint-plugin-markdown-13.4.1.tgz#8e1c78c4b5b501bf7e2def6c7d1cbd12a3a8436f" + integrity sha512-OcLkFKYmbYeGJ0kj2487qcicCYTiE2vJLwfPcUDJrNoMYak5JtvHJfWffck8gON2mEM00DPkHH0UdxZpFjDfeg== dependencies: - "@textlint/markdown-to-ast" "^13.2.0" + "@textlint/markdown-to-ast" "^13.4.1" -"@textlint/types@^13.2.0": - version "13.2.0" - resolved "https://registry.yarnpkg.com/@textlint/types/-/types-13.2.0.tgz#20c83f589b2cb7f9f72b4d1e741c83411a043b81" - integrity sha512-65kCcyym3zQFVU10tzGHGl7awyNDK43HtLTuJo/YUWxSpaQJRM3INk1ePVzfj+M+Uru4chnl+MPYQwd/X3z2hw== +"@textlint/types@^13.4.1": + version "13.4.1" + resolved "https://registry.yarnpkg.com/@textlint/types/-/types-13.4.1.tgz#612818525e25331cd7ee315cfbadc38ad070edee" + integrity sha512-1ApwQa31sFmiJeJ5yTNFqjbb2D1ICZvIDW0tFSM0OtmQCSDFNcKD3YrrwDBgSokZ6gWQq/FpNjlhi6iETUWt0Q== dependencies: - "@textlint/ast-node-types" "^13.2.0" + "@textlint/ast-node-types" "^13.4.1" -"@textlint/utils@^13.2.0": - version "13.2.0" - resolved "https://registry.yarnpkg.com/@textlint/utils/-/utils-13.2.0.tgz#60be68b39c158b9d89d50cb197cf7596780c3f0f" - integrity sha512-3DtR5AYbltOH+4GOhjmB4x3aF5xJhoDGfgOZ4Is9uoXeqC+1eyVCG6NeZ6QyuIuHZKy5p8S48t7JgWb8LM47aA== +"@textlint/utils@^13.4.1": + version "13.4.1" + resolved "https://registry.yarnpkg.com/@textlint/utils/-/utils-13.4.1.tgz#721b6c4c83a152f23a70ef0bbbdc7d1c635b5014" + integrity sha512-wX8RT1ejHAPTDmqlzngf0zI5kYoe3QvGDcj+skoTxSv+m/wOs/NyEr92d+ahCP32YqFYzXlqU7aDx2FkULKT+g== "@tsconfig/node10@^1.0.7": version "1.0.9" @@ -163,15 +163,17 @@ dependencies: "@types/unist" "*" -"@types/mocha@^10.0.1": - version "10.0.1" - resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-10.0.1.tgz#2f4f65bb08bc368ac39c96da7b2f09140b26851b" - integrity sha512-/fvYntiO1GeICvqbQ3doGDIP97vWmvFt83GKguJ6prmQM2iXZfFcq6YE8KteFyRtX2/h5Hf91BYvPodJKFYv5Q== +"@types/mocha@^10.0.6": + version "10.0.6" + resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-10.0.6.tgz#818551d39113081048bdddbef96701b4e8bb9d1b" + integrity sha512-dJvrYWxP/UcXm36Qn36fxhUKu8A/xMRXVT2cliFF1Z7UA9liG5Psj3ezNSZw+5puH2czDXRLcXQxf8JbJt0ejg== -"@types/node@^18.13.0": - version "18.13.0" - resolved "https://registry.yarnpkg.com/@types/node/-/node-18.13.0.tgz#0400d1e6ce87e9d3032c19eb6c58205b0d3f7850" - integrity sha512-gC3TazRzGoOnoKAhUx+Q0t8S9Tzs74z7m0ipwGpSqQrleP14hKxP4/JUeEQcD3W1/aIpnWl8pHowI7WokuZpXg== +"@types/node@^20.10.0": + version "20.10.0" + resolved "https://registry.yarnpkg.com/@types/node/-/node-20.10.0.tgz#16ddf9c0a72b832ec4fcce35b8249cf149214617" + integrity sha512-D0WfRmU9TQ8I9PFx9Yc+EBHw+vSpIub4IDvQivcp26PtPrdMGAq5SDcpXEo/epqa/DXotVpekHiLNTg3iaKXBQ== + dependencies: + undici-types "~5.26.4" "@types/normalize-package-data@^2.4.0": version "2.4.1" @@ -1379,10 +1381,15 @@ type-fest@^0.6.0: resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.6.0.tgz#8d2a2370d3df886eb5c90ada1c5bf6188acf838b" integrity sha512-q+MB8nYR1KDLrgr4G5yemftpMC7/QLqVndBmEEdqzmNj5dcFOO4Oo8qlwZE3ULT3+Zim1F8Kq4cBnikNhlCMlg== -typescript@^4.9.5: - version "4.9.5" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.9.5.tgz#095979f9bcc0d09da324d58d03ce8f8374cbe65a" - integrity sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g== +typescript@^5.3.2: + version "5.3.2" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.3.2.tgz#00d1c7c1c46928c5845c1ee8d0cc2791031d4c43" + integrity sha512-6l+RyNy7oAHDfxC4FzSJcz9vnjTKxrLpDG5M2Vu4SHRVNg6xzqZp6LYSR9zjqQTu8DU/f5xwxUdADOkbrIX2gQ== + +undici-types@~5.26.4: + version "5.26.5" + resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-5.26.5.tgz#bcd539893d00b56e964fd2657a4866b221a65617" + integrity sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA== unherit@^1.0.4: version "1.1.3"