如何在ESLint中禁止显示“没有匹配模式的文件”消息?

时间:2019-02-05 21:08:22

标签: continuous-integration eslint

在我的CI设置中,我有一个针对所有JS文件运行eslint的测试。如果不存在JS文件,则当前抛出错误。如果没有JS文件,我希望它能成功。这可能吗?

$ eslint "./src/assets/scripts/**/*.js"

Oops! Something went wrong! :(

ESLint: 5.7.0.
No files matching the pattern "./src/assets/scripts/**/*.js" were found.
Please check for typing mistakes in the pattern.

ERROR: Job failed: exit code 1

3 个答案:

答案 0 :(得分:18)

Node root = getNode(); String revisionID = getVersionName(); System.out.println("Commit ID is "+revisionID); Repository repository = git.getRepository(); RevWalk walk = new RevWalk(repository); walk.reset(); ObjectId id = repository.resolve(revisionID); RevCommit commit = walk.parseCommit(id); System.out.println("Found Commit again: " + commit); walk.dispose(); String fileName = root.getIdentifier() + ".yaml"; TreeWalk treeWalk = TreeWalk.forPath( repository, fileName, commit.getTree() ); InputStream yamlFile = repository.open( treeWalk.getObjectId( 0 ), Constants.OBJ_BLOB ).openStream(); // use the inputStream treeWalk.close(); 标志已添加到ESLint的--no-error-on-unmatched-pattern中。

https://eslint.org/docs/user-guide/command-line-interface#no-error-on-unmatched-pattern

答案 1 :(得分:12)

对我有用的是changing single quotes to escaped double quotes

所以来自:

"lint": "eslint '**/*.{ts,tsx}'"

致:

"lint": "eslint \"**/*.{ts,tsx}\""

原因是因为它取决于您使用的控制台 - 可能是操作系统(这就是为什么它可以为您工作而对其他人不起作用,反之亦然)来源:https://dev.to/gruckion/comment/b65c

答案 2 :(得分:1)

能够挖掘this closed issue on ESLint's GitHub。听起来这是一个普遍的问题,并且没有一个好的解决方法,除了按照@ user2864740的建议在尝试进行清理之前手动检查文件是否存在