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

Commit 228b27c

Browse files
committed
refactor: rename and reorganize modules
1 parent a46a7b5 commit 228b27c

17 files changed

+160
-19
lines changed

hint.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
'use strict';
22

33
// Create pipe for all hint messages from different modules
4-
require('./lib/modules/log');
4+
require('./src/modules/log');
55

66
// Load angular hint modules
7-
require('./lib/modules/controllers');
8-
// require('./lib/modules/directives');
9-
// require('./lib/modules/dom');
10-
// require('./lib/modules/events');
11-
// require('./lib/modules/interpolation');
12-
// require('./lib/modules/modules');
13-
require('./lib/modules/scopes');
7+
require('./src/modules/controllers');
8+
// require('./src/modules/directives');
9+
// require('./src/modules/dom');
10+
// require('./src/modules/events');
11+
// require('./src/modules/interpolation');
12+
require('./src/modules/modules');
13+
require('./src/modules/scopes');
1414

1515
// List of all possible modules
1616
// The default ng-hint behavior loads all modules
17-
var allModules = [
17+
var AVAILABLE_MODULES = [
1818
'ngHintControllers',
1919
// 'ngHintDirectives',
2020
// 'ngHintDom',
@@ -71,7 +71,7 @@ function loadModules() {
7171
} else if (elt = document.querySelector('[ng-hint-exclude]')) {
7272
modules = excludeModules(hintModulesFromElement(elt));
7373
} else if (document.querySelector('[ng-hint]')) {
74-
modules = allModules;
74+
modules = AVAILABLE_MODULES;
7575
} else {
7676
angular.hint.log('General', 'ngHint is included on the page, but is not active because ' +
7777
'there is no `ng-hint` attribute present', SEVERITY_WARNING);
@@ -80,7 +80,7 @@ function loadModules() {
8080
}
8181

8282
function excludeModules(modulesToExclude) {
83-
return allModules.filter(function(module) {
83+
return AVAILABLE_MODULES.filter(function(module) {
8484
return modulesToExclude.indexOf(module) === -1;
8585
});
8686
}
@@ -90,7 +90,7 @@ function hintModulesFromElement (elt) {
9090
elt.attributes['ng-hint-exclude']).value.split(' ');
9191

9292
return selectedModules.map(hintModuleName).filter(function (name) {
93-
return (allModules.indexOf(name) > -1) ||
93+
return (AVAILABLE_MODULES.indexOf(name) > -1) ||
9494
angular.hint.log('General', 'Module ' + name + ' could not be found', SEVERITY_WARNING);
9595
});
9696
}

karma.conf.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ var sauceConfig = require('./config/karma.sauce.conf');
44
var travisConfig = require('./config/karma.travis.conf');
55
//var fs = require('fs');
66

7-
//fs.readdirSync(__dirname + '/lib/modules').filter
7+
//fs.readdirSync(__dirname + '/src/modules').filter
88

99
module.exports = function(config) {
1010
var options = {
1111
frameworks: ['browserify', 'jasmine'],
1212
files: [
1313
'node_modules/angular/angular.js',
1414
'node_modules/angular-mocks/angular-mocks.js',
15-
'lib/modules/log.js',
16-
'lib/modules/*.js'
15+
'src/modules/log.js',
16+
'src/modules/*.js'
1717
],
1818
preprocessors: {
1919
'lib/modules/controllers.js': ['browserify'],
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

lib/modules/events.js renamed to src/modules/events.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
'use strict';
22

33
/**
4-
* Load necessary functions from /lib into variables.
4+
* Load necessary functions from /src into variables.
55
*/
6-
var EVENT_NAMES = require('../event-directives');
6+
var EVENT_NAMES = require('../lib/event-directives');
77

8-
var provider = require('../debug-parse');
8+
var provider = require('../lib/debug-parse');
99
var err = null;
1010
provider.onUndefined(function (text) {
1111
if (!err) {
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/modules/modules.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
'use strict';
2+
3+
var getModule = require('./src/getModule'),
4+
start = require('./src/start'),
5+
storeNgAppAndView = require('./src/storeNgAppAndView'),
6+
storeUsedModules = require('./src/storeUsedModules'),
7+
hasNameSpace = require('./src/hasNameSpace'),
8+
modData = require('./src/moduleData');
9+
10+
var doc = Array.prototype.slice.call(document.getElementsByTagName('*')),
11+
originalAngularModule = angular.module,
12+
modules = {};
13+
14+
storeNgAppAndView(doc);
15+
16+
angular.module = function(name, requiresOriginal) {
17+
var module = originalAngularModule.apply(this, arguments),
18+
name = module.name;
19+
20+
module.requiresOriginal = requiresOriginal;
21+
modules[name] = module;
22+
hasNameSpace(module);
23+
var modToCheck = getModule(name, true);
24+
25+
if(modToCheck && modToCheck.requiresOriginal !== module.requiresOriginal) {
26+
if(!modData.createdMulti[name]) {
27+
modData.createdMulti[name] = [getModule(name,true)];
28+
}
29+
modData.createdMulti[name].push(module);
30+
}
31+
modData.createdModules[name] = module;
32+
return module;
33+
};
34+
35+
angular.module('ngHintModules', []).config(function() {
36+
var ngAppMod = modules[modData.ngAppMod];
37+
storeUsedModules(ngAppMod, modules);
38+
start();
39+
});

src/modules/modules.spec.js

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
var hintLog = angular.hint;
2+
var start = require('./src/start');
3+
var modData = require('./src/moduleData');
4+
5+
describe('hintModules', function() {
6+
beforeEach(function() {
7+
modData.createdModules = {
8+
'createdAndNotLoaded': {name:'createdAndNotLoaded', requires: []},
9+
'testModule': {name:'testModule', requires: []}
10+
};
11+
modData.loadedModules = {
12+
'doesntExist': 'doesntExist',
13+
'testModule': 'testModule'
14+
};
15+
modData.createdMulti = {
16+
'testModule': ['testModule']
17+
};
18+
});
19+
20+
afterEach(function() {
21+
hintLog.flush();
22+
});
23+
24+
it('should identify modules created and not loaded', function() {
25+
angular.module('createdAndNotLoaded', []);
26+
start();
27+
expect(hintLog.flush().Modules.warning[0]).toBe('Module "createdAndNotLoaded" was' +
28+
' created but never loaded.');
29+
});
30+
31+
32+
it('should identify modules loaded that do not exist', function() {
33+
angular.module('testModule', ['doesntExist']);
34+
start();
35+
var log = hintLog.flush();
36+
expect(log.Modules.error[0]).toBe('Module "doesntExist" was loaded but' +
37+
' does not exist.');
38+
});
39+
40+
41+
it('should identify modules that have been loaded multiple times', function() {
42+
angular.module('testModule', []);
43+
start();
44+
expect(hintLog.flush().Modules.warning[1]).toBe('Multiple modules with name ' +
45+
'"testModule" are being created and they will overwrite each other.');
46+
});
47+
48+
49+
it('should identify modules that have been loaded twice', function() {
50+
angular.module('moduleDuplicate', []);
51+
angular.module('moduleDuplicate', []);
52+
start();
53+
expect(hintLog.flush().Modules.warning[3]).toBe('Multiple modules with name ' +
54+
'"moduleDuplicate" are being created and they will overwrite each other.');
55+
});
56+
57+
58+
it('should ignore modules loaded twice if one is just being called', function() {
59+
angular.module('testModule2', []);
60+
angular.module('testModule2').controller('controller', [function(){}]);
61+
start();
62+
var log = hintLog.flush().Modules;
63+
var duplicateMessages = log.warning;
64+
expect(duplicateMessages).not.toContain('Multiple modules with name "testModule2" are being ' +
65+
'created and they will overwrite each other.');
66+
});
67+
68+
69+
it('should warn if modules are not named with lowerCamelCase or dotted.segments', function() {
70+
angular.module('testmodule', []);
71+
start();
72+
var log = hintLog.flush();
73+
expect(log.Modules.suggestion[0]).toBe('The best practice for' +
74+
' module names is to use lowerCamelCase or dotted.segments. Check the name of "testmodule".');
75+
76+
angular.module('Testmodule', []);
77+
expect(hintLog.flush().Modules.suggestion[0]).toBe('The best practice for' +
78+
' module names is to use lowerCamelCase or dotted.segments. Check the name of "Testmodule".');
79+
});
80+
});
81+
82+
describe('hintModules integration', function() {
83+
it('should not warn about itself or other ngHintModules', function() {
84+
85+
// what is this i dont even
86+
modData.createdModules = {};
87+
modData.loadedModules = {};
88+
modData.createdMulti = {};
89+
90+
angular.module('ngHintControllers', []);
91+
angular.module('ngHintDirectives', []);
92+
angular.module('ngHintDom', []);
93+
angular.module('ngHintEvents', []);
94+
angular.module('ngHintInterpolation', []);
95+
angular.module('ngHintScopes', []);
96+
angular.module('ng', []);
97+
angular.module('ngLocale', []);
98+
99+
start();
100+
expect(hintLog.flush()['Modules']).not.toBeDefined();
101+
});
102+
});

lib/modules/scopes.js renamed to src/modules/scopes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
var summarize = require('../summarize-model');
3+
var summarize = require('../lib/summarize-model');
44
var debounceOn = require('debounce-on');
55

66
var hint = angular.hint;
File renamed without changes.

0 commit comments

Comments
 (0)