Skip to content

Commit

Permalink
Merge pull request #26514 from qmonmert/angsonar
Browse files Browse the repository at this point in the history
[Angular] Sonar: Fields that are only assigned in the constructor should be readonly
  • Loading branch information
mshima authored Jun 23, 2024
2 parents 280f11b + 639bb51 commit cfda77e
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export class JvmThreadsComponent {

private _threads: Thread[] | undefined;

private modalService = inject(NgbModal);
private readonly modalService = inject(NgbModal);

open(): void {
const modalRef = this.modalService.open(MetricsModalThreadsComponent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { TranslateService } from "@ngx-translate/core";
@Injectable()
export class AppPageTitleStrategy extends TitleStrategy {
<%_ if (enableTranslation) { _%>
private translateService = inject(TranslateService);
private readonly translateService = inject(TranslateService);
<%_ } _%>

override updateTitle(routerState: RouterStateSnapshot): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { ITEMS_PER_PAGE } from 'app/config/pagination.constants';

@Injectable({ providedIn: 'root' })
export class PaginationConfig {
private config = inject(NgbPaginationConfig);
private readonly config = inject(NgbPaginationConfig);
constructor() {
this.config.boundaryLinks = true;
this.config.maxSize = 5;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ import { StateStorageService } from 'app/core/auth/state-storage.service';

@Injectable()
export class AuthExpiredInterceptor implements HttpInterceptor {
private loginService = inject(LoginService);
private stateStorageService = inject(StateStorageService);
private router = inject(Router);
private readonly loginService = inject(LoginService);
private readonly stateStorageService = inject(StateStorageService);
private readonly router = inject(Router);

intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
return next.handle(request).pipe(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import { ApplicationConfigService } from '../config/application-config.service';

@Injectable()
export class AuthInterceptor implements HttpInterceptor {
private stateStorageService = inject(StateStorageService);
private applicationConfigService = inject(ApplicationConfigService);
private readonly stateStorageService = inject(StateStorageService);
private readonly applicationConfigService = inject(ApplicationConfigService);

intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
const serverApiUrl = this.applicationConfigService.getEndpointFor('');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { EventManager, EventWithContent } from 'app/core/util/event-manager.serv

@Injectable()
export class ErrorHandlerInterceptor implements HttpInterceptor {
private eventManager = inject(EventManager);
private readonly eventManager = inject(EventManager);

intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
return next.handle(request).pipe(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ export default class ErrorComponent implements OnInit<% if (enableTranslation) {
<%_ } _%>

<%_ if (enableTranslation) { _%>
private translateService = inject(TranslateService);
private readonly translateService = inject(TranslateService);
<%_ } _%>
private route = inject(ActivatedRoute);
private readonly route = inject(ActivatedRoute);

ngOnInit(): void {
this.route.data.subscribe(routeData => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ import { TranslateService, LangChangeEvent } from '@ngx-translate/core';
export default class ActiveMenuDirective implements OnInit {
<%= jhiPrefix %>ActiveMenu = input();

private el = inject(ElementRef);
private renderer = inject(Renderer2);
private translateService = inject(TranslateService);
private readonly el = inject(ElementRef);
private readonly renderer = inject(Renderer2);
private readonly translateService = inject(TranslateService);

ngOnInit(): void {
this.translateService.onLangChange.subscribe((event: LangChangeEvent) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { Pipe, PipeTransform } from '@angular/core';
name: 'findLanguageFromKey',
})
export default class FindLanguageFromKeyPipe implements PipeTransform {
private languages: { [key: string]: { name: string; rtl?: boolean } } = {
private readonly languages: { [key: string]: { name: string; rtl?: boolean } } = {
// jhipster-needle-i18n-language-key-pipe - JHipster will add/remove languages in this object
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ export class LazyTranslationModule {
],
})
export class TranslationModule {
private translateService = inject(TranslateService);
private stateStorageService = inject(StateStorageService);
private readonly translateService = inject(TranslateService);
private readonly stateStorageService = inject(StateStorageService);

constructor() {
this.translateService.setDefaultLang('<%= nativeLanguage %>');
Expand Down

0 comments on commit cfda77e

Please sign in to comment.