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

Add JSDoc to document plugin configs etc #2386

Merged
merged 7 commits into from
Mar 8, 2024
Merged

Add JSDoc to document plugin configs etc #2386

merged 7 commits into from
Mar 8, 2024

Conversation

colinrotherham
Copy link
Contributor

@colinrotherham colinrotherham commented Nov 30, 2023

Additional documentation to help reduce bugs when working with config and plugin management code

__tests__/utils/index.js Outdated Show resolved Hide resolved
/**
* @param {string} executionPath
* @param {string} nunjucksFileName
* @param {string | string[]} nunjucksPaths
Copy link
Contributor

Choose a reason for hiding this comment

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

I can't see any logic to support nunjucksPath being a string rather than an array of strings – I think we'd end up iterating over each character in the string on line 48?

It looks like this might also be optional?

Should it be…

Suggested change
* @param {string | string[]} nunjucksPaths
* @param {string[]} [nunjucksPaths]

Copy link
Contributor Author

@colinrotherham colinrotherham Mar 4, 2024

Choose a reason for hiding this comment

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

Ah sorry, the cypress tests use strings and a few places in the wild too:

UKHomeOffice/home_office_design_kit/blob/master/govuk-prototype-kit.config.json
that-firefly/testing-personal-prototypes/blob/testing-eg/govuk-prototype-kit.config.json

Possibly because we documented below (bit out of date) that strings were allowed?

* "nunjucksPaths": string | string[],
* "nunjucksFilters": string | string[],
* "nunjucksFunctions": string | string[],
* "pluginDependencies": [{"packageName": string, "minVersion": string, "maxVersion": string}],

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Definitely give #2354 a try to see lots more red squiggles

Similar to 77b7943 you'll see it's still possible to access configEntry.path and configEntry.importFrom even though configEntry might be a string etc

Or sometimes we just check the key name but not the type:

} else if (key === 'nunjucksMacros') {
checkNunjucksMacroExists(executionPath, configEntry.importFrom, pluginConfig.nunjucksPaths)
} else if (typeof configEntry === 'string' && configEntry[0] === '/') {

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like possibly the kit supports nunjucksPaths being a string but this validator doesn't allow for it?

I mean, technically you can pass a string, but it'll try and iterate over it character by character and result in errors – what are we trying to document in the JSDoc? Technical compatibility or how it's designed to be used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like possibly the kit supports nunjucksPaths being a string but this validator doesn't allow for it?

Yeah that's it exactly

Just tried it with GOV.UK and everything works. The code was simplified recently but it's flat() that does the magic:

nunjucksViews.push(...[config.nunjucksPaths].flat()
  .map(nunjucksPath => path.join(baseDir, nunjucksPath))

Copy link
Contributor Author

@colinrotherham colinrotherham Mar 5, 2024

Choose a reason for hiding this comment

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

what are we trying to document in the JSDoc? Technical compatibility or how it's designed to be used?

I added JSDoc to document how the kit is currently used

That way (in theory) the compiler can error or show red squiggles on all the code that doesn't support the current usage. Except for looping strings, which is valid 🤦‍♂️

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've pushed up a tweak to handle undefined and strings at the same time in 5e534e7

Ideally we should leave broken things broken and triage them?

@colinrotherham colinrotherham merged commit 7060f23 into main Mar 8, 2024
30 checks passed
@colinrotherham colinrotherham deleted the jsdoc branch March 8, 2024 10:46
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