How to use the regexpp.RegExpValidator function in regexpp

To help you get started, we’ve selected a few regexpp examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github eslint / eslint / lib / rules / no-invalid-regexp.js View on Github external
/**
 * @fileoverview Validate strings passed to the RegExp constructor
 * @author Michael Ficarra
 */
"use strict";

//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------

const RegExpValidator = require("regexpp").RegExpValidator;
const validator = new RegExpValidator({ ecmaVersion: 2018 });
const validFlags = /[gimuys]/gu;
const undefined1 = void 0;

//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------

module.exports = {
    meta: {
        type: "problem",

        docs: {
            description: "disallow invalid regular expression strings in `RegExp` constructors",
            category: "Possible Errors",
            recommended: true,
            url: "https://eslint.org/docs/rules/no-invalid-regexp"
github mysticatea / eslint-plugin-es / lib / rules / no-regexp-unicode-property-escapes.js View on Github external
function verify(context, node, pattern, flags) {
    try {
        let found = false

        new RegExpValidator({
            onUnicodePropertyCharacterSet() {
                found = true
            },
        }).validatePattern(pattern, 0, pattern.length, flags.includes("u"))

        if (found) {
            context.report({ node, messageId: "forbidden" })
        }
    } catch (error) {
        //istanbul ignore else
        if (error.message.startsWith("Invalid regular expression:")) {
            return
        }
        //istanbul ignore next
        throw error
    }
github mysticatea / eslint-plugin-es / lib / rules / no-regexp-named-capture-groups.js View on Github external
function verify(context, node, pattern, flags) {
    try {
        let found = false

        new RegExpValidator({
            onCapturingGroupEnter(_start, name) {
                if (name) {
                    found = true
                }
            },
            onBackreference(_start, _end, ref) {
                if (typeof ref === "string") {
                    found = true
                }
            },
        }).validatePattern(pattern, 0, pattern.length, flags.includes("u"))

        if (found) {
            context.report({ node, messageId: "forbidden" })
        }
    } catch (error) {
github mysticatea / eslint-plugin-es / lib / rules / no-regexp-lookbehind-assertions.js View on Github external
function verify(context, node, pattern, flags) {
    try {
        let found = false

        new RegExpValidator({
            onLookaroundAssertionEnter(_start, kind) {
                if (kind === "lookbehind") {
                    found = true
                }
            },
        }).validatePattern(pattern, 0, pattern.length, flags.includes("u"))

        if (found) {
            context.report({ node, messageId: "forbidden" })
        }
    } catch (error) {
        //istanbul ignore else
        if (error.message.startsWith("Invalid regular expression:")) {
            return
        }
        //istanbul ignore next
github eslint / eslint / lib / rules / no-control-regex.js View on Github external
constructor() {
        this.ecmaVersion = 2018;
        this._source = "";
        this._controlChars = [];
        this._validator = new RegExpValidator(this);
    }

regexpp

Regular expression parser for ECMAScript.

MIT
Latest version published 4 years ago

Package Health Score

70 / 100
Full package analysis