Skip to content

Added description for packages implementation - #65

Merged
Dan Gaeta (dgaeta) merged 6 commits into
masterfrom
dagaeta/package-comments
Jan 25, 2017
Merged

Dan Gaeta (dgaeta) merged 6 commits into
masterfrom
dagaeta/package-comments

Conversation

@dgaeta

@dgaeta Dan Gaeta (dgaeta) commented Jan 25, 2017 •

Copy link
Copy Markdown
Contributor
  • package descriptions are created at the top of the their index.ts file:
/**
 * A utility that analyzes a project, detects common JSDoc problems , and generates
 * a report of the exported Public API.
 */
declare const packageDescription: void;
  • if their is no package description no error is reported. We can see this is working by observing that testInput/example2 has a description and testInput/example1 has no package description (with no change in their reported errors count)

@octogonz Pete Gonzalez (octogonz) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I added some notes

@octogonz

Copy link
Copy Markdown
Collaborator

Please test against sp-client before merging your PR

Comment thread api-extractor/src/PrettyPrinter.ts Outdated
}
try {
const jsdoc: string = TypeScriptHelpers.getJsDocComments(node, console.log);
if (jsdoc && jsdoc.trim()) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Delete this COMMENT= code; it was just for testing. Also delete the console.log('**') thing above.

console.log(`${indent}${kindName}: [${trimmedText}]`);
for (const childNode of node.getChildren()) {
PrettyPrinter.dumpTree(childNode, indent + ' ');
try {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Keep this try/catch block though; it was a fix for a legitimate issue. The "expected exception" here is okay, since the function is only used for debugging.

if (this.apiItem instanceof ApiPackage) {
if (apiTagCount > 0) {
const tag: string = '@' + ApiTag[this.apiTag].toLowerCase();
this.reportError(`The ${tag} tag is not allowed on the package`);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggest to clarify The ${tag} tag is not allowed on the package, which is always public

private static _getOptions(analyzer: Analyzer, rootFileSymbol: ts.Symbol): IApiItemOptions {
let statement: ts.VariableStatement;
let foundDescription: ts.Node = undefined;
for (const statementNode of (rootFileSymbol.declarations[0] as ts.SourceFile).statements) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Clean up the (rootFileSymbol.declarations[0] as ts.SourceFile) expression

let foundDescription: ts.Node = undefined;
for (const statementNode of (rootFileSymbol.declarations[0] as ts.SourceFile).statements) {
if (statementNode.kind === ts.SyntaxKind.VariableStatement) {
statement = statementNode as ts.VariableStatement;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This typecast should be unnecessary. Could take a quick look at why the tagged union isn't working?

https://github.com/Microsoft/TypeScript/wiki/What's-new-in-TypeScript#tagged-union-types
https://www.typescriptlang.org/docs/handbook/advanced-types.html

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The second link was very useful.

"If we have a value that has a union type, we can only access members that are common to all types in the union."
"If a value has the type A | B, we only know for certain that it has members that both A and B have. In this example, Bird has a member named fly. We can’t be sure whether a variable typed as Bird | Fish has a fly method. If the variable is really a Fish at runtime, then calling pet.fly() will fail."

statement = statementNode as ts.VariableStatement;
for (const statementDeclaration of statement.declarationList.declarations) {
if (statementDeclaration.name.getText() === 'packageDescription') {
// The following line is useful for debugging

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Clean up

}
}
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

If they omit or misspell packageDescription, could you add a warning to *.api.ts? Something like this:

// (No packageDescription for this package) 

"type": "string",
"enum": [ "package" ]
},
"summary": {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should we support remarks also?

Comment thread api-extractor/src/PrettyPrinter.ts Outdated
if (node.kind === ts.SyntaxKind.FromKeyword) {
console.log('**');
}
try {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This code doesn't do anything

@dgaeta
Dan Gaeta (dgaeta) merged commit 53d3e3f into master Jan 25, 2017
Pete Gonzalez (octogonz) pushed a commit that referenced this pull request Feb 13, 2017
Added description for packages implementation
Christian Gonzalez (christiango) pushed a commit to christiango/web-build-tools that referenced this pull request Aug 22, 2017
Added description for packages implementation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants