# Travis 测试因 eslint 而失败

**URL:** https://meta.discourse.org/t/travis-tests-failing-due-to-eslint/163268
**Category:** Development
**Created:** [2020年九月7日 15:27 UTC](https://meta.discourse.org/t/travis-tests-failing-due-to-eslint/163268 "2020-09-07T15:27:41Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [2020年九月7日 15:27 UTC](https://meta.discourse.org/t/travis-tests-failing-due-to-eslint/163268/1 "2020-09-07T15:27:41Z")

</div>

我有两个插件在 Travis 测试中失败了。看起来它们里面没有任何 ES6 文件，所以 ESLint 觉得被冷落了吗？

```plaintext
运行 linters/prettyfiers
eslint yarn run v1.22.5
$ /var/www/discourse/node_modules/.bin/eslint -v
v6.8.0
Done in 0.32s.
prettier yarn run v1.22.5
$ /var/www/discourse/node_modules/.bin/prettier -v
2.1.1
Done in 0.28s.
[2020-09-07 01:34:21] bundle exec rubocop --parallel plugins/discourse-allow-pm-to-staff
检查 2 个文件
..
已检查 2 个文件，未发现违规
[2020-09-07 01:34:22] bundle exec ruby script/i18n_lint.rb plugins/discourse-allow-pm-to-staff/config/locales/{client,server}.en.yml
[2020-09-07 01:34:23] yarn eslint --global I18n --ext .es6 plugins/discourse-allow-pm-to-staff
yarn run v1.22.5
$ /var/www/discourse/node_modules/.bin/eslint --global I18n --ext .es6 plugins/discourse-allow-pm-to-staff
哎呀！出错了！: (
ESLint: 6.8.0.
未找到匹配模式 "plugins/discourse-allow-pm-to-staff" 的文件。
请检查模式中是否有拼写错误。
错误：命令执行失败，退出代码为 2。
有关此命令的文档，请访问 https://yarnpkg.com/en/docs/cli/run
列出 discourse-allow-pm-to-staff 中的 prettier 违规：

```

> **[Travis CI](https://app.travis-ci.com/github/pfaffman/discourse-allow-pm-to-staff/jobs/724771255)**
>
> Travis CI enables your team to test and ship your apps with confidence. Easily sync your projects with Travis CI and you'll be testing your code in minutes.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [2020年九月10日 16:39 UTC](https://meta.discourse.org/t/travis-tests-failing-due-to-eslint/163268/2 "2020-09-10T16:39:56Z")

</div>

是的，`eslint` 不喜欢无所事事。这样做让它感觉更有用。

```plaintext
mkdir -p assets/javascripts/discourse
touch assets/javascripts/discourse/eslint.js.es6
git add assets/javascripts/discourse/eslint.js.es6
git commit -m 'try to make eslint not feel left out'
git push

```

不过，我认为这才是真正的解决方案：

[https://github.com/discourse/discourse/compare/master...pfaffman:patch-5](https://github.com/discourse/discourse/compare/master...pfaffman:patch-5)

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [2020年九月10日 16:43 UTC](https://meta.discourse.org/t/travis-tests-failing-due-to-eslint/163268/3 "2020-09-10T16:43:40Z")

</div>

啊，但你怎么能在 eslint 不报错的情况下提交 PR 呢？ 😉

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [2020年九月10日 16:45 UTC](https://meta.discourse.org/t/travis-tests-failing-due-to-eslint/163268/4 "2020-09-10T16:45:28Z")

</div>

我对这里发生的事几乎一窍不通，差点没听懂你的笑话！

---

<div class="post-metadata">

### Author: ![j.jaffeux](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/j.jaffeux/32/60297_2.png) [@j.jaffeux](https://meta.discourse.org/u/j.jaffeux)
#### Post date: [2020年九月10日 18:04 UTC](https://meta.discourse.org/t/travis-tests-failing-due-to-eslint/163268/5 "2020-09-10T18:04:37Z")

</div>

是的，我前几天已经为 GitHub Actions 推送了这个修复：

> <https://github.com/discourse/discourse/commit/110f6ec6dd16b154ad796a7de124148321240e40>

基本上，新的 eslint 在匹配不到任何内容时不再喜欢这样。我也借此机会简化了命令，同样会应用到我们的 rake 任务中，不用担心。

---

<div class="post-metadata">

### Author: ![j.jaffeux](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/j.jaffeux/32/60297_2.png) [@j.jaffeux](https://meta.discourse.org/u/j.jaffeux)
#### Post date: [2020年九月10日 18:18 UTC](https://meta.discourse.org/t/travis-tests-failing-due-to-eslint/163268/6 "2020-09-10T18:18:14Z")

</div>

这应该能解决问题：

> <https://github.com/discourse/discourse/commit/a60ba75ac29f748774a495dd60beb28291a2bcb9>
>
> The recent upgrade of eslint fails if no files is found for the defined patterns….

请告诉我结果如何 👍

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [2020年九月10日 18:45 UTC](https://meta.discourse.org/t/travis-tests-failing-due-to-eslint/163268/7 "2020-09-10T18:45:03Z")

</div>

> **[Travis CI](https://app.travis-ci.com/github/pfaffman/discourse-topic-default-tag)**
>
> Travis CI enables your team to test and ship your apps with confidence. Easily sync your projects with Travis CI and you'll be testing your code in minutes.

```plaintext
2 files inspected, no offenses detected
[2020-09-10 18:43:13] bundle exec ruby script/i18n_lint.rb plugins/discourse-topic-default-tag/config/locales/{client,server}.en.yml
[2020-09-10 18:43:13] yarn eslint --global I18n --ext .es6 plugins/discourse-topic-default-tag
yarn run v1.22.5
$ /var/www/discourse/node_modules/.bin/eslint --global I18n --ext .es6 plugins/discourse-topic-default-tag
Oops! Something went wrong! :(
ESLint: 6.8.0.
No files matching the pattern "plugins/discourse-topic-default-tag" were found.
Please check for typing mistakes in the pattern.
error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Listing prettier offenses in discourse-topic-default-tag:

```

> [@j.jaffeux](#):
>
> 我的提交尚未进入 tests-passed

哎呀，是我的错。

---

<div class="post-metadata">

### Author: ![j.jaffeux](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/j.jaffeux/32/60297_2.png) [@j.jaffeux](https://meta.discourse.org/u/j.jaffeux)
#### Post date: [2020年九月10日 19:11 UTC](https://meta.discourse.org/t/travis-tests-failing-due-to-eslint/163268/8 "2020-09-10T19:11:27Z")

</div>

哦对，它确实使用了 discourse-plugin-ci 相关组件，如果你查看代码就会看到：

> <https://github.com/discourse/discourse-plugin-ci/blob/master/script.sh#L17>

而我的提交尚未出现在 tests-passed 中

---

<div class="post-metadata">

### Author: ![j.jaffeux](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/j.jaffeux/32/60297_2.png) [@j.jaffeux](https://meta.discourse.org/u/j.jaffeux)
#### Post date: [2020年九月12日 19:19 UTC](https://meta.discourse.org/t/travis-tests-failing-due-to-eslint/163268/9 "2020-09-12T19:19:52Z")

</div>

此主题在最后一次回复后 2 天自动关闭。不再允许新回复。
