Skip to content

Commit

Permalink
Added some code cleanup tools to package.json [#539]
Browse files Browse the repository at this point in the history
Developers can now do "yarn code-cleanup" to to fix any coding convention
errors in the Angular codebase.
  • Loading branch information
mcpierce committed Mar 1, 2021
1 parent 7fa4573 commit 6a66dfe
Show file tree
Hide file tree
Showing 15 changed files with 89 additions and 96 deletions.
11 changes: 3 additions & 8 deletions comixed-web/package.json
Expand Up @@ -7,19 +7,14 @@
"build": "ng build",
"test": "ng test --code-coverage",
"lint": "ng lint",
"e2e": "ng e2e"
"e2e": "ng e2e",
"code-cleanup": "prettier --write 'src/app/**/*.ts'"
},
"prettier": {
"singleQuote": true,
"useTabs": false,
"bracketSpacing": true,
"jsxBracketSameLine": true,
"langs": [
"js",
"javascript",
"typescript",
"html"
]
"jsxBracketSameLine": true
},
"private": true,
"dependencies": {
Expand Down
8 changes: 4 additions & 4 deletions comixed-web/src/app/app.effects.spec.ts
Expand Up @@ -16,10 +16,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses>
*/

import {TestBed} from '@angular/core/testing';
import {provideMockActions} from '@ngrx/effects/testing';
import {Observable} from 'rxjs';
import {AppEffects} from './app.effects';
import { TestBed } from '@angular/core/testing';
import { provideMockActions } from '@ngrx/effects/testing';
import { Observable } from 'rxjs';
import { AppEffects } from './app.effects';

describe('AppEffects', () => {
const actions$: Observable<any> = null;
Expand Down
12 changes: 6 additions & 6 deletions comixed-web/src/app/interceptors/http.interceptor.spec.ts
Expand Up @@ -24,15 +24,15 @@ import { AUTHENTICATION_TOKEN } from '@app/core/core.fixtures';
import {
HttpClientTestingModule,
HttpTestingController,
TestRequest,
TestRequest
} from '@angular/common/http/testing';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { HTTP_INTERCEPTORS, HttpClient } from '@angular/common/http';
import {
HTTP_AUTHORIZATION_HEADER,
HTTP_REQUESTED_WITH_HEADER,
HTTP_XML_REQUEST,
HTTP_XML_REQUEST
} from '@app/app.constants';

const TEST_REQUEST_URL = 'http://localhost';
Expand Down Expand Up @@ -61,10 +61,10 @@ describe('HttpInterceptor', () => {
provide: TokenService,
useValue: {
hasAuthToken: jasmine.createSpy('TokenService.hasAuthToken()'),
getAuthToken: jasmine.createSpy('TokenService.getAuthToken()'),
},
},
],
getAuthToken: jasmine.createSpy('TokenService.getAuthToken()')
}
}
]
});

tokenService = TestBed.inject(TokenService) as jasmine.SpyObj<TokenService>;
Expand Down
Expand Up @@ -24,11 +24,11 @@ import {
COMIC_FILE_1,
COMIC_FILE_2,
COMIC_FILE_3,
COMIC_FILE_4,
COMIC_FILE_4
} from '@app/library/library.fixtures';
import {
COMIC_IMPORT_FEATURE_KEY,
initialState as initialComicImportState,
initialState as initialComicImportState
} from '@app/library/reducers/comic-import.reducer';
import { MatTableModule } from '@angular/material/table';
import { TranslateModule } from '@ngx-translate/core';
Expand All @@ -51,9 +51,9 @@ describe('ComicFileListComponent', () => {
TranslateModule.forRoot(),
LoggerModule.forRoot(),
MatTableModule,
MatCheckboxModule,
MatCheckboxModule
],
providers: [provideMockStore({ initialState })],
providers: [provideMockStore({ initialState })]
}).compileComponents();

fixture = TestBed.createComponent(ComicFileListComponent);
Expand Down Expand Up @@ -158,7 +158,7 @@ describe('ComicFileListComponent', () => {

describe('selecting a row', () => {
it('emits an event', () => {
component.currentFile.subscribe((response) =>
component.currentFile.subscribe(response =>
expect(response).toEqual(FILE)
);
});
Expand Down
Expand Up @@ -28,7 +28,7 @@ import { compare } from '@app/core';
@Component({
selector: 'cx-comic-file-list',
templateUrl: './comic-file-list.component.html',
styleUrls: ['./comic-file-list.component.scss'],
styleUrls: ['./comic-file-list.component.scss']
})
export class ComicFileListComponent implements OnInit {
@Output() currentFile = new EventEmitter<ComicFile>();
Expand Down
Expand Up @@ -16,18 +16,18 @@
* along with this program. If not, see <http://www.gnu.org/licenses>
*/

import {Component, Input} from '@angular/core';
import {FormBuilder, FormGroup, Validators} from '@angular/forms';
import {LoggerService} from '@angular-ru/logger';
import {Store} from '@ngrx/store';
import { Component, Input } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { LoggerService } from '@angular-ru/logger';
import { Store } from '@ngrx/store';
import {
clearComicFileSelections,
loadComicFiles,
sendComicFiles,
setComicFilesSelectedState
} from '@app/library/actions/comic-import.actions';
import {getUserPreference, User} from '@app/user';
import {ComicFile} from '@app/library';
import { getUserPreference, User } from '@app/user';
import { ComicFile } from '@app/library';
import {
IMPORT_MAXIMUM_RESULTS_DEFAULT,
IMPORT_MAXIMUM_RESULTS_PREFERENCE,
Expand All @@ -50,11 +50,11 @@ export class ComicFileToolbarComponent {

const;
maximumOptions = [
{label: 'load-comic-files.maximum.all-files', value: 0},
{label: 'load-comic-files.maximum.10-files', value: 10},
{label: 'load-comic-files.maximum.50-files', value: 50},
{label: 'load-comic-files.maximum.100-files', value: 100},
{label: 'load-comic-files.maximum.1000-files', value: 1000}
{ label: 'load-comic-files.maximum.all-files', value: 0 },
{ label: 'load-comic-files.maximum.10-files', value: 10 },
{ label: 'load-comic-files.maximum.50-files', value: 50 },
{ label: 'load-comic-files.maximum.100-files', value: 100 },
{ label: 'load-comic-files.maximum.1000-files', value: 1000 }
];

constructor(
Expand Down Expand Up @@ -101,7 +101,7 @@ export class ComicFileToolbarComponent {
onSelectAll(): void {
this.logger.trace('Selecting all comic files');
this.store.dispatch(
setComicFilesSelectedState({files: this.comicFiles, selected: true})
setComicFilesSelectedState({ files: this.comicFiles, selected: true })
);
}

Expand Down
4 changes: 3 additions & 1 deletion comixed-web/src/app/library/effects/library.effects.spec.ts
Expand Up @@ -62,7 +62,9 @@ describe('LibraryEffects', () => {
});

effects = TestBed.inject(LibraryEffects);
comicService = TestBed.inject(LibraryService) as jasmine.SpyObj<LibraryService>;
comicService = TestBed.inject(LibraryService) as jasmine.SpyObj<
LibraryService
>;
alertService = TestBed.inject(AlertService);
spyOn(alertService, 'error');
});
Expand Down
Expand Up @@ -16,24 +16,24 @@
* along with this program. If not, see <http://www.gnu.org/licenses>
*/

import {Component, OnDestroy, OnInit} from '@angular/core';
import {Subscription} from 'rxjs';
import {ComicFile} from '@app/library/models/comic-file';
import {LoggerService} from '@angular-ru/logger';
import {Store} from '@ngrx/store';
import { Component, OnDestroy, OnInit } from '@angular/core';
import { Subscription } from 'rxjs';
import { ComicFile } from '@app/library/models/comic-file';
import { LoggerService } from '@angular-ru/logger';
import { Store } from '@ngrx/store';
import {
selectComicFiles,
selectComicFileSelections,
selectComicImportState
} from '@app/library/selectors/comic-import.selectors';
import {setBusyState} from '@app/core/actions/busy.actions';
import {ConfirmationService} from '@app/core';
import {TranslateService} from '@ngx-translate/core';
import {sendComicFiles} from '@app/library/actions/comic-import.actions';
import {selectUser} from '@app/user/selectors/user.selectors';
import {filter} from 'rxjs/operators';
import {getUserPreference, User} from '@app/user';
import {Title} from '@angular/platform-browser';
import { setBusyState } from '@app/core/actions/busy.actions';
import { ConfirmationService } from '@app/core';
import { TranslateService } from '@ngx-translate/core';
import { sendComicFiles } from '@app/library/actions/comic-import.actions';
import { selectUser } from '@app/user/selectors/user.selectors';
import { filter } from 'rxjs/operators';
import { getUserPreference, User } from '@app/user';
import { Title } from '@angular/platform-browser';
import {
DELETE_BLOCKED_PAGES_DEFAULT,
DELETE_BLOCKED_PAGES_PREFERENCE,
Expand All @@ -42,9 +42,9 @@ import {
PAGE_SIZE_DEFAULT,
PAGE_SIZE_PREFERENCE
} from '@app/library/library.constants';
import {MatDialog} from '@angular/material/dialog';
import {ComicFileDetailsComponent} from '@app/library/components/comic-file-details/comic-file-details.component';
import {ComicFileDetailsData} from '@app/library/models/ui/comic-file-details-data';
import { MatDialog } from '@angular/material/dialog';
import { ComicFileDetailsComponent } from '@app/library/components/comic-file-details/comic-file-details.component';
import { ComicFileDetailsData } from '@app/library/models/ui/comic-file-details-data';

@Component({
selector: 'cx-import-comics',
Expand Down Expand Up @@ -117,7 +117,7 @@ export class ImportComicsComponent implements OnInit, OnDestroy {
if (this.busy !== busy) {
this.logger.debug('Setting busy state:', busy);
this.busy = busy;
this.store.dispatch(setBusyState({enabled: busy}));
this.store.dispatch(setBusyState({ enabled: busy }));
}
this.importing = state.importing;
});
Expand Down Expand Up @@ -154,7 +154,7 @@ export class ImportComicsComponent implements OnInit, OnDestroy {
),
message: this.translateService.instant(
'import-comic-files.confirm-start-message',
{count: this.selectedFiles.length}
{ count: this.selectedFiles.length }
),
confirm: () => {
this.logger.debug('Starting import');
Expand Down
Expand Up @@ -21,7 +21,7 @@ import { ComicFile } from '@app/library/models/comic-file';
import { API_ROOT_URL } from '@app/core';

@Pipe({
name: 'comicFileCoverUrl',
name: 'comicFileCoverUrl'
})
export class ComicFileCoverUrlPipe implements PipeTransform {
transform(comicFile: ComicFile): string {
Expand Down
Expand Up @@ -19,7 +19,7 @@
import {
ComicImportState,
initialState,
reducer,
reducer
} from './comic-import.reducer';
import {
clearComicFileSelections,
Expand All @@ -30,13 +30,13 @@ import {
sendComicFiles,
sendComicFilesFailed,
setComicFilesSelectedState,
setImportingComicsState,
setImportingComicsState
} from '@app/library/actions/comic-import.actions';
import {
COMIC_FILE_1,
COMIC_FILE_2,
COMIC_FILE_3,
ROOT_DIRECTORY,
ROOT_DIRECTORY
} from '@app/library/library.fixtures';

describe('ComicImport Reducer', () => {
Expand Down Expand Up @@ -138,7 +138,7 @@ describe('ComicImport Reducer', () => {
});

it('adds the comics to the selection list', () => {
FILES.forEach((file) => expect(state.selections).toContain(file));
FILES.forEach(file => expect(state.selections).toContain(file));
});
});

Expand All @@ -150,7 +150,7 @@ describe('ComicImport Reducer', () => {
{ ...state, selections: FILES },
setComicFilesSelectedState({
files: [DESELECTED_FILE],
selected: false,
selected: false
})
);
});
Expand Down Expand Up @@ -180,7 +180,7 @@ describe('ComicImport Reducer', () => {
sendComicFiles({
files: FILES,
ignoreMetadata: true,
deleteBlockedPages: true,
deleteBlockedPages: true
})
);
});
Expand Down
Expand Up @@ -18,17 +18,17 @@

import {
COMIC_IMPORT_FEATURE_KEY,
ComicImportState,
ComicImportState
} from '../reducers/comic-import.reducer';
import {
selectComicFiles,
selectComicFileSelections,
selectComicImportState,
selectComicImportState
} from './comic-import.selectors';
import {
COMIC_FILE_1,
COMIC_FILE_2,
COMIC_FILE_3,
COMIC_FILE_3
} from '@app/library/library.fixtures';

describe('ComicImport Selectors', () => {
Expand All @@ -42,30 +42,30 @@ describe('ComicImport Selectors', () => {
files: FILES,
selections: FILES,
sending: Math.random() > 0.5,
importing: Math.random() > 0.5,
importing: Math.random() > 0.5
};
});

it('should select the feature state', () => {
expect(
selectComicImportState({
[COMIC_IMPORT_FEATURE_KEY]: state,
[COMIC_IMPORT_FEATURE_KEY]: state
})
).toEqual(state);
});

it('should select the comic files', () => {
expect(
selectComicFiles({
[COMIC_IMPORT_FEATURE_KEY]: state,
[COMIC_IMPORT_FEATURE_KEY]: state
})
).toEqual(state.files);
});

it('should select the selected comic files', () => {
expect(
selectComicFileSelections({
[COMIC_IMPORT_FEATURE_KEY]: state,
[COMIC_IMPORT_FEATURE_KEY]: state
})
).toEqual(state.selections);
});
Expand Down
6 changes: 3 additions & 3 deletions comixed-web/src/app/library/selectors/display.selectors.ts
@@ -1,6 +1,6 @@
import { createFeatureSelector, createSelector } from '@ngrx/store';
import * as fromDisplay from '../reducers/display.reducer';

export const selectDisplayState = createFeatureSelector<fromDisplay.DisplayState>(
fromDisplay.DISPLAY_FEATURE_KEY
);
export const selectDisplayState = createFeatureSelector<
fromDisplay.DisplayState
>(fromDisplay.DISPLAY_FEATURE_KEY);

0 comments on commit 6a66dfe

Please sign in to comment.