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

Commit 8885e0d

Browse files
committed
refactor(log): Remove log option
Now that we've switched to an event emitter, log was no longer used and was causing confusion. The major change here is that once we emit an event, it is not stored. If this turns out to be a big deal, we can implement a message storage module. Closes #81 tweaked test
1 parent 7230c9a commit 8885e0d

16 files changed

+63
-279
lines changed

CONTRIBUTING.md

+3-4
Original file line numberDiff line numberDiff line change
@@ -225,12 +225,11 @@ The following steps describe how an AngularHint module should be developed.
225225
- 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.
226226
- All AngularHint modules should load AngularHintLog as a dependency, see #3.
227227
228-
3. Message Logging
228+
3. Events
229229
230-
All AngularHint modules should use AngularHintLog to log their messages. This creates a standard pipeline for
231-
all AngularHint messages.
230+
All AngularHint modules should use `hint.emit` to emit their events. This creates a standard pipeline for all AngularHint events.
232231
233-
To use AngularHintLog, see its [README.md](https://github.com/angular/angular-hint-log#angular-hint-log).
232+
`angular.hint` is an instance of [EventEmitter2](https://github.com/asyncly/EventEmitter2).
234233
235234
4. Module Testing
236235

README.md

-3
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,6 @@ AngularHint is composed of several small modules that you may want to use indivi
7474
* [AngularHintInterpolation](https://github.com/angular/angular-hint-interpolation)
7575
* [AngularHintModules](https://github.com/angular/angular-hint-modules)
7676

77-
AngularHint uses [AngularHintLog](https://github.com/angular/angular-hint-log) to provide
78-
logging functionality.
79-
8077
## Interested in Contributing?
8178
See the [Contributing Guidelines](https://github.com/angular/angular-hint/blob/master/CONTRIBUTING.md)
8279

hint.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
'use strict';
22

3-
// Set up the event stuffs
4-
require('./src/modules/hintEmitter');
5-
63
// Create pipe for all hint messages from different modules
7-
require('./src/modules/log');
4+
require('./src/modules/hintEmitter');
85

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

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

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
var hintLog = angular.hint = require('./../log'),
2-
MODULE_NAME = 'Modules';
1+
var MODULE_NAME = 'Modules';
32

43
module.exports = function(modules) {
54
modules.forEach(function(module) {
6-
hintLog.log(MODULE_NAME, module.message, module.severity);
5+
angular.hint.emit(MODULE_NAME, module.message, module.severity);
76
});
87
};

src/modules/angular-hint-modules/getNgAppMod.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
var hintLog = angular.hint = require('./../log'),
2-
MODULE_NAME = 'Modules',
1+
var MODULE_NAME = 'Modules',
32
SEVERITY_ERROR = 1;
43
module.exports = function(attrs, ngAppFound) {
54
if(attrs['ng-app'] && ngAppFound) {
6-
hintLog.log(MODULE_NAME, 'ng-app may only be included once. The module "' +
5+
angular.hint.emit(MODULE_NAME, 'ng-app may only be included once. The module "' +
76
attrs['ng-app'].value + '" was not used to bootstrap because ng-app was already included.',
87
SEVERITY_ERROR);
98
}

src/modules/angular-hint-modules/hasNameSpace.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
var hintLog = angular.hint = require('./../log'),
2-
MODULE_NAME = 'Modules',
1+
var MODULE_NAME = 'Modules',
32
SEVERITY_SUGGESTION = 3;
43

54
module.exports = function(str) {
@@ -8,7 +7,7 @@ module.exports = function(str) {
87
}
98

109
if(str.toLowerCase() === str || str.charAt(0).toUpperCase() === str.charAt(0)) {
11-
hintLog.log(MODULE_NAME, 'The best practice for' +
10+
angular.hint.emit(MODULE_NAME, 'The best practice for' +
1211
' module names is to use lowerCamelCase. Check the name of "' + str + '".',
1312
SEVERITY_SUGGESTION);
1413
return false;

src/modules/controllers.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function processController(ctrlName) {
4747
}
4848

4949
function sendMessageForGlobalController(name) {
50-
angular.hint.log(MODULE_NAME,
50+
angular.hint.emit(MODULE_NAME + ':global',
5151
'add `' + name + '` to a module',
5252
angular.version.minor <= 2 ? SEVERITY_WARNING : SEVERITY_ERROR,
5353
CATEGORY_GLOBAL_CONTROLLER);
@@ -62,7 +62,7 @@ function sendMessageForControllerName(name) {
6262
newName = addControllerSuffix(newName);
6363
}
6464
if (name !== newName) {
65-
angular.hint.log(MODULE_NAME,
65+
angular.hint.emit(MODULE_NAME + ':rename',
6666
'Consider renaming `' + name + '` to `' + newName + '`.',
6767
SEVERITY_WARNING,
6868
CATEGORY_CONTROLLER_NAME);

src/modules/events.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ function ngEventDirectivesDecorator(ngEventAttrName) {
5353
property = property[0];
5454
propChain = lastProp + property;
5555
if ($parse(propChain)(scope) === undefined) {
56-
angular.hint.log(MODULE_NAME, propChain + ' is undefined');
56+
angular.hint.emit(MODULE_NAME + ':undef', propChain + ' is undefined');
5757
}
5858
boundFn = boundFn.replace(property, '');
5959
lastProp += property;

src/modules/hint-log.js

-48
This file was deleted.

src/modules/log.js

-53
This file was deleted.

test/controllers.spec.js

+17-34
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,11 @@ describe('controllerDecorator', function() {
1515
$controller = _$controller_;
1616
$rootScope = _$rootScope_;
1717
$compile = _$compile_;
18-
spyOn(angular.hint, 'log').and.callThrough();
18+
spyOn(angular.hint, 'emit').and.callThrough();
1919
}));
2020

2121

2222
afterEach(function () {
23-
angular.hint.flush();
2423
delete window.MockController;
2524
});
2625

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

3837
if (angular.version.minor < 3) {
39-
expect(angular.hint.log).toHaveBeenCalledWith('Controllers', 'add `MockController` to a module', SEVERITY_WARNING,
38+
expect(angular.hint.emit).toHaveBeenCalledWith('Controllers:global', 'add `MockController` to a module', SEVERITY_WARNING,
4039
'Using global functions as controllers is against Angular best practices and depricated in Angular 1.3 and up');
4140
} else {
42-
expect(angular.hint.log).toHaveBeenCalledWith('Controllers', 'add `MockController` to a module', SEVERITY_ERROR,
41+
expect(angular.hint.emit).toHaveBeenCalledWith('Controllers:global', 'add `MockController` to a module', SEVERITY_ERROR,
4342
'Using global functions as controllers is against Angular best practices and depricated in Angular 1.3 and up');
4443
}
4544
});
@@ -82,7 +81,7 @@ describe('controllerDecorator', function() {
8281
'</div>');
8382
$compile(elm)(scope);
8483
$rootScope.$digest();
85-
expect(angular.hint.log).not.toHaveBeenCalled();
84+
expect(angular.hint.emit).not.toHaveBeenCalled();
8685
});
8786

8887

@@ -149,7 +148,7 @@ describe('controllerDecorator', function() {
149148
'</div>');
150149
$compile(elm)(scope);
151150
$rootScope.$digest();
152-
expect(angular.hint.log).toHaveBeenCalledWith('Controllers',
151+
expect(angular.hint.emit).toHaveBeenCalledWith('Controllers:rename',
153152
'Consider renaming `globalFunction` to `GlobalFunctionController`.',
154153
SEVERITY_WARNING,
155154
'Name controllers according to best practices');
@@ -170,7 +169,7 @@ describe('controllerDecorator', function() {
170169
$controllerProvider.register('SampleController', function() {});
171170
$controller('SampleController');
172171

173-
expect(angular.hint.log).not.toHaveBeenCalledWith('Controllers', 'It is against Angular' +
172+
expect(angular.hint.emit).not.toHaveBeenCalledWith('Controllers', 'It is against Angular' +
174173
'best practices to instantiate a controller on the window. This behavior is deprecated in' +
175174
' Angular 1.3.0', (angular.version.minor < 3 ? SEVERITY_WARNING : SEVERITY_ERROR));
176175
});
@@ -179,7 +178,7 @@ describe('controllerDecorator', function() {
179178
it('should warn if a controller name does not begin with an uppercase letter', function(){
180179
$controllerProvider.register('sampleController', function() {});
181180
$controller('sampleController');
182-
expect(angular.hint.log).toHaveBeenCalledWith('Controllers',
181+
expect(angular.hint.emit).toHaveBeenCalledWith('Controllers:rename',
183182
'Consider renaming `sampleController` to `SampleController`.',
184183
SEVERITY_WARNING,
185184
'Name controllers according to best practices');
@@ -189,14 +188,14 @@ describe('controllerDecorator', function() {
189188
it('should not warn if a controller name begins with an uppercase letter', function(){
190189
$controllerProvider.register('SampleController', function() {});
191190
$controller('SampleController');
192-
expect(angular.hint.log).not.toHaveBeenCalled();
191+
expect(angular.hint.emit).not.toHaveBeenCalled();
193192
});
194193

195194

196195
it('should warn if a controller name does not include Controller', function(){
197196
$controllerProvider.register('Sample', function() {});
198197
$controller('Sample');
199-
expect(angular.hint.log).toHaveBeenCalledWith('Controllers',
198+
expect(angular.hint.emit).toHaveBeenCalledWith('Controllers:rename',
200199
'Consider renaming `Sample` to `SampleController`.',
201200
SEVERITY_WARNING,
202201
'Name controllers according to best practices');
@@ -206,7 +205,7 @@ describe('controllerDecorator', function() {
206205
it('should warn if a controller name does not end with Controller', function(){
207206
$controllerProvider.register('SampleControllerYay', function() {});
208207
$controller('SampleControllerYay');
209-
expect(angular.hint.log).toHaveBeenCalledWith('Controllers',
208+
expect(angular.hint.emit).toHaveBeenCalledWith('Controllers:rename',
210209
'Consider renaming `SampleControllerYay` to `SampleControllerYayController`.',
211210
SEVERITY_WARNING,
212211
'Name controllers according to best practices');
@@ -216,19 +215,7 @@ describe('controllerDecorator', function() {
216215
it('should not warn if a controller ends with Controller', function(){
217216
$controllerProvider.register('SampleController', function() {});
218217
$controller('SampleController');
219-
expect(angular.hint.log).not.toHaveBeenCalled();
220-
});
221-
222-
223-
it('should collect all hinting messages using angular.hint', function() {
224-
var sampleControl = $controller(MockController);
225-
$controllerProvider.register('sample', function() {});
226-
$controller('sample');
227-
var log = angular.hint.flush();
228-
var totalNumberOfMessages = log['Controllers'].warning.length +
229-
(log['Controllers'].error || []).length;
230-
231-
expect(totalNumberOfMessages).toBe(1);
218+
expect(angular.hint.emit).not.toHaveBeenCalled();
232219
});
233220
});
234221

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

239226
beforeEach(module('ngHintControllers'));
240227
beforeEach(function() {
241-
spyOn(angular.hint, 'log').and.callThrough();
242-
});
243-
244-
afterEach(function () {
245-
angular.hint.flush();
228+
spyOn(angular.hint, 'emit').and.callThrough();
246229
});
247230

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

252235
angular.module('sampleApp', []).controller('sampleController', angular.noop);
253-
expect(angular.hint.log).toHaveBeenCalled();
254-
expect(angular.hint.log.calls.count()).toBe(1);
236+
expect(angular.hint.emit).toHaveBeenCalled();
237+
expect(angular.hint.emit.calls.count()).toBe(1);
255238
});
256239

257240

@@ -260,7 +243,7 @@ describe('module.controller', function() {
260243
'SampleController': angular.noop,
261244
'sampleController': angular.noop
262245
});
263-
expect(angular.hint.log).toHaveBeenCalled();
264-
expect(angular.hint.log.calls.count()).toBe(1);
246+
expect(angular.hint.emit).toHaveBeenCalled();
247+
expect(angular.hint.emit.calls.count()).toBe(1);
265248
});
266249
});

0 commit comments

Comments
 (0)