简体   繁体   English

mac上的jshint和sublimelinter设置配置

[英]jshint and sublimelinter settings config on mac

I'm trying to configure sublimelinter, specifically jshint on my Mac. 我正在尝试配置sublimelinter,特别是我的Mac上的jshint。 On my windows version of SublimeText there is the following section in SublimeLinter.sublime-settings 在我的Windows版本的SublimeText上, SublimeLinter.sublime-settings有以下部分

 "jshint_options":
    {
        // To fix column positions for JSHint errors you may want to add `"indent": 1` to your
        // **User** "jshint_options". This issue affects users with tabs for indentation.
        // This fix was reverted due to a conflict with using the `"white": true` option.
        // "indent": 1,
        "evil": true,
        "regexdash": true,
        "browser": true,
        "wsh": true,
        "trailing": true,
        "sub": true
    },

When I view the file on my Mac this section doesn't exist, is there a place to edit these option on the Mac version without a separate settings file? 当我在Mac上查看该文件时,此部分不存在,是否有可以在Mac版本上编辑这些选项而没有单独的设置文件? Or a global settings file for jshint? 还是jshint的全局设置文件?

I've been digging through similar questions but haven't found a clear solution. 我一直在挖掘类似的问题,但没有找到一个明确的解决方案。

Update: 更新:

Actually it doesn't seem to catch any errors at all when using it on the console. 实际上,在控制台上使用它时似乎根本没有发现任何错误。 My javascript file doesn't end in .js how can I configure it to look at different extensions? 我的javascript文件不以.js结尾如何配置它以查看不同的扩展名? I can't find it in the docs. 我在文档中找不到它。

There's another way to set options globally , without using ".jshintrc" files. 还有另一种方法可以全局设置选项,而不使用“.jshintrc”文件。
1) create a file with any name (eg "jshint.conf"). 1)创建一个具有任何名称的文件(例如“jshint.conf”)。 my file is: 我的档案是:

{
  "globals": { "$": false },
  "globalstrict": true,
  "devel": true
}

2) put it anywhere. 2)把它放在任何地方。 in my case it is: "c:\\Users\\Smith\\AppData\\Roaming\\Sublime Text 3\\Packages\\User\\" 在我的情况下它是:“c:\\ Users \\ Smith \\ AppData \\ Roaming \\ Sublime Text 3 \\ Packages \\ User \\”

3) make the next reference in section "jshint"->"args" of sublime-linter user setting (user/SublimeLinter.sublime-settings): 3)在sublime-linter用户设置(user / SublimeLinter.sublime-settings)的“jshint” - >“args”部分中进行下一个引用:

{
    "user": {
        "linters": {
            "jshint": {
                "args": [
                    "--config", "c:\\Users\\Smith\\AppData\\Roaming\\Sublime Text 3\\Packages\\User\\jshint.conf"
                ]
            }
        }
    }
}

4) Enjoy! 4)享受!

In general I would recommend against configuring JSHint system-wide. 一般来说,我建议不要在系统范围内配置JSHint。 It's usually safer to create a .jshintrc file for each project your work on because it's likely they will have different JSHint requirements. 为您的每个项目创建一个.jshintrc文件通常更安全,因为它们可能会有不同的JSHint要求。

The jshint_options SublimeLinter setting you mention in your question is from the old version of SublimeLinter, which has recently been reworked to have a simple plugin architecture. 您在问题中提到的jshint_options SublimeLinter设置来自SublimeLinter的旧版本,该版本最近经过重新设计,具有简单的插件架构。 The JSHint plugin (which I assume you are using, since the settings you tried didn't work) makes the same recommendation : JSHint插件(我假设您正在使用,因为您尝试的设置不起作用)提出了相同的建议

You can configure jshint options in the way you would from the command line, with .jshintrc files. 您可以使用.jshintrc文件以命令行的方式配置jshint选项。

The added benefit of this approach is that you can commit the .jshintrc file to your repository and ensure that anyone who works on the project is working with the same JSHint rules, rather than their own system-wide settings. 此方法的.jshintrc好处是,您可以将.jshintrc文件提交到存储库,并确保在项目上工作的任何人都使用相同的JSHint规则,而不是他们自己的系统范围设置。

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

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