Skip to content

Latest commit

 

History

History
18 lines (12 loc) · 456 Bytes

no-unguarded-get-range-at.md

File metadata and controls

18 lines (12 loc) · 456 Bytes

Avoid unguarded getRangeAt (no-unguarded-get-range-at)

Some browsers (e.g. Safari) will throw an error when getRangeAt is called and there are no ranges in the selection.

Rule details

Example of incorrect code for this rule:

window.getSelection().getRangeAt( 0 );

Example of correct code for this rule:

const selection = window.getSelection();
const range = selection.rangeCount ? selection.getRangeAt( 0 ) : null;