refactor(lint): Don't allow console.log

Enable tslint check for `console.log` as a follow-up to
https://github.com/angular/angular/issues/13018
This commit is contained in:
Bowen Ni
2016-11-22 13:29:53 -08:00
committed by vsavkin
parent 6c2d931744
commit 2c02d34c05
32 changed files with 38 additions and 31 deletions

View File

@ -27,9 +27,7 @@ describe('firefox extension', function() {
browser.driver.get(TEST_URL);
browser.executeScript('window.startProfiler()').then(function() {
console.log('started measuring perf');
});
browser.executeScript('window.startProfiler()');
browser.executeAsyncScript('setTimeout(arguments[0], 1000);');
browser.executeScript('window.forceGC()');

View File

@ -44,7 +44,7 @@ export class CodeGenerator {
let root = this.options.basePath;
for (const eachRootDir of this.options.rootDirs || []) {
if (this.options.trace) {
console.log(`Check if ${filePath} is under rootDirs element ${eachRootDir}`);
console.error(`Check if ${filePath} is under rootDirs element ${eachRootDir}`);
}
if (path.relative(eachRootDir, filePath).indexOf('.') !== 0) {
root = eachRootDir;

View File

@ -56,7 +56,7 @@ export class PathMappedCompilerHost extends CompilerHost {
ts.resolveModuleName(m, rootedContainingFile, this.options, this.context).resolvedModule;
if (resolved) {
if (this.options.traceResolution) {
console.log('resolve', m, containingFile, '=>', resolved.resolvedFileName);
console.error('resolve', m, containingFile, '=>', resolved.resolvedFileName);
}
return this.getCanonicalFileName(resolved.resolvedFileName);
}
@ -71,7 +71,7 @@ export class PathMappedCompilerHost extends CompilerHost {
*/
fileNameToModuleName(importedFile: string, containingFile: string): string {
if (this.options.traceResolution) {
console.log(
console.error(
'getImportPath from containingFile', containingFile, 'to importedFile', importedFile);
}

View File

@ -369,7 +369,7 @@ export function extractProgramSymbols(
files.filter(fileName => _filterFileByPatterns(fileName, options)).forEach(sourceFile => {
const moduleMetadata = staticReflector.getModuleMetadata(sourceFile);
if (!moduleMetadata) {
console.log(`WARNING: no metadata found for ${sourceFile}`);
console.error(`WARNING: no metadata found for ${sourceFile}`);
return;
}

View File

@ -163,7 +163,7 @@ export class StaticReflector implements ReflectorReader {
}
return parameters;
} catch (e) {
console.log(`Failed on type ${JSON.stringify(type)} with error ${e}`);
console.error(`Failed on type ${JSON.stringify(type)} with error ${e}`);
throw e;
}
}

View File

@ -15,7 +15,6 @@ export function verifyNoBrowserErrors() {
const errors: any[] = [];
browserLog.filter(logEntry => {
const msg = logEntry.message;
console.log('>> ' + msg);
if (logEntry.level.value >= webdriver.logging.Level.INFO.value) {
errors.push(msg);
}

View File

@ -6,6 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
/* tslint:disable:no-console */
// #docregion Observable
import {Observable} from 'rxjs/Observable';
import {Subscriber} from 'rxjs/Subscriber';

View File

@ -6,6 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
/* tslint:disable:no-console */
// #docregion Observable
import 'rxjs/add/operator/map';

View File

@ -6,6 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
/* tslint:disable:no-console */
// #docregion Observable
import {Observable} from 'rxjs/Observable';
import {Subscriber} from 'rxjs/Subscriber';

View File

@ -6,6 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
/* tslint:disable:no-console */
// #docregion Component
import {Component} from '@angular/core';
import {FormArray, FormControl, FormGroup} from '@angular/forms';

View File

@ -6,6 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
/* tslint:disable:no-console */
// #docregion Component
import {Component} from '@angular/core';
import {FormControl, FormGroup, Validators} from '@angular/forms';

View File

@ -6,6 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
/* tslint:disable:no-console */
// #docregion Component
import {Component} from '@angular/core';
import {NgForm} from '@angular/forms';

View File

@ -6,6 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
/* tslint:disable:no-console */
// #docregion Component
import {Component} from '@angular/core';
import {NgForm} from '@angular/forms';

View File

@ -6,6 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
/* tslint:disable:no-console */
// #docregion Component
import {Component} from '@angular/core';
import {FormControl, FormGroup, Validators} from '@angular/forms';

View File

@ -129,6 +129,7 @@ export function isJsObject(o: any): boolean {
}
export function print(obj: Error | Object) {
// tslint:disable-next-line:no-console
console.log(obj);
}

View File

@ -85,6 +85,7 @@ export class BrowserDomAdapter extends GenericBrowserDomAdapter {
log(error: string): void {
if (window.console) {
// tslint:disable-next-line:no-console
window.console.log && window.console.log(error);
}
}

View File

@ -75,7 +75,9 @@ export class AngularProfiler {
(<any>window.console.profileEnd)(profileName);
}
const msPerTick = (end - start) / numTicks;
// tslint:disable-next-line:no-console
window.console.log(`ran ${numTicks} change detection cycles`);
// tslint:disable-next-line:no-console
window.console.log(`${msPerTick.toFixed(2)} ms per check`);
return new ChangeDetectionPerfRecord(msPerTick, numTicks);

View File

@ -63,6 +63,7 @@ export class Parse5DomAdapter extends DomAdapter {
logError(error: string) { console.error(error); }
// tslint:disable-next-line:no-console
log(error: string) { console.log(error); }
logGroup(error: string) { console.error(error); }

View File

@ -22,10 +22,12 @@ export class WorkerDomAdapter extends DomAdapter {
if (console.error) {
console.error(error);
} else {
// tslint:disable-next-line:no-console
console.log(error);
}
}
// tslint:disable-next-line:no-console
log(error: any /** TODO #9100 */) { console.log(error); }
logGroup(error: any /** TODO #9100 */) {
@ -33,6 +35,7 @@ export class WorkerDomAdapter extends DomAdapter {
console.group(error);
this.logError(error);
} else {
// tslint:disable-next-line:no-console
console.log(error);
}
}

View File

@ -15,7 +15,7 @@ export function stringify(obj: any): string {
export function onError(e: any) {
// TODO: (misko): We seem to not have a stack trace here!
console.log(e, e.stack);
console.error(e, e.stack);
throw e;
}

View File

@ -41,7 +41,7 @@ export function main() {
it('should throw an uncaught error', fakeAsync(() => {
const resolveSpy = jasmine.createSpy('resolveSpy');
spyOn(console, 'log');
spyOn(console, 'error');
expect(() => {
adapter.bootstrap(html('<ng2></ng2>'), ['ng1']).ready(resolveSpy);
@ -50,14 +50,14 @@ export function main() {
expect(resolveSpy).not.toHaveBeenCalled();
}));
it('should properly log to the console and re-throw', fakeAsync(() => {
spyOn(console, 'log');
it('should output an error message to the console and re-throw', fakeAsync(() => {
spyOn(console, 'error');
expect(() => {
adapter.bootstrap(html('<ng2></ng2>'), ['ng1']);
flushMicrotasks();
}).toThrowError();
expect(console.log).toHaveBeenCalled();
expect(console.log).toHaveBeenCalledWith(jasmine.any(Error), jasmine.any(String));
expect(console.error).toHaveBeenCalled();
expect(console.error).toHaveBeenCalledWith(jasmine.any(Error), jasmine.any(String));
}));
});