Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
*/
"use strict";
//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
const astUtils = require("./utils/ast-utils");
const regexpp = require("regexpp");
//------------------------------------------------------------------------------
// Helpers
//------------------------------------------------------------------------------
const regExpParser = new regexpp.RegExpParser();
const DOUBLE_SPACE = / {2}/u;
/**
* Check if node is a string
* @param {ASTNode} node node to evaluate
* @returns {boolean} True if its a string
* @private
*/
function isString(node) {
return node && node.type === "Literal" && typeof node.value === "string";
}
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
const {
CALL,
CONSTRUCT,
ReferenceTracker,
getStringIfConstant
} = require("eslint-utils");
const regexpp = require("regexpp");
//------------------------------------------------------------------------------
// Helpers
//------------------------------------------------------------------------------
const parser = new regexpp.RegExpParser();
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
module.exports = {
meta: {
type: "suggestion",
docs: {
description: "enforce using named capture group in regular expression",
category: "Best Practices",
recommended: false,
url: "https://eslint.org/docs/rules/prefer-named-capture-group"
},
create(context) {
const parser = new RegExpParser();
/**
* Verify a given regular expression.
* @param {Node} node The node to report.
* @param {string} pattern The regular expression pattern to verify.
* @param {string} flags The flags of the regular expression.
* @returns {void}
*/
function verify(node, pattern, flags) {
const patternNode = parser.parsePattern(
pattern,
0,
pattern.length,
flags.includes("u")
);
const has = {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const eslint_utils_1 = require("eslint-utils");
const regexpp_1 = require("regexpp");
const util_1 = require("../util");
const EQ_OPERATORS = /^[=!]=/;
const regexpp = new regexpp_1.RegExpParser();
exports.default = util_1.createRule({
name: 'prefer-string-starts-ends-with',
defaultOptions: [],
meta: {
type: 'suggestion',
docs: {
description: 'Enforce the use of `String#startsWith` and `String#endsWith` instead of other equivalent methods of checking substrings',
category: 'Best Practices',
recommended: 'error',
requiresTypeChecking: true,
},
messages: {
preferStartsWith: "Use 'String#startsWith' method instead.",
preferEndsWith: "Use the 'String#endsWith' method instead.",
},
schema: [],
import { TSESLint, TSESTree } from '@typescript-eslint/experimental-utils';
import {
isNotClosingParenToken,
getPropertyName,
getStaticValue,
} from 'eslint-utils';
import { RegExpParser, AST as RegExpAST } from 'regexpp';
import { createRule, getParserServices, getTypeName } from '../util';
const EQ_OPERATORS = /^[=!]=/;
const regexpp = new RegExpParser();
export default createRule({
name: 'prefer-string-starts-ends-with',
defaultOptions: [],
meta: {
type: 'suggestion',
docs: {
description:
'Enforce the use of `String#startsWith` and `String#endsWith` instead of other equivalent methods of checking substrings',
category: 'Best Practices',
recommended: 'error',
requiresTypeChecking: true,
},
messages: {
preferStartsWith: "Use 'String#startsWith' method instead.",
create(context) {
const parser = new RegExpParser();
/**
* Verify a given regular expression.
* @param {Node} node The node to report.
* @param {string} pattern The regular expression pattern to verify.
* @param {string} flags The flags of the regular expression.
* @returns {void}
*/
function verify(node, pattern, flags) {
const has = {
surrogatePairWithoutUFlag: false,
combiningClass: false,
variationSelector: false,
emojiModifier: false,
regionalIndicatorSymbol: false,
zwj: false