PageSourceSearch

https://textlint.org/assets/js/b35e4d71.eb08bd9b.js

js textlint.org collected 2026-09-25 20:03:25 UTC 5,852 bytes, 1 lines download raw bytes

1"use strict";(globalThis.webpackChunktextlint_website=globalThis.webpackChunktextlint_website||[]).push([[2444],{5175:(n,e,t)=>{t.d(e,{R:()=>i,x:()=>l});var r=t(3706);const o={},s=r.createContext(o);function i(n){const e=r.useContext(s);return r.useMemo((function(){return"function"==typeof n?n(e):{...e,...n}}),[e,n])}function l(n){let e;return e=n.disableParentContext?"function"==typeof n.components?n.components(o):n.components||o:i(n.components),r.createElement(s.Provider,{value:e},n.children)}},8018:(n,e,t)=>{t.r(e),t.d(e,{assets:()=>d,contentTitle:()=>l,default:()=>u,frontMatter:()=>i,metadata:()=>r,toc:()=>c});const r=JSON.parse('{"id":"faq/have-to-use-line-column-or-index","title":"Have to use {line, column} or index","description":"Target: Developer","source":"@site/../docs/faq/line-column-or-index.md","sourceDirName":"faq","slug":"/faq/have-to-use-line-column-or-index","permalink":"/docs/faq/have-to-use-line-column-or-index","draft":false,"unlisted":false,"editUrl":"https://github.com/textlint/textlint/edit/master/docs/../docs/faq/line-column-or-index.md","tags":[],"version":"current","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1790335860000,"frontMatter":{"id":"have-to-use-line-column-or-index","title":"Have to use {line, column} or index"}}');var o=t(1058),s=t(5175);const i={id:"have-to-use-line-column-or-index",title:"Have to use {line, column} or index"},l="Have to use {line, column} or index",d={},c=[{value:"What is this?",id:"what-is-this",level:3},{value:"Solution",id:"solution",level:3}];function a(n){const e={a:"a",code:"code",h1:"h1",h3:"h3",header:"header",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,s.R)(),...n.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(e.header,{children:(0,o.jsx)(e.h1,{id:"have-to-use-line-column-or-index",children:"Have to use {line, column} or index"})}),"\n",(0,o.jsxs)(e.p,{children:[(0,o.jsx)(e.strong,{children:"Target:"})," Developer"]}),"\n",(0,o.jsxs)(e.ul,{children:["\n",(0,o.jsxs)(e.li,{children:["Related: ",(0,o.jsx)(e.a,{href:"https://github.com/textlint/textlint/issues/134",title:"context.report(node, { index }): index-based report \xb7 Issue #134 \xb7 textlint/textlint",children:"context.report(node, { index }): index-based report \xb7 Issue #134 \xb7 textlint/textlint"})]}),"\n"]}),"\n",(0,o.jsx)(e.h3,{id:"what-is-this",children:"What is this?"}),"\n",(0,o.jsxs)(e.p,{children:["There is wrong that ",(0,o.jsx)(e.code,{children:"column"})," doesn't consider line break."]}),"\n",(0,o.jsx)(e.pre,{children:(0,o.jsx)(e.code,{className:"language-js",children:'//  surrogate pair\nfunction stringToArray(value) {\n    return value.match(/[\\uD800-\\uDBFF][\\uDC00-\\uDFFF]|[^\\uD800-\\uDFFF]/g) || [];\n}\n\nexport default function (context) {\n    const { Syntax, RuleError, report, getSource } = context;\n    return {\n        [Syntax.Str](node) {\n            const text = getSource(node);\n            const strArray = stringToArray(text);\n            for (let index = 0; index < strArray.length; index++) {\n                const item = strArray[index];\n                // \u274c\n                if (/\\u274c/.test(item)) {\n                    report(\n                        node,\n                        new RuleError("Use X insteadof \\u274c", {\n                            // This is wrong\n                            column: index\n                        })\n                    );\n                }\n            }\n        }\n    };\n}\n'})}),"\n",(0,o.jsx)(e.p,{children:"Input:"}),"\n",(0,o.jsx)(e.pre,{children:(0,o.jsx)(e.code,{children:"string\n\u274c\nstring\n"})}),"\n",(0,o.jsx)(e.p,{children:"Result of TextLintMessage:"}),"\n",(0,o.jsx)(e.pre,{children:(0,o.jsx)(e.code,{className:"language-json",children:'{\n   "message": "Use X insteadof \u274c",\n   "line": 1,\n   "column": 7\n}\n'})}),"\n",(0,o.jsx)(e.p,{children:"Expected:"}),"\n",(0,o.jsx)(e.pre,{children:(0,o.jsx)(e.code,{className:"language-json",children:'{\n   "message": "Use X insteadof \u274c",\n   "line": 2,\n   "column": 1\n}\n'})}),"\n",(0,o.jsxs)(e.p,{children:["You can use ",(0,o.jsx)(e.code,{children:"index"})," instead of this."]}),"\n",(0,o.jsx)(e.h3,{id:"solution",children:"Solution"}),"\n",(0,o.jsx)(e.pre,{children:(0,o.jsx)(e.code,{className:"language-js",children:'const paddingLocation = {\n    line: 1,\n    column: 2\n};\nreport(\n    node,\n    new RuleError("message", {\n        line: paddingLocation.line,\n        column: paddingLocation.column\n    })\n);\n'})}),"\n",(0,o.jsx)(e.p,{children:'OR use "index" property'}),"\n",(0,o.jsx)(e.pre,{children:(0,o.jsx)(e.code,{children:'const paddingIndexValue = 1;\nreport(node, new RuleError("message", {\n    index: paddingIndexValue\n});\n'})}),"\n",(0,o.jsx)(e.p,{children:"Fixed version:"}),"\n",(0,o.jsx)(e.pre,{children:(0,o.jsx)(e.code,{className:"language-js",children:'//  surrogate pair\nfunction stringToArray(value) {\n    return value.match(/[\\uD800-\\uDBFF][\\uDC00-\\uDFFF]|[^\\uD800-\\uDFFF]/g) || [];\n}\n\nexport default function (context) {\n    const { Syntax, RuleError, report, getSource }
1 = context;\n    return {\n        [Syntax.Str](node) {\n            const text = getSource(node);\n            const strArray = stringToArray(text);\n            for (let index = 0; index < strArray.length; index++) {\n                const item = strArray[index];\n                // \u274c\n                if (/\\u274c/.test(item)) {\n                    report(\n                        node,\n                        new RuleError("Use X insteadof \\u274c", {\n                            index\n                        })\n                    );\n                }\n            }\n        }\n    };\n}\n'})})]})}function u(n={}){const{wrapper:e}={...(0,s.R)(),...n.components};return e?(0,o.jsx)(e,{...n,children:(0,o.jsx)(a,{...n})}):a(n)}}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.