简体   繁体   English

使用自定义选项从控制台运行JSlint吗?

[英]Run JSlint from console with custom options?

In a previous question Run JSLint on a .js file from debugging console in chrome or firefox I learned how to run JSLint from console or from node. 在上一个问题中, 从chrome或firefox的调试控制台在.js文件上运行JSLint,我学习了如何从控制台或节点运行JSLint。

Is there a way to run JSLint (from the JavaScript code like in the answer given to the above mentioned question) but with custom options , for example for code that contains jQuery ( JSLint validation for Javascript with JQuery ) with the options Assume a browser and the option Predefined section with jQuery and $ as parameters? 有没有一种方式来运行的JSLint(从JavaScript代码就像给上述问题的答案), 而是使用自定义选项 ,例如对于包含的jQuery(代码JSLint的验证为Javascript与jQuery )使用选项假设一个浏览器 ,使用jQuery和$作为参数的预定义部分选项?

Pass an object with the options as second parameter to JSLINT . 将带有选项的对象作为第二个参数传递给JSLINT Global variables can be defined as an array of strings and assigned to the predef property of said options object. 全局变量可以定义为字符串数组,并分配给所述选项对象的predef属性。

From the JSLint source code : JSLint源代码

JSLINT is a global function. JSLINT是全局函数。 It takes two parameters. 它有两个参数。

 var myResult = JSLINT(source, option); 

The first parameter is either a string or an array of strings. 第一个参数是字符串或字符串数​​组。 If it is a string, it will be split on '\\n' or '\\r' . 如果是字符串,它将在'\\n''\\r'上拆分。 If it is an array of strings, it is assumed that each string represents one line. 如果它是字符串数组,则假定每个字符串代表一行。 The source can be a JavaScript text, or HTML text, or a JSON text, or a CSS text. 源可以是JavaScript文本,HTML文本,JSON文本或CSS文本。

The second parameter is an optional object of options that control the operation of JSLINT. 第二个参数是控制JSLINT操作的选项的可选对象。 Most of the options are booleans: They are all optional and have a default value of false. 大多数选项是布尔值:它们都是可选的,默认值为false。 One of the options, predef , can be an array of names, which will be used to declare global variables, or an object whose keys are used as global names, with a boolean value that determines if they are assignable. 选项predef可以是名称数组(用于声明全局变量),也可以是对象的键用作全局名的对象,其布尔值确定它们是否可分配。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM