tidyclass
v0.3.0
Published
Sorts classes and methods alphabetically
Readme
tidyclass
🧹 tidyclass - A CLI tool to automatically sort TypeScript class members in a structured order.
Installation
You can install tidyclass globally or use it as a local dependency in your project.
npm install -g tidyclassor
npm install --save-dev tidyclassUsage
[!TIP]
It's recommended to commit your work before running the script.
[!NOTE]
If you installed locally to your project, use
npx tidyclass.
To sort a single TypeScript file, run:
tidyclass path/to/file.tsIf no file is specified, tidyclass will process all TypeScript files in the project:
tidyclassIf you want to format the sorted files with Biome, use -b or --biome option, or with Prettier, use the -p or --prettier option:
tidyclass -bOptions
Opt classes out: To opt certain classes out of the member sorting, add the following JSDoc comment to the class.
/**
* @internal_sort skip
*/
class ThisClassWillNotBeSorted| CLI Option | Description |
|-----------------|---------------------------------------------------------------|
| -b, --biome | Run Biome formatting on affected files after sorting |
| -p, --prettier | Run Prettier formatting on affected files after sorting |
Sorting Order
Tidyclass organizes class members in the following structured order:
- Static public variables
- Static private variables
- Static public methods
- Static private methods
- Public instance variables
- Private instance variables
- Constructor
- Public instance methods
- Private instance methods
Each category is sorted alphabetically to ensure consistency. If the class structure changes, tidyclass updates it while maintaining logical order.
Example
Before running tidyclass:
class MyClass {
public rivetingFunc() {}
private instanceVarB = 2;
static private staticFuncB() {}
public instanceVarA = 1;
private funcX() {}
private static staticVarB = 20;
private static staticVarA = 10;
public static staticFuncAA() {}
static public staticVarAB = 5;
private funcC() {}
public funcA() {}
constructor() {}
static private staticFuncA() {}
}After running tidyclass (with formatting on):
class MyClass {
public static staticVarAB = 5;
private static staticVarA = 10;
private static staticVarB = 20;
public static staticFuncAA() {}
private static staticFuncA() {}
private static staticFuncB() {}
public instanceVarA = 1;
private instanceVarB = 2;
constructor() {}
public funcA() {}
public rivetingFunc() {}
private funcC() {}
private funcX() {}
}License
Apache 2.0
