Skip to content

Commit f582122

Browse files
aduthnosolosw
authored andcommitted
docgen: Omit docblocks with private tag (#15173)
1 parent 0ad0414 commit f582122

11 files changed

Lines changed: 86 additions & 87 deletions

File tree

packages/blocks/README.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,6 @@ In the random image block above, we've given the `alt` attribute of the image a
176176

177177
<!-- START TOKEN(Autogenerated API docs) -->
178178

179-
<a name="children" href="#children">#</a> **children**
180-
181-
Undocumented declaration.
182-
183179
<a name="cloneBlock" href="#cloneBlock">#</a> **cloneBlock**
184180

185181
Given a block object, returns a copy of the block object, optionally merging
@@ -536,10 +532,6 @@ _Returns_
536532

537533
- `boolean`: True if the parameter is a valid icon and false otherwise.
538534

539-
<a name="node" href="#node">#</a> **node**
540-
541-
Undocumented declaration.
542-
543535
<a name="normalizeIconObject" href="#normalizeIconObject">#</a> **normalizeIconObject**
544536

545537
Function that receives an icon as set by the blocks during the registration

packages/blocks/src/api/children.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,17 @@ export function matcher( selector ) {
138138
};
139139
}
140140

141+
/**
142+
* Object of utility functions used in managing block attribute values of
143+
* source `children`.
144+
*
145+
* @see https://github.com/WordPress/gutenberg/pull/10439
146+
*
147+
* @deprecated since 4.0. The `children` source should not be used, and can be
148+
* replaced by the `html` source.
149+
*
150+
* @private
151+
*/
141152
export default {
142153
concat,
143154
getChildrenArray,

packages/blocks/src/api/node.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,17 @@ export function matcher( selector ) {
118118
};
119119
}
120120

121+
/**
122+
* Object of utility functions used in managing block attribute values of
123+
* source `node`.
124+
*
125+
* @see https://github.com/WordPress/gutenberg/pull/10439
126+
*
127+
* @deprecated since 4.0. The `node` source should not be used, and can be
128+
* replaced by the `html` source.
129+
*
130+
* @private
131+
*/
121132
export default {
122133
isNodeOfType,
123134
fromDOM,

packages/docgen/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
## Master
22

3+
### Enhancements
4+
5+
- Docblocks including a `@private` tag will be omitted from the generated result.
6+
37
### Internal
48

59
- Remove unneccessary argument from an instance of `Array#pop`.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* Given a symbol object and tag name(s), returns tag objects from the symbol
3+
* matching the given name.
4+
*
5+
* @param {Object} symbol Symbol object.
6+
* @param {...string} names Names of tags to return.
7+
*
8+
* @return {Object[]} Matching tag objects.
9+
*/
10+
function getSymbolTagsByName( symbol, ...names ) {
11+
return symbol.tags.filter( ( tag ) => {
12+
return names.some( ( name ) => name === tag.title );
13+
} );
14+
}
15+
16+
module.exports = getSymbolTagsByName;

packages/docgen/src/index.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const { last } = require( 'lodash' );
1010
*/
1111
const engine = require( './engine' );
1212
const defaultMarkdownFormatter = require( './markdown' );
13+
const isSymbolPrivate = require( './is-symbol-private' );
1314

1415
/**
1516
* Helpers functions.
@@ -102,7 +103,17 @@ module.exports = function( sourceFile, options ) {
102103

103104
// Process
104105
const result = processFile( processDir, sourceFile );
105-
const filteredIr = result.ir.filter( ( { name } ) => options.ignore ? ! name.match( options.ignore ) : true );
106+
const filteredIR = result.ir.filter( ( symbol ) => {
107+
if ( isSymbolPrivate( symbol ) ) {
108+
return false;
109+
}
110+
111+
if ( options.ignore ) {
112+
return ! symbol.name.match( options.ignore );
113+
}
114+
115+
return true;
116+
} );
106117

107118
// Ouput
108119
if ( result === undefined ) {
@@ -113,9 +124,9 @@ module.exports = function( sourceFile, options ) {
113124
}
114125

115126
if ( options.formatter ) {
116-
runCustomFormatter( path.join( processDir, options.formatter ), processDir, doc, filteredIr, 'API' );
127+
runCustomFormatter( path.join( processDir, options.formatter ), processDir, doc, filteredIR, 'API' );
117128
} else {
118-
defaultMarkdownFormatter( options, processDir, doc, filteredIr, 'API' );
129+
defaultMarkdownFormatter( options, processDir, doc, filteredIR, 'API' );
119130
}
120131

121132
if ( debugMode ) {
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* Internal dependencies
3+
*/
4+
const getSymbolTagsByName = require( './get-symbol-tags-by-name' );
5+
6+
/**
7+
* Returns true if, given a symbol object, it contains a @private tag, or false
8+
* otherwise.
9+
*
10+
* @param {Object} symbol Symbol object.
11+
*
12+
* @return {boolean} Whether symbol is private.
13+
*/
14+
const isSymbolPrivate = ( symbol ) => getSymbolTagsByName( symbol, 'private' ).length > 0;
15+
16+
module.exports = isSymbolPrivate;

packages/docgen/src/markdown/formatter.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
const getTagsByName = ( tags, ...names ) => tags.filter( ( tag ) => names.some( ( name ) => name === tag.title ) );
1+
/**
2+
* Internal dependencies
3+
*/
4+
const getSymbolTagsByName = require( '../get-symbol-tags-by-name' );
25

36
const cleanSpaces = ( paragraph ) =>
47
paragraph ?
@@ -57,7 +60,7 @@ const getSymbolHeading = ( text ) => {
5760
};
5861

5962
module.exports = function( rootDir, docPath, symbols, headingTitle, headingStartIndex ) {
60-
const docs = [ ];
63+
const docs = [];
6164
let headingIndex = headingStartIndex || 1;
6265
if ( headingTitle ) {
6366
docs.push( getHeading( headingIndex, `${ headingTitle }` ) );
@@ -79,30 +82,30 @@ module.exports = function( rootDir, docPath, symbols, headingTitle, headingStart
7982
if ( symbols && symbols.length > 0 ) {
8083
symbols.forEach( ( symbol ) => {
8184
docs.push( getSymbolHeading( symbol.name ) );
82-
formatDeprecated( getTagsByName( symbol.tags, 'deprecated' ), docs );
85+
formatDeprecated( getSymbolTagsByName( symbol, 'deprecated' ), docs );
8386
formatDescription( symbol.description, docs );
8487
formatTag(
8588
'Related',
86-
getTagsByName( symbol.tags, 'see', 'link' ),
89+
getSymbolTagsByName( symbol, 'see', 'link' ),
8790
( tag ) => `\n- ${ tag.description }`,
8891
docs
8992
);
90-
formatExamples( getTagsByName( symbol.tags, 'example' ), docs );
93+
formatExamples( getSymbolTagsByName( symbol, 'example' ), docs );
9194
formatTag(
9295
'Type',
93-
getTagsByName( symbol.tags, 'type' ),
96+
getSymbolTagsByName( symbol, 'type' ),
9497
( tag ) => `\n- \`${ tag.type }\` ${ cleanSpaces( tag.description ) }`,
9598
docs
9699
);
97100
formatTag(
98101
'Parameters',
99-
getTagsByName( symbol.tags, 'param' ),
102+
getSymbolTagsByName( symbol, 'param' ),
100103
( tag ) => `\n- *${ tag.name }* \`${ tag.type }\`: ${ cleanSpaces( tag.description ) }`,
101104
docs
102105
);
103106
formatTag(
104107
'Returns',
105-
getTagsByName( symbol.tags, 'return' ),
108+
getSymbolTagsByName( symbol, 'return' ),
106109
( tag ) => `\n- \`${ tag.type }\`: ${ cleanSpaces( tag.description ) }`,
107110
docs
108111
);

packages/docgen/src/markdown/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ const appendOrEmbedContents = ( { options, newContents } ) => {
2424
};
2525
};
2626

27-
module.exports = function( options, processDir, doc, filteredIr, headingTitle ) {
27+
module.exports = function( options, processDir, doc, filteredIR, headingTitle ) {
2828
if ( options.toSection || options.toToken ) {
2929
const currentReadmeFile = fs.readFileSync( options.output, 'utf8' );
30-
const newContents = unified().use( remarkParser ).parse( formatter( processDir, doc, filteredIr, null ) );
30+
const newContents = unified().use( remarkParser ).parse( formatter( processDir, doc, filteredIR, null ) );
3131
remark()
3232
.use( { settings: { commonmark: true } } )
3333
.use( appendOrEmbedContents, { options, newContents } )
@@ -38,7 +38,7 @@ module.exports = function( options, processDir, doc, filteredIr, headingTitle )
3838
fs.writeFileSync( doc, file );
3939
} );
4040
} else {
41-
const output = formatter( processDir, doc, filteredIr, headingTitle );
41+
const output = formatter( processDir, doc, filteredIR, headingTitle );
4242
fs.writeFileSync( doc, output );
4343
}
4444
};

packages/docgen/src/test/fixtures/markdown/code.js

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)