GithubHelp home page GithubHelp logo

rajasegar / jscodeshift-collections Goto Github PK

View Code? Open in Web Editor NEW
17.0 3.0 1.0 1.08 MB

Collections for some AST nodes in jscodeshift

JavaScript 100.00%
jscodeshift codemod codemods collection collections ast hacktoberfest hacktoberfest-accepted

jscodeshift-collections's Introduction

jscodeshift-collections

Build and Deploy npm version Coverage Status semantic-release Conventional Commits

Some more Collections for jscodeshift for easy and terse api for writing Codemods

Install

npm install jscodeshift-collections

List of collections

Usage

const jscsCollections = require('jscodeshift-collections');

module.exports = function(fileInfo, api) {
  const j =  api.jscodeshift;

  jscsCollections.registerCollections(j);

  return j(fileInfo.source)
    .findFunctionDeclarations('foo')
    .renameTo('bar')
    .toSource();
}

Example

Say for example, if you want to rename a function declaration foo to bar

Transform with new Collection API

j.findFunctionDeclarations('foo')
 .renameTo('bar')

Before

function foo() {
}

After

function bar() {
}

List of Collections:

FunctionDeclaration

// Find all function declarations
j.findFunctionDeclarations()

// Find all function declarations with name=foo and rename them to bar
j.findFunctionDeclarations('foo')
    .renameTo('xyz');

// Find and remove params
  j.findFunctionDeclarations('bar')
    .removeParam('a');

// Find and add params
  j.findFunctionDeclarations('bar')
    .addParam('d');

CallExpression

// Find all call expressions
  j.findCallExpressions();

// Find all member expressions
  j.findCallExpressions('foo.bar');


// Find all nested member expressions
  j.findCallExpressions('foo.bar.baz');

// Find and rename call expressions
  j.findCallExpressions('foo')
  .renameTo('xyz');

// Find and rename member expressions
  j.findCallExpressions('foo')
  .renameTo('foo.bar');

//  Find and remove params
  j.findCallExpressions('bar')
  .removeParam('a');

// Find and add params
  j.findCallExpressions('bar')
  .addParam('d');

ImportDeclaration

// Find all import declarations
  j.findImportDeclarations();

// Find and rename
  j.findImportDeclarations('a')
  .renameTo('xyz');

// Find and remove specifiers
  j.findImportDeclarations('a')
  .removeSpecifier('a');

// Find and add specifiers
  j.findImportDeclarations('a')
  .addSpecifier('c');

ClassDeclaration

// Find all class declarations
j.findClassdeclarations();

// Find and rename
j.findClassDeclarations('foo').renameTo('bar')

jscodeshift-collections's People

Contributors

rajasegar avatar renovate-bot avatar renovate[bot] avatar semantic-release-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

jscodeshift-collections's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Rate-Limited

These updates are currently rate-limited. Click on a checkbox below to force their creation now.

  • chore(deps): update dependency eslint to v8.57.0
  • fix(deps): update dependency jscodeshift to ^0.15.0
  • fix(deps): update dependency recast to ^0.23.0
  • chore(deps): update actions/checkout action to v4
  • chore(deps): update actions/setup-node action to v4
  • chore(deps): update dependency @release-it/conventional-changelog to v8
  • chore(deps): update dependency eslint to v9
  • chore(deps): update dependency eslint-config-prettier to v9
  • chore(deps): update dependency eslint-plugin-prettier to v5
  • chore(deps): update dependency prettier to v3
  • chore(deps): update dependency semantic-release to v23
  • ๐Ÿ” Create all rate-limited PRs at once ๐Ÿ”

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/ci.yml
  • actions/checkout v3
  • actions/setup-node v3
  • actions/checkout v3
  • actions/setup-node v3
  • actions/checkout v3
  • actions/setup-node v3
.github/workflows/pull-requests.yml
  • actions/checkout v3
  • actions/setup-node v3
npm
package.json
  • jscodeshift ^0.14.0
  • recast ^0.22.0
  • @release-it/conventional-changelog 5.1.1
  • @semantic-release/changelog 6.0.2
  • @semantic-release/git 10.0.1
  • eslint 8.31.0
  • eslint-config-prettier 8.6.0
  • eslint-plugin-node 11.1.0
  • eslint-plugin-prettier 4.2.1
  • jest 29.3.1
  • prettier 2.8.1
  • semantic-release 20.0.2

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.