【问题标题】:What does the 'position' mean and how to find the position“职位”是什么意思以及如何找到职位
【发布时间】:2019-12-25 05:23:36
【问题描述】:

今天,当我在 powershell 中运行 npx eslint --fix ./ 时,它会在 .eslintrc.json 中记录 Unexpected token } in JSON at position 93。所以我在这里完全有疑问: 1.'位置93'是什么意思以及如何在我的代码中找到确切的位置,因为我不知道93,我曾经在控制台记录错误位于哪一行(列)时找到位置。 2.我的.eslintrc.json好像没有语法错误,能帮我看看问题吗?

{
    "env": {
        "node": true,
        "commonjs": true,
        "es6": true,
    },
    "extends": "eslint:recommended",
    "globals": {
        "Atomics": "readonly",
        "SharedArrayBuffer": "readonly"
    },
    "parserOptions": {
        "ecmaFeatures": {
            "jsx": true
        },
        "ecmaVersion": 2018
    },
    "plugins": [
        "react"
    ],
    "rules": {
        "indent": [
            "error",
            4
        ],
        "linebreak-style": [
            "error",
            "windows"
        ],
        "quotes": [
            "error",
            "single"
        ],
        "semi": [
            "error",
            "always"
        ]
    }
}

【问题讨论】:

  • "es6": true,后面的逗号
  • Json 文件不应有尾随逗号

标签: javascript json eslint


【解决方案1】:

请删除comma 行中的"es6": true,

您应该将您的 json 粘贴到工具检查验证 json 格式中。

例如:https://jsoneditoronline.org/是在线工具json格式

【讨论】:

  • 非常感谢您解决了我的问题!但是您能否给我一些关于如何找到职位的建议,例如position 93
  • 因为您的 json 格式未通过验证,因此控制台日志可能显示错误不正确
【解决方案2】:

如果给出单个数字。这意味着它是文件中的字符索引。例如:

//Hello
"The following dot is in position 52"
console.log('test');
       ^
       |___ this is position 52 (or 54 if your file contains "\r\n" as newlines)

是的,您需要根据天气将行尾计为一个或两个字节,它具有 Windows 行尾 (CRLF) 或 Unix 行尾 (LF)。

虽然有趣的是,多字节 unicode 字符被计为一个字符而不是多个字节(这是因为与多字节字符不同,“\r”和“\n”都是单独的字符)。

如果给定两个数字,有时在两者之间有一个:,那么第一个数字是行号,第二个是列号(从行首开始的字符索引)。所以上面的点有时会被称为position 3:7line 3 position 7line 3 column 7

【讨论】:

  • 啊哈!非常感谢你的详细回答。现在我不知道当只有一个数字时如何找到确切的位置:D
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多