Skip to content

Commit

Permalink
NAS-131866 / 25.04 / Enable some linter rules (#10892)
Browse files Browse the repository at this point in the history
  • Loading branch information
undsoft authored Oct 21, 2024
1 parent 2c160b6 commit 26d81aa
Show file tree
Hide file tree
Showing 20 changed files with 120 additions and 111 deletions.
46 changes: 17 additions & 29 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ module.exports = {
"order": "asc",
"caseInsensitive": false
}
}],
}],
"import/no-duplicates": ["error", {"considerQueryString": true}],
"import/extensions": ["error", "ignorePackages", {
"js": "never",
Expand Down Expand Up @@ -151,6 +151,16 @@ module.exports = {
"sonarjs/no-empty-test-file": ["off"],
"sonarjs/new-cap": ["off"],
"sonarjs/no-ignored-exceptions": ["off"],
"sonarjs/array-callback-without-return": "off",
"sonarjs/os-command": "off",
"sonarjs/sonar-prefer-optional-chain": "off",
"@typescript-eslint/member-ordering": "off",
"@typescript-eslint/no-unsafe-return": "off",
"sonarjs/no-misused-promises": "off",
"sonarjs/function-return-type": "off",
"@typescript-eslint/no-unnecessary-type-parameters": "off",
"no-multi-str": "off",
"@typescript-eslint/prefer-reduce-type-parameter": ["off"],

// TODO: Airbnb rules that are disabled for now as they cannot be fixed automatically
"no-restricted-syntax": ["error",
Expand Down Expand Up @@ -189,27 +199,7 @@ module.exports = {
},
],
"no-param-reassign": "off",
"@typescript-eslint/no-loop-func": "off",
"no-await-in-loop": "off",
"no-multi-str": "off",
"no-mixed-operators": ["error", {
groups: [
// TODO: Some operators from default config not implemented.
["&", "|", "^", "~", "<<", ">>", ">>>"],
["==", "!=", "===", "!==", ">", ">=", "<", "<="],
["&&", "||"],
["in", "instanceof"]
],
allowSamePrecedence: true
}],
"default-case": "off",
"@typescript-eslint/member-ordering": "off",
"@typescript-eslint/no-unsafe-return": "off",
"sonarjs/no-misused-promises": "off",
"sonarjs/function-return-type": "off",
"@typescript-eslint/no-unnecessary-type-parameters": "off",
"sonarjs/os-command": "off",
"sonarjs/sonar-prefer-optional-chain": "off",

// Other temporary disables
"sonarjs/prefer-nullish-coalescing": ["off"],
Expand All @@ -222,7 +212,6 @@ module.exports = {
"@typescript-eslint/no-unnecessary-condition": ["off"],
"@typescript-eslint/no-invalid-void-type": ["off"],
"@typescript-eslint/no-dynamic-delete": ["off"],
"@typescript-eslint/prefer-reduce-type-parameter": ["off"],
"sonarjs/no-selector-parameter": ["off"],
"sonarjs/concise-regex": ["off"],
"sonarjs/regex-complexity": ["off"],
Expand All @@ -236,11 +225,7 @@ module.exports = {
"sonarjs/slow-regex": ["off"],
"sonarjs/no-base-to-string": ["off"],
"sonarjs/link-with-target-blank": ["off"],
"sonarjs/array-callback-without-return": "off",
"sonarjs/no-nested-assignment": "off",
"sonarjs/reduce-initial-value": "off",
"sonarjs/use-type-alias": "off",
"sonarjs/no-dead-store": "off",

// Other overwrites
...(stylistic.configs.customize({
Expand Down Expand Up @@ -307,7 +292,7 @@ module.exports = {
}
},
],
"unicorn/filename-case": ["error", { case: "kebabCase"}],
"unicorn/filename-case": ["error", { case: "kebabCase" }],
"unicorn/prefer-array-find": ["error"],
"@angular-eslint/component-selector": ["error", {
"type": "element",
Expand Down Expand Up @@ -356,16 +341,18 @@ module.exports = {
}
],
"patterns": [{
"group": [ "../**"],
"group": ["../**"],
"message": "Use alias 'app' to replace part '../' of the path."
}],
}],
"@shopify/typescript-prefer-singular-enums": "error",
"@shopify/typescript-prefer-pascal-case-enums": "error",
"@shopify/prefer-early-return": ["error", { maximumStatements: 3 }],
"@shopify/prefer-early-return": ["error", {maximumStatements: 3}],
"import/no-default-export": "error",
"@typescript-eslint/consistent-indexed-object-style": "error",
"@angular-eslint/prefer-on-push-component-change-detection": "error",
"default-case": "off",
"@typescript-eslint/switch-exhaustiveness-check": "error",

// RxJS rules
"rxjs/no-unsafe-takeuntil": ["error", {
Expand Down Expand Up @@ -430,6 +417,7 @@ module.exports = {
"addElements": ["a", "mat-row", "mat-slider", "table"]
}],
"@angular-eslint/template/prefer-control-flow": ['error'],
"@angular-eslint/template/no-positive-tabindex": ["error"],

// TODO: To be enabled later
'@angular-eslint/template/no-negated-async': ['off'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,18 @@ export class MockEnclosureWebsocketService extends WebSocketService {
return this.mockStorage.webuiDashboardEnclosureResponse() ?? undefined;
case 'truenas.is_ix_hardware':
return true;
default:
return undefined;
}
return undefined;
}

private postCallOverride<M extends ApiCallMethod>(method: M, response: ApiCallResponse<M>): ApiCallResponse<M> {
switch (method) {
case 'webui.main.dashboard.sys_info':
case 'system.info':
return this.mockStorage.enhanceSystemInfoResponse(response as SystemInfo);
default:
return undefined;
}

return undefined;
}
}
3 changes: 2 additions & 1 deletion src/app/helpers/assert-unreachable.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
*
* If you get a type error that something is not assignable to never,
* then you forgot to handle a case in a switch statement.
* DO NOT JUST USE `as never` TO SILENCE THE ERROR.
*
* DO NOT just use `as never` to silence the error.
*/
export function assertUnreachable(value: never): void {
console.error(`No such case in exhaustive switch: ${String(value)}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export class GaugeChartComponent {
private conversionColor(color: string): string {
const colorType = (new ThemeUtils()).getValueType(color);
let resultColor = color;
// eslint-disable-next-line default-case
switch (colorType) {
case 'cssVar': {
const cssVar = color.replace('var(--', '').replace(')', '') as keyof Theme;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ export class JobProgressDialogComponent<T> implements OnInit, AfterViewChecked {
this.dialogRef.close();
},
complete: () => {
// eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
switch (this.job.state) {
case JobState.Failed:
this.jobFailure.emit(this.job);
Expand Down
3 changes: 3 additions & 0 deletions src/app/modules/empty/empty.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { TranslateModule } from '@ngx-translate/core';
import { RequiresRolesDirective } from 'app/directives/requires-roles/requires-roles.directive';
import { EmptyType } from 'app/enums/empty-type.enum';
import { Role } from 'app/enums/role.enum';
import { assertUnreachable } from 'app/helpers/assert-unreachable.utils';
import { EmptyConfig } from 'app/interfaces/empty-config.interface';
import { iconMarker, MarkedIcon } from 'app/modules/ix-icon/icon-marker.util';
import { IxIconComponent } from 'app/modules/ix-icon/ix-icon.component';
Expand Down Expand Up @@ -61,6 +62,8 @@ export class EmptyComponent {
case EmptyType.NoSearchResults:
icon = iconMarker('mdi-magnify-scan');
break;
default:
assertUnreachable(this.conf.type);
}
}
return icon;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { MatButton } from '@angular/material/button';
import { MatProgressSpinner } from '@angular/material/progress-spinner';
import { TranslateService, TranslateModule } from '@ngx-translate/core';
import { EmptyType } from 'app/enums/empty-type.enum';
import { assertUnreachable } from 'app/helpers/assert-unreachable.utils';
import { EmptyConfig } from 'app/interfaces/empty-config.interface';
import { iconMarker, MarkedIcon } from 'app/modules/ix-icon/icon-marker.util';
import { IxIconComponent } from 'app/modules/ix-icon/ix-icon.component';
Expand Down Expand Up @@ -79,6 +80,8 @@ export class IxTableEmptyRowComponent implements AfterViewInit {
case EmptyType.NoSearchResults:
icon = iconMarker('mdi-magnify-scan');
break;
default:
assertUnreachable(this.conf.type);
}
}
return icon;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ export class InstalledAppsComponent implements OnInit, AfterViewInit {
}
}

showLoadStatus(type: EmptyType): void {
showLoadStatus(type: EmptyType.FirstUse | EmptyType.NoPageData | EmptyType.Errors | EmptyType.NoSearchResults): void {
switch (type) {
case EmptyType.FirstUse:
case EmptyType.NoPageData:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export class WidgetInterfaceComponent implements WidgetComponent<WidgetInterface
filter((response) => !!response.length),
map((response) => {
const [update] = response;
return (update.data as number[][]).map((row) => (row = row.slice(1).map((value) => value * kb)));
return (update.data as number[][]).map((row) => row.slice(1).map((value) => value * kb));
}),
));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,8 @@ export class ReplicationWizardComponent {
if (requestsTasks.length) {
return forkJoin(requestsTasks).pipe(
map((createdSnapshotTasks) => {
return this.createdSnapshotTasks = (createdSnapshotTasks || []).filter((task) => !!task);
this.createdSnapshotTasks = (createdSnapshotTasks || []).filter((task) => !!task);
return this.createdSnapshotTasks;
}),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ export class OtherOptionsSectionComponent implements OnInit, OnChanges {
return;
}

// eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
switch (aclTypeControl.value) {
case DatasetAclType.Nfsv4:
if (!this.existing) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ export class InterfaceNameValidatorService {
case NetworkInterfaceType.Vlan:
interfaceName = this.translate.instant('VLAN interface');
break;
default:
console.error('Unsupported interface type', type);
}

return this.translate.instant(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ describe('LineChartComponent', () => {

describe('axisLabelFormatter', () => {
it('returns default formatted value', () => {
jest.spyOn(console, 'warn').mockImplementation();

expect(spectator.component.axisLabelFormatter(500000)).toBe('500k');
expect(console.warn).toHaveBeenCalled();
});

it('returns formatted value when labelY is set', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,8 @@ export class LineChartComponent implements AfterViewInit, OnDestroy, OnChanges {
case label.toLowerCase().includes('bits'):
units = 'bits';
break;
}

if (typeof units === 'undefined') {
console.warn('Could not infer units from ' + this.labelY);
default:
console.warn('Could not infer units from ' + this.labelY);
}

return units;
Expand Down
8 changes: 5 additions & 3 deletions src/app/pages/sharing/smb/smb-acl/smb-acl.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,16 @@ import { TestDirective } from 'app/modules/test-id/test.directive';
import { UserService } from 'app/services/user.service';
import { WebSocketService } from 'app/services/ws.service';

type NameOrId = string | number | null;

interface FormAclEntry {
ae_who_sid: string;
ae_who: NfsAclTag.Everyone | NfsAclTag.UserGroup | NfsAclTag.User | NfsAclTag.Both | null;
ae_perm: SmbSharesecPermission;
ae_type: SmbSharesecType;
user: string | number | null;
group: string | number | null;
both: string | number | null;
user: NameOrId;
group: NameOrId;
both: NameOrId;
}

@UntilDestroy()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,7 @@ export class TopologyCardComponent implements OnInit, OnChanges {
// There should only be one value
const allVdevWidths: Set<number> = this.storageService.getVdevWidths(vdevs);
const isMixedWidth = this.storageService.isMixedWidth(allVdevWidths);
let isSingleDeviceCategory = false;

switch (category) {
case VdevType.Spare:
case VdevType.Cache:
isSingleDeviceCategory = true;
}
const isSingleDeviceCategory = [VdevType.Spare, VdevType.Cache].includes(category);

if (!isMixedWidth && !isSingleDeviceCategory) {
vdevWidth = Array.from(allVdevWidths.values())[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ export class GenerateVdevsService {
let pickedDisk: DetailsDisk;

do {
// eslint-disable-next-line @typescript-eslint/no-loop-func
pickedDisk = remainingDisks.find((disk) => disk.enclosure?.id === nextEnclosure);
if (!pickedDisk) nextEnclosure = this.enclosureList.next();
} while (!pickedDisk);
Expand Down
Loading

0 comments on commit 26d81aa

Please sign in to comment.