简体   繁体   中英

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. I have tried to format it by pressing Shift + Option + F , but that also doesn't seem to work.

When I tried to initialise eslint, it is asking me to create a new package.json file which is already there.

This is the package.json file

{
    "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." instead of "eslint.js" in package.json , I get following identation errors

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 .

When eslint runs it's giving you linter output, so fix those issues.

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. Your options are:

  1. Fix the indentation and missing newline.
  2. Adjust your eslint script to ignore the file with those errors
  3. Adjust your lint rules to remove those two rules
  4. Stop using eslint.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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