lib/rules/no-unicode-codepoint-escapes.js
function findAndReport(text, node) {
            for (const match of codePointEscapeSearchGenerator(text)) {
                const start = match.index
                const end = start + match[0].length
                const range = [start + node.start, end + node.start]
                context.report({
                    node,
                    loc: {
                        start: sourceCode.getLocFromIndex(range[0]),
                        end: sourceCode.getLocFromIndex(range[1]),
                    },
                    messageId: "forbidden",
                    fix(fixer) {
                        const codePointStr = text.slice(start + 3, end - 1)
                        // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint
                        let codePoint = Number(`0x${codePointStr}`)
                        let replacement = null
                        if (codePoint <= 0xffff) {
                            // BMP code point
                            replacement = toHex(codePoint)
                        } else {
                            // Astral code point; split in surrogate halves
                            // http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
                            codePoint -= 0x10000
                            const highSurrogate = (codePoint >> 10) + 0xd800
                            const lowSurrogate = (codePoint % 0x400) + 0xdc00
                            replacement = `${toHex(highSurrogate)}\\u${toHex(
                                lowSurrogate
                            )}`
                        }
                        return fixer.replaceTextRange(
                            [range[0] + 2, range[1]],
                            replacement
                        )
                    },
                })
            }
        }
function findAndReport(text, node) {
            for (const match of codePointEscapeSearchGenerator(text)) {
                const start = match.index
                const end = start + match[0].length
                const range = [start + node.start, end + node.start]
                context.report({
                    node,
                    loc: {
                        start: sourceCode.getLocFromIndex(range[0]),
                        end: sourceCode.getLocFromIndex(range[1]),
                    },
                    messageId: "forbidden",
                    fix(fixer) {
                        const codePointStr = text.slice(start + 3, end - 1)
                        // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint
                        let codePoint = Number(`0x${codePointStr}`)
                        let replacement = null
                        if (codePoint <= 0xffff) {
                            // BMP code point
                            replacement = toHex(codePoint)
                        } else {
                            // Astral code point; split in surrogate halves
                            // http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
                            codePoint -= 0x10000
                            const highSurrogate = (codePoint >> 10) + 0xd800
                            const lowSurrogate = (codePoint % 0x400) + 0xdc00
                            replacement = `${toHex(highSurrogate)}\\u${toHex(
                                lowSurrogate
                            )}`
                        }
                        return fixer.replaceTextRange(
                            [range[0] + 2, range[1]],
                            replacement
                        )
                    },
                })
            }
        }
function findAndReport ( text , node ) { for ( const match of codePointEscapeSearchGenerator ( text ) ) { const start = match . index const end = start + match [ 0 ] . length const range = [ start + node . start , end + node . start ] context . report ( { node , loc : { start : sourceCode . getLocFromIndex ( range [ 0 ] ) , end : sourceCode . getLocFromIndex ( range [ 1 ] ) , } , messageId : "forbidden" , fix ( fixer ) { const codePointStr = text . slice ( start + 3 , end - 1 ) // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint let codePoint = Number ( ` ${ codePointStr } ` ) let replacement = null if ( codePoint <= 0xffff ) { // BMP code point replacement = toHex ( codePoint ) } else { // Astral code point; split in surrogate halves // http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae codePoint -= 0x10000 const highSurrogate = ( codePoint >> 10 ) + 0xd800 const lowSurrogate = ( codePoint % 0x400 ) + 0xdc00 replacement = ` ${ toHex ( highSurrogate ) } \\ ${ toHex ( lowSurrogate ) } ` } return fixer . replaceTextRange ( [ range [ 0 ] + 2 , range [ 1 ] ] , replacement ) } , } ) } }
find code point escape, and report
@param  {string} text text
@param  {Node} node node
@returns {void}
find code point escape and report