Skip to content

refactor(@angular-devkit/schematics): add explicit return types to functions #30212

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

Merged
merged 1 commit into from
Apr 30, 2025
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
8 changes: 4 additions & 4 deletions packages/angular_devkit/schematics/src/engine/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ export class CollectionImpl<CollectionT extends object, SchematicT extends objec
public readonly baseDescriptions?: Array<CollectionDescription<CollectionT>>,
) {}

get description() {
get description(): CollectionDescription<CollectionT> {
return this._description;
}
get name() {
get name(): string {
return this.description.name || '<unknown>';
}

Expand Down Expand Up @@ -183,10 +183,10 @@ export class SchematicEngine<CollectionT extends object, SchematicT extends obje
protected _workflow?: Workflow,
) {}

get workflow() {
get workflow(): Workflow | null {
return this._workflow || null;
}
get defaultMergeStrategy() {
get defaultMergeStrategy(): MergeStrategy {
return this._host.defaultMergeStrategy || MergeStrategy.Default;
}

Expand Down
4 changes: 2 additions & 2 deletions packages/angular_devkit/schematics/src/engine/schematic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ export class SchematicImpl<CollectionT extends object, SchematicT extends object
}
}

get description() {
get description(): SchematicDescription<CollectionT, SchematicT> {
return this._description;
}
get collection() {
get collection(): Collection<CollectionT, SchematicT> {
return this._collection;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/angular_devkit/schematics/src/sink/host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export class HostSink extends SimpleSinkBase {
return EMPTY;
}

_done() {
_done(): Observable<void> {
// Really commit everything to the actual filesystem.
return concatObservables(
observableFrom([...this._filesToDelete.values()]).pipe(
Expand Down
22 changes: 11 additions & 11 deletions packages/angular_devkit/schematics/src/tree/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,28 @@ let _id = 1;
export class ActionList implements Iterable<Action> {
private _actions: Action[] = [];

protected _action(action: Partial<Action>) {
protected _action(action: Partial<Action>): void {
this._actions.push({
...(action as Action),
id: _id++,
parent: this._actions[this._actions.length - 1]?.id ?? 0,
});
}

create(path: Path, content: Buffer) {
create(path: Path, content: Buffer): void {
this._action({ kind: 'c', path, content });
}
overwrite(path: Path, content: Buffer) {
overwrite(path: Path, content: Buffer): void {
this._action({ kind: 'o', path, content });
}
rename(path: Path, to: Path) {
rename(path: Path, to: Path): void {
this._action({ kind: 'r', path, to });
}
delete(path: Path) {
delete(path: Path): void {
this._action({ kind: 'd', path });
}

optimize() {
optimize(): void {
const toCreate = new Map<Path, Buffer>();
const toRename = new Map<Path, Path>();
const toOverwrite = new Map<Path, Buffer>();
Expand Down Expand Up @@ -122,13 +122,13 @@ export class ActionList implements Iterable<Action> {
});
}

push(action: Action) {
push(action: Action): void {
this._actions.push(action);
}
get(i: number) {
get(i: number): Action {
return this._actions[i];
}
has(action: Action) {
has(action: Action): boolean {
for (let i = 0; i < this._actions.length; i++) {
const a = this._actions[i];
if (a.id == action.id) {
Expand All @@ -144,10 +144,10 @@ export class ActionList implements Iterable<Action> {
find(predicate: (value: Action) => boolean): Action | null {
return this._actions.find(predicate) || null;
}
forEach(fn: (value: Action, index: number, array: Action[]) => void, thisArg?: {}) {
forEach(fn: (value: Action, index: number, array: Action[]) => void, thisArg?: {}): void {
this._actions.forEach(fn, thisArg);
}
get length() {
get length(): number {
return this._actions.length;
}
[Symbol.iterator](): IterableIterator<Action> {
Expand Down
8 changes: 4 additions & 4 deletions packages/angular_devkit/schematics/src/tree/entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ export class SimpleFileEntry implements FileEntry {
private _content: Buffer,
) {}

get path() {
get path(): Path {
return this._path;
}
get content() {
get content(): Buffer {
return this._content;
}
}
Expand All @@ -31,10 +31,10 @@ export class LazyFileEntry implements FileEntry {
private _load: (path?: Path) => Buffer,
) {}

get path() {
get path(): Path {
return this._path;
}
get content() {
get content(): Buffer {
return this._content || (this._content = this._load(this._path));
}
}
10 changes: 5 additions & 5 deletions packages/angular_devkit/schematics/src/tree/host-tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export class HostTree implements Tree {

private _dirCache = new Map<Path, HostDirEntry>();

[TreeSymbol]() {
[TreeSymbol](): this {
return this;
}

Expand All @@ -132,19 +132,19 @@ export class HostTree implements Tree {
return normalize('/' + path);
}

protected _willCreate(path: Path) {
protected _willCreate(path: Path): boolean {
return this._record.willCreate(path);
}

protected _willOverwrite(path: Path) {
protected _willOverwrite(path: Path): boolean {
return this._record.willOverwrite(path);
}

protected _willDelete(path: Path) {
protected _willDelete(path: Path): boolean {
return this._record.willDelete(path);
}

protected _willRename(path: Path) {
protected _willRename(path: Path): boolean {
return this._record.willRename(path);
}

Expand Down
8 changes: 4 additions & 4 deletions packages/angular_devkit/schematics/src/tree/null.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ export class NullTreeDirEntry implements DirEntry {
return null;
}

visit() {}
visit(): void {}
}

export class NullTree implements Tree {
[TreeSymbol]() {
[TreeSymbol](): this {
return this;
}

Expand All @@ -74,10 +74,10 @@ export class NullTree implements Tree {
get(_path: string) {
return null;
}
getDir(path: string) {
getDir(path: string): NullTreeDirEntry {
return new NullTreeDirEntry(normalize('/' + path));
}
visit() {}
visit(): void {}

// Change content of host files.
beginUpdate(path: string): never {
Expand Down
4 changes: 2 additions & 2 deletions packages/angular_devkit/schematics/src/tree/recorder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ export class UpdateRecorderBase implements UpdateRecorder {
return new UpdateRecorderBase(entry.content, entry.path);
}

get path() {
get path(): string {
return this._path;
}

protected _assertIndex(index: number) {
protected _assertIndex(index: number): void {
if (index < 0 || index > this.content.original.length) {
throw new IndexOutOfBoundException(index, 0, this.content.original.length);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/angular_devkit/schematics/src/tree/scoped.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ export class ScopedTree implements Tree {
return scopedActions;
}

[TreeSymbol]() {
[TreeSymbol](): this {
return this;
}

Expand Down
10 changes: 7 additions & 3 deletions packages/angular_devkit/schematics/src/tree/static.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,19 @@ import { SchematicsException } from '../exception/exception';
import { FilterHostTree, HostTree } from './host-tree';
import { FilePredicate, MergeStrategy, Tree } from './interface';

export function empty() {
export function empty(): HostTree {
return new HostTree();
}

export function branch(tree: Tree) {
export function branch(tree: Tree): Tree {
return tree.branch();
}

export function merge(tree: Tree, other: Tree, strategy: MergeStrategy = MergeStrategy.Default) {
export function merge(
tree: Tree,
other: Tree,
strategy: MergeStrategy = MergeStrategy.Default,
): Tree {
tree.merge(other, strategy);

return tree;
Expand Down
Loading