JavaScript

JavaScript

Made by DeepSource
Found unreachable code JS-0025
Performance
Major

Some code paths are unreachable because the return, throw, break, and continue statements unconditionally exit a block of code. The code statements after the above keywords (which exit the code block) will not execute.

Avoid using setState in componentDidMount JS-0442
Performance
Major

componentDidMount() is invoked immediately after a component is mounted. This method is a good place to load data from an endpoint as it is invoked before the browser updates the screen. Using setState() in componentDidMount() will trigger an extra rendering, so it causes performance issues as render() will be called twice.

Bad usage of RegExp#exec and String#match JS-D007
Performance
Major

RegExp#exec and String#match should only be used when we need to use the parts of a string that match a specific pattern:

arguments.caller or arguments.callee should not be used JS-0053
Performance
Minor

The use of arguments.caller and arguments.callee make several code optimizations impossible. They have been deprecated in future versions of JavaScript and their use is forbidden in ECMAScript 5 while in strict mode.

Module imported is not necessary JS-0234
Performance
Minor

Imports are an ES6/ES2015 standard for making the functionality of other modules available in your current module. In CommonJS this is implemented through the require() call. Why would you want to restrict imports?

Require symbol description JS-0250
Performance
Minor

The Symbol function may have an optional description:

Found unused variables in TypeScript code JS-0356
Performance
Major

Unused variables are generally considered a code smell and should be avoided.

Unnecessary catch clauses found JS-0112
Performance
Minor

A catch clause that only rethrows the original error is redundant, and has no effect on the runtime behavior of the program. These redundant clauses can be a source of confusion and code bloat, so it's better to disallow these unnecessary catch clauses.

Specify consistent use of $scope.digest() or $scope.apply() JS-0552
Performance
Minor

For the execution of the watchers, the $digest method will start from the scope in which we call the method. This will cause an performance improvement comparing to the $apply method, who start from the $rootScope. Rule based on Angular 1.x

Found impure pipes JS-0575
Performance
Major
Autofix

Impure pipes should be avoided because they are invoked on each change-detection cycle. Impure pipes can’t leverage caching, instance re-use and simple tests.

Cyclomatic complexity is more than allowed for the template JS-0590
Performance
Minor

Cyclomatic complexity is a quantitative measure of the number of linearly independent paths through a program’s source code. Cyclomatic complexity over some threshold indicates that the logic should be moved outside the template.

Prefer using Meteor.defer over Meteor.setTimeout JS-0729
Performance
Minor
Autofix

Meteor.setTimeout can be used to defer the execution of a function, but Meteor has a built-in method for deferring called Meteor.defer. It is better to use the dedicated method instead of relying on a side-effect of Meteor.setTimeout. Using Meteor.defer is preferred because it uses native setImmediate or postMessage methods if available. Otherwise, it can fall back to setTimeout. Also, setTimeout adds a delay of at least 2ms in Chrome, 10ms in other browsers, which results in performance issues.

Prefer not to use words image, photo in image alt content JS-0750
Performance
Minor

Enforce img alt attribute does not contain the word image, picture, or photo. Screenreaders already announce img elements as an image. There is no need to use words such as image, photo, and/or picture.

Interactive elements should be focusable JS-0751
Performance
Minor

Elements with an interactive role and interaction handlers (mouse or key press) must be focusable as it will be helpful for keyboard and screen reader users.

Consider using onFocus/onBlur with onMouseOver/onMouseOut event JS-0755
Performance
Minor

Enforce onmouseover/onmouseout are accompanied by onfocus/onblur. Coding for the keyboard is important for users with physical disabilities who cannot use a mouse, AT compatibility, and screenreader users.

Prefer that no distracting elements are used JS-0758
Performance
Minor

Enforces that no distracting elements are used. Elements that can be visually distracting can cause accessibility issues with visually impaired users. Such elements are most likely deprecated, and should be avoided. By default, the following elements are visually distracting: <marquee> and <blink>.

tabIndex declared on a non-interactive element JS-0762
Performance
Minor

Tab key navigation should be limited to elements on the page that can be interacted with. Thus it is not necessary to add a tabindex to items in an unordered list, for example, to make them navigable through assistive technology. These applications already afford page traversal mechanisms based on the HTML of the page. Generally, we should try to reduce the size of the page's tab ring rather than increasing it.

Prefer explicit role property in HTML tags JS-0764
Performance
Minor

Some HTML elements have native semantics that are implemented by the browser. This includes default/implicit ARIA roles. Setting an ARIA role that matches its default/implicit role is redundant since it is already set by the browser.