Skip to content
This repository was archived by the owner on Apr 4, 2025. It is now read-only.

refactor(log): Remove log option #84

Closed
wants to merge 1 commit into from
Closed
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
7 changes: 3 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,12 +225,11 @@ The following steps describe how an AngularHint module should be developed.
- Each AngularHint module should load its own dependencies using `browserify`. For instance, AngularHintDOM depends on the library `domInterceptor`. This dependency is included within AngularHintDom by the browserify `require` function.
- All AngularHint modules should load AngularHintLog as a dependency, see #3.

3. Message Logging
3. Events

All AngularHint modules should use AngularHintLog to log their messages. This creates a standard pipeline for
all AngularHint messages.
All AngularHint modules should use `hint.emit` to emit their events. This creates a standard pipeline for all AngularHint events.

To use AngularHintLog, see its [README.md](https://github.com/angular/angular-hint-log#angular-hint-log).
`angular.hint` is an instance of [EventEmitter2](https://github.com/asyncly/EventEmitter2).

4. Module Testing

Expand Down
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,6 @@ AngularHint is composed of several small modules that you may want to use indivi
* [AngularHintInterpolation](https://github.com/angular/angular-hint-interpolation)
* [AngularHintModules](https://github.com/angular/angular-hint-modules)

AngularHint uses [AngularHintLog](https://github.com/angular/angular-hint-log) to provide
logging functionality.

## Interested in Contributing?
See the [Contributing Guidelines](https://github.com/angular/angular-hint/blob/master/CONTRIBUTING.md)

Expand Down
9 changes: 3 additions & 6 deletions hint.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
'use strict';

// Set up the event stuffs
require('./src/modules/hintEmitter');

// Create pipe for all hint messages from different modules
require('./src/modules/log');
require('./src/modules/hintEmitter');

// Load angular hint modules
require('./src/modules/controllers');
Expand Down Expand Up @@ -76,7 +73,7 @@ function loadModules() {
} else if (document.querySelector('[ng-hint]')) {
modules = AVAILABLE_MODULES;
} else {
angular.hint.log('General', 'ngHint is included on the page, but is not active because ' +
angular.hint.emit('general:noinclude', 'ngHint is included on the page, but is not active because ' +
'there is no `ng-hint` attribute present', SEVERITY_WARNING);
}
return modules;
Expand All @@ -94,7 +91,7 @@ function hintModulesFromElement (elt) {

return selectedModules.map(hintModuleName).filter(function (name) {
return (AVAILABLE_MODULES.indexOf(name) > -1) ||
angular.hint.log('General', 'Module ' + name + ' could not be found', SEVERITY_WARNING);
angular.hint.emit('general:404module', 'Module ' + name + ' could not be found', SEVERITY_WARNING);
});
}

Expand Down
5 changes: 2 additions & 3 deletions src/modules/angular-hint-modules/display.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
var hintLog = angular.hint = require('./../log'),
MODULE_NAME = 'Modules';
var MODULE_NAME = 'Modules';

module.exports = function(modules) {
modules.forEach(function(module) {
hintLog.log(MODULE_NAME, module.message, module.severity);
angular.hint.emit(MODULE_NAME, module.message, module.severity);
});
};
5 changes: 2 additions & 3 deletions src/modules/angular-hint-modules/getNgAppMod.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
var hintLog = angular.hint = require('./../log'),
MODULE_NAME = 'Modules',
var MODULE_NAME = 'Modules',
SEVERITY_ERROR = 1;
module.exports = function(attrs, ngAppFound) {
if(attrs['ng-app'] && ngAppFound) {
hintLog.log(MODULE_NAME, 'ng-app may only be included once. The module "' +
angular.hint.emit(MODULE_NAME, 'ng-app may only be included once. The module "' +
attrs['ng-app'].value + '" was not used to bootstrap because ng-app was already included.',
SEVERITY_ERROR);
}
Expand Down
5 changes: 2 additions & 3 deletions src/modules/angular-hint-modules/hasNameSpace.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
var hintLog = angular.hint = require('./../log'),
MODULE_NAME = 'Modules',
var MODULE_NAME = 'Modules',
SEVERITY_SUGGESTION = 3;

module.exports = function(str) {
Expand All @@ -8,7 +7,7 @@ module.exports = function(str) {
}

if(str.toLowerCase() === str || str.charAt(0).toUpperCase() === str.charAt(0)) {
hintLog.log(MODULE_NAME, 'The best practice for' +
angular.hint.emit(MODULE_NAME, 'The best practice for' +
' module names is to use lowerCamelCase. Check the name of "' + str + '".',
SEVERITY_SUGGESTION);
return false;
Expand Down
4 changes: 2 additions & 2 deletions src/modules/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function processController(ctrlName) {
}

function sendMessageForGlobalController(name) {
angular.hint.log(MODULE_NAME,
angular.hint.emit(MODULE_NAME + ':global',
'add `' + name + '` to a module',
angular.version.minor <= 2 ? SEVERITY_WARNING : SEVERITY_ERROR,
CATEGORY_GLOBAL_CONTROLLER);
Expand All @@ -62,7 +62,7 @@ function sendMessageForControllerName(name) {
newName = addControllerSuffix(newName);
}
if (name !== newName) {
angular.hint.log(MODULE_NAME,
angular.hint.emit(MODULE_NAME + ':rename',
'Consider renaming `' + name + '` to `' + newName + '`.',
SEVERITY_WARNING,
CATEGORY_CONTROLLER_NAME);
Expand Down
2 changes: 1 addition & 1 deletion src/modules/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function ngEventDirectivesDecorator(ngEventAttrName) {
property = property[0];
propChain = lastProp + property;
if ($parse(propChain)(scope) === undefined) {
angular.hint.log(MODULE_NAME, propChain + ' is undefined');
angular.hint.emit(MODULE_NAME + ':undef', propChain + ' is undefined');
}
boundFn = boundFn.replace(property, '');
lastProp += property;
Expand Down
48 changes: 0 additions & 48 deletions src/modules/hint-log.js

This file was deleted.

53 changes: 0 additions & 53 deletions src/modules/log.js

This file was deleted.

51 changes: 17 additions & 34 deletions test/controllers.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@ describe('controllerDecorator', function() {
$controller = _$controller_;
$rootScope = _$rootScope_;
$compile = _$compile_;
spyOn(angular.hint, 'log').and.callThrough();
spyOn(angular.hint, 'emit').and.callThrough();
}));


afterEach(function () {
angular.hint.flush();
delete window.MockController;
});

Expand All @@ -36,10 +35,10 @@ describe('controllerDecorator', function() {
} catch (e) {};

if (angular.version.minor < 3) {
expect(angular.hint.log).toHaveBeenCalledWith('Controllers', 'add `MockController` to a module', SEVERITY_WARNING,
expect(angular.hint.emit).toHaveBeenCalledWith('Controllers:global', 'add `MockController` to a module', SEVERITY_WARNING,
'Using global functions as controllers is against Angular best practices and depricated in Angular 1.3 and up');
} else {
expect(angular.hint.log).toHaveBeenCalledWith('Controllers', 'add `MockController` to a module', SEVERITY_ERROR,
expect(angular.hint.emit).toHaveBeenCalledWith('Controllers:global', 'add `MockController` to a module', SEVERITY_ERROR,
'Using global functions as controllers is against Angular best practices and depricated in Angular 1.3 and up');
}
});
Expand Down Expand Up @@ -82,7 +81,7 @@ describe('controllerDecorator', function() {
'</div>');
$compile(elm)(scope);
$rootScope.$digest();
expect(angular.hint.log).not.toHaveBeenCalled();
expect(angular.hint.emit).not.toHaveBeenCalled();
});


Expand Down Expand Up @@ -149,7 +148,7 @@ describe('controllerDecorator', function() {
'</div>');
$compile(elm)(scope);
$rootScope.$digest();
expect(angular.hint.log).toHaveBeenCalledWith('Controllers',
expect(angular.hint.emit).toHaveBeenCalledWith('Controllers:rename',
'Consider renaming `globalFunction` to `GlobalFunctionController`.',
SEVERITY_WARNING,
'Name controllers according to best practices');
Expand All @@ -170,7 +169,7 @@ describe('controllerDecorator', function() {
$controllerProvider.register('SampleController', function() {});
$controller('SampleController');

expect(angular.hint.log).not.toHaveBeenCalledWith('Controllers', 'It is against Angular' +
expect(angular.hint.emit).not.toHaveBeenCalledWith('Controllers', 'It is against Angular' +
'best practices to instantiate a controller on the window. This behavior is deprecated in' +
' Angular 1.3.0', (angular.version.minor < 3 ? SEVERITY_WARNING : SEVERITY_ERROR));
});
Expand All @@ -179,7 +178,7 @@ describe('controllerDecorator', function() {
it('should warn if a controller name does not begin with an uppercase letter', function(){
$controllerProvider.register('sampleController', function() {});
$controller('sampleController');
expect(angular.hint.log).toHaveBeenCalledWith('Controllers',
expect(angular.hint.emit).toHaveBeenCalledWith('Controllers:rename',
'Consider renaming `sampleController` to `SampleController`.',
SEVERITY_WARNING,
'Name controllers according to best practices');
Expand All @@ -189,14 +188,14 @@ describe('controllerDecorator', function() {
it('should not warn if a controller name begins with an uppercase letter', function(){
$controllerProvider.register('SampleController', function() {});
$controller('SampleController');
expect(angular.hint.log).not.toHaveBeenCalled();
expect(angular.hint.emit).not.toHaveBeenCalled();
});


it('should warn if a controller name does not include Controller', function(){
$controllerProvider.register('Sample', function() {});
$controller('Sample');
expect(angular.hint.log).toHaveBeenCalledWith('Controllers',
expect(angular.hint.emit).toHaveBeenCalledWith('Controllers:rename',
'Consider renaming `Sample` to `SampleController`.',
SEVERITY_WARNING,
'Name controllers according to best practices');
Expand All @@ -206,7 +205,7 @@ describe('controllerDecorator', function() {
it('should warn if a controller name does not end with Controller', function(){
$controllerProvider.register('SampleControllerYay', function() {});
$controller('SampleControllerYay');
expect(angular.hint.log).toHaveBeenCalledWith('Controllers',
expect(angular.hint.emit).toHaveBeenCalledWith('Controllers:rename',
'Consider renaming `SampleControllerYay` to `SampleControllerYayController`.',
SEVERITY_WARNING,
'Name controllers according to best practices');
Expand All @@ -216,19 +215,7 @@ describe('controllerDecorator', function() {
it('should not warn if a controller ends with Controller', function(){
$controllerProvider.register('SampleController', function() {});
$controller('SampleController');
expect(angular.hint.log).not.toHaveBeenCalled();
});


it('should collect all hinting messages using angular.hint', function() {
var sampleControl = $controller(MockController);
$controllerProvider.register('sample', function() {});
$controller('sample');
var log = angular.hint.flush();
var totalNumberOfMessages = log['Controllers'].warning.length +
(log['Controllers'].error || []).length;

expect(totalNumberOfMessages).toBe(1);
expect(angular.hint.emit).not.toHaveBeenCalled();
});
});

Expand All @@ -238,20 +225,16 @@ describe('module.controller', function() {

beforeEach(module('ngHintControllers'));
beforeEach(function() {
spyOn(angular.hint, 'log').and.callThrough();
});

afterEach(function () {
angular.hint.flush();
spyOn(angular.hint, 'emit').and.callThrough();
});

it('should accept name and constructor as separate arguments', function() {
angular.module('sampleApp', []).controller('SampleController', angular.noop);
expect(angular.hint.log).not.toHaveBeenCalled();
expect(angular.hint.emit).not.toHaveBeenCalled();

angular.module('sampleApp', []).controller('sampleController', angular.noop);
expect(angular.hint.log).toHaveBeenCalled();
expect(angular.hint.log.calls.count()).toBe(1);
expect(angular.hint.emit).toHaveBeenCalled();
expect(angular.hint.emit.calls.count()).toBe(1);
});


Expand All @@ -260,7 +243,7 @@ describe('module.controller', function() {
'SampleController': angular.noop,
'sampleController': angular.noop
});
expect(angular.hint.log).toHaveBeenCalled();
expect(angular.hint.log.calls.count()).toBe(1);
expect(angular.hint.emit).toHaveBeenCalled();
expect(angular.hint.emit.calls.count()).toBe(1);
});
});
Loading