[英]is it possible to run JSLint as commandline in windows with help of node.js?
我的意思是像這樣運行它:
node.exe lint.js my_js_file.js
然后輸出到控制台。
我需要下載什么? 我只需要將http://www.jslint.com/
保存到磁盤然后獲取一些附加的js文件,或者我需要為node.js尋找特殊版本嗎?
全局安裝jshint
然后您可以從命令行使用它。
npm install -g jshint
jshint testfile.js
所有這一切都假設您已經在Windows機器上運行了node
和npm
。
編輯
我只是注意到我回答了jshint
而不是jslint
的答案,正如另一個答案所指出的那樣,它們相似但不一樣。 我的答案適用於兩者。
對於jslint
:
npm install -g jslint
jslint testfile.js
March的回答是針對jsHint的。 jsLint的微小變化,帶有“L”,如果這正是你想要的。
這是Ubuntu的一個不錯的指南。 大多數翻譯: http : //blog.simplytestable.com/installing-jslint-for-command-line-use-on-ubuntu/
因此,一旦安裝了節點,就可以執行以下操作:
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)
請注意,我從Ubuntu方向借用了我的C:\\
驅動器的路徑。 您可以將jslint模塊放在任何您想要的位置。 只需確保在下面的jslint調用中更改路徑。
現在我可以使用我安裝的jslint模塊對任何我想要的文件運行jslint。 我為了好玩而下載了jQuery development 1.11 ,並將其保存到c:\\temp\\jquery-1.11.0.js
。 讓我們來jslint吧。
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
...
等等我在上面的C:\\usr\\share\\node-jslint
,但我已經使用了jslint.js
的完整路徑,所以我可以在任何地方使用相同的調用。
而且你是在發癢。
npm install jshint -g
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.