@k88/typescript-compile-error-formatter
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -1,22 +0,18 @@ | ||
interface MessageFunctional { | ||
getType: () => string; | ||
getSeverity: () => string; | ||
getFile: () => string; | ||
getLine: () => string; | ||
getContent: () => string; | ||
import { IssueOrigin } from 'fork-ts-checker-webpack-plugin/lib/issue/IssueOrigin'; | ||
import { IssueSeverity } from 'fork-ts-checker-webpack-plugin/lib/issue/IssueSeverity'; | ||
import { Issue } from 'fork-ts-checker-webpack-plugin/lib/issue'; | ||
export { IssueOrigin as Origin }; | ||
export { IssueSeverity as Severity }; | ||
export { Issue }; | ||
interface IssueFunctional { | ||
getOrigin: () => IssueOrigin; | ||
getSeverity: () => IssueSeverity; | ||
getCode: () => string; | ||
getCharacter: () => string; | ||
isWarningSeverity: () => boolean; | ||
getMessage: () => string; | ||
getFile?: () => string; | ||
getLine?: () => number; | ||
getCharacter?: () => number; | ||
getStack?: () => string; | ||
} | ||
export interface Message { | ||
type: string; | ||
severity: string; | ||
file: string; | ||
line: string; | ||
content: string; | ||
code: string; | ||
character: string; | ||
isWarningSeverity: () => boolean; | ||
} | ||
declare const _default: (message: MessageFunctional | Message, useColors?: boolean) => string; | ||
declare const _default: (issue: Issue | IssueFunctional, useColors?: boolean) => string; | ||
export default _default; |
@@ -8,24 +8,33 @@ "use strict"; | ||
var fs_1 = __importDefault(require("fs")); | ||
var IssueOrigin_1 = require("fork-ts-checker-webpack-plugin/lib/issue/IssueOrigin"); | ||
exports.Origin = IssueOrigin_1.IssueOrigin; | ||
var IssueSeverity_1 = require("fork-ts-checker-webpack-plugin/lib/issue/IssueSeverity"); | ||
exports.Severity = IssueSeverity_1.IssueSeverity; | ||
var chalk_1 = __importDefault(require("chalk")); | ||
var code_frame_1 = require("@babel/code-frame"); | ||
var decomposeMessage = function (message) { | ||
if ('getFile' in message && typeof message.getFile === 'function') { | ||
var decomposeIssue = function (issue) { | ||
if ('getOrigin' in issue && typeof issue.getOrigin === 'function') { | ||
return { | ||
type: message.getFile(), | ||
severity: message.getSeverity(), | ||
file: message.getFile(), | ||
line: message.getLine(), | ||
content: message.getContent(), | ||
code: message.getCode(), | ||
character: message.getCharacter(), | ||
isWarningSeverity: message.isWarningSeverity, | ||
origin: issue.getOrigin(), | ||
severity: issue.getSeverity(), | ||
code: issue.getCode(), | ||
message: issue.getMessage(), | ||
file: issue.getFile && issue.getFile(), | ||
line: issue.getLine && issue.getLine(), | ||
character: issue.getCharacter && issue.getCharacter(), | ||
stack: issue.getStack && issue.getStack(), | ||
}; | ||
} | ||
return message; | ||
return issue; | ||
}; | ||
var types = { diagnostic: 'TypeScript', lint: 'TSLint' }; | ||
exports.default = (function (message, useColors) { | ||
var types = { | ||
typescript: 'TypeScript', | ||
lint: 'Lint', | ||
internal: 'Internal', | ||
}; | ||
exports.default = (function (issue, useColors) { | ||
if (useColors === void 0) { useColors = true; } | ||
var _a = decomposeMessage(message), type = _a.type, severity = _a.severity, file = _a.file, line = _a.line, content = _a.content, code = _a.code, character = _a.character, isWarningSeverity = _a.isWarningSeverity; | ||
var messageColor = isWarningSeverity() ? chalk_1.default.yellow : chalk_1.default.red; | ||
var _a = decomposeIssue(issue), origin = _a.origin, severity = _a.severity, file = _a.file, line = _a.line, message = _a.message, code = _a.code, character = _a.character; | ||
var isWarning = severity === IssueSeverity_1.IssueSeverity.WARNING; | ||
var messageColor = isWarning ? chalk_1.default.yellow : chalk_1.default.red; | ||
var fileAndNumberColor = chalk_1.default.bold.cyan; | ||
@@ -40,6 +49,6 @@ var source = file && fs_1.default.existsSync(file) && fs_1.default.readFileSync(file, 'utf-8'); | ||
return [ | ||
messageColor.bold(types[type] + " " + severity.toLowerCase() + " in ") + | ||
messageColor.bold(types[origin] + " " + severity.toLowerCase() + " in ") + | ||
fileAndNumberColor(file + "(" + line + "," + character + ")") + | ||
messageColor(':'), | ||
content + " " + messageColor.underline((type === 'lint' ? 'Rule: ' : 'TS') + code), | ||
message + " " + messageColor.underline((origin === IssueOrigin_1.IssueOrigin.ESLINT ? 'Rule: ' : 'TS') + code), | ||
'', | ||
@@ -46,0 +55,0 @@ frame, |
{ | ||
"name": "@k88/typescript-compile-error-formatter", | ||
"version": "1.0.0", | ||
"description": "Formats Typescript error messages", | ||
"version": "1.0.1", | ||
"description": "Formats Typescript error messages from Fork TS Checker Webpack Plugin", | ||
"keywords": [ | ||
@@ -9,3 +9,4 @@ "typescript", | ||
"webpack error", | ||
"webpack warning" | ||
"webpack warning", | ||
"fork-ts-checker-webpack-plugin" | ||
], | ||
@@ -50,3 +51,4 @@ "homepage": "https://github.com/ktalebian/typescript-compile-error-formatter#readme", | ||
"eslint": "^6.8.0", | ||
"eslint-config-twilio-ts": "^1.22.0", | ||
"eslint-config-twilio-ts": "^1.22.1", | ||
"fork-ts-checker-webpack-plugin": "^4.1.3", | ||
"husky": "^4.2.5", | ||
@@ -56,3 +58,6 @@ "ts-node": "^8.8.2", | ||
}, | ||
"peerDependencies": { | ||
"fork-ts-checker-webpack-plugin": "^4.1.3" | ||
}, | ||
"reveal": true | ||
} |
@@ -1,4 +0,1 @@ | ||
# typescript-compile-error-formatter | ||
A error formatter for typescript compile errors, taking from create-react-app | ||
<h1 align="center">@k88/typescript-compile-error-formatter</h1> | ||
@@ -24,10 +21,8 @@ <p align="center">A error formatter for typescript compile errors, taken from <a href="hhttps://github.com/facebook/create-react-app/blob/master/packages/react-dev-utils/typescriptFormatter.js" target="_blank">react-dev-utils</a>, but is published as a standalone module and has Typescript definition.</p> | ||
Install using | ||
This formatter best works with the output of [fork-ts-checker-webpack-plugin](https://www.npmjs.com/package/fork-ts-checker-webpack-plugin) and is used as a peer dependency. Install both using: | ||
```bash | ||
npm install @k88/typescript-compile-error-formatter | ||
npm install @k88/typescript-compile-error-formatter fork-ts-checker-webpack-plugin --save-dev | ||
``` | ||
This formatter best works with the output of [fork-ts-checker-webpack-plugin](https://www.npmjs.com/package/fork-ts-checker-webpack-plugin). | ||
## Usage | ||
@@ -46,2 +41,2 @@ | ||
}); | ||
``` | ||
``` |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10037
73
5
7
41