Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure Babel to remove non-public comments #3958

Merged
merged 4 commits into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@ module.exports = {
}
],

// JSDoc blocks are optional
'jsdoc/require-jsdoc': 'off',
'jsdoc/require-param-description': 'off',
'jsdoc/require-param': 'off',

// Check for valid formatting
'jsdoc/check-line-alignment': [
'warn',
Expand All @@ -57,6 +52,19 @@ module.exports = {
}
],

// JSDoc blocks can use `@preserve` to prevent removal
'jsdoc/check-tag-names': [
'warn',
{
definedTags: ['preserve']
}
],

// JSDoc blocks are optional
'jsdoc/require-jsdoc': 'off',
'jsdoc/require-param-description': 'off',
'jsdoc/require-param': 'off',

// Require hyphens before param description
// Aligns with TSDoc style: https://tsdoc.org/pages/tags/param/
'jsdoc/require-hyphen-before-param-description': 'warn',
Expand Down
2 changes: 2 additions & 0 deletions docs/contributing/coding-standards/js.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ component
```mjs
/**
* Component name
*
* @preserve
*/
export class Example {
/**
Expand Down
21 changes: 21 additions & 0 deletions packages/govuk-frontend/babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,27 @@ module.exports = function (api) {
const browserslistEnv = isBrowser ? 'javascripts' : 'node'

return {
generatorOpts: {
shouldPrintComment(comment) {
if (!isBrowser || comment.includes('* @preserve')) {
return true
}

// Assume all comments are public unless
// tagged with `@private` or `@internal`
const isPrivate = ['* @internal', '* @private'].some((tag) =>
comment.includes(tag)
)

// Flag any JSDoc comments worth keeping
const isDocumentation = ['* @param', '* @returns', '* @typedef'].some(
(tag) => comment.includes(tag)
)

// Print only public JSDoc comments
return !isPrivate && isDocumentation
}
},
presets: [
[
'@babel/preset-env',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { I18n } from '../../i18n.mjs'
*
* The state of each section is saved to the DOM via the `aria-expanded`
* attribute, which also provides accessibility.
*
* @preserve
*/
export class Accordion {
/** @private */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const DEBOUNCE_TIMEOUT_IN_SECONDS = 1

/**
* JavaScript enhancements for the Button component
*
* @preserve
*/
export class Button {
/** @private */
Expand All @@ -24,7 +26,6 @@ export class Button {
debounceFormSubmitTimer = null

/**
*
* @param {Element} $module - HTML element to use for button
* @param {ButtonConfig} [config] - Button config
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { I18n } from '../../i18n.mjs'
*
* You can configure the message to only appear after a certain percentage
* of the available characters/words has been entered.
*
* @preserve
*/
export class CharacterCount {
/** @private */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/**
* Checkboxes component
*
* @preserve
*/
export class Checkboxes {
/** @private */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { normaliseDataset } from '../../common/normalise-dataset.mjs'
* Error summary component
*
* Takes focus on initialisation for accessible announcement, unless disabled in configuration.
*
* @preserve
*/
export class ErrorSummary {
/** @private */
Expand All @@ -17,7 +19,6 @@ export class ErrorSummary {
config

/**
*
* @param {Element} $module - HTML element to use for error summary
* @param {ErrorSummaryConfig} [config] - Error summary config
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { I18n } from '../../i18n.mjs'

/**
* Exit This Page component
*
* @preserve
*/
export class ExitThisPage {
/** @private */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/**
* Header component
*
* @preserve
*/
export class Header {
/** @private */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { normaliseDataset } from '../../common/normalise-dataset.mjs'

/**
* Notification Banner component
*
* @preserve
*/
export class NotificationBanner {
/** @private */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/**
* Radios component
*
* @preserve
*/
export class Radios {
/** @private */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/**
* Skip link component
*
* @preserve
*/
export class SkipLink {
/** @private */
Expand All @@ -15,7 +17,6 @@ export class SkipLink {
linkedElementListener = false

/**
*
* @param {Element} $module - HTML element to use for skip link
*/
constructor($module) {
Expand Down
2 changes: 2 additions & 0 deletions packages/govuk-frontend/src/govuk/components/tabs/tabs.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/**
* Tabs component
*
* @preserve
*/
export class Tabs {
/** @private */
Expand Down