ESLint 不会破坏 Github 操作的构建

ESLint doesn't break build with Github Actions

我正在使用 Github Actions for the first time. I'm using Vue-CLI & 我想创建一个作业,在 push 上检查我的文件 & 如果有 ESLint'errors.

这是我的 package.json 的脚本:

"scripts": {
  "serve": "vue-cli-service serve",
  "build": "vue-cli-service build",
  "lint": "vue-cli-service lint",
},

这是我的 .github/workflows/main.yml 文件:

name: Lint files on push

on: push

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Install modules
        run: npm install
      - name: Run ESLint
        run: npm run lint

我使用 this template 作为灵感。正如您在下面的屏幕截图中看到的那样。作业已成功完成,但不会破坏构建或修复 linting。我做错了什么?

您可以指定 --no-fix 这样它就不会自动修复 errors/warnings 并将 --max-warnings 设置为 0 因为您的项目中似乎有一个警告并且想要它被视为错误。

在你的package.json中:

{
  ....
  "scripts": {
    "lint": "vue-cli-service lint --no-fix --max-warnings 0",
    ....
  }
}

checkout documentation

日志输出:

warning: Delete `⏎········` (prettier/prettier) at src/components/QuestionInfo.vue:5:25:
  3 |     <div class="question_card container">
  4 |       <BaseTag
> 5 |         :class="['tag', 
    |                         ^
  6 |         'p-5', 'pb-0', 'pl-0', 'ml-5']"
  7 |         :tag-name="this.tag"
  8 |       />


1 warning found.
1 warning potentially fixable with the `--fix` option.
Eslint found too many warnings (maximum: 0).

我想通了。我正在整理文件,但由于我没有提交和推送新更改,所以我看不到我的 PR 中的更改。

我重构了我的 Github Action's workflow 以检查文件并将它们推送到存储库。

name: Lint files on push

on: push

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Installing node_modules
        run: npm install
      - name: Running ESLint
        run: npm run lint
      - name: Setting Github user.email
        run: git config --global user.email "<github-email-goes-here>"
      - name: Setting Github user.name
        run: git config --global user.name "<github-name-goes-here>"
      - name: Adding fixes for committing
        run: git add .
      - name: Committing ESLint fixes
        run: git commit -m "fixed ESLint issues"
      - name: Pushing fixes to current PR branch
        run: git push

您可以通过在终端中分别输入 git config --global user.emailgit config --global user.name 来获取 user.emailuser.name