Skip to content

Commit 31fdf0f

Browse files
josephperrottAndrewKushnir
authored andcommitted
refactor: migrate core to prettier formatting (angular#55488)
Migrate formatting to prettier for core from clang-format PR Close angular#55488
1 parent be17de5 commit 31fdf0f

File tree

581 files changed

+54924
-43616
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

581 files changed

+54924
-43616
lines changed

.ng-dev/format.mts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export const format: FormatConfig = {
1818
'packages/benchpress/**/*.{js,ts}',
1919
'packages/common/**/*.{js,ts}',
2020
'packages/compiler/**/*.{js,ts}',
21-
'packages/core/primitives/**/*.{js,ts}',
21+
'packages/core/**/*.{js,ts}',
2222
'packages/docs/**/*.{js,ts}',
2323
'packages/elements/**/*.{js,ts}',
2424
'packages/examples/**/*.{js,ts}',
@@ -40,6 +40,11 @@ export const format: FormatConfig = {
4040
// not be modified.
4141
'!third_party/**',
4242
'!.yarn/**',
43+
// Do not format the locale files which are checked-in for Google3, but generated using
44+
// the `generate-locales-tool` from `packages/common/locales`.
45+
'!packages/core/src/i18n/locale_en.ts',
46+
'!packages/common/locales/closure-locale.ts',
47+
'!packages/common/src/i18n/currencies.ts',
4348
],
4449
},
4550
'clang-format': {
@@ -77,7 +82,7 @@ export const format: FormatConfig = {
7782
'!packages/benchpress/**/*.{js,ts}',
7883
'!packages/common/**/*.{js,ts}',
7984
'!packages/compiler/**/*.{js,ts}',
80-
'!packages/core/primitives/**/*.{js,ts}',
85+
'!packages/core/**/*.{js,ts}',
8186
'!packages/docs/**/*.{js,ts}',
8287
'!packages/elements/**/*.{js,ts}',
8388
'!packages/examples/**/*.{js,ts}',

goldens/public-api/core/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1205,7 +1205,7 @@ export class NgProbeToken {
12051205

12061206
// @public
12071207
export class NgZone {
1208-
constructor({ enableLongStackTrace, shouldCoalesceEventChangeDetection, shouldCoalesceRunChangeDetection }: {
1208+
constructor({ enableLongStackTrace, shouldCoalesceEventChangeDetection, shouldCoalesceRunChangeDetection, }: {
12091209
enableLongStackTrace?: boolean | undefined;
12101210
shouldCoalesceEventChangeDetection?: boolean | undefined;
12111211
shouldCoalesceRunChangeDetection?: boolean | undefined;

packages/core/rxjs-interop/src/output_from_observable.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,16 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {assertInInjectionContext, DestroyRef, inject, OutputOptions, OutputRef, OutputRefSubscription, ɵRuntimeError, ɵRuntimeErrorCode} from '@angular/core';
9+
import {
10+
assertInInjectionContext,
11+
DestroyRef,
12+
inject,
13+
OutputOptions,
14+
OutputRef,
15+
OutputRefSubscription,
16+
ɵRuntimeError,
17+
ɵRuntimeErrorCode,
18+
} from '@angular/core';
1019
import {Observable} from 'rxjs';
1120

1221
import {takeUntilDestroyed} from './take_until_destroyed';
@@ -31,15 +40,16 @@ class OutputFromObservableRef<T> implements OutputRef<T> {
3140
subscribe(callbackFn: (value: T) => void): OutputRefSubscription {
3241
if (this.destroyed) {
3342
throw new ɵRuntimeError(
34-
ɵRuntimeErrorCode.OUTPUT_REF_DESTROYED,
35-
ngDevMode &&
36-
'Unexpected subscription to destroyed `OutputRef`. ' +
37-
'The owning directive/component is destroyed.');
43+
ɵRuntimeErrorCode.OUTPUT_REF_DESTROYED,
44+
ngDevMode &&
45+
'Unexpected subscription to destroyed `OutputRef`. ' +
46+
'The owning directive/component is destroyed.',
47+
);
3848
}
3949

4050
// Stop yielding more values when the directive/component is already destroyed.
4151
const subscription = this.source.pipe(takeUntilDestroyed(this.destroyRef)).subscribe({
42-
next: value => callbackFn(value),
52+
next: (value) => callbackFn(value),
4353
});
4454

4555
return {
@@ -73,7 +83,9 @@ class OutputFromObservableRef<T> implements OutputRef<T> {
7383
* @developerPreview
7484
*/
7585
export function outputFromObservable<T>(
76-
observable: Observable<T>, opts?: OutputOptions): OutputRef<T> {
86+
observable: Observable<T>,
87+
opts?: OutputOptions,
88+
): OutputRef<T> {
7789
ngDevMode && assertInInjectionContext(outputFromObservable);
7890
return new OutputFromObservableRef<T>(observable);
7991
}

packages/core/rxjs-interop/src/output_to_observable.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ import {Observable} from 'rxjs';
2020
export function outputToObservable<T>(ref: OutputRef<T>): Observable<T> {
2121
const destroyRef = ɵgetOutputDestroyRef(ref);
2222

23-
return new Observable<T>(observer => {
23+
return new Observable<T>((observer) => {
2424
// Complete the observable upon directive/component destroy.
2525
// Note: May be `undefined` if an `EventEmitter` is declared outside
2626
// of an injection context.
2727
destroyRef?.onDestroy(() => observer.complete());
2828

29-
const subscription = ref.subscribe(v => observer.next(v));
29+
const subscription = ref.subscribe((v) => observer.next(v));
3030
return () => subscription.unsubscribe();
3131
});
3232
}

packages/core/rxjs-interop/src/take_until_destroyed.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export function takeUntilDestroyed<T>(destroyRef?: DestroyRef): MonoTypeOperator
2626
destroyRef = inject(DestroyRef);
2727
}
2828

29-
const destroyed$ = new Observable<void>(observer => {
29+
const destroyed$ = new Observable<void>((observer) => {
3030
const unregisterFn = destroyRef!.onDestroy(observer.next.bind(observer));
3131
return unregisterFn;
3232
});

packages/core/rxjs-interop/src/to_observable.ts

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,15 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {assertInInjectionContext, DestroyRef, effect, inject, Injector, Signal, untracked} from '@angular/core';
9+
import {
10+
assertInInjectionContext,
11+
DestroyRef,
12+
effect,
13+
inject,
14+
Injector,
15+
Signal,
16+
untracked,
17+
} from '@angular/core';
1018
import {Observable, ReplaySubject} from 'rxjs';
1119

1220
/**
@@ -33,24 +41,24 @@ export interface ToObservableOptions {
3341
*
3442
* @developerPreview
3543
*/
36-
export function toObservable<T>(
37-
source: Signal<T>,
38-
options?: ToObservableOptions,
39-
): Observable<T> {
44+
export function toObservable<T>(source: Signal<T>, options?: ToObservableOptions): Observable<T> {
4045
!options?.injector && assertInInjectionContext(toObservable);
4146
const injector = options?.injector ?? inject(Injector);
4247
const subject = new ReplaySubject<T>(1);
4348

44-
const watcher = effect(() => {
45-
let value: T;
46-
try {
47-
value = source();
48-
} catch (err) {
49-
untracked(() => subject.error(err));
50-
return;
51-
}
52-
untracked(() => subject.next(value));
53-
}, {injector, manualCleanup: true});
49+
const watcher = effect(
50+
() => {
51+
let value: T;
52+
try {
53+
value = source();
54+
} catch (err) {
55+
untracked(() => subject.error(err));
56+
return;
57+
}
58+
untracked(() => subject.next(value));
59+
},
60+
{injector, manualCleanup: true},
61+
);
5462

5563
injector.get(DestroyRef).onDestroy(() => {
5664
watcher.destroy();

packages/core/rxjs-interop/src/to_signal.ts

Lines changed: 48 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,19 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {assertInInjectionContext, assertNotInReactiveContext, computed, DestroyRef, inject, Injector, signal, Signal, WritableSignal, ɵRuntimeError, ɵRuntimeErrorCode} from '@angular/core';
9+
import {
10+
assertInInjectionContext,
11+
assertNotInReactiveContext,
12+
computed,
13+
DestroyRef,
14+
inject,
15+
Injector,
16+
signal,
17+
Signal,
18+
WritableSignal,
19+
ɵRuntimeError,
20+
ɵRuntimeErrorCode,
21+
} from '@angular/core';
1022
import {Observable, Subscribable} from 'rxjs';
1123

1224
/**
@@ -61,23 +73,27 @@ export interface ToSignalOptions {
6173
}
6274

6375
// Base case: no options -> `undefined` in the result type.
64-
export function toSignal<T>(source: Observable<T>|Subscribable<T>): Signal<T|undefined>;
76+
export function toSignal<T>(source: Observable<T> | Subscribable<T>): Signal<T | undefined>;
6577
// Options with `undefined` initial value and no `requiredSync` -> `undefined`.
6678
export function toSignal<T>(
67-
source: Observable<T>|Subscribable<T>,
68-
options: ToSignalOptions&{initialValue?: undefined, requireSync?: false}): Signal<T|undefined>;
79+
source: Observable<T> | Subscribable<T>,
80+
options: ToSignalOptions & {initialValue?: undefined; requireSync?: false},
81+
): Signal<T | undefined>;
6982
// Options with `null` initial value -> `null`.
7083
export function toSignal<T>(
71-
source: Observable<T>|Subscribable<T>,
72-
options: ToSignalOptions&{initialValue?: null, requireSync?: false}): Signal<T|null>;
84+
source: Observable<T> | Subscribable<T>,
85+
options: ToSignalOptions & {initialValue?: null; requireSync?: false},
86+
): Signal<T | null>;
7387
// Options with `undefined` initial value and `requiredSync` -> strict result type.
7488
export function toSignal<T>(
75-
source: Observable<T>|Subscribable<T>,
76-
options: ToSignalOptions&{initialValue?: undefined, requireSync: true}): Signal<T>;
89+
source: Observable<T> | Subscribable<T>,
90+
options: ToSignalOptions & {initialValue?: undefined; requireSync: true},
91+
): Signal<T>;
7792
// Options with a more specific initial value type.
7893
export function toSignal<T, const U extends T>(
79-
source: Observable<T>|Subscribable<T>,
80-
options: ToSignalOptions&{initialValue: U, requireSync?: false}): Signal<T|U>;
94+
source: Observable<T> | Subscribable<T>,
95+
options: ToSignalOptions & {initialValue: U; requireSync?: false},
96+
): Signal<T | U>;
8197

8298
/**
8399
* Get the current value of an `Observable` as a reactive `Signal`.
@@ -104,28 +120,31 @@ export function toSignal<T, const U extends T>(
104120
* @developerPreview
105121
*/
106122
export function toSignal<T, U = undefined>(
107-
source: Observable<T>|Subscribable<T>,
108-
options?: ToSignalOptions&{initialValue?: U}): Signal<T|U> {
123+
source: Observable<T> | Subscribable<T>,
124+
options?: ToSignalOptions & {initialValue?: U},
125+
): Signal<T | U> {
109126
ngDevMode &&
110-
assertNotInReactiveContext(
111-
toSignal,
112-
'Invoking `toSignal` causes new subscriptions every time. ' +
113-
'Consider moving `toSignal` outside of the reactive context and read the signal value where needed.');
127+
assertNotInReactiveContext(
128+
toSignal,
129+
'Invoking `toSignal` causes new subscriptions every time. ' +
130+
'Consider moving `toSignal` outside of the reactive context and read the signal value where needed.',
131+
);
114132

115133
const requiresCleanup = !options?.manualCleanup;
116134
requiresCleanup && !options?.injector && assertInInjectionContext(toSignal);
117-
const cleanupRef =
118-
requiresCleanup ? options?.injector?.get(DestroyRef) ?? inject(DestroyRef) : null;
135+
const cleanupRef = requiresCleanup
136+
? options?.injector?.get(DestroyRef) ?? inject(DestroyRef)
137+
: null;
119138

120139
// Note: T is the Observable value type, and U is the initial value type. They don't have to be
121140
// the same - the returned signal gives values of type `T`.
122-
let state: WritableSignal<State<T|U>>;
141+
let state: WritableSignal<State<T | U>>;
123142
if (options?.requireSync) {
124143
// Initially the signal is in a `NoValue` state.
125144
state = signal({kind: StateKind.NoValue});
126145
} else {
127146
// If an initial value was passed, use it. Otherwise, use `undefined` as the initial value.
128-
state = signal<State<T|U>>({kind: StateKind.Value, value: options?.initialValue as U});
147+
state = signal<State<T | U>>({kind: StateKind.Value, value: options?.initialValue as U});
129148
}
130149

131150
// Note: This code cannot run inside a reactive context (see assertion above). If we'd support
@@ -135,8 +154,8 @@ export function toSignal<T, U = undefined>(
135154
// subscription. Additional context (related to async pipe):
136155
// https://github.com/angular/angular/pull/50522.
137156
const sub = source.subscribe({
138-
next: value => state.set({kind: StateKind.Value, value}),
139-
error: error => {
157+
next: (value) => state.set({kind: StateKind.Value, value}),
158+
error: (error) => {
140159
if (options?.rejectErrors) {
141160
// Kick the error back to RxJS. It will be caught and rethrown in a macrotask, which causes
142161
// the error to end up as an uncaught exception.
@@ -150,8 +169,9 @@ export function toSignal<T, U = undefined>(
150169

151170
if (ngDevMode && options?.requireSync && state().kind === StateKind.NoValue) {
152171
throw new ɵRuntimeError(
153-
ɵRuntimeErrorCode.REQUIRE_SYNC_WITHOUT_SYNC_EMIT,
154-
'`toSignal()` called with `requireSync` but `Observable` did not emit synchronously.');
172+
ɵRuntimeErrorCode.REQUIRE_SYNC_WITHOUT_SYNC_EMIT,
173+
'`toSignal()` called with `requireSync` but `Observable` did not emit synchronously.',
174+
);
155175
}
156176

157177
// Unsubscribe when the current context is destroyed, if requested.
@@ -170,8 +190,9 @@ export function toSignal<T, U = undefined>(
170190
// This shouldn't really happen because the error is thrown on creation.
171191
// TODO(alxhub): use a RuntimeError when we finalize the error semantics
172192
throw new ɵRuntimeError(
173-
ɵRuntimeErrorCode.REQUIRE_SYNC_WITHOUT_SYNC_EMIT,
174-
'`toSignal()` called with `requireSync` but `Observable` did not emit synchronously.');
193+
ɵRuntimeErrorCode.REQUIRE_SYNC_WITHOUT_SYNC_EMIT,
194+
'`toSignal()` called with `requireSync` but `Observable` did not emit synchronously.',
195+
);
175196
}
176197
});
177198
}
@@ -196,4 +217,4 @@ interface ErrorState {
196217
error: unknown;
197218
}
198219

199-
type State<T> = NoValueState|ValueState<T>|ErrorState;
220+
type State<T> = NoValueState | ValueState<T> | ErrorState;

0 commit comments

Comments
 (0)