From 739ed3fe2fd7526cda286e8e9f64bc98565b6f13 Mon Sep 17 00:00:00 2001 From: Alexej Yaroshevich Date: Thu, 1 Oct 2015 02:52:36 +0300 Subject: [PATCH] Fix: add ExportNamedDeclaration to enforceExistence Fixes #159 Closes gh-162 --- lib/rules/validate-jsdoc/enforce-existence.js | 2 +- .../rules/validate-jsdoc/enforce-existence.js | 52 ++++++++++++++----- 2 files changed, 40 insertions(+), 14 deletions(-) diff --git a/lib/rules/validate-jsdoc/enforce-existence.js b/lib/rules/validate-jsdoc/enforce-existence.js index 1542523..b9cc2b4 100644 --- a/lib/rules/validate-jsdoc/enforce-existence.js +++ b/lib/rules/validate-jsdoc/enforce-existence.js @@ -72,7 +72,7 @@ function enforceExistence(node, err) { } } if (policy.exports === false) { - if (parentNode.type === 'ExportDefaultDeclaration') { + if (parentNode.type === 'ExportDefaultDeclaration' || parentNode.type === 'ExportNamedDeclaration') { // don't check es6 export return; } else if (parentNode.type === 'AssignmentExpression') { diff --git a/test/lib/rules/validate-jsdoc/enforce-existence.js b/test/lib/rules/validate-jsdoc/enforce-existence.js index 57620e1..377900b 100644 --- a/test/lib/rules/validate-jsdoc/enforce-existence.js +++ b/test/lib/rules/validate-jsdoc/enforce-existence.js @@ -153,22 +153,38 @@ describe('lib/rules/validate-jsdoc/enforce-existence', function () { checker.cases([ /* jshint ignore:start */ { - it: 'should report jsdoc absence for named function export (#159)', + it: 'should report jsdoc absence for default named function export (#159)', + code: 'export default function named (v) {};', + errors: 1, + }, { + it: 'should not report jsdoc absence for default named function export (#159)', code: [ - 'export default function named (v) {', - '};', + '/** Foo bar */', + 'export default function named (v) {};', ].join('\n'), + errors: 0, + }, { + it: 'should report jsdoc absence for named function export (#159)', + code: 'export function named (v) {};', errors: 1, }, { it: 'should not report jsdoc absence for named function export (#159)', code: [ - '/**', - ' * Foo bar', - ' */', - 'export default function named (v) {', - '};', + '/** Foo bar */', + 'export function named (v) {};', + ].join('\n'), + }, { + skip: true, + it: 'should report jsdoc absence for default arrow function export (#159)', + code: 'export default (v) => {};', + errors: 1, + }, { + skip: true, + it: 'should not report jsdoc absence for default arrow function export (#159)', + code: [ + '/** Foo bar */', + 'export default (v) => {};', ].join('\n'), - errors: 0, }, /* jshint ignore:end */ ]); @@ -196,11 +212,21 @@ describe('lib/rules/validate-jsdoc/enforce-existence', function () { checker.cases([ /* jshint ignore:start */ { + it: 'should not report jsdoc absence for default named function export (#159)', + code: 'export default function named (v) {};', + errors: 0, + }, { it: 'should not report jsdoc absence for named function export (#159)', - code: [ - 'export default function named (v) {', - '};', - ].join('\n'), + code: 'export function named (v) {};', + errors: 0, + }, { + it: 'should not report jsdoc absence for default anonymous function export (#159)', + code: 'export default function (v) {};', + errors: 0, + }, { + skip: true, + it: 'should not report jsdoc absence for default arrow function export (#159)', + code: 'export default (v) => {};', errors: 0, } /* jshint ignore:end */