Skip to content

An prettier plugin that simply sorts the objects returned by a function

Notifications You must be signed in to change notification settings

momei-LJM/prettier-plugin-sort-return

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Installation

npm i prettier-plugin-sort-return -D

Use

Add prettier-plugin-sort-return to your .prettierrc file:

export default {
  //...
  plugins: ["prettier-plugin-sort-return"],
};

Example

export const fn = () => {
  const NOT_NULL_CONST = "NOT_NULL_CONST";
  const NOT_NULL_CONST2 = "NOT_NULL_CONST2";
  const SELECT_NOT_NULL_CONST = "SELECT_NOT_NULL_CONST";

  const a = 1;
  const foo = 2;
  const bar = 3;
  const baz = 4;

  return {
    NOT_NULL_CONST,
    NOT_NULL_CONST2,
    foo,
    baz,
    SELECT_NOT_NULL_CONST,
    bar,
    a,
    subObj: {
      NOT_NULL_CONST,
      NOT_NULL_CONST2,
      foo,
      baz,
      SELECT_NOT_NULL_CONST,
      bar,
      a,
    },
  };
};
// formatted:
export const fn = () => {
  const NOT_NULL_CONST = "NOT_NULL_CONST";
  const NOT_NULL_CONST2 = "NOT_NULL_CONST2";
  const SELECT_NOT_NULL_CONST = "SELECT_NOT_NULL_CONST";

  const a = 1;
  const foo = 2;
  const bar = 3;
  const baz = 4;

  return {
    a,
    foo,
    baz,
    bar,
    subObj: {
      a,
      foo,
      baz,
      bar,
      NOT_NULL_CONST,
      NOT_NULL_CONST2,
      SELECT_NOT_NULL_CONST,
    },
    NOT_NULL_CONST,
    NOT_NULL_CONST2,
    SELECT_NOT_NULL_CONST,
  };
};

About

An prettier plugin that simply sorts the objects returned by a function

Resources

Stars

Watchers

Forks

Packages

No packages published