ESLint no-undef - 与BigCommerce的js问题

Cir*_*e B 0 javascript bigcommerce eslint

我在.js文件中有这个代码,我正在通过ESLint运行.但它在这一行上引发了一个错误:iFrameResize({.

说:error 'iFrameResize' is not defined no-undef.

如果我这样定义: const iFrameResize()

我的代码不再有效,如何让ESLint高兴并保持代码正常工作?

export default class Page extends PageManager {

before(next) {
    next();
}

loaded(next) {
    next();
}

after(next) {
    const url = Url.parse(location.href, true);
    const IC_PAGE = '/international-checkout';
    const currentPageUrl = url.pathname;
    if (currentPageUrl.indexOf(IC_PAGE) !== -1 && $('#icForm').length === 1) {
        $(document).ready(() => {
            if ($('#icForm').length === 1) {
                if ($('.GiftStatus') && $('.GiftStatus').val() === '1') {
                    alert('Gift Certificate is not available for international orders. Please remove Gift Certificate from shopping cart before proceeding with International Checkout.');
                    window.parent.location.href = '/cart.php';
                    return false;
                }
                $('.icformfields').each((i, e) => {
                    const currentId = $(e).attr('id');
                    const res = currentId.split('-');
                    const finalId = Number(res[1]) + 1;
                    const finalName = $(e).attr('name') + finalId;
                    $(e.currentTarget).attr('name', finalName);
                });
                document.getElementById('icIframe').src = 'https://www.internationalcheckout.com/cart.php';
                document.getElementById('icForm').submit();
                $('#icIframe').load(() => {
                    $('#icForm').remove();
                    $('#loading').css('display', 'none');
                    $('html, body').animate({
                        scrollTop: $('#icIframe').offset().top,
                    }, 1000);
                    $('#icIframe').fadeIn();
                });
            }
        });
        iFrameResize({
            checkOrigin: false,
            enablePublicMethods: true,
        });
    }
    next();
}

}
Run Code Online (Sandbox Code Playgroud)

我想知道如何在不禁用特定行的错误报告的情况下满足ESLint.

Dan*_*ore 5

同样值得注意的是,eslint提供了多种方法.请参阅eslint文档.

我建议将以下内容添加到文件的顶部.使用此方法定义仅在几个位置使用的全局依赖项:

/* global iFrameResize */
Run Code Online (Sandbox Code Playgroud)

您还可以提供一个数组:

/* global iFrameResize, iFrameManage, etc */
Run Code Online (Sandbox Code Playgroud)

如果您经常使用iFrameResize,或者如果您依赖于jQuery之类的东西,请考虑将其定义为.eslintrc文件中的全局.

"globals": {
    "iFrameManage": true,
}
Run Code Online (Sandbox Code Playgroud)