Autofix support in JavaScript analyzer

Support for Autofix in the JavaScript analyzer has been one of the most requested feature from the community. The wait is now over. DeepSource’s JavaScript analyzer now supports Autofix, starting with 30 issues. Here are some of them:

JS-0022 - Regex Literals should not have multiple spaces

Fixes this code:

var re = /foo   bar/;
var re = new RegExp("foo   bar");

to this:

var re = /foo {3}bar/;
var re = new RegExp("foo {3}bar");

JS-0049 - Prefer to use dot notation whenever possible

Fixes this code:

var x = foo["bar"];

to this:

var x = foo.bar;

JS-0055 - Found division operators explicitly at the beginning of regular expressions

function bar() { return /=foo/; }

to this:

function bar() { return /[=]foo/; }

JS-0062 - Unnecessary calls to .bind()

var x = function () {
    foo();
}.bind(bar);

to this:

var x = function () {
    foo();
};

JS-0253 - Detected parseInt() and Number.parseInt() in favor of binary, octal, and hexadecimal literals

Number.parseInt("111110111", 2) === 503;

to this:

0b111110111 === 503;

How to use this?

If you are using the JavaScript analyzer, you should start seeing an Autofix button if we’ve found an issue that can be Autofixed. All you need to do is click on that, review the changes, and confirm. DeepSource will automatically create a pull-request on the repository that you can merge.

We are keen to know how you use Autofix for JavaScript. Send us your feedback!

2 Likes