Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

Added tags logic for completed-docs #2415

Merged
merged 8 commits into from Oct 20, 2017
Merged

Added tags logic for completed-docs #2415

merged 8 commits into from Oct 20, 2017

Conversation

JoshuaKGoldberg
Copy link
Contributor

@JoshuaKGoldberg JoshuaKGoldberg commented Mar 27, 2017

Fixes #1921.

Changelog entry

[enhancement] Allow completed-docs to list doc tags that mark a node as not requiring a documentation body. Tags can also provide a regexp matcher to validate that their contents are docs-valid.

Josh Goldberg added 2 commits March 27, 2017 17:17
Used a factory instead of public/private static methods. Splitting
across files meant I was forced to keep a clean deliniation of
responsibilities, showing that the statics was dirty in the first place.

#2399.
Inverted the "requirement" concept into an "exclusion" concept. Instead
of caring about whether nodes currently _require_ a doc comment (which
implies they don't have one at the moment), we now check if there's
anything _excluding_ a node from needing to check whether it has a
documentation body.
@JoshuaKGoldberg
Copy link
Contributor Author

:( tests pass locally! Might be a TypeScript version-specific issue? Will take a look soon...

Also, I couldn't find existing examples of how to specify an object mapping strings to strings for the config settings (though I have a vague recollection of looking before). Will do a real scan-through soon also...

@nchen63
Copy link
Contributor

nchen63 commented Mar 28, 2017

Looks like it fails for 2.0.10. I think we can remove support for that in 5.0 so I'll remove the test requirement

@JoshuaKGoldberg
Copy link
Contributor Author

TS 2.0.1

Great. Does that mean reviewing this PR will be blocked until 5.0?

JSON schema

Is it ok to wait to standardize these into something other than an any type? #2428

@ajafff
Copy link
Contributor

ajafff commented Mar 29, 2017

Does that mean reviewing this PR will be blocked until 5.0?

v5.0 is almost ready, see #2426


public excludes(node: ts.Declaration) {
const documentationNode = this.getDocumentationNode(node);
const tagsWithContents = this.parseTagsWithContents(documentationNode.getFullText());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you want to get the jsdoc comment, you can simply do this:

const [firstChild] = documentationNode.getChildren();
if (firstChild.kind === ts.SyntaxKind.JSDocComment) {
    // firstChild is ts.JSDoc
    // do stuff with the comment
}

For more info on JSDoc, see https://github.com/Microsoft/TypeScript/blob/master/src/compiler/types.ts#L2065
You also don't need to parse it manually with the regex magic below. Typescript's parser already did that for you

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually there may be more JSDocComments for a given node. but all of them precede nodes of other kinds.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @ajafff, I haven't been able to get that to work. Adding an if check for the node being any of the JSDoc kinds in a new visitNode isn't getting triggered. Either I'm missing something obvious or being silly. Are you ok with either taking a look yourself or letting this pass with a followup issue to clean this rule up (switch to the more efficient walker type and use the new APIs instead of type checking)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bump @ajafff ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JoshuaKGoldberg SyntaxWalker#visitNode will never visit any JSDoc nodes, that's why I pointed you to node.getChildren() which does some magic to include jsdoc as the first entries if available.
However, I don't consider this a blocker for the PR. I'm fine with merging this without that change and tweaking it afterwards.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 thanks. If this goes in I'll file a followup bug to do that and refactor this to the newer, more-performant walker style.

return [];
}

return symbol.getDocumentationComment();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

starting from ts@2.1 you don't necessarily need the typechecker for that, see my other comment above

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome thanks, I'll update this...

@adidahiya
Copy link
Contributor

friendly ping @JoshuaKGoldberg

@JoshuaKGoldberg
Copy link
Contributor Author

JoshuaKGoldberg commented Apr 12, 2017

Sorry, been busy. :( should be able to fix this up within the week...

Edit: got to it, tests pass, but couldn't resolve ajaff's feedback..

Josh Goldberg added 2 commits June 3, 2017 12:12
The default visibility for class items should always be considered public.
# Conflicts:
#	src/rules/completedDocsRule.ts
@JoshuaKGoldberg
Copy link
Contributor Author

@ajafff The moon and stars aligned again and I was able to get to this. Could you please take a look?

I still hope to send a followup PR after this to no longer need the type checker (especially considering #2767).

Copy link
Contributor

@ajafff ajafff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
This PR is overwhelming. Especially as its main objective is just to allow configuration which tags do not require a full blown docs comment. That may be caused by your rather verbose coding style. But don't worry, that's not a bad thing.
Fortunately the bulk of the diff is just extracting Requirement -> Exclusion.

@@ -0,0 +1,42 @@
/**
* @license
* Copyright 2013 Palantir Technologies, Inc.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2017

@adidahiya adidahiya merged commit aa35097 into palantir:master Oct 20, 2017
@JoshuaKGoldberg JoshuaKGoldberg deleted the completed-docs-tags branch October 20, 2017 15:37
HyphnKnight pushed a commit to HyphnKnight/tslint that referenced this pull request Apr 9, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants