简体   繁体   English

如何从 package.json 脚本中正确调用 eslint?

[英]How can I properly invoke eslint from a package.json script?

I am trying to deploy a function to firebase and there seems to be a problem with ESLint.我正在尝试将 function 部署到 firebase 并且 ESLint 似乎有问题。 I have tried to format it by pressing Shift + Option + F , but that also doesn't seem to work.我试图通过按Shift + Option + F来格式化它,但这似乎也不起作用。

When I tried to initialise eslint, it is asking me to create a new package.json file which is already there.当我尝试初始化 eslint 时,它要求我创建一个已经存在的新 package.json 文件。

This is the package.json file这是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
}

This is the error I am getting:这是我得到的错误: 在此处输入图像描述

If I use "eslint."如果我使用"eslint." instead of "eslint.js" in package.json , I get following identation errors而不是 package.json 中的"eslint.js" 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

You answered your own question.你是在自问自答。 To run eslint, you just want eslint in the script, not eslint.js .要运行 eslint,你只需要脚本中的eslint ,而不是eslint.js

When eslint runs it's giving you linter output, so fix those issues.当 eslint 运行时,它会给你 linter output,所以修复这些问题。

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

This is eslint output indicating you have code that violates the lint rules.这是 eslint output 表明您有违反 lint 规则的代码。 Your options are:您的选择是:

  1. Fix the indentation and missing newline.修复缩进和缺少换行符。
  2. Adjust your eslint script to ignore the file with those errors调整您的 eslint 脚本以忽略具有这些错误的文件
  3. Adjust your lint rules to remove those two rules调整您的 lint 规则以删除这两个规则
  4. Stop using eslint.停止使用 eslint。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM