Skip to content

Commit fc9db95

Browse files
authored
Merge pull request #3473 from D4N14L/user/danade/FileError
[node-core-library] Add `FileError` class for errors found in target files
2 parents 1339994 + bf286bf commit fc9db95

File tree

21 files changed

+922
-345
lines changed

21 files changed

+922
-345
lines changed

apps/heft/src/pluginFramework/logging/FileError.ts

Lines changed: 0 additions & 86 deletions
This file was deleted.

apps/heft/src/pluginFramework/logging/LoggingManager.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33

44
import { IHeftPlugin } from '../IHeftPlugin';
55
import { ScopedLogger } from './ScopedLogger';
6-
import { ITerminalProvider } from '@rushstack/node-core-library';
7-
import { FileErrorFormat, FileError } from './FileError';
6+
import {
7+
FileError,
8+
FileLocationStyle,
9+
ITerminalProvider,
10+
IFileErrorFormattingOptions
11+
} from '@rushstack/node-core-library';
812

913
export interface ILoggingManagerOptions {
1014
terminalProvider: ITerminalProvider;
@@ -48,38 +52,41 @@ export class LoggingManager {
4852
}
4953
}
5054

51-
public getErrorStrings(fileErrorFormat?: FileErrorFormat): string[] {
55+
public getErrorStrings(fileLocationStyle?: FileLocationStyle): string[] {
5256
const result: string[] = [];
5357

5458
for (const scopedLogger of this._scopedLoggers.values()) {
5559
result.push(
5660
...scopedLogger.errors.map(
57-
(error) => `[${scopedLogger.loggerName}] ${LoggingManager.getErrorMessage(error, fileErrorFormat)}`
61+
(error) =>
62+
`[${scopedLogger.loggerName}] ` +
63+
LoggingManager.getErrorMessage(error, { format: fileLocationStyle })
5864
)
5965
);
6066
}
6167

6268
return result;
6369
}
6470

65-
public getWarningStrings(fileErrorFormat?: FileErrorFormat): string[] {
71+
public getWarningStrings(fileErrorFormat?: FileLocationStyle): string[] {
6672
const result: string[] = [];
6773

6874
for (const scopedLogger of this._scopedLoggers.values()) {
6975
result.push(
7076
...scopedLogger.warnings.map(
7177
(warning) =>
72-
`[${scopedLogger.loggerName}] ${LoggingManager.getErrorMessage(warning, fileErrorFormat)}`
78+
`[${scopedLogger.loggerName}] ` +
79+
LoggingManager.getErrorMessage(warning, { format: fileErrorFormat })
7380
)
7481
);
7582
}
7683

7784
return result;
7885
}
7986

80-
public static getErrorMessage(error: Error, fileErrorFormat?: FileErrorFormat): string {
87+
public static getErrorMessage(error: Error, options?: IFileErrorFormattingOptions): string {
8188
if (error instanceof FileError) {
82-
return error.toString(fileErrorFormat);
89+
return error.getFormattedErrorMessage(options);
8390
} else {
8491
return error.message;
8592
}

apps/heft/src/pluginFramework/logging/test/FileError.test.ts

Lines changed: 0 additions & 36 deletions
This file was deleted.

apps/heft/src/plugins/TypeScriptPlugin/Eslint.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import * as path from 'path';
55
import * as crypto from 'crypto';
66
import * as semver from 'semver';
77
import * as TEslint from 'eslint';
8+
import { FileError } from '@rushstack/node-core-library';
89

910
import { LinterBase, ILinterBaseOptions, ITiming } from './LinterBase';
1011
import { IExtendedProgram, IExtendedSourceFile } from './internalTypings/TypeScriptInternals';
11-
import { FileError } from '../../pluginFramework/logging/FileError';
1212

1313
interface IEslintOptions extends ILinterBaseOptions {
1414
eslintPackagePath: string;
@@ -68,22 +68,18 @@ export class Eslint extends LinterBase<TEslint.ESLint.LintResult> {
6868
const warnings: Error[] = [];
6969

7070
for (const eslintFileResult of this._lintResult) {
71-
const buildFolderRelativeFilePath: string = path.relative(
72-
this._buildFolderPath,
73-
eslintFileResult.filePath
74-
);
7571
for (const message of eslintFileResult.messages) {
7672
eslintFailureCount++;
7773
// https://eslint.org/docs/developer-guide/nodejs-api#◆-lintmessage-type
7874
const formattedMessage: string = message.ruleId
7975
? `(${message.ruleId}) ${message.message}`
8076
: message.message;
81-
const errorObject: FileError = new FileError(
82-
formattedMessage,
83-
buildFolderRelativeFilePath,
84-
message.line,
85-
message.column
86-
);
77+
const errorObject: FileError = new FileError(formattedMessage, {
78+
absolutePath: eslintFileResult.filePath,
79+
projectFolder: this._buildFolderPath,
80+
line: message.line,
81+
column: message.column
82+
});
8783
switch (message.severity) {
8884
case EslintMessageSeverity.error: {
8985
errors.push(errorObject);

apps/heft/src/plugins/TypeScriptPlugin/Tslint.ts

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44
import * as path from 'path';
55
import type * as TTslint from 'tslint';
66
import * as crypto from 'crypto';
7-
import { Import, ITerminal, JsonFile } from '@rushstack/node-core-library';
7+
import { Import, ITerminal, JsonFile, FileError } from '@rushstack/node-core-library';
88

99
import { LinterBase, ILinterBaseOptions } from './LinterBase';
1010
import { IExtendedSourceFile, IExtendedProgram } from './internalTypings/TypeScriptInternals';
1111
import { IExtendedLinter } from './internalTypings/TslintInternals';
12-
import { FileError } from '../../pluginFramework/logging/FileError';
1312
import { TypeScriptCachedFileSystem } from '../../utilities/fileSystem/TypeScriptCachedFileSystem';
1413

1514
interface ITslintOptions extends ILinterBaseOptions {
@@ -101,18 +100,14 @@ export class Tslint extends LinterBase<TTslint.RuleFailure> {
101100
);
102101

103102
for (const tslintFailure of this._lintResult.failures) {
104-
const buildFolderRelativeFilename: string = path.relative(
105-
this._buildFolderPath,
106-
tslintFailure.getFileName()
107-
);
108103
const { line, character } = tslintFailure.getStartPosition().getLineAndCharacter();
109104
const formattedFailure: string = `(${tslintFailure.getRuleName()}) ${tslintFailure.getFailure()}`;
110-
const errorObject: FileError = new FileError(
111-
formattedFailure,
112-
buildFolderRelativeFilename,
113-
line + 1,
114-
character + 1
115-
);
105+
const errorObject: FileError = new FileError(formattedFailure, {
106+
absolutePath: tslintFailure.getFileName(),
107+
projectFolder: this._buildFolderPath,
108+
line: line + 1,
109+
column: character + 1
110+
});
116111
switch (tslintFailure.getRuleSeverity()) {
117112
case 'error': {
118113
this._scopedLogger.emitError(errorObject);

apps/heft/src/plugins/TypeScriptPlugin/TypeScriptBuilder.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import {
1212
ITerminalProvider,
1313
FileSystem,
1414
Path,
15-
Async
15+
Async,
16+
FileError
1617
} from '@rushstack/node-core-library';
1718
import type * as TTypescript from 'typescript';
1819
import {
@@ -29,7 +30,6 @@ import { PerformanceMeasurer, PerformanceMeasurerAsync } from '../../utilities/P
2930
import { Tslint } from './Tslint';
3031
import { Eslint } from './Eslint';
3132
import { IScopedLogger } from '../../pluginFramework/logging/ScopedLogger';
32-
import { FileError } from '../../pluginFramework/logging/FileError';
3333

3434
import { EmitFilesPatch, ICachedEmitModuleKind } from './EmitFilesPatch';
3535
import { HeftSession } from '../../pluginFramework/HeftSession';
@@ -736,12 +736,13 @@ export class TypeScriptBuilder extends SubprocessRunnerBase<ITypeScriptBuilderCo
736736
if (diagnostic.file) {
737737
const { line, character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start!);
738738
const message: string = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n');
739-
const buildFolderRelativeFilename: string = path.relative(
740-
this._configuration.buildFolder,
741-
diagnostic.file.fileName
742-
);
743739
const formattedMessage: string = `(TS${diagnostic.code}) ${message}`;
744-
errorObject = new FileError(formattedMessage, buildFolderRelativeFilename, line + 1, character + 1);
740+
errorObject = new FileError(formattedMessage, {
741+
absolutePath: diagnostic.file.fileName,
742+
projectFolder: this._configuration.buildFolder,
743+
line: line + 1,
744+
column: character + 1
745+
});
745746
diagnosticMessage = errorObject.toString();
746747
} else {
747748
diagnosticMessage = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n');

apps/heft/src/utilities/subprocess/SubprocessCommunication.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ export interface ISerializedErrorValue {
1515
}
1616

1717
export interface ISerializedFileErrorValue extends ISerializedErrorValue {
18-
filePath: string;
18+
absolutePath: string;
19+
projectFolder: string;
1920
line: number | undefined;
2021
column: number | undefined;
2122
}

apps/heft/src/utilities/subprocess/SubprocessRunnerBase.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import * as childProcess from 'child_process';
55
import * as path from 'path';
6-
import { ITerminalProvider, ITerminal, Terminal } from '@rushstack/node-core-library';
6+
import { ITerminalProvider, ITerminal, Terminal, FileError } from '@rushstack/node-core-library';
77

88
import {
99
ISubprocessMessageBase,
@@ -21,7 +21,6 @@ import {
2121
} from './SubprocessCommunicationManagerBase';
2222
import { IScopedLogger } from '../../pluginFramework/logging/ScopedLogger';
2323
import { SubprocessLoggerManager } from './SubprocessLoggerManager';
24-
import { FileError } from '../../pluginFramework/logging/FileError';
2524
import { SubprocessTerminator } from './SubprocessTerminator';
2625

2726
export interface ISubprocessInnerConfiguration {
@@ -344,7 +343,8 @@ export abstract class SubprocessRunnerBase<
344343
value: {
345344
errorMessage: arg.message,
346345
errorStack: arg.stack,
347-
filePath: arg.filePath,
346+
absolutePath: arg.absolutePath,
347+
projectFolder: arg.projectFolder,
348348
line: arg.line,
349349
column: arg.column
350350
}
@@ -402,12 +402,12 @@ export abstract class SubprocessRunnerBase<
402402
case SupportedSerializableArgType.FileError: {
403403
const typedArg: ISubprocessApiCallArgWithValue<ISerializedFileErrorValue> =
404404
arg as ISubprocessApiCallArgWithValue<ISerializedFileErrorValue>;
405-
const result: FileError = new FileError(
406-
typedArg.value.errorMessage,
407-
typedArg.value.filePath,
408-
typedArg.value.line,
409-
typedArg.value.column
410-
);
405+
const result: FileError = new FileError(typedArg.value.errorMessage, {
406+
absolutePath: typedArg.value.absolutePath,
407+
projectFolder: typedArg.value.projectFolder,
408+
line: typedArg.value.line,
409+
column: typedArg.value.column
410+
});
411411
result.stack = typedArg.value.errorStack;
412412
return result;
413413
}

0 commit comments

Comments
 (0)