Code Monkey home page Code Monkey logo

vscodemod's People

Stargazers

Daniel Bodnar avatar  avatar Austin S avatar Pratik Bhonsle avatar hong avatar Alan Lins avatar Daniel Rodríguez Rivero avatar Matthew Lindsey avatar Lucas N. Munhoz avatar Tucker Bickler avatar Nico Koelewijn avatar  avatar Ahmed Hassanein avatar Wayne Maurer avatar Evgenii Karagodin avatar Mike Joyce avatar marky avatar Oliver Joseph Ash avatar Sigurd Fosseng avatar Will Klein avatar Pascal Iske avatar AMAGI / Jun Yuri avatar Dmitriy avatar David Sancho avatar bokuweb avatar Gleb Bahmutov avatar Aria avatar Sabrican Ozan avatar İsmail Codar avatar Chris Witko avatar

Watchers

Kenneth Devik avatar Mikael Brevik avatar James Cloos avatar Alan Lins avatar Nico Koelewijn avatar Pascal Iske avatar Sebastian "Sebbie" Silbermann avatar  avatar

vscodemod's Issues

Add ability to do dry-runs

Would be great to have something like a preview of the transformation before you actually do it. For instance as a popup similar to the "find all references" preview. This would be handy in cases where you run large modifications.

How to install?

Hey @mikaelbr!

I tried to find this on the VSCode extension marketplace to no avail. Is it not on there yet?

Thanks,
Olly

Make more codemods

For the time being, this project is accumulating code transformations. When we have enough and stable enough codemods, the project can be published. If you have some manual transformations you often do while programming, it might belong as a automatic codemod in this project! Try coding a transformation and submit it as a pull request!

How?

You cna use jscodeshift to write transformations. Check out this repo for a super quick intro. Or the jscodeshift repo for documentation. ASTExplorer.net is a great tool to use while writing transformations. Check it out.

Add infrastructure for tests

Add some sort of infrastructure for running tests on codemods. Maybe Jests snapshot tests would be a good fit here. It isn't as good when writing transformations, but works great to illustrate before and after, also preventing regression errors. Which can be likely with these types of codemods.

Passing cursor position/selection range to custom codemod that operates on entire file

I'm in the process of switching from Atom to VSCode. I had a bunch of custom codemods at my disposal in Atom that I'm planning to get working in VSCode, for instance: https://github.com/jedwards1211/material-ui-codemorphs

For convenience, my addStyles codemod in that package doesn't require the user to select the component to be modified; instead it can just determine which component contains the cursor position by using my https://github.com/jedwards1211/jscodeshift-paths-in-range package.

Furthermore, it wouldn't be sufficient for addStyles to transform only the selected code, because it also has to add import statements to the top of the file, and potentially rename some identifiers. But it has to know the cursor position/selection to determine which component to modify.

My own codemods for adding block statements to arrow functions also worked this way; it's a lot less hassle to just put the cursor inside the function than selecting the whole thing.

I was planning on making an extension for running codemods, then I found your extension. This wouldn't currently satisfy my needs, but I figured I would talk to you about this before making my own extension. Basically it would have to pass the selection range (or cursor position) to the transform via the options argument. This will make it possible to do more complex transforms in the future than just operating on selected code.

Codemod suggestion: Add BlockStatement to arrow function

Something like this:

function transform(file, api, options) {
  const j = api.jscodeshift;

  const printOptions = options.printOptions || { quote: 'single' };
  const root = j(file.source);

  function createFunctionExpression (fn) {
    return j.arrowFunctionExpression(fn.params, j.blockStatement([j.returnStatement(fn.body)]));
  };

  const replacedCallbacks =
    root
      .find(j.ArrowFunctionExpression)
      .filter(path => path.value.body.type !== "BlockStatement" )
      .forEach(path => j(path).replaceWith(createFunctionExpression(path.value)))
      .size() > 0;

  return replacedCallbacks ? root.toSource(printOptions) : null;
}

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.