Search code examples
sublimetext3sublimelinterjscs

How to select a custom .jscsrc file


We have multiple projects with various .jscsrc files. I'd like to use one that I defined, which is stricter than most projects.

In my case its ~/.jscsrc.

How can I configure sublime-linter to use that file for jscs?

Thanks!


Solution

  • SublimeLinter is executing jscs on your system. To define the path to the config file (according to the docs) for jscs using the CLI, you'd run:

    jscs path[ path[...]] --config=~/.config.json

    To set this for the SublimeLinter package you can use SublimeLinter's args setting for jscs and set the config path. This would be in your SublimeLinter.sublime-settings (default or user):

    {
        "user": {
            "linters": {
                "jscs": {
                    "args": [
                        "--config=~/.jscsrc"
                    ]
                }
            }
        }  
    }
    

    Or alternatively, you can just use "args": "--config=~/.jscsrc".

    Note, from the docs:

    If there is no --config option specified, jscs it will consequentially search for jscsConfig option in package.json file then for .jscsrc (which is a just JSON with comments) and .jscs.json files in the current working directory then in nearest ancestor until it hits the system root.

    Also, the path to the .jscsrc file is cached, so if you create a new .jscsrc that should have precedence over the previous one (according to the above), you need to clear the cache for the linter to use the new .jcscrc You can clear the cache by going to: Tools > SublimeLinter > Clear Caches.

    You can also override and use default/global settings with other packages with this same approach, when applicable and if the linter supports it. Another good example is with the SublimeLinter-jshint plugin.