为我的云函数启用ESLint的命令是什么?
为了了解一些背景信息,我运行了firebase init并进行了设置,但出于某种原因,它使用的是ESLint而不是TSLint。我重新做了firebase init,这一次当它问我是否想使用ESLint时,我回答了“不”。然而,正如评论所指出的那样,ESLint现在受到青睐,而TSLint则不受欢迎。所以现在我需要为这个项目重新启用ESLint。
发布于 2022-10-03 01:34:50
下面这个视频是关于如何设置云功能的一个很好的入门,包括您提到的eslint,类型记录,非常丰富的解释
发布于 2022-10-03 01:44:11
通过查看firebase-tools实用程序的存储库,您可以找到firebase init命令中使用的模板。
要使用eslint进行链接,您需要以下文件:
适当更新这些文件后,在您的npm install目录中运行functions,以便下载所需的库。
您还需要将这些行添加到项目目录中的firebase.json文件中,以便在部署之前对函数进行链接和转换。
// PROJECT_DIR/firebase.json
{
"functions": {
"source": "functions",
"predeploy": [
"npm --prefix \"$RESOURCE_DIR\" run lint",
"npm --prefix \"$RESOURCE_DIR\" run build"
],
/* ... */
},
/* ... */
}.eslintrc.js、package.json和tsconfig.dev.json在撰写本报告时已被包括在下面,以便于使用。请咨询他们各自的链接,如果他们获得在未来,因为他们可能已经改变。
// PROJECT_DIR/functions/.eslintrc.js
module.exports = {
root: true,
env: {
es6: true,
node: true,
},
extends: [
"eslint:recommended",
"plugin:import/errors",
"plugin:import/warnings",
"plugin:import/typescript",
"google",
"plugin:@typescript-eslint/recommended",
],
parser: "@typescript-eslint/parser",
parserOptions: {
project: ["tsconfig.json", "tsconfig.dev.json"],
sourceType: "module",
},
ignorePatterns: [
"/lib/**/*", // Ignore built files.
],
plugins: [
"@typescript-eslint",
"import",
],
rules: {
"quotes": ["error", "double"],
"import/no-unresolved": 0,
},
};// PROJECT_DIR/functions/package.json
{
"name": "functions",
"scripts": {
"lint": "eslint --ext .js,.ts .",
"build": "tsc",
"build:watch": "tsc --watch",
"serve": "npm run build && firebase emulators:start --only functions",
"shell": "npm run build && firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"engines": {
"node": "16"
},
"main": "lib/index.js",
"dependencies": {
"firebase-admin": "^10.0.2",
"firebase-functions": "^3.18.0"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^5.12.0",
"@typescript-eslint/parser": "^5.12.0",
"eslint": "^8.9.0",
"eslint-config-google": "^0.14.0",
"eslint-plugin-import": "^2.25.4",
"firebase-functions-test": "^0.2.0",
"typescript": "^4.5.4"
},
"private": true
}// PROJECT_DIR/functions/tsconfig.dev.json
{
"include": [
".eslintrc.js"
]
}https://stackoverflow.com/questions/73930351
复制相似问题