Skip to content
This repository was archived by the owner on May 1, 2023. It is now read-only.

Commit 372a41a

Browse files
committed
first commit
0 parents  commit 372a41a

File tree

6 files changed

+770
-0
lines changed

6 files changed

+770
-0
lines changed

LICENSE.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2018 Coralie Reuter
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# import-sort-style-angular
2+
3+
A personal style for [import-sort](https://github.com/renke/import-sort) that is focused on angular.
4+
5+
```
6+
// Absolute modules with side effects (not sorted because order may matter)
7+
import "a";
8+
import "c";
9+
import "b";
10+
11+
// Relative modules with side effects (not sorted because order may matter)
12+
import "./a";
13+
import "./c";
14+
import "./b";
15+
16+
// Modules from the Node.js "standard" library sorted by name
17+
import {readFile, writeFile} from "fs";
18+
import * as path from "path";
19+
20+
// angular modules
21+
import { HttpClientModule } from '@angular/common/http';
22+
import { ErrorHandler, NgModule } from '@angular/core';
23+
import { BrowserModule } from '@angular/platform-browser';
24+
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
25+
26+
// ngxs modules
27+
import { NgxsReduxDevtoolsPluginModule } from '@ngxs/devtools-plugin';
28+
import { NgxsFormPluginModule } from '@ngxs/form-plugin';
29+
import { NgxsLoggerPluginModule } from '@ngxs/logger-plugin';
30+
import { NgxsRouterPluginModule } from '@ngxs/router-plugin';
31+
import { NgxsStoragePluginModule } from '@ngxs/storage-plugin';
32+
import { NgxsModule } from '@ngxs/store';
33+
34+
// barrel modules
35+
import { LoadingIndicatorModule } from '@app/lib/modules/loading-indicator';
36+
import { NotificationModule } from '@app/lib/modules/notification';
37+
38+
// First-party modules sorted by relative depth and then by name
39+
import { AppComponent } from '../app.component';
40+
41+
import { HomeComponent } from './home.component';
42+
```

lib/index.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import { IStyleAPI, IStyleItem } from 'import-sort-style';
2+
export default function (styleApi: IStyleAPI): Array<IStyleItem>;

lib/index.js

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
function default_1(styleApi) {
4+
const { alias, and, dotSegmentCount, hasNoMember, hasOnlyNamedMembers, isNodeModule, isAbsoluteModule, isRelativeModule, moduleName, naturally, not, unicode } = styleApi;
5+
const isAngularModule = imported => Boolean(imported.moduleName.match(/^@angular\//));
6+
const isNgxsModule = imported => Boolean(imported.moduleName.match(/^@ngxs\//));
7+
const isScopedAppModule = imported => Boolean(imported.moduleName.match(/^@app\//));
8+
const isScopedModule = imported => Boolean(imported.moduleName.startsWith('@'));
9+
const isCssModule = imported => Boolean(imported.moduleName.match(/\.s?css$/));
10+
const isRootModule = imported => Boolean(imported.moduleName.match(/^~\//));
11+
const isLocalModule = imported => Boolean(imported.moduleName.match(/^\.\//));
12+
return [
13+
// import "foo"
14+
{ match: and(hasNoMember, isAbsoluteModule) },
15+
{ separator: true },
16+
// import "./foo" or import "~/foo"
17+
{ match: and(hasNoMember, isRelativeModule, not(isCssModule)) },
18+
{ match: and(hasNoMember, isRootModule, not(isCssModule)) },
19+
{ separator: true },
20+
// import ... from "fs";
21+
{
22+
match: isNodeModule,
23+
sort: moduleName(naturally),
24+
sortNamedMembers: alias(naturally)
25+
},
26+
{ separator: true },
27+
// import ... from "foo";
28+
{
29+
match: and(isAbsoluteModule, not(isScopedModule)),
30+
sort: moduleName(naturally),
31+
sortNamedMembers: alias(unicode)
32+
},
33+
{ separator: true },
34+
// import {...} "@angular/...";
35+
{
36+
match: isAngularModule,
37+
sort: moduleName(naturally),
38+
sortNamedMembers: alias(unicode)
39+
},
40+
{ separator: true },
41+
// import ... "@ngxs/...";
42+
{
43+
match: isNgxsModule,
44+
sort: moduleName(naturally),
45+
sortNamedMembers: alias(unicode)
46+
},
47+
{ separator: true },
48+
// import ... "@app/...";
49+
{
50+
match: isScopedAppModule,
51+
sort: moduleName(naturally),
52+
sortNamedMembers: alias(unicode)
53+
},
54+
{ separator: true },
55+
// import ... "@...";
56+
{
57+
match: and(isScopedModule, not(isAngularModule), not(isNgxsModule), not(isScopedAppModule)),
58+
sort: moduleName(naturally),
59+
sortNamedMembers: alias(unicode)
60+
},
61+
{ separator: true },
62+
// import ... from "../foo";
63+
{
64+
match: and(isRelativeModule, not(isCssModule), not(isLocalModule)),
65+
sort: [dotSegmentCount, moduleName(naturally)],
66+
sortNamedMembers: alias(unicode)
67+
},
68+
{ separator: true },
69+
// import ... from "./foo";
70+
{
71+
match: isLocalModule,
72+
sort: [dotSegmentCount, moduleName(naturally)],
73+
sortNamedMembers: alias(unicode)
74+
},
75+
{ separator: true },
76+
// import styles from "foo.(s)css";
77+
{
78+
match: isCssModule,
79+
sort: [dotSegmentCount, moduleName(naturally)],
80+
sortNamedMembers: alias(unicode)
81+
},
82+
{ separator: true },
83+
{ separator: true }
84+
];
85+
}
86+
exports.default = default_1;

0 commit comments

Comments
 (0)