Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ducktordanny/eslint-plugin-ng-module-sort
Sort Angular and NestJS module imports, declarations, exports, controls, etc.
https://github.com/ducktordanny/eslint-plugin-ng-module-sort
angular angular-eslint angular2 eslint eslint-plugin eslint-rule eslint-rules nestjs sort
Last synced: 26 days ago
JSON representation
Sort Angular and NestJS module imports, declarations, exports, controls, etc.
- Host: GitHub
- URL: https://github.com/ducktordanny/eslint-plugin-ng-module-sort
- Owner: ducktordanny
- License: mit
- Created: 2023-04-09T23:46:03.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-06-17T20:52:17.000Z (5 months ago)
- Last Synced: 2024-10-11T16:01:52.516Z (27 days ago)
- Topics: angular, angular-eslint, angular2, eslint, eslint-plugin, eslint-rule, eslint-rules, nestjs, sort
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/eslint-plugin-ng-module-sort
- Size: 78.1 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# eslint-plugin-ng-module-sort
> Sort Angular and NestJS module imports, declarations, exports, controls, etc. Make it easier to find modules in the arrays by having an auto sort.
## Installation
[![NPM](https://img.shields.io/npm/v/eslint-plugin-ng-module-sort.svg)](https://www.npmjs.com/package/eslint-plugin-ng-module-sort)
You'll first need to install [ESLint](https://eslint.org/):
```sh
npm i eslint --save-dev
```Next, install `eslint-plugin-ng-module-sort`:
```sh
npm install eslint-plugin-ng-module-sort --save-dev
```## Usage
Add `ng-module-sort` to the plugins section of your `.eslintrc` configuration file. You can omit the `eslint-plugin-` prefix:
```json
{
"plugins": ["ng-module-sort"]
}
```Then configure the rules you want to use under the rules section.
## Rules
### decorator-array-items
With this rule you can detect unsorted arrays of imports, declarations, providers, exports, controllers and bootstrap in the following Angular and NestJS decorators:
- NgModule
- Component
- Pipe
- Decorator
- Module```json
{
"rules": {
"ng-module-sort/decorator-array-items": [
"error",
{
"reverseSort": false,
"extraDecorators": [],
"extraProperties": []
}
]
}
}
```A few example of it:
- Error
```ts
import {Component} from '@angular/core';@Component({
selector: 'app-example',
template: '',
standalone: true,
imports: [ // Run `eslint --fix .` to sort the members of imports.
MatButtonModule,
SharedModule,
CommonModule,
MagicComponent,
],
})
```- Fix with default options
```ts
import {Component} from '@angular/core';@Component({
selector: 'app-example',
template: '',
standalone: true,
imports: [
CommonModule,
MagicComponent,
MatButtonModule,
SharedModule,
],
})
```- With option `"reverseSort": true`
```ts
import {Component} from '@angular/core';@Component({
selector: 'app-example',
template: '',
standalone: true,
imports: [
SharedModule,
MatButtonModule,
MagicComponent,
CommonModule,
],
})
```- By using options `extraDecorator: ['YourDecorators']` and `extraProperties: ['yourProperties']` you can extend the default list that is used for the checks.
```ts
import {Component} from '@angular/core';@YourDecorators({
yourProperties: [
Apple,
Banana,
Paprika,
SomethingElse,
],
})
```The default options can be found [here](./lib/constants.ts).
### decorator-properties
This rule is still in progress, but basically it will check if the properties in the above decorators are sorted, and provide an autofix to sort them.