簡體   English   中英

如何設置ESLint規則以識別功能是否為駝峰式?

[英]How to set ESLint rule to identify functions are either camelcase or not?

如果我檢查ESLint文檔,那么有一個完美的插件可用於駝峰式案例屬性 ,而同一件事我正在嘗試識別是否為駝峰式案例的函數。

index.js

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

.eslintrc

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

如果我運行eslint index.js ,我將得到一個像這樣的正確的皮棉錯誤

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

✖ 1 problem (1 error, 0 warnings)

同樣,我也想為功能實現這一點。 在這里, getfirstname不在正確的getfirstname中。 我需要得到一個皮棉錯誤,所以我將規則更改為

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

如果我設置了上述值,則不會出錯。 我應該怎么做才能使用eslint模塊對功能進行驗證? 請提出另一種方法來識別這種棉絨。

在上面的問題中,類似地,我也希望此功能也能實現,在此getfirstname不適用於此情況,因此我需要獲取lint錯誤

您將無法自動檢測到諸如getfirstname的不正確的駝峰式情況。 短絨棉絨靴可以肯定的是,如果看到下划線,這不是駱駝的情況,但是在這里看起來就像一個單詞,知道不是這樣的話並不是很聰明。

如果這樣做的話,它將不得不拒絕XMLHttpRequestsetTimeoutfs.realpath類的東西。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM