jshint grunt导出选项 [英] jshint grunt exported options

查看:148
本文介绍了jshint grunt导出选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图达到以下目的。我使用grunt进行jshint验证。



我用过的文件中的某处:

  var logger = function(){
// some ode
}

由于记录器从未实际使用,因此jshint正确地向我显示了以下错误。

  W098:定义了'记录器'但从未使用过。 

我可以将unused设置为false,并且它可以很好地工作。但我实际上希望在其他文件中进行选择并警告我关于未使用的变量。所以未使用的选项是不会为我工作的。



我也看到我可以使用这样的内联注释:
* export EXPORTED_LIB * /

p>

但我实际上更愿意避免使用这些评论来混淆我的文件。是否有机会我可以在我的grunt文件中指定导出的选项,例如我可以为全局变量。



继承我的grunt文件的jshint部分:

  jshint:{
//全局选项
选项:{
camelcase:true,
卷曲:true,
eqeqeq:true,
forin:true,
immed:true,
indent:4,
latedef:true,
newcap:true ,
noarg:true,
nonew:true,
plusplus:false,
quotmark:'single',
undef:true,
unused:true ,
strict:true,
maxparams:4,
maxdepth:4,
尾随:true,
maxlen:120,
浏览器:true,
node:true
},
server_logger:{
src:[BASE_PATH_SERVER_L OGGER,'/ ** / *。js']。join(''),
options:{
browser:false
}
},
client_logger: {
src:[BASE_PATH_CLIENT_LOGGER,'/ ** / *。js']。join(''),
options:{
node:false,
devel:true
}

}
}

感谢您的时间。



问候语
Playerwtf



更新:关于jshint github存储库的一个问题此处

解决方案

这是最近修复过的问题,现在正如我所期望的那样工作。 github-issue



作为一个例子,我在我的例子中使用它gruntfile

  client_logger:{
展开:true,
cwd:BASE_PATH_CLIENT_LOGGER,
src:'** / *。js',
选项:{
节点:false,
devel:true,
globals:{
logger:true,
expect:true,
it:true,
describe: true,
beforeEach:true,
afterEach:true
},
导出:['logger']
}
}

但npm模块尚未更新。如果你想让它工作,你必须从jshint github仓库手动复制最新版本,并替换当前模块中的最新版本,或者等到更新。


Hi I'm trying to achieve the following. I'm using grunt for jshint validating.

Somewhere in a file I have used:

var logger = function () {
 // some ode
}

Because logger is never actually used jshint correctly shows me the following error.

W098: 'logger' is defined but never used.

I could set unused to false and it would work perfectly. But I actually want the option to take place in other files and warn me about unused variables. So the unused option is not gonna work for me.

I also saw that I could use a inline comment like this: * exported EXPORTED_LIB */

But I would actually prefer to avoid cluttering my files with such comments. Is there any chance I can specify an exported options in my grunt file like I can for example for globals.

Heres the jshint part of my gruntfile:

jshint: {
        // global options
        options: {
            camelcase: true,
            curly: true,
            eqeqeq: true,
            forin: true,
            immed: true,
            indent: 4,
            latedef: true,
            newcap: true,
            noarg: true,
            nonew: true,
            plusplus: false,
            quotmark: 'single',
            undef: true,
            unused: true,
            strict: true,
            maxparams: 4,
            maxdepth: 4,
            trailing: true,
            maxlen: 120,
            browser: true,
            node: true
        },
        server_logger: {
            src: [BASE_PATH_SERVER_LOGGER, '/**/*.js'].join(''),
            options: {
                browser: false
            }
        },
        client_logger: {
            src: [BASE_PATH_CLIENT_LOGGER, '/**/*.js'].join(''),
            options: {
                node: false,
                devel: true
            }

        }
    }

Thanks for your time.

Best regards Playerwtf

UPDATE: I made an issue on jshint github repository here

解决方案

This was recently fixxed and works now as I would expect it.

github-issue

As an example I use it like this in my gruntfile

client_logger: {
    expand: true,
    cwd: BASE_PATH_CLIENT_LOGGER,
    src: '**/*.js',
    options: {
        node: false,
        devel: true,
        globals: {
            logger: true,
            expect: true,
            it: true,
            describe: true,
            beforeEach: true,
            afterEach: true
        },
        exported: ['logger']
    }
}

But the npm module was not yet updated. If you want this to work you will have to manually copy the newest version from the jshint github repository and replace the one in the current module or wait until it is updated.

这篇关于jshint grunt导出选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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