如何设置ESLint规则以识别功能是否为驼峰式? [英] How to set ESLint rule to identify functions are either camelcase or not?

查看:1491
本文介绍了如何设置ESLint规则以识别功能是否为驼峰式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我检查ESLint文档,则有一个完美的插件可用于骆驼盒属性,而无论是否为驼峰,我都试图识别它们.

If I check for ESLint docs there is a perfect plugin available for camel case properties, whereas the same thing I'm trying to identify functions if they are either camelcase or not.

index.js

var first_name;
var lastName;
function getFirstName(a,b){
    return firstName;
}

.eslintrc

module.exports = {
    "rules": {
         "camelcase": [2, {"properties": "always"}] 
    }
}

如果我运行 eslint index.js ,我将收到类似这样的正确的皮棉错误

if I ran eslint index.js, I will be getting a proper lint error like this

  2:5  error  Identifier 'first_name' is not in camel case  camelcase

✖ 1 problem (1 error, 0 warnings)

类似地,我也想为功能实现这一点.在这里,getfirstname不在正确的驼峰格式中.我需要得到一个皮棉错误,所以我将规则更改为

Similarly, I want to achieve this for functions too. Here, getfirstname is not in proper camelcase. I need to get a lint error, so I have changed the rule to

 module.exports = {
        "rules": {
             **"camelcase": [2, {"functions": "always"}]**  
        }
    }

如果我设置了上述值,则不会收到错误消息.我应该怎么做才能使用eslint模块对功能进行验证?请提出另一种方法来识别这种棉絮.

if I set the above, I'm not getting the error. what should I do to validate linting for functions using the eslint module? please suggest another way to identify this linting.

推荐答案

在上面的问题中,我也希望此功能也能实现,在这里getfirstname不适用于此情况,因此我需要获取lint错误

In the above problem similarly i want this to achieve for functions too,here getfirstname is not proper camel case for this i need to get lint error

您将无法自动检测到getfirstname之类的不合适的骆驼情况.短绒猫可以肯定的是,如果看到下划线,这不是骆驼的情况,但在这里看起来就像一个单词,知道不是这样的话就不那么聪明了.

You will not be able to detect automatically things like getfirstname that is not a proper camel case. The linter can be sure that it's not camel case if it sees an underscore but here it just looks like one word and it's not that intelligent to know that it isn't.

如果这样做,则必须拒绝XMLHttpRequestsetTimeoutfs.realpath之类的东西.

If it did then it would have to reject things like XMLHttpRequest, setTimeout and fs.realpath.

这篇关于如何设置ESLint规则以识别功能是否为驼峰式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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