Skip to content

Releases: nicoespeon/abracadabra

Make it Generic vol. 2 🏭

18 May 22:49
Compare
Choose a tag to compare

Added

  • "Extract Generic Type" now works on function declarations.

Make it Generic 🏭

01 May 21:58
Compare
Choose a tag to compare

Added

  • [Extract Generic Type] To turn TS types into generics with a simple shortcut. Works like "Extract Variable".

It's limited to interfaces for now.

  • [Convert Switch to If/Else] To reverse Convert If/Else to Switch refactoring. Thanks to @delaaxe.

Fixed

  • Extract the instantiated class instead of the Identifier when cursor is on Identifier. Given this code:
console.log(new Error("It failed"));

With the cursor on Error, previous version of Abracadabra would have produced:

const extracted = Error;
console.log(new extracted("It failed"));

Which is not what you'd expect. Thus, it will now produce:

const extracted = new Error("It failed");
console.log(extracted);

Back in Black 🎸

10 Apr 14:20
Compare
Choose a tag to compare

Added

  • Get "Convert to Template Literal" back for the only scenario VS Code doesn't handle natively: simple strings. So you can convert a simple string into a template literal again, which is really convenient!

Fixed

  • Quick Fixes used to log errors when code couldn't be parsed. This is not useful, so they don't anymore!

Cover up that folder… 🙈

30 Mar 12:37
Compare
Choose a tag to compare

Removed (= Breaking)

  • Removed "Convert to Template Literal" refactoring. This is now natively include in VS Code with a similar, great developer experience (e.g. you can trigger the Quick Fix wherever your cursor is). We're happy of this and there's no point in providing a duplicate implementation of it 👐

Changed

  • (Breaking) We stopped proposing "Convert to Pure Component" as a Quick Fix. The refactoring can still be executed through the Command Palette.
  • Improved the extension performances when proposing Quick Fixes, thanks to @visusnet hard work! Since that occurs anytime you move the cursor, it makes a great difference for your machine. Especially if you work on large files 🚀

Added

  • [New Refactoring] Remove Braces from If Statement, thanks to @automatensalat
  • A new setting abracadabra.ignoredFolders that you can use to disable the extension Quick Fixes in specified folders. Default is ["node_modules", "build", "dist"].

Fixed

  • "Merge if statements" and "Add braces to if statements" were proposed, even when the refactoring was not applicable. This is now fixed.

The Class Without an Interface 🎭

20 Feb 12:52
Compare
Choose a tag to compare

Fixed

  • Convert to Template Literal now works on JSX attributes which were not already wrapped with braces. Concretely, <MyComponent prop="test" /> will now produce <MyComponent prop={test} /> instead of failing.
  • Don't propose Convert to Template Literal on imports

Added

  • [New Refactoring] Add Braces to JSX Attribute
  • [New Refactoring] Remove Braces from JSX Attribute
  • [New Refactoring] Extract Interface (TS specific)

Keep 'em simple 🌱

15 Jan 02:26
Compare
Choose a tag to compare

Added

  • [New Refactoring] Simplify Ternary
  • [New Refactoring] Add Braces to If Statement

Finding good shortcuts is hard 🤪

20 Dec 11:27
Compare
Choose a tag to compare

Added

  • [New Refactoring] Convert to Pure Component (React specific)

Changed

  • (Breaking) So… Move Statement Up/Down keybinding was conflicting with VS Code native shortcuts on Mac OS too. It was ⌘ ⇧ ↑/↓, now it's Alt + Shift + U / D for everyone.

Extract Variable now destructures member expressions properties

Consider the following code:

console.log(session.user.address);

Before, extracting address would have produced:

const address = session.user.address;
console.log(address);

This was fine… But it could be optimized. From our own experience, we always destructure the address property after the extraction.

Thus, from now on, extracting address will produce:

const { address } = session.user;
console.log(address);

Since you end up renaming the symbol, you can provide a different name than address and it will work.

Fixed

  • Don't Convert For-Loop to ForEach if counter doesn't start from 0

A better shortcut 🛣

12 Dec 17:18
Compare
Choose a tag to compare

Changed

  • (Breaking) Changed keybinding of Move Statement Up/Down on Windows and Linux since it conflicts with VS Code native shortcuts. It was Ctrl + Shift + ↑ / ↓, now it's Alt + Shift + U / D
  • Configure Alt ↵ keybinding to trigger VS Code Quick Fixes, so it's more convenient to use the extension by default.

Convert If/Else to Ternary handles implicit else return statements

Useful when dealing with guard clauses patterns.

Consider the following code:

function calculateYear(selectedDates) {
  if (selectedDates[0].getMonth() === 0) {
    return selectedDates[0].getFullYear() - 1;
  }

  return selectedDates[0].getFullYear();
}

Before this change, you couldn't convert this to a ternary directly, since the else statement is not explicit. But it's still here. It's a typical guard clause pattern.

Now, Abracadabra will recognize this pattern and it will produce the expected code:

function calculateYear(selectedDates) {
  return selectedDates[0].getMonth() === 0
    ? selectedDates[0].getFullYear() - 1
    : selectedDates[0].getFullYear();
}

Fixed

  • Inline Variable now handles destructured "this" expressions correctly (e.g. you can inline const { id } = this.user).

Big head, shorthand 🦖

28 Nov 23:46
Compare
Choose a tag to compare

Changed

Extract Variable creates shorthand object properties

Consider the following code:

console.log({
  foo: "bar"
});

Before, extracting the "bar" string literal would have produced:

const extracted = "bar";
console.log({
  foo: extracted
});

This worked. But in practice, we realized that we continue modifying the code manually to get there:

const foo = "bar";
console.log({
  foo
});

So now, this is what Extract Variable will generate by default. Obviously, you'll have the capability to rename foo directly, so you can adapt the name if you want to provide another one.

We believe this will make extracting object properties even more fluid.

Fixed

  • Extract Variable won't extract type annotation as it doesn't handle them properly yet.

Keep movin' 🏃‍♀️

21 Nov 23:09
Compare
Choose a tag to compare

Changed

  • Extract Variable now extracts JSX Attributes (e.g. <Header title="Home" /> will extract "Home" if cursor is on it).
  • Extract Variable now suggest a better variable name when you extract member expressions (e.g. const name = this.props.location.name instead of const extracted = this.props.location.name).
  • Move Statements now work on object methods, class methods and class properties!

Fixed

  • Extract Variable don't suggest an invalid variable name when extracting a string starting with a number.
  • Stop jumping cursor to the end of the file when performing some refactorings. That was a regression introduced when we improve cursor scrolling on Move Statements, in v1.0.0 😅