admin管理员组

文章数量:1188233

I am using slick.js jquery plugin inside requireJS. Thus in order to make the plugin available I have to require it, which is introducing an

'slick' is defined but never used no-unused-vars

error from eslint. Here is the code

define(['jquery', 'slick'], function($, slick) {
    'use strict';

    $.widget("mage.promobanner", {
        _addSlider: function(self) {
            setTimeout(function(){
                $(self.element).slick(self.options);
            }, 2000);
        }
    });
    return $.mage.promobanner;
});

I have tried creating an exception for this variable per the varsIgnorePattern documentation

/*eslint no-unused-vars: ["error", { "varsIgnorePattern": "slick" }]*/

however the error persists. Is there something wrong with the ignore pattern I have created? Seems like a no-brainer regex: exact match!

I am using slick.js jquery plugin inside requireJS. Thus in order to make the plugin available I have to require it, which is introducing an

'slick' is defined but never used no-unused-vars

error from eslint. Here is the code

define(['jquery', 'slick'], function($, slick) {
    'use strict';

    $.widget("mage.promobanner", {
        _addSlider: function(self) {
            setTimeout(function(){
                $(self.element).slick(self.options);
            }, 2000);
        }
    });
    return $.mage.promobanner;
});

I have tried creating an exception for this variable per the varsIgnorePattern documentation

/*eslint no-unused-vars: ["error", { "varsIgnorePattern": "slick" }]*/

however the error persists. Is there something wrong with the ignore pattern I have created? Seems like a no-brainer regex: exact match!

Share Improve this question asked Jul 16, 2020 at 15:24 quickshiftinquickshiftin 69.6k11 gold badges71 silver badges97 bronze badges 0
Add a comment  | 

1 Answer 1

Reset to default 32

The correct exception uses argsIgnorePattern, not varsIgnorePattern.

varsIgnorePattern

The varsIgnorePattern option specifies exceptions not to check for usage: variables whose names match a regexp pattern.

argsIgnorePattern

The argsIgnorePattern option specifies exceptions not to check for usage: arguments whose names match a regexp pattern.

So use:

/* eslint no-unused-vars: [ "error", { "argsIgnorePattern": "slick" } ] */

本文标签: javascripteslint nounusedvars varIgnorePattern not workingStack Overflow