首页 > 解决方案 > 如何从 package.json 脚本中正确调用 eslint?

问题描述

我正在尝试将功能部署到 firebase,但 ESLint 似乎存在问题。我试图通过按Shift++Option对其进行格式化F,但这似乎也不起作用。

当我尝试初始化 eslint 时,它要求我创建一个已经存在的新 package.json 文件。

这是package.json文件

{
    "name": "functions",
    "description": "Cloud Functions for Firebase",
    "scripts": {
        "lint": "eslint.js",
        "serve": "firebase emulators:start --only functions",
        "shell": "firebase functions:shell",
        "start": "npm run shell",
        "deploy": "firebase deploy --only functions",
        "logs": "firebase functions:log"
    },
    "engines": {
        "node": "14"
    },
    "main": "index.js",
    "dependencies": {
        "firebase-admin": "^9.8.0",
        "firebase-functions": "^3.14.1"
    },
    "devDependencies": {
        "eslint": "^7.6.0",
        "eslint-config-google": "^0.14.0",
        "firebase-functions-test": "^0.2.0"
    },
    "private": true
}

这是我得到的错误: 在此处输入图像描述

如果我使用"eslint ."而不是"eslint.js"in package.json,我会收到以下标识错误

8:1  error  Expected indentation of 6 spaces but found 8   indent
9:8  error  Newline required at end of file but not found  eol-last

标签: javascripteslint

解决方案


你是在自问自答。要运行 eslint,你只需要eslint在脚本中,而不是eslint.js.

当 eslint 运行时,它会为您提供 linter 输出,因此请修复这些问题。

8:1  error  Expected indentation of 6 spaces but found 8   indent
9:8  error  Newline required at end of file but not found  eol-last

这是 eslint 输出,表明您有违反 lint 规则的代码。您的选择是:

  1. 修复缩进和缺少换行符。
  2. 调整您的 eslint 脚本以忽略具有这些错误的文件
  3. 调整您的 lint 规则以删除这两个规则
  4. 停止使用 eslint。

推荐阅读