簡體   English   中英

如何在沒有節點的情況下獲取自定義eslint規則來執行context.report?

[英]How can I get a custom eslint rule to do context.report without having a node?

我想要一個非常簡單的eslint規則,以確保每個文件的頂部都顯示“ ouch”。 像這樣的事情似乎可行-但如何在沒有節點的情況下進行上下文報告? 或如何獲取要使用的文件第一行的節點? 我是否應該使用在'return'中的事件上聲明的回調(如果是,則是哪個事件)? 謝謝!

'use strict';
function checkFirstLine (context) {
    if (context.getSourceCode().lines[0] !== 'ouch') {
        // How do I context.report without a node?
    }
}

module.exports = {
    meta : {
        docs : {
            description : 'check first line',
            category : 'Possible Errors',
            recommended : true
        },
    },
    create : function (context) {
        checkFirstLine (context);
        return {};
    }
};

剛弄清楚,我可以使用:

context.report(context.getSourceCode().ast, 'Cripes');

暫無
暫無

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

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