在记事本中使用 JSLint++

发布于 2024-07-25 10:46:24 字数 111 浏览 3 评论 0 原文

我见过其他文本编辑器使用扩展来允许语法检查,例如 JSLint,这可以用 Notepad++ 实现吗?

I have seen other text editors use extensions to allow syntax checkers such as JSLint, is this possible with Notepad++?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

浅忆流年 2024-08-01 10:46:24

我已经设法使用 notepad++NppExec 插件。

NppExec 插件通常是默认安装的,可以在插件 -> 下找到。 NppExec。 (使用 NppExec 0.3 RC1 和 Notepad++ 5.1+)。

1) JSLint

首先从 WSH 版本的 jslint href="http://www.jslint.com" rel="noreferrer">http://www.jslint.com。
修改文件的最后部分如下:

(function() {
    if(!JSLINT(WScript.StdIn.ReadAll(),{passfail:false})) {
        var e;
        for(var i in JSLINT.errors) {
            e=JSLINT.errors[i];
            WScript.StdOut.WriteLine('Lint at line '+(e.line+1)+' character '+(e.character+1)+': '+e.reason);
            WScript.StdOut.WriteLine('    '+(e.evidence||'').replace(/^\s*(\S*(\s+\S+)*)\s*$/,"$1"));
        }
        WScript.Quit(1);
    }
}());

(此处为修改前的版本)< br>
这会导致 JSLint 输出所有错误,而不仅仅是第一个错误。

接下来,Notepad++ 的 NppExec 不允许使用 StdIn,所以我编写了一个 批处理文件实际执行命令。
这还允许我添加一个配置文件,该文件插入在所有 javascript 文件之前。 这些选项可以在此处查看。
批处理文件如下所示:

@copy /b "C:\Program Files\jslint\conf.txt"+%1 "C:\Program Files\jslint\lastoutput.txt" > temp.txt
@cscript /Nologo "C:\Program Files\jslint\jslint.js" < "C:\Program Files\jslint\lastoutput.txt"

您可能需要根据放置 jslint.js 文件的位置修改路径。
conf.txt 文件如下所示:

/*jslint forin:true*/

确保在此行的末尾。 如果有回车,则所有行数都会减一。

最后,我在 NppExec 中输入的命令是:

"C:\Program Files\jslint\jslint.bat" "$(FULL_CURRENT_PATH)" 

2) Javascript Lint

Javascript lint 稍微不那么严格解析器并且更容易实现。

首先从 http://www.javascriptlint.com/download.htm 并解压它。
那么 NppExec 命令是:(

"C:\Program Files\JavascriptLint\jsl.exe" -conf "C:\Program Files\JavascriptLint\jsl.default.conf" -process "$(FULL_CURRENT_PATH)"

注意:大多数 Javascript Lint 指令都会说在命令末尾添加“pauseatend”,我发现这会在 Notepad++ 中引起问题,所以我将其保留)

希望这对某人有帮助,
干杯,
安迪.

I have managed to get two lint programs to run using the notepad++'s NppExec Plugin.

The NppExec plugin is usually installed by default and can be found under plugins -> NppExec. (Using NppExec 0.3 RC1 and Notepad++ 5.1+).

1) JSLint

first download the WSH version of jslint from http://www.jslint.com.
Modify the last part of the file as follows:

(function() {
    if(!JSLINT(WScript.StdIn.ReadAll(),{passfail:false})) {
        var e;
        for(var i in JSLINT.errors) {
            e=JSLINT.errors[i];
            WScript.StdOut.WriteLine('Lint at line '+(e.line+1)+' character '+(e.character+1)+': '+e.reason);
            WScript.StdOut.WriteLine('    '+(e.evidence||'').replace(/^\s*(\S*(\s+\S+)*)\s*$/,"$1"));
        }
        WScript.Quit(1);
    }
}());

(Pre-modified version here)
This causes JSLint to output all of the errors, not just the first one.

Next, Notepad++'s NppExec doesn't allow the use of StdIn so I wrote a batch file to actually execute the command.
This also allowed me to add a config file that is inserted before all javascript files. The options can be seen here.
The batch file looks like this:

@copy /b "C:\Program Files\jslint\conf.txt"+%1 "C:\Program Files\jslint\lastoutput.txt" > temp.txt
@cscript /Nologo "C:\Program Files\jslint\jslint.js" < "C:\Program Files\jslint\lastoutput.txt"

You may need to modify the paths depending on where you put the jslint.js file.
The conf.txt file looks like this:

/*jslint forin:true*/

Make sure there is no return carriage at the end of this line. If there is a return carriage all the lines counts will be off by one.

Finally, the command I entered into NppExec is:

"C:\Program Files\jslint\jslint.bat" "$(FULL_CURRENT_PATH)" 

2) Javascript Lint

Javascript lint is a slightly less strict parser and was much easier to implement.

First grab a copy of the windows version from http://www.javascriptlint.com/download.htm and unzip it.
Then the NppExec command is:

"C:\Program Files\JavascriptLint\jsl.exe" -conf "C:\Program Files\JavascriptLint\jsl.default.conf" -process "$(FULL_CURRENT_PATH)"

(note: Most instructions for Javascript Lint will say to add "pauseatend" to the end of the command, I found this caused problems in Notepad++ so I left it off)

Hope this helps someone,
Cheers,
Andy.

临走之时 2024-08-01 10:46:24

您可以尝试 Notepad++ 的 JSLint 插件:

https://sourceforge.net/projects/jslintnpp/

You may try JSLint Plugin for Notepad++:

https://sourceforge.net/projects/jslintnpp/

誰認得朕 2024-08-01 10:46:24

安装插件后,您应该转到:

插件 -> JSLint -> JSLint 选项

并将“选择 JavaScript lint 工具:”更改为 JSHint

JSHint 给出了很多无意义的“错误”。

After you've installed the plugin you should go to:

Plugins -> JSLint -> JSLint options

and change "Choose JavaScript lint tool:" to JSHint.

JSHint gives alot less meaningless "errors".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文