refactor: remove unnecessary TSLint rule flags (#59365)

There are many TSLint rule flags in the source code that have no effect, and they can be safely removed to keep the code clean.

PR Close #59365
This commit is contained in:
Johnson Chu
2025-01-06 15:37:07 +08:00
committed by Jessica Janiuk
parent 0e23f20c41
commit a6cdbec09f
37 changed files with 3 additions and 84 deletions
@@ -79,7 +79,6 @@ export class DocViewer implements OnChanges {
private readonly injector = inject(Injector);
private readonly appRef = inject(ApplicationRef);
// tslint:disable-next-line:no-unused-variable
private animateContent = false;
private readonly pendingTasks = inject(PendingTasks);
@@ -220,7 +220,6 @@ export class CodeMirrorEditor {
if (!this.currentFile().filename.endsWith('.ts')) return;
this.tsVfsWorker.postMessage(request);
// tslint:disable-next-line:semicolon
};
private getVfsEnvFileSystemMap(): Map<string, string> {
@@ -491,8 +491,7 @@ export class HomeAnimation {
this.canvas.update(time, deltaTime, frame, this.progress);
// TODO: add support for class fields arrow function
// Using disable-next-line to avoid tslint errors - An arrow function is required for binding to the listener
// tslint:disable-next-line:semicolon
// An arrow function is required for binding to the listener
};
/**
@@ -24,7 +24,6 @@ import {FrameManager} from '../../../../../projects/ng-devtools/src/lib/frame_ma
new IFrameMessageBus(
'angular-devtools',
'angular-devtools-backend',
// tslint:disable-next-line: no-non-null-assertion
() => (document.querySelector('#sample-app') as HTMLIFrameElement).contentWindow!,
),
);
@@ -490,7 +490,6 @@ const getRootLViewsHelper = (element: Element, rootLViews = new Set<any>()): Set
rootLViews.add(lView);
return rootLViews;
}
// tslint:disable-next-line: prefer-for-of
for (let i = 0; i < element.children.length; i++) {
getRootLViewsHelper(element.children[i], rootLViews);
}
@@ -6,7 +6,6 @@
* found in the LICENSE file at https://angular.dev/license
*/
// tslint:disable-next-line:deprecation
import {DefaultIterableDiffer} from '@angular/core';
export interface MovedRecord {
@@ -56,7 +55,6 @@ export const diff = <T>(
(a[record.currentIndex] as any)[prop] = (b[record.currentIndex] as any)[prop];
});
if (!alreadySet[record.previousIndex]) {
// tslint:disable-next-line: no-non-null-assertion
a[record.previousIndex] = null!;
}
alreadySet[record.currentIndex] = true;
@@ -79,7 +77,6 @@ export const diff = <T>(
return;
}
if (record.currentIndex === null && !alreadySet[record.previousIndex]) {
// tslint:disable-next-line: no-non-null-assertion
a[record.previousIndex] = null!;
}
removedItems.push(record.item);
@@ -110,7 +110,6 @@ describe('ElementPropertyResolver', () => {
});
const fooController = resolver.getDirectiveController('FooCmp');
expect(fooController).toBeTruthy();
// tslint:disable-next-line: no-non-null-assertion
const fooProps = fooController!.getExpandedProperties();
expect(fooProps).toEqual([
{
@@ -130,7 +129,6 @@ describe('ElementPropertyResolver', () => {
const barController = resolver.getDirectiveController('BarDir');
expect(barController).toBeTruthy();
// tslint:disable-next-line: no-non-null-assertion
const barProps = barController!.getExpandedProperties();
expect(barProps).toEqual([
{
@@ -83,7 +83,6 @@ export class PriorityAwareMessageBus extends MessageBus<Events> {
if (blockedBy) {
// The source code here is safe.
// TypeScript type inference ignores the null check here.
// tslint:disable-next-line: no-non-null-assertion
for (const blocker of blockedBy!) {
if (this._inProgress[blocker]) {
return false;
@@ -26,7 +26,6 @@ export const DEVTOOL_ROUTES: Routes = [
new IFrameMessageBus(
'angular-devtools',
'angular-devtools-backend',
// tslint:disable-next-line: no-non-null-assertion
() => (document.querySelector('#sample-app') as HTMLIFrameElement).contentWindow!,
),
);
-1
View File
@@ -6,7 +6,6 @@
* found in the LICENSE file at https://angular.dev/license
*/
/* tslint:disable:no-console */
urlParamsToForm();
export function getIntParameter(name: string) {
-1
View File
@@ -495,7 +495,6 @@ export class MockFetchFactory extends FetchFactory {
this.clearWarningTimeout = () => clearTimeout(timeoutId);
return this.promise;
// tslint:disable:semicolon
};
mockFlush(
-1
View File
@@ -16,7 +16,6 @@ export function setRootDomAdapter(adapter: DomAdapter) {
_DOM ??= adapter;
}
/* tslint:disable:requireParameterType */
/**
* Provides DOM operations in an environment-agnostic way.
*
@@ -603,7 +603,6 @@ export class FakeNavigationHistoryEntry implements NavigationHistoryEntry {
private readonly state: unknown;
private readonly historyState: unknown;
// tslint:disable-next-line:no-any
ondispose: ((this: NavigationHistoryEntry, ev: Event) => any) | null = null;
constructor(
@@ -90,10 +90,8 @@ export function removeEventListener(element: Element, info: EventHandlerInfo) {
const options = typeof info.passive === 'boolean' ? {capture: info.capture} : info.capture;
element.removeEventListener(info.eventType, info.handler as EventListener, options);
// `detachEvent` is an old DOM API.
// tslint:disable-next-line:no-any
} else if ((element as any).detachEvent) {
// `detachEvent` is an old DOM API.
// tslint:disable-next-line:no-any
(element as any).detachEvent(`on${info.eventType}`, info.handler);
}
}
@@ -147,13 +145,10 @@ let isMac: boolean = typeof navigator !== 'undefined' && /Macintosh/.test(naviga
function isMiddleClick(e: Event): boolean {
return (
// `which` is an old DOM API.
// tslint:disable-next-line:no-any
(e as any).which === 2 ||
// `which` is an old DOM API.
// tslint:disable-next-line:no-any
((e as any).which == null &&
// `button` is an old DOM API.
// tslint:disable-next-line:no-any
(e as any).button === 4) // middle click for IE
);
}
@@ -168,14 +163,11 @@ function isMiddleClick(e: Event): boolean {
export function isModifiedClickEvent(e: Event): boolean {
return (
// `metaKey` is an old DOM API.
// tslint:disable-next-line:no-any
(isMac && (e as any).metaKey) ||
// `ctrlKey` is an old DOM API.
// tslint:disable-next-line:no-any
(!isMac && (e as any).ctrlKey) ||
isMiddleClick(e) ||
// `shiftKey` is an old DOM API.
// tslint:disable-next-line:no-any
(e as any).shiftKey
);
}
@@ -214,7 +206,6 @@ export function isValidActionKeyTarget(el: Element): boolean {
return false;
}
// `isContentEditable` is an old DOM API.
// tslint:disable-next-line:no-any
if ((el as any).isContentEditable) {
return false;
}
@@ -230,16 +221,12 @@ export function isValidActionKeyTarget(el: Element): boolean {
function hasModifierKey(e: Event): boolean {
return (
// `ctrlKey` is an old DOM API.
// tslint:disable-next-line:no-any
(e as any).ctrlKey ||
// `shiftKey` is an old DOM API.
// tslint:disable-next-line:no-any
(e as any).shiftKey ||
// `altKey` is an old DOM API.
// tslint:disable-next-line:no-any
(e as any).altKey ||
// `metaKey` is an old DOM API.
// tslint:disable-next-line:no-any
(e as any).metaKey
);
}
@@ -294,10 +281,8 @@ export function shouldCallPreventDefaultOnNativeHtmlControl(e: Event): boolean {
export function isActionKeyEvent(e: Event): boolean {
let key =
// `which` is an old DOM API.
// tslint:disable-next-line:no-any
(e as any).which ||
// `keyCode` is an old DOM API.
// tslint:disable-next-line:no-any
(e as any).keyCode;
if (!key && (e as KeyboardEvent).key) {
key = ACTION_KEY_TO_KEYCODE[(e as KeyboardEvent).key];
@@ -374,10 +359,8 @@ const NATIVELY_FOCUSABLE_ELEMENTS: {[key: string]: number} = {
export function isSpaceKeyEvent(e: Event): boolean {
const key =
// `which` is an old DOM API.
// tslint:disable-next-line:no-any
(e as any).which ||
// `keyCode` is an old DOM API.
// tslint:disable-next-line:no-any
(e as any).keyCode;
const el = getTarget(e);
const elementName = ((el as HTMLInputElement).type || el.tagName).toUpperCase();
@@ -404,7 +387,6 @@ export function isSpaceKeyEvent(e: Event): boolean {
*/
export function isMouseSpecialEvent(e: Event, type: string, element: Element): boolean {
// `relatedTarget` is an old DOM API.
// tslint:disable-next-line:no-any
const related = (e as any).relatedTarget as Node;
return (
@@ -436,7 +418,6 @@ export function createMouseSpecialEvent(e: Event, target: Element): Event {
// this event into a pseudo-real mouseenter/mouseleave event by adjusting
// its type.
//
// tslint:disable-next-line:no-any
const copy: {-readonly [P in keyof Event]?: Event[P]} = {};
for (const property in e) {
if (property === 'srcElement' || property === 'target') {
@@ -444,14 +425,12 @@ export function createMouseSpecialEvent(e: Event, target: Element): Event {
}
const key = property as keyof Event;
// Making a copy requires iterating through all properties of `Event`.
// tslint:disable-next-line:no-dict-access-on-struct-type
const value = e[key];
if (typeof value === 'function') {
continue;
}
// Value should be the expected type, but the value of `key` is not known
// statically.
// tslint:disable-next-line:no-any
copy[key] = value as any;
}
if (e.type === EventType.MOUSEOVER) {
@@ -523,14 +502,12 @@ export function recreateTouchEventAsClick(event: TouchEvent): MouseEvent {
}
const key = property as keyof TouchEvent;
// Making a copy requires iterating through all properties of `TouchEvent`.
// tslint:disable-next-line:no-dict-access-on-struct-type
const value = event[key];
if (typeof value === 'function') {
continue;
}
// Value should be the expected type, but the value of `key` is not known
// statically.
// tslint:disable-next-line:no-any
click[key as keyof MouseEvent] = value as any;
}
@@ -193,7 +193,6 @@ function dispatchMouseEvent(
} = {},
) {
// createEvent/initMouseEvent is used to support IE11
// tslint:disable:deprecation
const event = document.createEvent('MouseEvent');
event.initMouseEvent(
type,
@@ -239,7 +238,6 @@ function dispatchKeyboardEvent(
} = {},
) {
// createEvent/initKeyboardEvent is used to support IE11
// tslint:disable:deprecation
const event = document.createEvent('KeyboardEvent');
event.initKeyboardEvent(
type,
@@ -621,7 +621,6 @@ describe('event test.ts', () => {
const originalEvent = document.createEvent('UIEvent') as TouchEvent;
originalEvent.initEvent('touchend', false, false);
// touches is readonly.
// tslint:disable-next-line:no-any
(originalEvent as any).touches = [
{clientX: 1, clientY: 2, screenX: 3, screenY: 4, pageX: 5, pageY: 6},
{},
@@ -640,7 +639,6 @@ describe('event test.ts', () => {
const originalEvent = document.createEvent('UIEvent') as TouchEvent;
originalEvent.initEvent('touchend', false, false);
// changedTouches is readonly.
// tslint:disable-next-line:no-any
(originalEvent as any).changedTouches = [
{
clientX: 'other',
@@ -660,7 +658,6 @@ describe('event test.ts', () => {
expect(event.screenX).toBe(3);
expect(event.screenY).toBe(4);
// originalEventType is a non-standard added property.
// tslint:disable-next-line:no-any
expect((event as any).originalEventType).toBe('touchend');
});
@@ -668,10 +665,8 @@ describe('event test.ts', () => {
const originalEvent = document.createEvent('UIEvent') as TouchEvent;
originalEvent.initEvent('touchend', false, false);
// changedTouches is readonly.
// tslint:disable-next-line:no-any
(originalEvent as any).changedTouches = [];
// touches is readonly.
// tslint:disable-next-line:no-any
(originalEvent as any).touches = [{clientX: 1}, {}];
const event = jsactionEvent.recreateTouchEventAsClick(originalEvent);
@@ -685,7 +680,6 @@ describe('event test.ts', () => {
const originalEvent = document.createEvent('UIEvent') as TouchEvent;
originalEvent.initEvent('touchend', false, false);
// touches is readonly.
// tslint:disable-next-line:no-any
(originalEvent as any).touches = [
{'clientX': 101, 'clientY': 102, 'screenX': 201, 'screenY': 202},
];
@@ -698,7 +692,6 @@ describe('event test.ts', () => {
expect(event.type).toBe(EventType.CLICK);
// originalEventType is a non-standard added property.
// tslint:disable-next-line:no-any
expect((event as any).originalEventType).toBe(EventType.TOUCHEND);
expect(event.target).toBe(div);
expect(event.clientX).toBe(101);
@@ -720,7 +713,6 @@ describe('event test.ts', () => {
expect(event.type).toBe(EventType.CLICK);
// originalEventType is a non-standard added property.
// tslint:disable-next-line:no-any
expect((event as any).originalEventType).toBe(EventType.TOUCHEND);
expect(event.target).toBe(div);
expect(event.clientX).toBeUndefined();
@@ -733,7 +725,6 @@ describe('event test.ts', () => {
const originalEvent = document.createEvent('UIEvent') as TouchEvent;
originalEvent.initEvent('touchend', false, false);
// touches is readonly.
// tslint:disable-next-line:no-any
(originalEvent as any).touches = [
{clientX: 1, clientY: 2, screenX: 3, screenY: 4, pageX: 5, pageY: 6},
{},
@@ -747,11 +738,9 @@ describe('event test.ts', () => {
expect(event.defaultPrevented).toBe(true);
// _propagationStopped is a non-standard added property.
// tslint:disable-next-line:no-any
expect((event as any)['_propagationStopped']).toBe(false);
event.stopPropagation();
// _propagationStopped is a non-standard added property.
// tslint:disable-next-line:no-any
expect((event as any)['_propagationStopped']).toBe(true);
});
@@ -759,7 +748,6 @@ describe('event test.ts', () => {
const originalEvent = document.createEvent('UIEvent') as TouchEvent;
originalEvent.initEvent('touchend', false, false);
// touches is readonly.
// tslint:disable-next-line:no-any
(originalEvent as any).touches = [
{clientX: 1, clientY: 2, screenX: 3, screenY: 4, pageX: 5, pageY: 6},
{},
@@ -129,7 +129,6 @@ function dispatchMouseEvent(
} = {},
) {
// createEvent/initMouseEvent is used to support IE11
// tslint:disable:deprecation
const event = document.createEvent('MouseEvent');
event.initMouseEvent(
type,
@@ -301,7 +300,6 @@ describe('EventContract', () => {
});
// createEvent/initEvent is used to support IE11
// tslint:disable:deprecation
const animationEndEvent = document.createEvent('AnimationEvent');
animationEndEvent.initEvent('webkitanimationend', true, true);
// tslint:enable:deprecation
-1
View File
@@ -16,7 +16,6 @@ export class Console {
}
// Note: for reporting errors use `DOM.logError()` as it is platform specific
warn(message: string): void {
// tslint:disable-next-line:no-console
console.warn(message);
}
}
+2 -1
View File
@@ -110,7 +110,8 @@ export interface EventEmitter<T> extends Subject<T>, OutputRef<T> {
}
class EventEmitter_ extends Subject<any> implements OutputRef<any> {
__isAsync: boolean; // tslint:disable-line
// tslint:disable-next-line:require-internal-with-underscore
__isAsync: boolean;
destroyRef: DestroyRef | undefined = undefined;
private readonly pendingTasks: PendingTasksInternal | undefined = undefined;
-1
View File
@@ -250,7 +250,6 @@ export function withDomHydration(): EnvironmentProviders {
'Make sure the `provideClientHydration()` is included into the list ' +
'of providers in the server part of the application configuration.',
);
// tslint:disable-next-line:no-console
console.warn(message);
}
},
@@ -334,7 +334,6 @@ export function reconcile<T, V>(
'.',
);
// tslint:disable-next-line:no-console
console.warn(message);
}
}
@@ -51,7 +51,6 @@ export const createNgModuleRef = createNgModule;
export class NgModuleRef<T> extends viewEngine_NgModuleRef<T> implements InternalNgModuleRef<T> {
// tslint:disable-next-line:require-internal-with-underscore
_bootstrapComponents: Type<any>[] = [];
// tslint:disable-next-line:require-internal-with-underscore
private readonly _r3Injector: R3Injector;
override instance!: T;
destroyCbs: (() => void)[] | null = [];
@@ -21,10 +21,8 @@ if (typeof ngI18nClosureMode === 'undefined') {
// Make sure to refer to ngI18nClosureMode as ['ngI18nClosureMode'] for closure.
// NOTE: we need to have it in IIFE so that the tree-shaker is happy.
(function () {
// tslint:disable-next-line:no-toplevel-property-access
global['ngI18nClosureMode'] =
// TODO(FW-1250): validate that this actually, you know, works.
// tslint:disable-next-line:no-toplevel-property-access
typeof goog !== 'undefined' && typeof goog.getMsg === 'function';
})();
}
@@ -3078,11 +3078,9 @@ const DEFAULT_COMPONENT_ID = '1';
exp2: any = false;
event1: AnimationEvent | undefined;
event2: AnimationEvent | undefined;
// tslint:disable:semicolon
callback1 = (event: any) => {
this.event1 = event;
};
// tslint:disable:semicolon
callback2 = (event: any) => {
this.event2 = event;
};
@@ -6,7 +6,6 @@
* found in the LICENSE file at https://angular.dev/license
*/
/* tslint:disable:no-console */
import {browser} from 'protractor';
import {logging} from 'selenium-webdriver';
@@ -6,7 +6,6 @@
* found in the LICENSE file at https://angular.dev/license
*/
/* tslint:disable:no-console */
import {browser} from 'protractor';
import {logging} from 'selenium-webdriver';
@@ -6,7 +6,6 @@
* found in the LICENSE file at https://angular.dev/license
*/
/* tslint:disable:no-console */
import {browser, by, element} from 'protractor';
import {logging} from 'selenium-webdriver';
@@ -6,7 +6,6 @@
* found in the LICENSE file at https://angular.dev/license
*/
/* tslint:disable:no-console */
import {browser} from 'protractor';
import {logging} from 'selenium-webdriver';
@@ -6,7 +6,6 @@
* found in the LICENSE file at https://angular.dev/license
*/
/* tslint:disable:no-console */
import {browser, by, element} from 'protractor';
import {logging} from 'selenium-webdriver';
@@ -6,7 +6,6 @@
* found in the LICENSE file at https://angular.dev/license
*/
/* tslint:disable:no-console */
import {browser, by, element, ExpectedConditions} from 'protractor';
import {logging} from 'selenium-webdriver';
@@ -6,7 +6,6 @@
* found in the LICENSE file at https://angular.dev/license
*/
/* tslint:disable:no-console */
import {browser, by, element, ElementHelper} from 'protractor';
import {logging} from 'selenium-webdriver';
@@ -5,7 +5,6 @@
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
/* tslint:disable:no-console */
import {
ChangeDetectionStrategy,
ChangeDetectorRef,
@@ -24,7 +24,6 @@ import {BrowserModule} from '@angular/platform-browser';
// #docregion basic-how-to
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
// #enddocregion
/* tslint:disable: no-duplicate-imports */
// #docregion basic-how-to
import {downgradeComponent, downgradeModule, UpgradeComponent} from '@angular/upgrade/static';
@@ -132,7 +132,6 @@ export class InMemoryBackendConfig implements InMemoryBackendConfigArgs {
/** Return information (UriInfo) about a URI */
export function parseUri(str: string): UriInfo {
// Adapted from parseuri package - http://blog.stevenlevithan.com/archives/parseuri
// tslint:disable-next-line:max-line-length
const URL_REGEX =
/^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/;
const m = URL_REGEX.exec(str);
@@ -163,7 +163,6 @@ function provideZoneJsCompatibilityDetector(): Provider[] {
'that uses a custom or a noop Zone.js implementation. ' +
'This is not yet a fully supported configuration.',
);
// tslint:disable-next-line:no-console
console.warn(message);
}
},
-7
View File
@@ -782,7 +782,6 @@ export function initZone(): ZoneType {
mark('Zone');
class ZoneImpl implements AmbientZone {
// tslint:disable-next-line:require-internal-with-underscore
static __symbol__: (name: string) => string = __symbol__;
static assertZonePatched() {
@@ -813,7 +812,6 @@ export function initZone(): ZoneType {
return _currentTask;
}
// tslint:disable-next-line:require-internal-with-underscore
static __load_patch(name: string, fn: PatchFn, ignoreDuplicate = false): void {
if (patches.hasOwnProperty(name)) {
// `checkDuplicate` option is defined from global variable
@@ -1372,7 +1370,6 @@ export function initZone(): ZoneType {
}
}
// tslint:disable-next-line:require-internal-with-underscore
_updateTaskCount(type: TaskType, count: number) {
const counts = this._taskCounts;
const prev = counts[type];
@@ -1400,12 +1397,9 @@ export function initZone(): ZoneType {
public data: TaskData | undefined;
public scheduleFn: ((task: Task) => void) | undefined;
public cancelFn: ((task: Task) => void) | undefined;
// tslint:disable-next-line:require-internal-with-underscore
_zone: ZoneImpl | null = null;
public runCount: number = 0;
// tslint:disable-next-line:require-internal-with-underscore
_zoneDelegates: _ZoneDelegate[] | null = null;
// tslint:disable-next-line:require-internal-with-underscore
_state: TaskState = 'notScheduled';
constructor(
@@ -1464,7 +1458,6 @@ export function initZone(): ZoneType {
this._transitionTo(notScheduled, scheduling);
}
// tslint:disable-next-line:require-internal-with-underscore
_transitionTo(toState: TaskState, fromState1: TaskState, fromState2?: TaskState) {
if (this._state === fromState1 || this._state === fromState2) {
this._state = toState;
@@ -29,6 +29,5 @@
);
})();
var no_initializer;
// tslint:disable-next-line:no-console
console.error(new A().a(), new B().b());
})();