11var assert = require ( 'assert' ) ;
2+ var esprimaHelpers = require ( '../../esprima-helpers' ) ;
23
34module . exports = enforceExistence ;
45module . exports . scopes = [ 'function' ] ;
@@ -16,7 +17,8 @@ enforceExistence.configure = function(options) {
1617 all : true ,
1718 anonymous : false ,
1819 exports : true ,
19- expressions : true
20+ expressions : true ,
21+ 'paramless-procedures' : true ,
2022 } ;
2123
2224 // check options are valid
@@ -26,18 +28,23 @@ enforceExistence.configure = function(options) {
2628 'jsDoc.enforceExistence rule was not configured properly'
2729 ) ;
2830
31+ var optionsToPolicyMap = Object . keys ( policy ) ;
32+ /**
33+ * @param {string } option
34+ */
35+ function updatePolicyRules ( option ) {
36+ if ( o . allExcept . indexOf ( option ) > - 1 ) {
37+ policy [ option ] = ! policy [ option ] ;
38+ }
39+ }
40+
2941 // parse options for policies
3042 if ( o === false ) {
3143 policy . all = false ;
3244 } else if ( typeof o === 'string' && o === 'exceptExports' ) { // backward compatible string option
3345 policy . exports = false ;
3446 } else if ( typeof o === 'object' && Array . isArray ( o . allExcept ) ) {
35- if ( o . allExcept . indexOf ( 'exports' ) > - 1 ) {
36- policy . exports = false ;
37- }
38- if ( o . allExcept . indexOf ( 'expressions' ) > - 1 ) {
39- policy . expressions = false ;
40- }
47+ optionsToPolicyMap . forEach ( updatePolicyRules ) ;
4148 }
4249
4350} ;
@@ -80,6 +87,21 @@ function enforceExistence(node, err) {
8087 return ;
8188 }
8289 }
90+ if ( policy [ 'paramless-procedures' ] === false ) {
91+ var hasReturnsWhichRequireJsdoc = false ;
92+ this . _iterate ( function ( n ) {
93+ if ( hasReturnsWhichRequireJsdoc ) {
94+ return ;
95+ }
96+ var isReturnWithValue = n && n . type === 'ReturnStatement' && n . argument ;
97+ var isInCurrentScope = node === esprimaHelpers . closestScopeNode ( n ) ;
98+ hasReturnsWhichRequireJsdoc = isReturnWithValue && isInCurrentScope ;
99+ } , node ) ;
100+ if ( ! node . params . length && ! hasReturnsWhichRequireJsdoc ) {
101+ // don't check functions without params
102+ return ;
103+ }
104+ }
83105
84106 // now clear to check for documentation
85107 if ( node . jsdoc ) {
0 commit comments