Skip to content

Commit

Permalink
chore: add import lint plugin for sorting imports
Browse files Browse the repository at this point in the history
  • Loading branch information
manfredsteyer committed Sep 16, 2024
1 parent 671c2e7 commit 4a3c360
Show file tree
Hide file tree
Showing 62 changed files with 1,388 additions and 406 deletions.
20 changes: 19 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"root": true,
"ignorePatterns": ["**/*"],
"plugins": ["@nx"],
"plugins": ["import", "@nx"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
Expand All @@ -24,6 +24,24 @@
{
"argsIgnorePattern": "^_"
}
],
"import/order": [
"error",
{
"groups": [
"builtin",
"external",
"internal",
"parent",
"sibling",
"index"
],
"newlines-between": "always",
"alphabetize": {
"order": "asc",
"caseInsensitive": true
}
}
]
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
- main

jobs:
lint_and_test:
build_job:
runs-on: ubuntu-latest

steps:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ In case users have used multiple names, as appearing in the `git log`, use the `
{
[...]
"aliases": {
"jdoe": "John Doe",
"jdoe": "John Doe",
"janedoe": "Jane Doe"
}
[...]
Expand Down
20 changes: 11 additions & 9 deletions apps/backend/src/express.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
import express from 'express';
import path from 'path';
import fs from 'fs';
import { calcCoupling } from './services/coupling';
import path from 'path';
import { cwd } from 'process';

import express from 'express';

import { getCommitCount } from './infrastructure/git';
import { Limits } from './model/limits';
import { Options } from './options/options';
import { calcChangeCoupling } from './services/change-coupling';
import { calcCoupling } from './services/coupling';
import { inferFolders } from './services/folders';
import { calcModuleInfo } from './services/module-info';
import { calcTeamAlignment } from './services/team-alignment';
import {
aggregateHotspots,
ComplexityMetric,
findHotspotFiles,
HotspotCriteria,
} from './services/hotspot';
import { calcChangeCoupling } from './services/change-coupling';
import { Options } from './options/options';
import { Limits } from './model/limits';
import { isStale, updateLogCache } from './services/log-cache';
import { getCommitCount } from './infrastructure/git';
import { calcModuleInfo } from './services/module-info';
import { calcTeamAlignment } from './services/team-alignment';

export function setupExpress(options: Options) {
const app = express();
Expand Down
4 changes: 3 additions & 1 deletion apps/backend/src/infrastructure/config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import fs from 'fs';
import path from 'path';
import { cwd } from 'process';

import { Config } from '../model/config';
import { Options } from '../options/options';
import fs from 'fs';

import { DETECTIVE_DIR } from './paths';

const initConfig: Config = {
Expand Down
9 changes: 6 additions & 3 deletions apps/backend/src/infrastructure/deps.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { Options } from '../options/options';
import { Deps } from '../model/deps';
import fs from 'fs';
import { cwd } from 'process';

import { getProjectData } from '@softarc/sheriff-core';
import { globSync } from 'fast-glob';

import { Deps } from '../model/deps';
import { Options } from '../options/options';

import { loadConfig } from './config';
import { cwd } from 'process';

const DEFAULT_ENTRIES = [
'src/main.ts',
Expand Down
3 changes: 2 additions & 1 deletion apps/backend/src/infrastructure/git.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { spawn, spawnSync } from 'child_process';
import * as fs from 'fs';

import { noLimits } from '../model/limits';
import { spawn, spawnSync } from 'child_process';

export function isRepo(): boolean {
return fs.existsSync('.git');
Expand Down
1 change: 1 addition & 0 deletions apps/backend/src/infrastructure/log.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as fs from 'fs';
import * as path from 'path';

import { DETECTIVE_DIR, LOG_FILE } from './paths';

const logFile = path.join(DETECTIVE_DIR, LOG_FILE);
Expand Down
1 change: 1 addition & 0 deletions apps/backend/src/infrastructure/tree-hash.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as fs from 'fs';
import * as path from 'path';

import { DETECTIVE_DIR, HASH_FILE } from './paths';

const hashFile = path.join(DETECTIVE_DIR, HASH_FILE);
Expand Down
6 changes: 3 additions & 3 deletions apps/backend/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/usr/bin/env node

import { parseOptions } from './options/parse-options';
import { setupExpress } from './express';
import { ensureConfig } from './infrastructure/config';
import { getEntryGlobs, inferDeps } from './infrastructure/deps';
import { isRepo } from './infrastructure/git';
import { openSync } from './utils/open';
import { setupExpress } from './express';
import { DETECTIVE_VERSION } from './infrastructure/version';
import { parseOptions } from './options/parse-options';
import { openSync } from './utils/open';

const options = parseOptions(process.argv.slice(2));

Expand Down
3 changes: 2 additions & 1 deletion apps/backend/src/options/validate-options.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Options } from './options';
import fs from 'fs';

import { Options } from './options';

export function validateOptions(options: Options) {
try {
if (!fs.existsSync(options.sheriffDump)) {
Expand Down
1 change: 1 addition & 0 deletions apps/backend/src/services/change-coupling.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { emptyConfig } from '../model/config';
import { Limits } from '../model/limits';
import { defaultOptions } from '../options/options';

import { calcChangeCoupling } from './change-coupling';

const now = new Date();
Expand Down
3 changes: 2 additions & 1 deletion apps/backend/src/services/coupling.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { emptyConfig } from '../model/config';
import { Deps } from '../model/deps';
import { defaultOptions } from '../options/options';

import { calcCoupling } from './coupling';
import { Deps } from '../model/deps';

const scopes = ['/booking', '/checkin', '/shared'];

Expand Down
9 changes: 5 additions & 4 deletions apps/backend/src/services/coupling.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Deps } from '../model/deps';
import { Options } from '../options/options';
import { loadConfig } from '../infrastructure/config';
import { loadDeps } from '../infrastructure/deps';
import { calcModuleInfo, ModuleInfo } from './module-info';
import { toPercent } from '../utils/to-percent';
import { Deps } from '../model/deps';
import { Options } from '../options/options';
import { getEmptyMatrix } from '../utils/matrix';
import { normalizeFolder } from '../utils/normalize-folder';
import { toPercent } from '../utils/to-percent';

import { calcModuleInfo, ModuleInfo } from './module-info';

export type CouplingResult = {
groups: string[];
Expand Down
3 changes: 2 additions & 1 deletion apps/backend/src/services/folders.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { emptyConfig } from '../model/config';
import { Deps } from '../model/deps';
import { defaultOptions } from '../options/options';

import { inferFolders } from './folders';
import { Deps } from '../model/deps';

const scopes = ['/booking', '/checkin', '/shared'];

Expand Down
2 changes: 1 addition & 1 deletion apps/backend/src/services/folders.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Options } from '../options/options';
import { loadDeps } from '../infrastructure/deps';
import { Options } from '../options/options';

export type Folder = {
name: string;
Expand Down
1 change: 1 addition & 0 deletions apps/backend/src/services/hotspot.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { emptyConfig } from '../model/config';
import { Limits } from '../model/limits';
import { defaultOptions } from '../options/options';

import {
aggregateHotspots,
findHotspotFiles,
Expand Down
11 changes: 5 additions & 6 deletions apps/backend/src/services/hotspot.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import path from 'path';
import * as fs from 'fs';
import path from 'path';

import { Options } from '../options/options';
import { LogBodyEntry, parseGitLog, ParseOptions } from '../utils/git-parser';
import { loadConfig } from '../infrastructure/config';
import { normalizeFolder, toDisplayFolder } from '../utils/normalize-folder';
import { Filter } from '../model/config';
import { Limits } from '../model/limits';

import { Options } from '../options/options';
import { calcCyclomaticComplexity } from '../utils/complexity';
import { countLinesInFile } from '../utils/count-lines';
import { Filter } from '../model/config';
import { LogBodyEntry, parseGitLog, ParseOptions } from '../utils/git-parser';
import { normalizeFolder, toDisplayFolder } from '../utils/normalize-folder';

export type ComplexityMetric = 'McCabe' | 'Length';

Expand Down
2 changes: 1 addition & 1 deletion apps/backend/src/services/log-cache.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { loadTreeHash, saveTreeHash } from '../infrastructure/tree-hash';
import { calcTreeHash, getGitLog } from '../infrastructure/git';
import { saveCachedLog } from '../infrastructure/log';
import { loadTreeHash, saveTreeHash } from '../infrastructure/tree-hash';
import { DETECTIVE_VERSION } from '../infrastructure/version';

export function isStale(): boolean {
Expand Down
1 change: 1 addition & 0 deletions apps/backend/src/services/team-alignment.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { emptyConfig } from '../model/config';
import { Limits } from '../model/limits';
import { defaultOptions, Options } from '../options/options';

import { calcTeamAlignment } from './team-alignment';

const now = new Date();
Expand Down
3 changes: 2 additions & 1 deletion apps/backend/src/utils/complexity.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as ts from 'typescript';
import * as fs from 'fs';

import * as ts from 'typescript';

export function calcCyclomaticComplexity(fileName: string): number {
const code = fs.readFileSync(fileName, 'utf-8');
return calcComplexityForCode(code);
Expand Down
5 changes: 3 additions & 2 deletions apps/backend/src/utils/git-parser.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { loadCachedLog } from '../infrastructure/log';
import { emptyConfig } from '../model/config';
import { LogEntry, parseGitLog, ParseOptions } from './git-parser';
import { getToday, subtractMonths, subtractSeconds } from '../utils/date-utils';
import { loadCachedLog } from '../infrastructure/log';

import { LogEntry, parseGitLog, ParseOptions } from './git-parser';

const today = getToday();
const past = subtractSeconds(subtractMonths(today, 1), 1);
Expand Down
8 changes: 5 additions & 3 deletions apps/backend/src/utils/git-parser.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import * as path from 'path';
import { Limits, noLimits } from '../model/limits';

import microMatch from 'micromatch';

import { loadCachedLog } from '../infrastructure/log';
import { getToday, subtractMonths } from '../utils/date-utils';
import { Filter } from '../model/config';
import microMatch from 'micromatch';
import { Limits, noLimits } from '../model/limits';
import { getToday, subtractMonths } from '../utils/date-utils';

type State = 'header' | 'body' | 'skip';

Expand Down
31 changes: 0 additions & 31 deletions apps/frontend/src/app/app.component.spec.ts

This file was deleted.

3 changes: 2 additions & 1 deletion apps/frontend/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Component, inject, OnInit } from '@angular/core';
import { RouterOutlet } from '@angular/router';
import { NavComponent } from './shell/nav/nav.component';

import { StatusStore } from './data/status.store';
import { NavComponent } from './shell/nav/nav.component';

@Component({
selector: 'app-root',
Expand Down
7 changes: 3 additions & 4 deletions apps/frontend/src/app/app.config.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { provideHttpClient } from '@angular/common/http';
import {
ApplicationConfig,
importProvidersFrom,
provideZoneChangeDetection,
} from '@angular/core';
import { provideRouter, withComponentInputBinding } from '@angular/router';

import { MatDialogModule } from '@angular/material/dialog';
import { provideAnimationsAsync } from '@angular/platform-browser/animations/async';
import { provideRouter, withComponentInputBinding } from '@angular/router';

import { routes } from './app.routes';
import { provideHttpClient } from '@angular/common/http';
import { provideAnimationsAsync } from '@angular/platform-browser/animations/async';
import { AppErrorHandler, provideErrorHandler } from './utils/error-handler';

export const appConfig: ApplicationConfig = {
Expand Down
7 changes: 4 additions & 3 deletions apps/frontend/src/app/app.routes.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Routes, ActivatedRoute } from '@angular/router';
import { Routes } from '@angular/router';

import { CouplingComponent } from './features/coupling/coupling.component';
import { GraphTypeData } from './model/graph-type';
import { ensureCache } from './shell/cache.guard';
import { HotspotComponent } from './features/hotspot/hotspot.component';
import { TeamAlignmentComponent } from './features/team-alignment/team-alignment.component';
import { GraphTypeData } from './model/graph-type';
import { AboutComponent } from './shell/about/about.component';
import { ensureCache } from './shell/cache.guard';

export const routes: Routes = [
{
Expand Down
3 changes: 2 additions & 1 deletion apps/frontend/src/app/data/cache.service.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { HttpClient } from '@angular/common/http';
import { inject, Injectable } from '@angular/core';
import { CacheStatus } from '../model/cache-status';
import { Observable } from 'rxjs';

import { CacheStatus } from '../model/cache-status';

@Injectable({ providedIn: 'root' })
export class CacheService {
private http = inject(HttpClient);
Expand Down
1 change: 1 addition & 0 deletions apps/frontend/src/app/data/config.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { HttpClient } from '@angular/common/http';
import { inject, Injectable } from '@angular/core';
import { Observable } from 'rxjs';

import { Config } from '../model/config';

@Injectable({ providedIn: 'root' })
Expand Down
1 change: 1 addition & 0 deletions apps/frontend/src/app/data/coupling.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { HttpClient } from '@angular/common/http';
import { inject, Injectable } from '@angular/core';
import { Observable } from 'rxjs';

import { CouplingResult } from '../model/coupling-result';
import { GraphType } from '../model/graph-type';
import { initLimits } from '../model/limits';
Expand Down
Loading

0 comments on commit 4a3c360

Please sign in to comment.