什么会导致 eslint-plugin-prettier 在 CircleCI 上报错,但在本地却保持沉默?

What could cause eslint-plugin-prettier to report error on CircleCI but be silent locally?

我必须从 CircleCI 1.0 迁移到 2.0。在我将旧配置更改为新配置后,构建失败,因为 eslint-plugin-prettier 报告了更漂亮的间距违规。

MyProject - 是我的 GitHub 存储库,它包含一个文件夹 client,其中包含我要在 CI 上构建的所有前端代码。在 client 文件夹中有

.eslintrc.json

...
"extends": ["airbnb", "prettier"],
"plugins": ["prettier"],
...

.prettierrc

{
    "tabWidth": 4,
    "trailingComma": "all",
    "singleQuote": true
}

.gitattributes(我在 Windows 10 上工作)使用以下代码:

*.js text eol=crlf
*.jsx text eol=crlf

当然还有package.json

新圈子CI配置:

version: 2

jobs:
  build:
    working_directory: ~/MyProject
    docker:
      - image: circleci/node:6.14.3-jessie-browsers
    steps:
      - checkout
      - run:
          name: Install Packages
          command: npm install
          working_directory: client
      - run:
          name: Test
          command: npm run validate
          working_directory: client

老圈CI配置:

## Customize dependencies
machine:
  node:
    version: 6.1.0

 # Remove cache before new build. It takes much time
 # but fixing a build which is broken long time ago (and not detected because of cache)  
 # is even more time consuming
dependencies:
  post:
   - rm -r ~/.npm 

## Customize test commands
test:
  override:
    - npm run validate

general:
  build_dir: client

由于linting问题构建失败(都是关于空格数):

那么,是什么导致了这些错误?我在这里没有想法。我一开始以为可能是因为没有找到.prettierrc。但是,当我为实验删除它并在本地 运行 时,我在所有文件中得到的错误总数超过 1000 个。而在 CI 上使用 .prettierrc 时,少数文件中只有 188 个。

终于想通了

我的 package.json 文件包含以下对 Prettier 的依赖: "prettier": "^1.11.1"

我不得不努力学习这个小符号的含义 ^。它允许安装与 1.11.1 兼容的任何版本的 Prettier。在我的 CircleCI 2.0 案例中,它安装了 1.14.2,它为 Prettier 添加了新功能。

我相信它在 CircleCI 1.0 版和本地没有中断,因为缓存 node_modules 包含与 1.11.1

兼容的早期 Prettier 版本

关于语义版本控制,video 很不错。