Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Angular] Sonar: Fields that are only assigned in the constructor should be readonly #26514

Merged
merged 2 commits into from
Jun 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading