is it possible to run JSLint as commandline in win

2019-04-07 12:00发布

I mean to run it like this:

node.exe lint.js my_js_file.js

And then get output to a console.

What do I need to download ? Do I need just to save http://www.jslint.com/ to disk and then grab some attached js file or I need to look for special version for node.js ?

3条回答
Animai°情兽
2楼-- · 2019-04-07 12:53
  1. install Node;
  2. run npm install jshint -g from CMD
  3. add "C:\Users\xxx\AppData\Roaming\npm\" to "%Path%"
查看更多
来,给爷笑一个
3楼-- · 2019-04-07 12:58

Install jshint globally then you can use it from the command line.

npm install -g jshint
jshint testfile.js

All this is assuming that you already have node and npm running on you windows machine.

Edit
I just noticed that I responded with an answer for jshint instead of jslint, the as the other answer points out, they are similar but not the same. My answer holds true for both though.
For jslint:

npm install -g jslint
jslint testfile.js
查看更多
虎瘦雄心在
4楼-- · 2019-04-07 13:00

March's answer is for jsHint. Minor changes for jsLint, with an "L", if that's precisely what you want.

Here's a decent guide for Ubuntu. Most of it translates: http://blog.simplytestable.com/installing-jslint-for-command-line-use-on-ubuntu/

So once you've installed node, you can do the following:

C:\Users\YourName>mkdir C:\usr\share\node-jslint

C:\Users\YourName>cd C:\usr\share\node-jslint

C:\usr\share\node-jslint>npm install jslint
npm http GET https://registry.npmjs.org/jslint
npm http 200 https://registry.npmjs.org/jslint
npm http GET https://registry.npmjs.org/jslint/-/jslint-0.2.10.tgz
npm http 200 https://registry.npmjs.org/jslint/-/jslint-0.2.10.tgz
npm http GET https://registry.npmjs.org/nopt
npm http 200 https://registry.npmjs.org/nopt
npm http GET https://registry.npmjs.org/nopt/-/nopt-1.0.10.tgz
npm http 200 https://registry.npmjs.org/nopt/-/nopt-1.0.10.tgz
npm http GET https://registry.npmjs.org/abbrev
npm http 200 https://registry.npmjs.org/abbrev
npm http GET https://registry.npmjs.org/abbrev/-/abbrev-1.0.4.tgz
npm http 200 https://registry.npmjs.org/abbrev/-/abbrev-1.0.4.tgz
jslint@0.2.10 node_modules\jslint
+-- nopt@1.0.10 (abbrev@1.0.4)

Note that I borrowed the path from the Ubuntu directions for my C:\ drive. You can put the jslint module wherever you want. Just ensure that you change the path in the jslint call, below.

Now I can run jslint against any file I want using the jslint module I've installed. I downloaded jQuery development 1.11 just for fun, and saved it to c:\temp\jquery-1.11.0.js. So let's jslint it.

C:\usr\share\node-jslint>node C:/usr/share/node-jslint/node_modules/jslint/bin/jslint.js c:\temp\jquery-1.11.0.js

c:\temp\jquery-1.11.0.js
 #1 Expected exactly one space between 'function' and '('.
    (function( global, factory ) { // Line 15, Pos 10
 #2 Unexpected space between '(' and 'global'.
    (function( global, factory ) { // Line 15, Pos 12
 #3 Unexpected space between 'factory' and ')'.
    (function( global, factory ) { // Line 15, Pos 28
 #4 Use spaces, not tabs.
    if ( typeof module === "object" && typeof module.exports === "object" ) { //
 Line 17, Pos 1
 ...

Etc etc. I'm in C:\usr\share\node-jslint, above, but I've used the full path to jslint.js, so I can use the same call anywhere.

And you're linting.

查看更多
登录 后发表回答