简体   繁体   English

如何为 protractor 项目设置 angular-eslint?

[英]How do I need to setup angular-eslint for a protractor project?

I'm currently migrating to eslint with angular-eslint with since TSLint is deprecated.我目前正在使用angular-eslint迁移到 eslint,因为 TSLint 已被弃用。 In the documentation for it I see no mention of protractor.在它的文档中,我没有看到 protractor 的提及。 Is it possible to use the default.eslintrc.json config for protractor or do I need to migrate it too with是否可以为 protractor 使用 default.eslintrc.json 配置,还是我也需要迁移它

ng g @angular-eslint/schematics:convert-tslint-to-eslint project-name-e2e ng g @angular-eslint/schematics:convert-tslint-to-eslint project-name-e2e

Current configuration: angular.json (replaced actual project name with "project-name" and "project-name-e2e")当前配置:angular.json(将实际项目名称替换为“项目名称”和“项目名称-e2e”)

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "project-name": {
      "root": "",
      "sourceRoot": "src",
      "projectType": "application",
      "prefix": "app",
      "schematics": {
        "@schematics/angular:component": {
          "style": "scss"
        }
      },
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "aot": true,
            "outputPath": "dist/...",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "src/tsconfig.app.json",
            "assets": [
              "src/favicon.ico",
              "src/assets",
              "src/Staticfile"
            ],
            "styles": [
              ...
            ],
            "stylePreprocessorOptions": {
              "includePaths": [
                "src/assets/scss"
              ]
            },
            "scripts": []
          },
          "configurations": {
            "production": {
              "budgets": [
                {
                  "type": "anyComponentStyle",
                  "maximumWarning": "6kb"
                }
              ],
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ],
              "optimization": {
                "fonts": false
              },
              "outputHashing": "all",
              "sourceMap": false,
              "namedChunks": false,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true
            },
            "es5": {
              "tsConfig": "src/tsconfig-es5.app.json"
            }
          }
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "project-name:build"
          },
          "configurations": {
            "production": {
              "browserTarget": "project-name:build:production"
            },
            "es5": {
              "browserTarget": "project-name:build:es5"
            }
          }
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "project-name:build"
          }
        },
        "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "main": "src/test.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "src/$.spec.json",
            "karmaConfig": "src/karma.conf.js",
            "styles": [
              ...
            ],
            "scripts": [],
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ]
          }
        },
        "lint": {
          "builder": "@angular-eslint/builder:lint",
          "options": {
            "lintFilePatterns": [
              "src/**/*.ts",
              "src/**/*.html"
            ]
          }
        }
      }
    },
    "project-name-e2e": {
      "root": "e2e/",
      "projectType": "application",
      "architect": {
        "e2e": {
          "builder": "@angular-devkit/build-angular:protractor",
          "options": {
            "protractorConfig": "e2e/protractor.conf.js"
          },
          "configurations": {
            "production": {
              "devServerTarget": "..."
            },
            "dev": {
              "protractorConfig": "e2e/..."
            },
            "devbsi": {
              "protractorConfig": "e2e/..."
            },
            "test": {
              "protractorConfig": "e2e/..."
            },
            "sit": {
              "protractorConfig": "e2e/..."
            }
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": "e2e/tsconfig.e2e.json",
            "exclude": [
              "**/node_modules/**"
            ]
          }
        }
      }
    }
  },
  "defaultProject": "project-name"
}

.eslintrc.json .eslintrc.json

{
  "root": true,
  "ignorePatterns": [
    "projects/**/*"
  ],
  "overrides": [
    {
      "files": [
        "*.ts"
      ],
      "parserOptions": {
        "project": [
          "tsconfig.json",
          "e2e/tsconfig.json"
        ],
        "createDefaultProgram": true
      },
      "extends": [
        "plugin:@angular-eslint/ng-cli-compat",
        "plugin:@angular-eslint/ng-cli-compat--formatting-add-on",
        "plugin:@angular-eslint/template/process-inline-templates"
      ],
      "rules": {
        "@typescript-eslint/consistent-type-definitions": "error",
        "@typescript-eslint/dot-notation": "off",
        "@typescript-eslint/explicit-member-accessibility": [
          "off",
          {
            "accessibility": "explicit"
          }
        ],
        "brace-style": [
          "error",
          "1tbs"
        ],
        "id-blacklist": "off",
        "id-match": "off",
        "max-len": [
          "error",
          {
            "code": 160
          }
        ],
        "no-underscore-dangle": "off"
      }
    },
    {
      "files": [
        "*.html"
      ],
      "extends": [
        "plugin:@angular-eslint/template/recommended"
      ],
      "rules": {}
    }
  ]
}

We also struggled with this a little bit.我们也为此苦苦挣扎。 After following along the migration guide VS Code was complaining inside protractor.conf.js遵循迁移指南后,VS Code 在 protractor.conf.js 中抱怨

Parsing error: The keyword 'const' is reserved

We fixed this message by adding the env configuration to.eslintrc.json in the angular project我们通过将 env 配置添加到 angular 项目中的 .eslintrc.json 来修复此消息

{
  ...
  "env": {
    "browser": true,
    "node": true,
    "es6": true 
  },
  ...
}

From here everything still seems to work as expected.从这里开始,一切似乎仍然按预期工作。

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

相关问题 How do I install the right version of @angular-eslint/schematic to match my angular-compiler? - How do I install the right version of @angular-eslint/schematic to match my angular-compiler? 如何添加@angular-eslint/schematics? 错误 - How add @angular-eslint/schematics? Error 如何运行@angular-eslint/schematics:convert-tslint-to-eslint - How to run @angular-eslint/schematics:convert-tslint-to-eslint 使用“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/template/i18n` 掉落 `mat-icon` 元素 - How to prevent rule `@angular-eslint/template/i18n` from linting `mat-icon` elements 在@angular-eslint/template 中使用缩进规则 - use of indent rule in @angular-eslint/template 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 和 typescript-eslint 之间的区别 - Difference between angular-eslint and typescript-eslint 将 @angular-eslint/template/eqeqeq 设置为 off 不适用于 angular 13 - Setting @angular-eslint/template/eqeqeq to off not working with angular 13
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM