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

DEV-117 linter #18

Merged
merged 22 commits into from
May 26, 2024
Merged
Show file tree
Hide file tree
Changes from 19 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
50 changes: 50 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"root": true,
"ignorePatterns": [
"projects/**/*"
],
"overrides": [
{
"files": [
"*.ts"
],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:@angular-eslint/recommended",
"plugin:@angular-eslint/template/process-inline-templates"
],
"rules": {
"@typescript-eslint/no-explicit-any": ["off"],
"@angular-eslint/directive-selector": [
"error",
{
"type": "attribute",
"prefix": "app",
"style": "camelCase"
}
],
"@angular-eslint/component-selector": [
"error",
{
"type": "element",
"prefix": "app",
"style": "kebab-case"
}
]
}
},
{
"files": [
"*.html"
],
"extends": [
"plugin:@angular-eslint/template/recommended",
"plugin:@angular-eslint/template/accessibility"
],
"rules": {
"@angular-eslint/template/click-events-have-key-events": "off"
}
}
]
}
12 changes: 12 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Tests
on: [push]

jobs:
eslint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install modules
run: npm install
- name: Run ESLint
run: ng.js lint
10 changes: 5 additions & 5 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DOCUMENT, isPlatformBrowser } from '@angular/common';
import { Component, Inject, PLATFORM_ID } from '@angular/core';
import { AfterViewInit, Component, Inject, OnInit, PLATFORM_ID } from '@angular/core';
import { Meta } from '@angular/platform-browser';
import { NavigationEnd, NavigationError, NavigationStart, Router, Event, RouterModule } from '@angular/router';
import { initFlowbite } from 'flowbite';
Expand All @@ -15,7 +15,7 @@ import { AnalyticsService } from './services/analytics.service';
templateUrl: './app.component.html',
styleUrl: './app.component.scss'
})
export class AppComponent {
export class AppComponent implements OnInit, AfterViewInit {
title = 'sc-www';

constructor(@Inject(PLATFORM_ID) private platformId: object,
Expand Down Expand Up @@ -47,14 +47,14 @@ export class AppComponent {
});
}

ngOnInit() {
ngOnInit(): void {
register();
if (isPlatformBrowser(this.platformId)) {
initFlowbite();
}
}

ngAfterViewInit() {
ngAfterViewInit(): void {
if (isPlatformBrowser(this.platformId)) {
this.analytics.initializeTracking();
}
Expand All @@ -63,7 +63,7 @@ export class AppComponent {
updateCanonical(url: string) {
const canonicalUrl = url;
const head = this.document.getElementsByTagName('head')[0];
var element: HTMLLinkElement | null = this.document.querySelector(`link[rel='canonical']`) || null;
let element: HTMLLinkElement | null = this.document.querySelector(`link[rel='canonical']`) || null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using const instead of let for element since it is not reassigned.

- let element: HTMLLinkElement | null = this.document.querySelector(`link[rel='canonical']`) || null;
+ const element: HTMLLinkElement | null = this.document.querySelector(`link[rel='canonical']`) || null;

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
let element: HTMLLinkElement | null = this.document.querySelector(`link[rel='canonical']`) || null;
const element: HTMLLinkElement | null = this.document.querySelector(`link[rel='canonical']`) || null;

if (element == null) {
element = this.document.createElement('link') as HTMLLinkElement;
head.appendChild(element);
Expand Down
71 changes: 0 additions & 71 deletions src/app/app.module.ts

This file was deleted.

1 change: 1 addition & 0 deletions src/app/components/faq/faq.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<h3 class="font-bold text-3xl">{{ item }} FAQs</h3>
<div class="pl-2 mt-2" itemscope="" itemtype="https://schema.org/FAQPage">
<div *ngFor="let item of FAQQuestions, let i = index" itemscope="" itemprop="mainEntity" itemtype="https://schema.org/Question">
<!-- eslint-disable-next-line @angular-eslint/template/interactive-supports-focus -->
<div class="flex items-center justify-between cursor-pointer mb-2 border-b border-solid border-gray-200 py-3" (click)="toggleFAQ(i)">
<h4 itemprop="name">{{item.question}}</h4>
<lucide-icon [name]="FAQIcon(i)"></lucide-icon>
Expand Down
1 change: 1 addition & 0 deletions src/app/pages/article/article.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ <h1 class="text-emerald-400 text-3xl font-bold mb-2"> {{articleMeta.title}} </h1
<img
src="assets/images/team/{{articleMeta.author}}.webp"
class="w-8 max-h-8 rounded-full"
alt="{{articleMeta.author}} profile picture"
/>
</div>
<div>
Expand Down
8 changes: 4 additions & 4 deletions src/app/pages/article/article.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, ElementRef, Inject, PLATFORM_ID, Renderer2, ViewChild } from '@angular/core';
import { Component, ElementRef, Inject, PLATFORM_ID, Renderer2, OnInit, ViewChild } from '@angular/core';
import { BreadcrumbSegment, BreadcrumbsComponent } from '../../components/breadcrumbs/breadcrumbs.component';
import { ActivatedRoute, RouterLink } from '@angular/router';
import { CommonModule, isPlatformBrowser } from '@angular/common';
Expand All @@ -17,7 +17,7 @@ import { Lightbox, LightboxModule } from 'ngx-lightbox';
templateUrl: './article.component.html',
styleUrl: './article.component.scss'
})
export class ArticleComponent {
export class ArticleComponent implements OnInit {

@ViewChild('articleDiv') articleDiv!: ElementRef;

Expand Down Expand Up @@ -62,7 +62,7 @@ export class ArticleComponent {

if(isPlatformBrowser(this.platformId)) {
// Wait for the articleDiv to be rendered
let checkExist = setInterval(() => {
const checkExist = setInterval(() => {
if (this.articleDiv) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The use of setInterval for checking the existence of articleDiv is not the most efficient method. Consider using Angular's ViewChild with { static: false } to handle this more elegantly.

- const checkExist = setInterval(() => {
-   if (this.articleDiv) {
-     this.renderer.listen(this.articleDiv.nativeElement, 'click', (event) => {
-       if (event.target.tagName === 'IMG' && event.target.classList[0] == 'zoomin') {
-         this.openLightbox(event.target.src);
-       }
-     });
-     clearInterval(checkExist);
-   }
- }, 100);
+ @ViewChild('articleDiv', { static: false }) set content(content: ElementRef) {
+   if(content) {
+     this.renderer.listen(content.nativeElement, 'click', (event) => {
+       if (event.target.tagName === 'IMG' && event.target.classList.contains('zoomin')) {
+         this.openLightbox(event.target.src);
+       }
+     });
+   }
+ }

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
const checkExist = setInterval(() => {
@ViewChild('articleDiv', { static: false }) set content(content: ElementRef) {
if(content) {
this.renderer.listen(content.nativeElement, 'click', (event) => {
if (event.target.tagName === 'IMG' && event.target.classList.contains('zoomin')) {
this.openLightbox(event.target.src);
}
});
}
}

this.renderer.listen(this.articleDiv.nativeElement, 'click', (event) => {
if (event.target.tagName === 'IMG' && event.target.classList[0] == 'zoomin') {
Expand All @@ -82,7 +82,7 @@ export class ArticleComponent {
const lines = str.split('\n');
const result: any = {};

for (let line of lines) {
for (const line of lines) {
const [key, ...valueParts] = line.split(':');
const value = valueParts.join(':').trim();
if(key?.length > 0 && value?.length > 0) {
Expand Down
8 changes: 4 additions & 4 deletions src/app/pages/articles/articles.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component } from '@angular/core';
import { Component, OnInit } from '@angular/core';
import { ArticleMeta, ArticlesService } from '../../services/articles.service';
import { BreadcrumbSegment, BreadcrumbsComponent } from '../../components/breadcrumbs/breadcrumbs.component';
import { CommonModule } from '@angular/common';
Expand All @@ -13,7 +13,7 @@ import { ArticleCardComponent } from '../../components/article-card/article-card
templateUrl: './articles.component.html',
styleUrl: './articles.component.scss'
})
export class ArticlesComponent {
export class ArticlesComponent implements OnInit {

breadcrumbs: BreadcrumbSegment[] = [
{ name: 'Home', url: '/' },
Expand All @@ -29,7 +29,7 @@ export class ArticlesComponent {

ngOnInit() {
this.route.queryParams.subscribe(params => {
let category = params['tag'];
const category = params['tag'];
this.articles.getArticlesByType(category).then(articles => {
this.featuredArticles = articles;
});
Expand All @@ -40,7 +40,7 @@ export class ArticlesComponent {

];

let title = category ? category.charAt(0).toUpperCase() + category.slice(1) : '';
const title = category ? category.charAt(0).toUpperCase() + category.slice(1) : '';

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use template literals consistently for better readability and to avoid errors.

- const title = category ? category.charAt(0).toUpperCase() + category.slice(1) : '';
+ const title = category ? `${category.charAt(0).toUpperCase()}${category.slice(1)}` : '';

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
const title = category ? category.charAt(0).toUpperCase() + category.slice(1) : '';
const title = category ? `${category.charAt(0).toUpperCase()}${category.slice(1)}` : '';

if(category) {
this.breadcrumbs.push(
Expand Down
1 change: 1 addition & 0 deletions src/app/pages/datacenters/datacenters.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ <h1 class="text-4xl font-bold">Datacenters</h1>
<td> {{item.country_id | countryIdtoName}}</td>
<td> {{item.founding_year || '-'}}</td>
<td>
<!-- eslint-disable-next-line @angular-eslint/template/interactive-supports-focus -->
<div class="flex justify-end" (click)="$event.stopPropagation()">
<a routerLink="/servers" [queryParams]="{datacenters: item.datacenter_id}">
<lucide-icon name="chevron-right" class="h-6 w-6 text-emerald-400"></lucide-icon>
Expand Down
6 changes: 3 additions & 3 deletions src/app/pages/datacenters/datacenters.component.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Component } from '@angular/core';
import { Component, OnInit } from '@angular/core';
import { BreadcrumbSegment, BreadcrumbsComponent } from '../../components/breadcrumbs/breadcrumbs.component';
import { SeoHandlerService } from '../../services/seo-handler.service';
import { KeeperAPIService } from '../../services/keeper-api.service';
import { OrderDir, Server, TableDatacenterTableDatacenterGetData } from '../../../../sdk/data-contracts';
import { OrderDir, TableDatacenterTableDatacenterGetData } from '../../../../sdk/data-contracts';
import { CountryIdtoNamePipe } from '../../pipes/country-idto-name.pipe';
import { FormsModule } from '@angular/forms';
import { CommonModule } from '@angular/common';
Expand All @@ -16,7 +16,7 @@ import { Router, RouterModule } from '@angular/router';
templateUrl: './datacenters.component.html',
styleUrl: './datacenters.component.scss'
})
export class DatacentersComponent {
export class DatacentersComponent implements OnInit {

breadcrumbs: BreadcrumbSegment[] = [
{
Expand Down
20 changes: 10 additions & 10 deletions src/app/pages/landingpage/landingpage.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
class="button font-bold text-3xl"
[disabled]="isSpinning"
(click)="spinClicked()"
autofocus>SPIN
>SPIN
</button>
<div class="button__bottom" [attr.disabled]="isSpinning"></div>
</div>
Expand Down Expand Up @@ -81,7 +81,7 @@
<div class="slot flex flex-col align-center" [style]="getStyle(i)" *ngFor="let item of spinnerContents[0], let i = index" >
<div class="slot_inner" [style]="getInnerStyle(i)">
<div *ngIf="!item.logo" class="text-center font-bold text-3xl">{{item.name}}</div>
<img *ngIf="item.logo" src="{{item.logo}}" style="margin: 0.5rem;" class="rounded-lg">
<img *ngIf="item.logo" src="{{item.logo}}" style="margin: 0.5rem;" class="rounded-lg" alt="{{item.name}} logo">
</div>
</div>
</div>
Expand Down Expand Up @@ -147,12 +147,12 @@
<div class="flex gap-24 justify-center flex-col lg:flex-row">
<div class="flex justify-center">
<!-- 550x380 -->
<img class="h-full object-contain mx-auto" src="/assets/images/media/sqlstats.webp" >
<img class="h-full object-contain mx-auto" src="/assets/images/media/sqlstats.webp" alt="SQL query to show statistics on the Spare Cores inventory and update frequency" >
</div>
<div class="flex flex-col justify-center">
<div style="width: 450px; margin: auto;">
<div *ngFor="let item of features, let i = index">
<div *ngIf="i != 0" class="w-full h-4 mb-3 border-b border-gray-400 border-solid" ></div>
<div *ngIf="i !== 0" class="w-full h-4 mb-3 border-b border-gray-400 border-solid" ></div>
<div class="flex gap-2 text-2xl items-center text-gray-200">
<div class="px-1 py-1 rounded-full bg-teal-500 h-6 w-6">
<lucide-icon name="check" class="h-4 w-4"></lucide-icon>
Expand Down Expand Up @@ -183,7 +183,7 @@
<div class="w-full lg:w-1/3 flex flex-col gap-6">
<div class="w-full h-260 rounded-lg">
<!-- 300x260 -->
<img class="rounded-lg h-full object-contain mx-auto" src="/assets/images/media/step1.webp">
<img class="rounded-lg h-full object-contain mx-auto" src="/assets/images/media/step1.webp" alt="Screenshot of the server listing page, focusing on the filter elements in the sidebar">
</div>
<div class="flex gap-2 align-center">
<div class="text-emerald-400 rounded-full bg-white px-2 font-bold">1</div>
Expand All @@ -196,7 +196,7 @@
<div class="w-full lg:w-1/3 flex flex-col gap-6">
<div class="w-full h-260 rounded-lg">
<!-- 300x260 -->
<img class="rounded-lg h-full object-contain mx-auto" src="/assets/images/media/step2.webp">
<img class="rounded-lg h-full object-contain mx-auto" src="/assets/images/media/step2.webp" alt="Screenshot of the server listing page, focusing on the search results, showing 3 instance records in a table">
</div>
<div class="flex gap-2 align-center">
<div class="text-emerald-400 rounded-full bg-white px-2 font-bold">2</div>
Expand All @@ -209,7 +209,7 @@
<div class="w-full lg:w-1/3 flex flex-col gap-6">
<div class="w-full h-260 rounded-lg">
<!-- 300x260 -->
<img class="rounded-lg h-full object-contain mx-auto" src="/assets/images/media/step3.webp">
<img class="rounded-lg h-full object-contain mx-auto" src="/assets/images/media/step3.webp" alt="Running the SC runner CLI tool to start a t4g.nano instance">
</div>
<div class="flex gap-2 align-center">
<div class="text-emerald-400 rounded-full bg-white px-2 font-bold">3</div>
Expand Down Expand Up @@ -247,7 +247,7 @@
<div class="w-full lg:w-2/5 justify-center flex">
<a href="https://ngi.eu" target="_blank" rel="noopener">
<!-- 550x380 -->
<img class="rounded-lg h-full object-contain mx-auto" src="/assets/images/media/ngi-eu-open-source.webp">
<img class="rounded-lg h-full object-contain mx-auto" src="/assets/images/media/ngi-eu-open-source.webp" alt="Banner image showing NGI (Next Generation Internet) funding for the SC (Spare Cores) project">
</a>
</div>
</div>
Expand Down Expand Up @@ -281,15 +281,15 @@
</a>
<a href="https://pypi.org/project/{{item.pypi}}"
*ngIf="item.pypi" target="_blank" rel="noopener">
<img src="assets/images/icons/python.svg"
<img src="assets/images/icons/python.svg" alt="Python logo"
style="width: 24px; vertical-align:middle;" />
</a>
<a href="{{item.docs}}"
*ngIf="item.docs" target="_blank" rel="noopener">
<lucide-icon name="book-text"></lucide-icon>
</a>
<a href="{{item.www}}" *ngIf="item.www" target="_blank" rel="noopener">
<img src="assets/images/icons/www.svg"
<img src="assets/images/icons/www.svg" alt="WWW logo"
style="width: 24px; vertical-align:middle;" />
</a>
<a href="{{item.data}}" *ngIf="item.data" target="_blank" rel="noopener">
Expand Down
Loading
Loading