Search code examples
webstorm

Disabling certain WebStorm inspections only in specific file types or contexts


I'm working on an Aurelia project and as the part of the templating system use references to my view-model JavaScript files inside of my view HTML files. For example:

<label>${contact.lastName}</label>

<input value.bind="contact.lastName">

In both lines, WebStorm correctly identifies contact.lastName as a JavaScript fragment and therefore highlights it with the "Expression statement is not assignment or call" inspection. While this is technically true, it's not a problem in this context.

I know that the simple solution is to disable that inspection in WebStorm, but that would also presumably disable it in all of my actual JavaScript files too where I would still want this inspection to happen.

What I want to know is, is there a way to turn off this inspection only in HTML files?


Solution

  • is there a way to turn off this inspection only in HTML files?

    Yes -- every inspection can be altered on scope level (scope works with whole files). By default every inspection has 1 rule that affects whole project.

    1. Settings/Preferences | Appearance & Behaviour | Scopes

      Go there and create a custom Scope that would include such unwanted files/folders.

    2. Save changes (either Apply ... or use OK and re-open Settings screen again)

    3. Settings/Preferences | Editor | Inspections

    4. Locate inspection which you wish to alter.

    5. Create new rule for recently created Scope. For that just click on In All Scopes button (it's a button when only 1 rule is defined) and choose that scope.

      enter image description here

    6. Now just disable this inspection for that scope.

      enter image description here

    (Screenshots are for another language/inspection and done in older IDE version but everything else remains the same)

    Official help pages: