简体   繁体   English

eslint 错误 '$localize' 没有为 angular 项目定义

[英]eslint error '$localize' is not defined for angular project

I added localization to my angular 15 project (which works).我将本地化添加到我的 angular 15 项目(有效)。 But linting now is broken for .ts files:但是现在.ts文件的 linting 被破坏了:

error '$localize' is not defined no-undef错误“$localize”未定义 no-undef

Here's the .eslintrc.json :这是.eslintrc.json

{
  "root": true,
  "ignorePatterns": [
    "projects/**/*"
  ],
  "env": {
    "browser": true
  },
  "overrides": [
    {
      "files": [
        "*.ts"
      ],
      "parserOptions": {
        "project": [
          "tsconfig.json"
        ],
        "createDefaultProgram": true
      },
      "extends": [
        "eslint:recommended",
        "plugin:@angular-eslint/recommended",
        "plugin:@angular-eslint/template/process-inline-templates",
        "plugin:prettier/recommended"
      ],
      "rules": {
        "@angular-eslint/directive-selector": [
          "error",
          {
            "type": "attribute",
            "prefix": "ilg",
            "style": "camelCase"
          }
        ],
        "@angular-eslint/component-selector": [
          "error",
          {
            "type": "element",
            "prefix": "ilg",
            "style": "kebab-case"
          }
        ],
        "@typescript-eslint/consistent-type-assertions": [
          "error",
          {
            "assertionStyle": "as"
          }
        ],
        "max-statements-per-line": [
          "error",
          {
            "max": 1
          }
        ],
        "constructor-super": "error",
        "no-unused-vars": "off"
      }
    },
    {
      "files": [
        "*.ts"
      ],
      "parser": "@typescript-eslint/parser",
      "parserOptions": {
        "ecmaVersion": 2019,
        "project": "./tsconfig.json",
        "sourceType": "module"
      },
      "plugins": [
        "ngrx"
      ],
      "rules": {
        "@ngrx/updater-explicit-return-type": "warn",
        "@ngrx/no-dispatch-in-effects": "warn",
        "@ngrx/no-effects-in-providers": "error",
        "@ngrx/prefer-action-creator-in-of-type": "warn",
        "@ngrx/prefer-concat-latest-from": "warn",
        "@ngrx/prefer-effect-callback-in-block-statement": "warn",
        "@ngrx/use-effects-lifecycle-interface": "warn",
        "@ngrx/avoid-combining-selectors": "warn",
        "@ngrx/avoid-dispatching-multiple-actions-sequentially": "warn",
        "@ngrx/avoid-duplicate-actions-in-reducer": "warn",
        "@ngrx/avoid-mapping-selectors": "warn",
        "@ngrx/good-action-hygiene": "warn",
        "@ngrx/no-multiple-global-stores": "warn",
        "@ngrx/no-reducer-in-key-names": "warn",
        "@ngrx/no-store-subscription": "warn",
        "@ngrx/no-typed-global-store": "warn",
        "@ngrx/on-function-explicit-return-type": "warn",
        "@ngrx/prefer-action-creator-in-dispatch": "warn",
        "@ngrx/prefer-action-creator": "warn",
        "@ngrx/prefer-inline-action-props": "warn",
        "@ngrx/prefer-one-generic-in-create-for-feature-selector": "warn",
        "@ngrx/prefer-selector-in-select": "warn",
        "@ngrx/prefix-selectors-with-select": "warn",
        "@ngrx/select-style": "warn",
        "@ngrx/use-consistent-global-store-name": "warn"
      }
    },
    {
      "files": [
        "*.html"
      ],
      "extends": [
        "plugin:@angular-eslint/template/recommended"
      ],
      "rules": {}
    },
    {
      "files": [
        "*.ts"
      ],
      "extends": [
        "plugin:@ngrx/strict-requiring-type-checking"
      ]
    }
  ]
}

polyfills.ts contains the import for localize: polyfills.ts包含本地化的导入:

import "@angular/localize/init";

Please help me fix this as I couldn't find anything myself.请帮我解决这个问题,因为我自己找不到任何东西。

I added the following to .eslintrc.json for now:我现在将以下内容添加到.eslintrc.json

  "globals": {
    "$localize": "readonly"
  },

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

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