从子目录运行eslint [英] Running eslint from subdirectory

查看:133
本文介绍了从子目录运行eslint的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目包含一个子项目,该子项目具有自己的 .eslintrc (即在 ./path/to/subproject 下)
我正在尝试运行 lint ,但是它要么转到根项目 .eslintrc 文件,要么找不到 .eslintrc 文件
我在 package.json 中尝试了以下配置:

My project contains a subproject with its own .eslintrc (i.e. under ./path/to/subproject)
I'm trying to run lint but it either goes to the root project .eslintrc file or it can't find the .eslintrc file
I've tried the following configurations in package.json:

cd path/to/subproject

和:

"lint": "tsc && eslint -c .eslintrc.js ./**/*.ts --"

"lint": "tsc && eslint -c ./.eslintrc.js ./**/*.ts --"

也在root目录中尝试过

Also tried in root dir:

"lint": "tsc && eslint -c path/to/subproject/.eslintrc.js ./**/*.ts --"

"lint": "tsc && eslint -c .eslintrc.js ./**/*.ts --"

使用

npm run lint --prefix path/to/subproject/

但是它一直引用根项目 .eslintrc 文件:

But it keeps referring the root project .eslintrc file:

Oops! Something went wrong! :(

ESLint: 6.4.0.

ESLint couldn't find the config "configname" to extend from. Please check that the name of the config is correct.

The config "configname" was referenced from the config file in "/home/vsts/work/1/s/.eslintrc.js". <-- this is the wrong .eslintrc

环境是具有Ubuntu 16.04的Azure DevOps管道

The environment is Azure DevOps pipeline with Ubuntu 16.04

推荐答案

所以 eslint 似乎支持此
我要做的是将"root":true 添加到我的eslint配置文件中,现在看起来像这样:

So it looks like eslint supports this
What I had to do is add "root": true to my eslint config file, it now looks something like this:

module.exports = {
    "extends": [
        "configname"
    ],
    "root": true
}

请参见文档此处

这篇关于从子目录运行eslint的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆