News

Introducing the Kotlin/JS Inspection Pack: IR Migration Help, Quick-Fixes, and More

We’re introducing a new plugin for your Kotlin/JS applications – the Kotlin/JS Inspection Pack. It adds valuable inspections and quick-fixes that help you build and maintain your Kotlin/JS projects.

GET KOTLIN/JS INSPECTION PACK

The plugin is especially helpful if you want to migrate your projects to the new Kotlin/JS IR compiler that’s been promoted to Beta in the latest 1.5.30 release. There are some major differences between the legacy compiler and the new one, so switching your Kotlin/JS project to the new backend may require some changes in your code. Fortunately, the Kotlin/JS Inspection Pack has a number of quick-fixes that should simplify the process. Try the Kotlin/JS IR backend.

How to get the plugin

Adding the plugin to your development environment is easy. Just search for ‘Kotlin/JS Inspection Pack’ in your IDE’s Plugins section or get the latest version from the JetBrains Marketplace.

The plugin is compatible with versions 2020.3 and later of both IntelliJ IDEA and Android Studio.

Inspections and quick-fixes in the Kotlin/JS Inspection Pack

While the Kotlin/JS Inspection Pack can help you fix common migration issues, we recommend checking out our Kotlin/JS IR migration guide to get the broader picture. Now let’s have a look at the tips that the Kotlin/JS Inspection Pack can provide.

Turn JS and React-related classes and interfaces into external interfaces

If some of your interfaces and classes (including data classes) come from pure JavaScript classes, you may get a ClassCastException error. The reason is that the IR compiler assumes that they’re Kotlin objects, when in fact they’re plain JS objects not defined in the code. For example, this problem occurs with React’s State and Props classes.

The plugin highlights such classes and interfaces and offers to turn them into external interfaces:

Make properties of external interfaces mutable

When working with external interfaces, pay attention to immutable properties. You can assign values to them only after the object is created with js() or jsObject().

As a workaround, make such properties mutable var properties, following the plugin’s suggestions:

Make boolean variables nullable in external interfaces

Another migration issue you may encounter involves the nullability of boolean variables in external interfaces. In contrast to JavaScript, where such variables can be null or undefined, Kotlin requires you to explicitly specify the nullability.

To prevent another ClassCastException error, the Kotlin/JS Inspection Pack underlines boolean properties in external interfaces and advises making them nullable (Boolean?):

Future plans

The current scope of the plugin is only the beginning. We’re planning to add more inspections to make Kotlin/JS development easier for you. Stay tuned!

If you have any feedback, encounter any issues, or want to suggest new inspections for the plugin, please don’t hesitate to report them in our issue tracker. Thank you!

GET KOTLIN/JS INSPECTION PACK

See also

Discover more