eslint-plugin-jsdoc icon indicating copy to clipboard operation
eslint-plugin-jsdoc copied to clipboard

`publicOnly` to handle more export formats

Open brettz9 opened this issue 5 years ago • 7 comments

The new publicOnly of require-jsdoc seems not to be able to handle exports of any of these forms (with esm: true) as these fail to report missing jsdoc:

  • [x] export default function () {, export default class {}, export default () => {} - (The first two of these anonymous defaults were giving errors, but this is now fixed.)
  • [x] The named variety: export var a = function () {} (export {name} is already implemented)
  • [ ] Checking scopes
  • [x] TSInterfaceDeclaration (see #492)

With some strange structures like the following, besides the fact of adding support, it would let us remove some /* istanbul ignore next */ directives (see #286 , an issue interrelated with this one), but this won't pass now, and would need to support scopes (which the code comments indicate is not yet supported) and may in some cases be more complexity than its worth (e.g., parsing template properties):

var a = {};
if (true) {
  a = {q: function () {}};
}
var test = a[`q`];

class Clss {}
var test2 = a[Clss];

export { test, test2 }

@Extersky


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

brettz9 avatar Jun 23 '19 12:06 brettz9

As the first two items are fixed, I can take a look at the object keys, scoping and writing test cases for uncovered lines of exportparser file. Scoping likely requires more strict tracking of ECMAScript specification than the resolver does so far, to not give wrong results. Implementing static analysis of if blocks also opens other questions, such as, what values should be statically analyzable.

Extersky avatar Jun 25 '19 17:06 Extersky

Sounds good... Re: object keys, FWIW, while there are probably better examples, I happened to find in exploring the uncovered lines a little, that, per my example, putting a template and function in the position of a key handled a couple of those uncovered lines (now exempted from coverage)--as unusual as the latter is.

brettz9 avatar Jun 25 '19 22:06 brettz9

What about catch export simple variables with jsdoc/require-jsdoc?

export let someBool = false;
export let someString = "foo-bar";
export const someObject = {};

orlov-vo avatar Jul 17 '19 10:07 orlov-vo

@orlov-vo : You can get this by using the contexts option:

{
    contexts: ['ExportNamedDeclaration']
}

However, this cannot be used with publicOnly, which insists on functions or classes.

So, if you use this approach, you will need to whitelist the other contexts where you wish support, e.g., FunctionExpression, so if you want jsdocs required for all possible exports, I think the following should be enough to get them:

{
    contexts: [
        'ArrowFunctionExpression',
        'ClassDeclaration',
        'ClassExpression',
        'ExportNamedDeclaration',
        'FunctionDeclaration',
        'FunctionExpression'
    ]
}

brettz9 avatar Jul 17 '19 23:07 brettz9

@brettz9 thank you! It's work for me

orlov-vo avatar Jul 19 '19 13:07 orlov-vo

I have a similar issue with exporting a class. My config is:

"jsdoc/require-jsdoc": [
    "error", {
        enableFixer: false,
        publicOnly:  true,
        require:     {
            ClassDeclaration:        true,
            ClassExpression:         true,
            FunctionDeclaration:     true,
            FunctionExpression:      true,
            MethodDefinition:        true,
            ArrowFunctionExpression: true,
        },
    },
],

This flavor of exporting a class triggers Missing JSDoc comment on the method but not the class:

class Utility {
    mthd() {
        return false;
    }
}

module.exports = Utility;

This flavor of exporting a class triggers Missing JSDoc comment on the class but not the method:

module.exports = class Utility {
    mthd() {
        return false;
    }
};

apowers313 avatar Oct 04 '20 20:10 apowers313

@apowers313 : I have confirmed this is a bug, and though no guarantees on my getting to it, please file as a separate issue so there is a greater chance it can be discovered and given priority as a bug. I'd like to keep this issue now limited to general types of detection rather than AST-node-type-specific problems. Thanks!

brettz9 avatar Oct 05 '20 01:10 brettz9

I think the most critical items are discoverable, so closing.

brettz9 avatar May 28 '23 18:05 brettz9