Brackets Tip: Specifying one linter (the right way)

A few days ago I noticed Brackets was no longer linting JSON files. I had recently updated so I assumed it was a bug with that particular extension. Like a good developer, I checked the console and when I didn't see anything, I filed a report and moved on. (For folks curious, the extension I was using is called "JSONLint Extension for Brackets" by Ingo Richter. Oh, and for what I used when it was't working - I used JSONLint.com.) Turns out the issue was a mistake I made in my preferences.

Brackets has a pretty complex preferences system. While there isn't a UI for it, you can open your global preferences file by going to the Debug menu and selecting Open Preferences File. Brackets ships with a linter for JavaScript files called JSLint. I have another extension that wraps JSHint that I prefer. By default, if Brackets sees multiple linters for a file, it will display issues from both:

shot

That's not really ideal so I checked out the Preferences docs on how I could correct this.

I focused my attention on two settings: linting.prefer and lintingUsePrefferedOnly. The first lets you specify an order of preferred linters and the second specifies that you only want to use the preferred one. So I added this to my global preferences:

"linting.prefer": [
    "JSHint"
],
"linting.usePreferredOnly": true,

Seems legit, right? I prefer JSHint and I only want to use that. However, this was the root of my issues. Because this preference was global, it applied to all file types. When reading the docs, I had focused in on the table of settings and missed this crucial detail:

Within either file, there are three levels of specificity at which you can set a preference:
  • default - global (user-level file) or project-global (project-level file)
  • "path" layer - overrides in effect for files that match the given path/filename wildcard
  • "language" layer - overrides in effect for files that Brackets detects as the given programming language (this is also filename/extension based, but it's easier to work with since Brackets already understands many file extensions out of the box, and additional languages supported by Brackets extensions can automatically be used here too).

Basically, you can specify settings per language, which is what I needed to do for JavaScript. Here is the corrected version:

"language": {
    "javascript": {
        "linting.prefer": [
        "JSHint"
    ],
    "linting.usePreferredOnly": true
    }
},

And that corrected it. In JavaScript I only see JSHint and my other linters work fine elsewhere. A big thank you to Randy Edmunds for pointing out my mistake.

Like This?

If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can also subscribe to the email feed to get notified of new posts.