Skip to content
This repository has been archived by the owner on Sep 14, 2021. It is now read-only.

print warning with line and column info #171

Merged
merged 2 commits into from Apr 16, 2017
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
* [BREAKING] Dropped support for node v4, added support for node v8. See our [node version support policy](https://www.polymer-project.org/2.0/docs/tools/node-support) for details.
* Dependency updates. Upgraded to new `polymer-bundler`, `polymer-analyzer` and `dom5` versions.
* Fixed bug where `<html>`, `<head>` and `<body>` were added to documents mutated by `HtmlSplitter` and the `CustomElementsES5AdapterInjector`.
* Print build-time warnings and errors with full location information, and precise underlines of the place where the problem was identified.

## [1.1.0] - 2017-04-14

Expand Down
28 changes: 3 additions & 25 deletions src/analyzer.ts
Expand Up @@ -13,7 +13,7 @@
*/

import * as path from 'path';
import {Analyzer, Document, Severity, UrlLoader, Warning} from 'polymer-analyzer';
import {Analyzer, Document, Severity, UrlLoader, Warning, WarningPrinter} from 'polymer-analyzer';
import {PassThrough, Transform} from 'stream';

import File = require('vinyl');
Expand Down Expand Up @@ -43,20 +43,6 @@ export interface DepsIndex {
fragmentToFullDeps: Map<string, DocumentDeps>;
}

/**
* Get a longer, single-line error message for logging and exeption-handling
* analysis Warning objects.
*
* Note: We cannot use WarningPrinter.printWarning() from the polymer-analyzer
* codebase because after minification & optimization its reported source
* ranges don't match the original source code. Instead we use this custom
* message generator that only includes the file name in the error message.
*/
function getFullWarningMessage(warning: Warning): string {
return `In ${warning.sourceRange.file}: [${warning.code}] - ${warning.message
}`;
}

/**
* A stream that tells the BuildAnalyzer to resolve each file it sees. It's
* important that files are resolved here in a seperate stream, so that analysis
Expand Down Expand Up @@ -350,16 +336,8 @@ export class BuildAnalyzer {
}

printWarnings(): void {
for (const warning of this.warnings) {
const message = getFullWarningMessage(warning);
if (warning.severity === Severity.ERROR) {
logger.error(message);
} else if (warning.severity === Severity.WARNING) {
logger.warn(message);
} else {
logger.debug(message);
}
}
const warningPrinter = new WarningPrinter(process.stdout, { analyzer: this.analyzer });
warningPrinter.printWarnings(this.warnings);
}

private countWarningsByType(): Map<Severity, number> {
Expand Down