hapi-capitalize-modules
Advanced tools
Comparing version 1.0.0 to 1.1.0
'use strict'; | ||
module.exports = function(context) { | ||
var message = 'Imported module variable name not capitalized.'; | ||
var globalScopeOnly = context.options[0] === 'global-scope-only'; | ||
@@ -22,2 +23,6 @@ | ||
function check(node) { | ||
if (globalScopeOnly === true && context.getScope().type !== 'global') { | ||
return; | ||
} | ||
if (node.type === 'VariableDeclarator' && | ||
@@ -24,0 +29,0 @@ isRequire(node.init) && |
{ | ||
"name": "hapi-capitalize-modules", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "ESLint rule to enforce the capitalization of imported module variables", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -9,1 +9,8 @@ # hapi-capitalize-modules | ||
ESLint rule to enforce the capitalization of imported module variables. | ||
## Rule options | ||
### `global-scope-only` | ||
If the string `'global-scope-only'` is passed as the first option to this rule, | ||
then it will only be enforced on assignments in the module's top level scope. |
@@ -21,3 +21,4 @@ 'use strict'; | ||
'var hapi = require("hapi");', | ||
'var poop; poop = require("poop");' | ||
'var poop; poop = require("poop");', | ||
'var foo = {bar: function() { var hapi = require("hapi"); }};' | ||
]; | ||
@@ -43,3 +44,4 @@ | ||
'var Hapi = require("hapi");', | ||
'var Poop; Poop = require("poop");' | ||
'var Poop; Poop = require("poop");', | ||
'Code = require("code");' | ||
]; | ||
@@ -59,2 +61,36 @@ | ||
it('only warns on globals when global-scope-only is set', function(done) { | ||
var code = [ | ||
'function foo() { var hapi = require("hapi"); }', | ||
'var foo = function() { var hapi = require("hapi"); }', | ||
'var foo = {bar: function() { hapi = require("hapi"); }};' | ||
]; | ||
linterConfig.rules[HapiCapitalizeModules.esLintRuleName] = [1, 'global-scope-only']; | ||
for (var i = 0; i < code.length; ++i) { | ||
var result = linter.verify(code[i], linterConfig); | ||
expect(result).to.be.an.array(); | ||
expect(result.length).to.equal(0); | ||
} | ||
code = [ | ||
'hapi = require("hapi");', | ||
'var poop; poop = require("poop");' | ||
]; | ||
for (var i = 0; i < code.length; ++i) { | ||
var result = linter.verify(code[i], linterConfig); | ||
expect(result).to.be.an.array(); | ||
expect(result.length).to.equal(1); | ||
expect(result[0].ruleId).to.equal(HapiCapitalizeModules.esLintRuleName); | ||
expect(result[0].message).to.equal('Imported module variable name not capitalized.'); | ||
expect(result[0].nodeType).to.match(/VariableDeclarator|AssignmentExpression/); | ||
} | ||
done(); | ||
}); | ||
it('does not report anything for non-module variables', function(done) { | ||
@@ -61,0 +97,0 @@ var code = [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8023
126
16