Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixup rule configuration asserts and add tests #44

Merged
merged 1 commit into from
Nov 10, 2014
Merged
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
22 changes: 11 additions & 11 deletions lib/rules/validate-jsdoc/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ var validatorsByName = module.exports = {

Object.defineProperty(validatorsByName, 'load', {
value: function loadValidators(passedOptions) {
var validators = [];

if (!passedOptions) {
return validators;
return [];
}

var validators = [];

Object.keys(validatorsByName).forEach(function(name) {
var v = validatorsByName[name];

Expand All @@ -50,22 +50,22 @@ Object.defineProperty(validatorsByName, 'load', {

Object.defineProperty(validatorsByName, 'checkOptions', {
value: function checkOptions(validator, options) {
Object.keys(validator.options).forEach(function(data, option) {
Object.keys(validator.options).forEach(function(option) {
var data = validator.options[option];
if (!data.allowedValues) {
return;
}

var values;
if (typeof data.allowedValues === 'function') {
values = data.allowedValues();
var values = data.allowedValues;
if (typeof values === 'function') {
values = values();
}

if (!Array.isArray(values)) {
throw new Error('Internal error in jsDoc validator ' + validator._name);
assert(Array.isArray(values), 'Internal error in jsDoc validator ' + validator._name);

} else if (values.length > 1) {
if (values.length > 1) {
assert(values.indexOf(options[option]) !== -1,
'Available values for option jsDoc.' + option + ' are ' + values.map(JSON.stringify).join(', '));
'Accepted values for option jsDoc.' + option + ' are ' + values.map(JSON.stringify).join(', '));

} else if (values.length) {
assert(values[0] === options[option],
Expand Down
1 change: 1 addition & 0 deletions test/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var expect = chai.expect;
global.parse = parse;
global.fnBody = fnBody;
global.checker = rulesChecker;
global.expect = expect;

function fnBody(func) {
var str = func.toString();
Expand Down
20 changes: 18 additions & 2 deletions test/lib/rules/validate-jsdoc/check-param-names.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
describe('rules/validate-jsdoc', function () {
describe('lib/rules/validate-jsdoc/check-param-names', function () {
var checker = global.checker({
additionalRules: ['lib/rules/validate-jsdoc.js']
});

describe('check-param-names', function () {
describe('configured', function() {

it('with undefined should throws', function() {
global.expect(function() {
checker.configure({checkParamNames: undefined});
}).to.throws(/accepted value/i);
});

it('with undefined should throws', function() {
global.expect(function() {
checker.configure({checkParamNames: {}});
}).to.throws(/accepted value/i);
});

});

describe('with true', function() {
checker.rules({checkParamNames: true});

checker.cases([
Expand Down
20 changes: 18 additions & 2 deletions test/lib/rules/validate-jsdoc/check-redundant-access.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
describe('rules/validate-jsdoc', function () {
describe('lib/rules/validate-jsdoc/check-redundant-access', function () {
var checker = global.checker({
additionalRules: ['lib/rules/validate-jsdoc.js']
});

describe('check-redundant-access', function () {
describe('configured', function() {

it('with undefined should throws', function() {
global.expect(function() {
checker.configure({checkRedundantAccess: undefined});
}).to.throws(/accepted value/i);
});

it('with undefined should throws', function() {
global.expect(function() {
checker.configure({checkRedundantAccess: {}});
}).to.throws(/accepted value/i);
});

});

describe('with true', function() {
checker.rules({checkRedundantAccess: true});

checker.cases([
/* jshint ignore:start */
{
Expand Down
20 changes: 18 additions & 2 deletions test/lib/rules/validate-jsdoc/check-redundant-params.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
describe('rules/validate-jsdoc', function () {
describe('lib/rules/validate-jsdoc/check-redundant-params', function () {
var checker = global.checker({
additionalRules: ['lib/rules/validate-jsdoc.js']
});

describe('check-redundant-params', function () {
describe('configured', function() {

it('with undefined should throws', function() {
global.expect(function() {
checker.configure({checkRedundantParams: undefined});
}).to.throws(/accepted value/i);
});

it('with undefined should throws', function() {
global.expect(function() {
checker.configure({checkRedundantParams: {}});
}).to.throws(/accepted value/i);
});

});

describe('with this', function() {
checker.rules({checkRedundantParams: true});

checker.cases([
Expand Down
20 changes: 18 additions & 2 deletions test/lib/rules/validate-jsdoc/check-redundant-returns.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
describe('rules/validate-jsdoc', function () {
describe('lib/rules/validate-jsdoc/check-redundant-returns', function () {
var checker = global.checker({
additionalRules: ['lib/rules/validate-jsdoc.js']
});

describe('check-redundant-returns', function() {
describe('configured', function() {

it('with undefined should throws', function() {
global.expect(function() {
checker.configure({checkRedundantReturns: undefined});
}).to.throws(/accepted value/i);
});

it('with undefined should throws', function() {
global.expect(function() {
checker.configure({checkRedundantReturns: {}});
}).to.throws(/accepted value/i);
});

});

describe('with true', function() {
checker.rules({checkRedundantReturns: true});

checker.cases([
Expand Down
20 changes: 18 additions & 2 deletions test/lib/rules/validate-jsdoc/check-return-types.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
describe('rules/validate-jsdoc', function () {
describe('lib/rules/validate-jsdoc/check-return-types', function () {
var checker = global.checker({
additionalRules: ['lib/rules/validate-jsdoc.js']
});

describe('check-return-types', function () {
describe('configured', function() {

it('with undefined should throws', function() {
global.expect(function() {
checker.configure({checkReturnTypes: undefined});
}).to.throws(/accepted value/i);
});

it('with undefined should throws', function() {
global.expect(function() {
checker.configure({checkReturnTypes: {}});
}).to.throws(/accepted value/i);
});

});

describe('with true', function() {
checker.rules({checkReturnTypes: true});

checker.cases([
/* jshint ignore:start */
{
Expand Down
20 changes: 18 additions & 2 deletions test/lib/rules/validate-jsdoc/check-types.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
describe('rules/validate-jsdoc', function() {
describe('lib/rules/validate-jsdoc/check-types', function() {
var checker = global.checker({
additionalRules: ['lib/rules/validate-jsdoc.js']
});

describe('check-types', function() {
describe('configured', function() {

it('with undefined should throws', function() {
global.expect(function() {
checker.configure({checkTypes: undefined});
}).to.throws(/accepted value/i);
});

it('with undefined should throws', function() {
global.expect(function() {
checker.configure({checkTypes: {}});
}).to.throws(/accepted value/i);
});

});

describe('with true', function() {
checker.rules({checkTypes: true});

checker.cases([
/* jshint ignore:start */
{
Expand Down
20 changes: 18 additions & 2 deletions test/lib/rules/validate-jsdoc/enforce-existence.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
describe('rules/validate-jsdoc', function () {
describe('lib/rules/validate-jsdoc/enforce-existence', function () {
var checker = global.checker({
additionalRules: ['lib/rules/validate-jsdoc.js']
});

describe('enforce-existence', function () {
describe('configured', function() {

it('with undefined should throws', function() {
global.expect(function() {
checker.configure({enforceExistence: undefined});
}).to.throws(/accepted value/i);
});

it('with undefined should throws', function() {
global.expect(function() {
checker.configure({enforceExistence: {}});
}).to.throws(/accepted value/i);
});

});

describe('with true', function() {
checker.rules({enforceExistence: true});

checker.cases([
/* jshint ignore:start */
{
Expand Down
21 changes: 19 additions & 2 deletions test/lib/rules/validate-jsdoc/leading-underscore-access.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,31 @@
describe('rules/validate-jsdoc', function () {
describe('lib/rules/validate-jsdoc/leading-underscore-access', function () {
var checker = global.checker({
additionalRules: ['lib/rules/validate-jsdoc.js']
});

describe('leading-underscore-access', function () {
describe('configured', function() {

it('with undefined should throws', function() {
global.expect(function() {
checker.configure({leadingUnderscoreAccess: undefined});
}).to.throws(/accepted value/i);
});

it('with object should throws', function() {
global.expect(function() {
checker.configure({leadingUnderscoreAccess: {}});
}).to.throws(/accepted value/i);
});

});

describe('common', function() {

checker.cases([
/* jshint ignore:start */
{
it: 'should not throw',
rules: {leadingUnderscoreAccess: true},
code: function() {
function yay(yey) {
}
Expand Down
20 changes: 18 additions & 2 deletions test/lib/rules/validate-jsdoc/require-param-types.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
describe('rules/validate-jsdoc', function () {
describe('lib/rules/validate-jsdoc/require-param-types', function () {
var checker = global.checker({
additionalRules: ['lib/rules/validate-jsdoc.js']
});

describe('require-param-types', function () {
describe('configured', function() {

it('with undefined should throws', function() {
global.expect(function() {
checker.configure({requireParamTypes: undefined});
}).to.throws(/accepted value/i);
});

it('with undefined should throws', function() {
global.expect(function() {
checker.configure({requireParamTypes: {}});
}).to.throws(/accepted value/i);
});

});

describe('with true', function() {
checker.rules({requireParamTypes: true});

checker.cases([
Expand Down
20 changes: 18 additions & 2 deletions test/lib/rules/validate-jsdoc/require-return-types.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
describe('rules/validate-jsdoc', function () {
describe('lib/rules/validate-jsdoc/require-return-types', function () {
var checker = global.checker({
additionalRules: ['lib/rules/validate-jsdoc.js']
});

describe('require-return-types', function() {
describe('configured', function() {

it('with undefined should throws', function() {
global.expect(function() {
checker.configure({requireReturnTypes: undefined});
}).to.throws(/accepted value/i);
});

it('with undefined should throws', function() {
global.expect(function() {
checker.configure({requireReturnTypes: {}});
}).to.throws(/accepted value/i);
});

});

describe('with true', function() {
checker.rules({requireReturnTypes: true});

checker.cases([
/* jshint ignore:start */
{
Expand Down