简体   繁体   English

在@angular-eslint/template 中使用缩进规则

[英]use of indent rule in @angular-eslint/template

I have a project made with Angular.我有一个用 Angular 制作的项目。

I want to set a indent rule for the Angular *.html file.我想为 Angular *.html文件设置缩进规则。

I do that in my .eslintrc :我在我的.eslintrc中这样做:

{
  "files": ["*.html"],
  "extends": [
    "plugin:@angular-eslint/template/recommended"
  ],
  "rules": {
    "indent": [2, 2]
  }
}

But this give my the following error:但这给了我以下错误:

TypeError: Cannot read property 'start' of undefined

I don't understand why.我不明白为什么。


My full .eslintrc我的完整.eslintrc

{
  "root": true,
  "ignorePatterns": ["projects/**/*"],
  "plugins": ["import"],
  "rules": {
    "import/no-extraneous-dependencies": [
      2,
      { "devDependencies": ["**/*spec.ts"] }
    ],
    "quotes": [ 2, "single" ],
    "padded-blocks": "off",
    "no-plusplus": "off",
    "object-curly-spacing": [2, "always"],
    "space-in-parens": [2, "never"],
    "keyword-spacing": 2,
    "comma-spacing": 2,
    "comma-dangle": [2, {
      "arrays": "always-multiline",
      "objects": "always-multiline",
      "functions": "always-multiline"
    }],
    "key-spacing": 2,
    "space-infix-ops": 2,
    "arrow-spacing": 2
  },
  "overrides": [
    {
      "files": ["*.ts", "*.js", "*.tsx"],
      "parserOptions": {
        "project": ["tsconfig.json"],
        "createDefaultProgram": true
      },
      "plugins": [
        "promise",
        "jsdoc",
        "import"
      ],
      "extends": [
        "plugin:@angular-eslint/recommended",
        "plugin:@angular-eslint/template/process-inline-templates"
      ],
      "rules": {
        "@angular-eslint/directive-selector": [
          "error",
          {
            "type": "attribute",
            "prefix": "fbo",
            "style": "camelCase"
          }
        ],
        "@angular-eslint/component-selector": [
          "error",
          {
            "type": "element",
            "prefix": "fbo",
            "style": "kebab-case"
          }
        ],
        "indent": [2, 2],
        "max-lines-per-function": ["error", 75],
        "promise/catch-or-return": "error",
        "promise/always-return": "off",
        "promise/no-return-wrap": "error",
        "promise/param-names": "error",
        "promise/no-native": "off",
        "promise/no-nesting": "warn",
        "promise/no-promise-in-callback": "warn",
        "promise/no-callback-in-promise": "warn",
        "promise/avoid-new": "off",
        "promise/no-new-statics": "error",
        "promise/no-return-in-finally": "warn",
        "promise/valid-params": "warn",
        "no-useless-constructor": "off",
        "@typescript-eslint/no-useless-constructor": 2,
        "import/extensions": "off",
        "import/prefer-default-export": "off",
        "@typescript-eslint/no-unused-vars": 2,
        "no-console": 2,
        "@typescript-eslint/no-explicit-any": 2,
        "semi": 2,
        "linebreak-style": [2, "unix"],
        "jsdoc/newline-after-description": 0,
        "jsdoc/no-undefined-types": 0,
        "jsdoc/check-access": 2,
        "jsdoc/check-alignment": 2,
        "jsdoc/check-param-names": 2,
        "jsdoc/check-property-names": 2,
        "jsdoc/check-tag-names": 2,
        "jsdoc/check-types": 2,
        "jsdoc/check-values": 2,
        "jsdoc/empty-tags": 2,
        "jsdoc/implements-on-classes": 2,
        "jsdoc/require-jsdoc": ["error", {
          "require": {
            "FunctionDeclaration": true,
            "MethodDefinition": true,
            "ClassDeclaration": false,
            "ArrowFunctionExpression": false,
            "FunctionExpression": false
          }
        }],
        "jsdoc/require-description": 2,
        "jsdoc/require-param": 2,
        "jsdoc/require-param-description": 2,
        "jsdoc/require-param-name": 2,
        "jsdoc/require-param-type": 2,
        "jsdoc/require-property": 2,
        "jsdoc/require-property-description": 2,
        "jsdoc/require-property-name": 2,
        "jsdoc/require-property-type": 2,
        "jsdoc/require-returns": 2,
        "jsdoc/require-returns-check": 2,
        "jsdoc/require-returns-description": 2,
        "jsdoc/require-returns-type": 2,
        "jsdoc/require-yields": 2,
        "jsdoc/require-yields-check": 2,
        "jsdoc/valid-types": 2,
        "@typescript-eslint/explicit-function-return-type": 2,
        "@typescript-eslint/naming-convention": [
          "error",
          {
            "selector": "interface",
            "format": ["PascalCase"],
            "custom": {
              "regex": "^I[A-Z]",
              "match": true
            }
          },
          {
            "selector": "class",
            "format": ["PascalCase"]
          }
        ],
        "@typescript-eslint/member-ordering": 2
      }
    },
    {
      "files": [
        "*.html"
      ],
      "extends": [
        "plugin:@angular-eslint/template/recommended"
      ],
      "rules": {
        "indent": [2, 2]
      }
    }
  ]
}

If you are using prettier and eslint at the same time, the indent property of the first doesn't match with the indent property of the lattest.如果您同时使用 prettier 和 eslint,则 first 的缩进属性与 lattest 的缩进属性不匹配。 My suggestion is,if using prettier, to disable eslint's indent rule.我的建议是,如果使用 prettier,禁用 eslint 的缩进规则。

On the other hand, if you are using eslint only try to replace indent property with the follow:另一方面,如果您只使用 eslint,请尝试将缩进属性替换为以下内容:

indent: [2, 2, { SwitchCase: 1}]

Why SwitchCase?为什么选择 SwitchCase?

  • Indent of 2 spaces with SwitchCase set to 0 will not indent case clauses with respect to switch statements.将 SwitchCase 设置为 0 的 2 个空格的缩进将不会缩进与 switch 语句相关的 case 子句。
  • Indent of 2 spaces with SwitchCase set to 1 will indent case clauses with 2 spaces with respect to switch statements.将 SwitchCase 设置为 1 的 2 个空格的缩进将相对于 switch 语句缩进 2 个空格的 case 子句。
  • Indent of 2 spaces with SwitchCase set to 2 will indent case clauses with 4 spaces with respect to switch statements.将 SwitchCase 设置为 2 的 2 个空格缩进将相对于 switch 语句缩进 4 个空格的 case 子句。
  • Indent of tab with SwitchCase set to 2 will indent case clauses with 2 tabs with respect to switch statements. Indent of tab with SwitchCase set to 2 将相对于 switch 语句缩进 2 个制表符的 case 子句。

If you need some info about it: eslint docs .如果您需要一些相关信息: eslint docs

Let me know if it works.让我知道它是否有效。

Have a nice day.祝你今天过得愉快。

暂无
暂无

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

相关问题 Angular 9 + eslint:找不到规则“@angular-eslint/…”的错误定义 - Angular 9 + eslint: error Definition for rule '@angular-eslint/…' was not found @angular-eslint/no-input-rename ESLint 规则有什么意义? - What is the point of the @angular-eslint/no-input-rename ESLint rule? 将 @angular-eslint/template/eqeqeq 设置为 off 不适用于 angular 13 - Setting @angular-eslint/template/eqeqeq to off not working with angular 13 如何防止规则 `@angular-eslint/template/i18n` 掉落 `mat-icon` 元素 - How to prevent rule `@angular-eslint/template/i18n` from linting `mat-icon` elements 使用“typescript-eslint/recommended”和“@angular-eslint/recommended”扩展多个规则集可以吗? - Extending multiple rule-sets using "typescript-eslint/recommended" with "@angular-eslint/recommended" is this okay to do? 如何添加@angular-eslint/schematics? 错误 - How add @angular-eslint/schematics? Error 不支持:关键字“id”,使用“$id”作为模式 ID:TSLint(ng add @angular-eslint/schematics) - NOT SUPPORTED: keyword "id", use "$id" for schema ID : TSLint (ng add @angular-eslint/schematics) 如何运行@angular-eslint/schematics:convert-tslint-to-eslint - How to run @angular-eslint/schematics:convert-tslint-to-eslint angular-eslint 和 typescript-eslint 之间的区别 - Difference between angular-eslint and typescript-eslint 如何为 protractor 项目设置 angular-eslint? - How do I need to setup angular-eslint for a protractor project?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM