const create = context => { const options = context.options[0] || {}; const rules = { 'CallExpression[callee.name="require"]': node => importIndex(context, node, node.arguments[0]) }; if (!options.ignoreImports) { rules.ImportDeclaration = node => importIndex(context, node, node.source); } return rules; }
const fix = (node, identifierName, preferedSelector) => { const nodeToBeFixed = node.arguments[0]; if (identifierName === 'getElementsByTagName' || !hasValue(nodeToBeFixed)) { return fixer => fixer.replaceText(node.callee.property, preferedSelector); } const getArgumentFix = nodeToBeFixed.type === 'Literal' ? getLiteralFix : getTemplateLiteralFix; return function * (fixer) { yield * getArgumentFix(fixer, nodeToBeFixed, identifierName); yield fixer.replaceText(node.callee.property, preferedSelector); }; }
const isTypecheckingIdentifier = (node, callExpression, isMemberExpression) => callExpression !== undefined && callExpression.arguments.length > 0 && node.type === 'Identifier' && ((isMemberExpression === true && tcIdentifiers.has(node.name)) || (isMemberExpression === false && tcGlobalIdentifiers.has(node.name)))
const makeNewImports = ( decs ) => { const imports = []; decs.forEach( ( dec ) => { const local = dec.value.init.arguments[ 0 ].value.replace( 'lodash/', '' ); const name = dec.value.id.name; const newImport = j.importDeclaration( [ j.importSpecifier( j.identifier( local ), j.identifier( name ) ) ], j.literal( 'lodash' ) ); imports.push( newImport ); } ); return imports; }
function getTarget( arg ) { if ( arg.type === 'Literal' ) { return arg.value; } if ( arg.type === 'CallExpression' ) { // More checks? return arg.arguments[ 0 ].value; } }
const fix = (context, node, fixer) => { let [name, value] = node.arguments; const calleeObject = parseNodeText(context, node.callee.object); name = dashToCamelCase(name.value.slice(5)); value = parseNodeText(context, value); const replacement = `${calleeObject}.dataset${ isValidVariableName(name) ? `.${name}` : `[${quoteString(name)}]` } = ${value}`; return fixer.replaceText(node, replacement); }
const create = context => { return { [selector](node) { const name = node.arguments[0].value; if (typeof name !== 'string' || !name.startsWith('data-') || name === 'data-') { return; } context.report({ node, message: 'Prefer `.dataset` over `setAttribute(…)`.', fix: fixer => fix(context, node, fixer) }); } }; }
const fixDirectApplyCall = (node, sourceCode) => { if ( astUtils.getPropertyName(node.callee) === 'apply' && node.arguments.length === 2 && isApplySignature(node.arguments[0], node.arguments[1]) ) { return fixer => ( fixer.replaceText( node, getReflectApplyCall(sourceCode, node.callee.object, node.arguments[0], node.arguments[1]) ) ); } }
// Check that the given call expression is `config.isEnabled( 'flag' )` with // `config` as the default export or namespace, and return the `flag` literal value. const isCallOnDefaultOrNamespace = ( parser, moduleName, expr ) => { return moduleName && parser.evaluate( moduleName ).identifier === 'imported var' && expr.callee.type === 'MemberExpression' && expr.callee.object.type === 'Identifier' && expr.callee.object.name === moduleName && expr.callee.property.type === 'Identifier' && expr.callee.property.name === 'isEnabled' && expr.arguments.length === 1 && expr.arguments[ 0 ].type === 'Literal' ? expr.arguments[ 0 ].value : null; }
function validateArgv(count) { var argv=validateArgv.caller.arguments; if(argv.length<count) { return false; } for(var i=0;i<argv.length;i++) { if(argv[i]==null || argv[i]==undefined) { return false; } } return true; }
node.arguments.forEach( function ( arg ) { let value = getTextContentFromNode( arg ); if ( 'string' !== typeof value ) { return; } value = value.replace( RX_PLACEHOLDERS, '' ); if ( 0 === value.length ) { context.report( arg, rule.ERROR_MESSAGE ); return; } value = value.replace( RX_INTERPOLATED_COMPONENTS, '' ); if ( 0 === value.length ) { context.report( arg, rule.ERROR_MESSAGE ); } } );
const isInternalImport = node => { let source = ''; if (node.type === 'Variable') { source = node.node.init.arguments[0].value; } else if (node.type === 'ImportBinding') { source = node.parent.source.value; } return ( !source.includes('node_modules') && (source.startsWith('.') || source.startsWith('/')) ); }
// Check that the given call expression is `isEnabled( 'flag' )` // and return the `flag` literal value. const isNamedCall = ( parser, methodName, expr ) => { return methodName && parser.evaluate( methodName ).identifier === 'imported var' && expr.callee.type === 'Identifier' && expr.callee.name === methodName && expr.arguments.length === 1 && expr.arguments[ 0 ].type === 'Literal' ? expr.arguments[ 0 ].value : null; }