How to use the codemod-cli.jscodeshift function in codemod-cli

To help you get started, we’ve selected a few codemod-cli 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 ember-codemods / ember-test-helpers-codemod / transforms / integration / transforms / text.js View on Github external
'use strict';

const { getParser } = require('codemod-cli').jscodeshift;
const { createFindExpression, isJQuerySelectExpression, addImportStatement, writeImportStatements } = require('../../utils');

/**
 * Creates a `find(selector).textContent` expression
 *
 * @param j
 * @param findArgs
 * @returns {*}
 */
function createExpression(j, findArgs) {
  return j.memberExpression(
    createFindExpression(j, findArgs),
    j.identifier('textContent')
  );
}
github ember-codemods / ember-test-helpers-codemod / transforms / integration / transforms / attr.js View on Github external
'use strict';

const { getParser } = require('codemod-cli').jscodeshift;
const { createFindExpression, createPropExpression, isJQuerySelectExpression, addImportStatement, writeImportStatements } = require('../../utils');

/**
 * Creates a `find(selector).getAttribute(attr)` expression
 *
 * @param j
 * @param findArgs
 * @param attr
 * @returns {*}
 */
function createAttributeExpression(j, findArgs, attr) {
  return j.callExpression(
    j.memberExpression(
      createFindExpression(j, findArgs),
      j.identifier('getAttribute')
    ), [attr]
github ember-codemods / ember-test-helpers-codemod / transforms / integration / transforms / get.js View on Github external
'use strict';

const { getParser } = require('codemod-cli').jscodeshift;
const {
  createFindAllExpression,
  isJQuerySelectExpression,
  addImportStatement,
  writeImportStatements,
} = require('../../utils');

/**
 * Creates a `findAll(selector)[0]` expression
 *
 * @param j
 * @param findArgs
 * @param indexArg
 * @returns {*}
 */
function createExpression(j, findArgs, indexArg) {
github ember-codemods / ember-test-helpers-codemod / transforms / integration / transforms / click.js View on Github external
'use strict';

const { getParser } = require('codemod-cli').jscodeshift;
const { createClickExpression, makeParentFunctionAsync, isJQuerySelectExpression, addImportStatement, writeImportStatements } = require('../../utils');

/**
 * Check if `node` is a `this.$(selector).click()` expression
 *
 * @param j
 * @param node
 * @returns {*|boolean}
 */
function isJQueryExpression(j, path) {
  let node = path.node;
  return j.CallExpression.check(node)
    && j.MemberExpression.check(node.callee)
    && isJQuerySelectExpression(j, node.callee.object, path)
    && j.Identifier.check(node.callee.property)
    && node.callee.property.name === 'click';
github ember-codemods / ember-test-helpers-codemod / transforms / find / index.js View on Github external
'use strict';

const { getParser } = require('codemod-cli').jscodeshift;
const { createQuerySelectorExpression, createQuerySelectorAllExpression } = require('../utils');

/**
 * Transform find/findAll to this.element.querySelector/-All
 *
 * @param file
 * @param api
 * @returns {*|string}
 */
function transform(file, api) {
  let source = file.source;
  let j = getParser(api);
  let root = j(source);

  let importStatement = root.find(j.ImportDeclaration, {
    source: { value: '@ember/test-helpers' }
github ember-codemods / ember-test-helpers-codemod / transforms / acceptance / transforms / get-value.js View on Github external
'use strict';

const { getParser } = require('codemod-cli').jscodeshift;
const { createFindExpression, isFindExpression, addImportStatement, writeImportStatements } = require('../../utils');

/**
 * Creates a `find(selector).value` expression
 *
 * @param j
 * @param findArgs
 * @returns {*}
 */
function createExpression(j, findArgs) {
  return j.memberExpression(
    createFindExpression(j, findArgs),
    j.identifier('value')
  );
}
github ember-codemods / ember-test-helpers-codemod / transforms / integration / transforms / key-event.js View on Github external
'use strict';

const { getParser } = require('codemod-cli').jscodeshift;
const { migrateSelector, makeParentFunctionAsync, isJQuerySelectExpression, addImportStatement, writeImportStatements } = require('../../utils');

/**
 * Creates a `await keyEvent(selector, eventName, keyCode)` expression
 *
 * @param j
 * @param selector
 * @param eventName
 * @param keyCode
 * @returns {*}
 */
function createExpression(j, selector, eventName, keyCode) {
  return j.awaitExpression(
    j.callExpression(
      j.identifier('keyEvent'),
      [migrateSelector(j, selector), eventName, keyCode]
github ember-codemods / ember-test-helpers-codemod / transforms / native-dom / index.js View on Github external
'use strict';

const { getParser } = require('codemod-cli').jscodeshift;
const { addImportStatement, writeImportStatements } = require('../utils');

const importMigrations = [
  'click',
  'find',
  'findAll',
  'fillIn',
  'focus',
  'blur',
  'triggerEvent',
  ['keyEvent', 'triggerKeyEvent'],
  'waitFor',
  'waitUntil',
  'currentURL',
  'currentRouteName',
  'visit'
github ember-codemods / ember-test-helpers-codemod / transforms / integration / transforms / trigger.js View on Github external
'use strict';

const { getParser } = require('codemod-cli').jscodeshift;
const { makeParentFunctionAsync, createTriggerExpression, createClickExpression, isJQuerySelectExpression, addImportStatement, writeImportStatements } = require('../../utils');

/**
 * Check if `node` is a `this.$(selector).trigger(eventName)` expression
 *
 * @param j
 * @param node
 * @returns {*|boolean}
 */
function isJQueryExpression(j, path) {
  let node = path.node;
  return j.CallExpression.check(node)
    && j.MemberExpression.check(node.callee)
    && isJQuerySelectExpression(j, node.callee.object, path)
    && j.Identifier.check(node.callee.property)
    && node.callee.property.name === 'trigger'
github ember-codemods / ember-3x-codemods / transforms / jquery-apis / index.js View on Github external
const { getParser } = require('codemod-cli').jscodeshift;
const { getOptions } = require('codemod-cli');

module.exports = function transformer(file, api) {
  const j = getParser(api);
  const options = getOptions();
  const root = j(file.source);

  root
    .find(j.CallExpression, {
      callee: {
        object: {
          callee: {
            object: {
              type: "ThisExpression"
            },
            property: {

codemod-cli

a command line tool for generating, testing, and publishing codemods

MIT
Latest version published 3 years ago

Package Health Score

45 / 100
Full package analysis