简体   繁体   English

如何在Node.js中以编程方式使用JSHINT?

[英]How to use JSHINT programmatically within Node.js?

I was using npm jshint package in command line tool, but now I want to use it programmatically. 我在命令行工具中使用npm jshint包,但现在我想以编程方式使用它。 Documentation refers to this example, but it doesn't say how to include or require that JSHINT function 文档是指这个例子,但它没有说明如何包含或require JSHINT函数

var source = [
  'function goo() {}',
  'foo = 3;'
];
var options = {
  undef: true
};
var predef = {
  foo: false
};

JSHINT(source, options, predef);

console.log(JSHINT.data());

Documentation refers that 文档指的是

JSHint exposes a JavaScript API for programmatic access in environments like web browsers and Node.js. JSHint公开了一个JavaScript API,用于在Web浏览器和Node.js等环境中进行编程访问。

But exposes how ? 但暴露如何

I installed the npm package locally (I want it locally) 我在本地安装了npm包(我想在本地使用)

npm install jshint --save

and I did as it's there and I get 我做了,因为它在那里,我得到了

JSHINT(code, JShintOpt);
^
ReferenceError: JSHINT is not defined

I also tried 我也试过了

const JSHINT = require('jshint');

But it doesn't work either. 但它也不起作用。

Use the following: 使用以下内容:

const { JSHINT } = require('jshint');

Which is equivalent to: 这相当于:

const JSHINT = require('jshint').JSHINT;

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

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