javascript - package.json 和 Eslint glob 扩展

标签 javascript eslint glob package.json

我的 package.json 在下面。如何更新它以便 eslint 运行:

测试目录

为了

.js .jsx 只有文件?现在 * 通配符包括我不想要的 .json 。

包.json

{
...

"lint": "eslint {src/**/*.js*,test/**/*.js*}

...
}

最佳答案

您可以阅读 eslint documentation :

Please note that when passing a glob as a parameter, it will be expanded by your shell. The results of the expansion can vary depending on your shell, and its configuration. If you want to use node glob syntax, you have to quote your parameter (using double quotes if you need it to run in Windows), as follows:



所以建议使用双引号。一旦您使用双引号(需要在 json 字符串中转义),您可以稍微修改您的模式,例如
{
...

"lint": "eslint \"{src,test}/**/*.{js,jsx}\""

...
}

使用 globster.xyz 进行测试(globster.xyz 一开始需要 / 但 eslint 不需要,不知道为什么......)

通常有不止一种方法可以实现你想要的,但我认为这将是最简洁的。

关于javascript - package.json 和 Eslint glob 扩展,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55070172/

相关文章:

用于带有规则文件的 Gulp 的 PHP Linter?

next.js - 为什么从 CRA 迁移到 Next.js 后 eslint 不起作用?

python - 否定 fnmatch 模式

javascript - jquery重复节点匹配和删除

javascript - JQuery:在追加时得到一个 child

vue.js - ES6 意外的字符串连接

java - sonar-project.properties 中的 Glob

arrays - 为什么 Dir.glob ("*.txt").sort 也需要 .each?

javascript - 如何在 Firefox 插件中覆盖 preventDefault/stopPropagation

javascript - 如何在CasperJS中获取href属性值?