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.
.bind()
or local functions in JSX properties JS-0417Using .bind()
or passing local callback functions as props to react component incurs a performance overhead.
Consider using React.useCallback
, or if possible, moving the callback definition outside the component.
EXCEPTIONS: This rule may not apply if your react component is only rendered once, or if your application is not performance sensitive. In such cases, consider adding a skipcq to prevent DeepSource from raising this issue on a single component. Alternatively, for small applications, you could add this issue in the ignore rules section.
Note that the performance overhead is not determined by the size of the callback function, but instead the number of times the component is rendered.
setState
in componentDidMount
JS-0442componentDidMount()
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.
arguments.caller
or arguments.callee
should not be used JS-0053The 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.
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?
The Symbol
function may have an optional description:
Unused variables are generally considered a code smell and should be avoided.
catch
clauses found JS-0112A 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.
return await
function found JS-0111Returning an awaited value (like with return await f()
) has two problems: - It queues an extra microtask, blocking the callstack until return
is executed.
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.
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.
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.
onFocus/onBlur
with onMouseOver/onMouseOut
event JS-0755Enforce 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.
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>
.
Non-interactive HTML elements and non-interactive ARIA roles indicate content and containers in the user interface. A non-interactive element does not support event handlers (mouse and key handlers). Non-interactive elements include <main>
, <area>
, <h1>
(,<h2>
, etc), <p>
, <img>
, <li>
, <ul>
and <ol>
. Non-interactive WAI-ARIA roles include article
, banner
, complementary
, img
, listitem
, main
, region
and tooltip
.
tabIndex
declared on a non-interactive element JS-0762Tab 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.
attrs
in ember hooks JS-0777In 2.0.0, didReceiveAttrs
and didUpdateAttrs
hooks were introduced. These hooks are called whenever the references of arguments to a component change. These hooks receive arguments, however one should not use them as they can be very costly when you have a lot of components on the page.
@each
in deeply nested computed property JS-0780Ember does not allow deeply-nested computed property dependent keys with @each
. At runtime, it will show a warning about this. You should use @each
only one level deep otherwise it will create a complex equation and effect your application performance.
Interactive HTML elements indicate controls in the user interface. Interactive elements include <a href>
, <button>
, <input>
, <select>
, <textarea>
. Non-interactive HTML elements and non-interactive ARIA roles indicate content and containers in the user interface. Non-interactive elements include <main>
, <area>
, <h1>
(,<h2>
, etc), <img>
, <li>
, <ul>
and <ol>
.
Non-interactive HTML elements indicate content and containers in the user interface. Non-interactive elements include <main>
, <area>
, <h1>
(,<h2>
, etc), <img>
, <li>
, <ul>
and <ol>
. Interactive HTML elements indicate controls in the user interface. Interactive elements include <a href>
, <button>
, <input>
, <select>
, <textarea>
.