DEV Community

Cui Mingda
Cui Mingda

Posted on

How to know which rules of ESLint are actived?

ESLint有一个--print-config参数,设置以后不执行校验,只是会显示应用到对应文件的所有设置,当然这其中包含规则列表,比如:

yarn eslint --print-config src/App.jsx
Enter fullscreen mode Exit fullscreen mode

考虑到上面的输出结果就是个json,我们用jq提取一下规则列表:

yarn eslint --print-config src/App.jsx | jq '.rules'
Enter fullscreen mode Exit fullscreen mode

直接报错:parse error: Invalid numeric literal at line 1, column 5,原来执行yarn run,是有一些日志输出的,不属于json的一部分,我们需要将不需要的日志输出去掉:

yarn --silent eslint --print-config src/App.jsx | jq '.rules'
Enter fullscreen mode Exit fullscreen mode

下一步,我们把规则的key提取出来,这样就能得到一个针对jsx文件的规则列表了。

yarn --silent eslint --print-config src/App.jsx | jq '.rules' | jq 'keys[]'
Enter fullscreen mode Exit fullscreen mode

References

Top comments (1)

Collapse
 
chloeperez5 profile image
ChloePerez5

ESLint is completely pluggable, and the right point is put into your post!! I found informative information in your post!!! best tantrik in Jalandhar

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

Rather than just generating snippets, our agents understand your entire project context, can make decisions, use tools, and carry out tasks autonomously.

Read full post