ahutchings / atom-refactoring-codemods

atom plugin that provides refactoring support for JavaScript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

atom-refactoring-codemods package

Build Status Dependency Status devDependency Status

JavaScript refactoring support for Atom

This package allows you to rename a file and have all internal relative imports/requires paths be updated to new location (if moved to a new dir) and all dependent files in your projects imports/requires be updated with your new file path.

This Atom package is a work in progress. The goal is to provide refactoring support to Atom, during file rename, file or directory move, and renaming of exported module.

The UI is a work in progress, all critiques are welcome - please read the Contribute section below if you are interested in making this package better.

Usage

Right click on any .js file to expose the Rename (with refactor support) option. Selecting this option will open a modalPanel that will allow the user to update the file path/name. Pressing Enter Key will apply the file rename/move and then run a codemod on the root folder.

How it all works

atom-refactoring-codemods is a UI package that executes jscodeshift codemods in memory. I've written 2 refactoring-codemods that do the heavy lifting of building the AST and updating the sources to match.

import-declaration-transform updates all dependent import/require paths when a file has been renamed/moved. This codemod takes the previousPath and newPath of the file and then all dependent import/require paths will be updated to match the new file name/location.

Example:

import foo from './bar';

becomes

import foo from './new/path/to/bar';

import-specifier-transform updates all dependent import/require variables when a file export been renamed. This codemod takes the previousExportName and newExportName for a given file and then all dependent import/require variables will be updated to match the new file export name.

Example:

import foo from './bar';

foo();

becomes

import fooPrime from './bar';

fooPrime();

Progress

  • Single File Rename with refactors
  • Directory Rename with refactors
  • Export Rename with refactors
  • Interactive Mode - show a panel with all refactors possible let user select/deselect files to update

Install

apm i atom-refactoring-codemods

Develop

> cd atom-refactoring-codemods
> npm i
> apm link

Contribute

  • Please open an issue before submitting a PR
  • All PR's should be accompanied wth tests 🚀

About

atom plugin that provides refactoring support for JavaScript

License:MIT License


Languages

Language:JavaScript 98.8%Language:CSS 1.2%