Skip to content

Commit cb858ff

Browse files
authored
refactor: update and fix error types in JSDoc comments (#213)
1 parent 79b4646 commit cb858ff

File tree

5 files changed

+16
-6
lines changed

5 files changed

+16
-6
lines changed

packages/config-array/src/config-array.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ function assertNormalized(configArray) {
555555
* Ensures that config types are valid.
556556
* @param {Array<string>} extraConfigTypes The config types to check.
557557
* @returns {void}
558-
* @throws {Error} When the config types array is invalid.
558+
* @throws {TypeError} When the config types array is invalid.
559559
*/
560560
function assertExtraConfigTypes(extraConfigTypes) {
561561
if (extraConfigTypes.length > 2) {
@@ -577,7 +577,7 @@ function assertExtraConfigTypes(extraConfigTypes) {
577577
* Returns path-handling implementations for Unix or Windows, depending on a given absolute path.
578578
* @param {string} fileOrDirPath The absolute path to check.
579579
* @returns {PathImpl} Path-handling implementations for the specified path.
580-
* @throws An error is thrown if the specified argument is not an absolute path.
580+
* @throws {Error} An error is thrown if the specified argument is not an absolute path.
581581
*/
582582
function getPathImpl(fileOrDirPath) {
583583
// Posix absolute paths always start with a slash.
@@ -655,6 +655,7 @@ export class ConfigArray extends Array {
655655
* @param {Object} [options.schema] The additional schema
656656
* definitions to use for the ConfigArray schema.
657657
* @param {Array<string>} [options.extraConfigTypes] List of config types supported.
658+
* @throws {TypeError} When the `basePath` is not a non-empty string,
658659
*/
659660
constructor(
660661
configs,

packages/config-helpers/src/define-config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ function normalizePluginConfig(userNamespace, plugin, config) {
204204
* @param {Config|LegacyConfig|(Config|LegacyConfig)[]} pluginConfig The plugin config to normalize.
205205
* @param {string} pluginConfigName The name of the plugin config.
206206
* @return {InfiniteConfigArray} The normalized plugin config.
207+
* @throws {TypeError} If the plugin config is a legacy config.
207208
*/
208209
function deepNormalizePluginConfig(
209210
userPluginNamespace,
@@ -238,6 +239,7 @@ function deepNormalizePluginConfig(
238239
* @param {Config} config The config object.
239240
* @param {string} pluginConfigName The name of the plugin config.
240241
* @return {InfiniteConfigArray} The plugin config.
242+
* @throws {TypeError} If the plugin config is not found or is a legacy config.
241243
*/
242244
function findPluginConfig(config, pluginConfigName) {
243245
const { namespace: userPluginNamespace, name: configName } =
@@ -386,6 +388,7 @@ function extendConfig(baseConfig, baseConfigName, extension, extensionName) {
386388
* @param {ConfigWithExtends} config The config object.
387389
* @param {WeakMap<Config, string>} configNames The map of config objects to their names.
388390
* @return {Config[]} The flattened list of config objects.
391+
* @throws {TypeError} If the `extends` property is not an array or if nested `extends` is found.
389392
*/
390393
function processExtends(config, configNames) {
391394
if (!config.extends) {
@@ -490,6 +493,7 @@ function processConfigList(configList, configNames) {
490493
* Helper function to define a config array.
491494
* @param {ConfigWithExtendsArray} args The arguments to the function.
492495
* @returns {Config[]} The config array.
496+
* @throws {TypeError} If no arguments are provided or if an argument is not an object.
493497
*/
494498
export function defineConfig(...args) {
495499
const configNames = new WeakMap();

packages/config-helpers/src/global-ignores.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ let globalIgnoreCount = 0;
2424
* @param {string[]} ignorePatterns The ignore patterns.
2525
* @param {string} [name] The name of the global ignores config.
2626
* @returns {Config} The global ignores config.
27+
* @throws {TypeError} If ignorePatterns is not an array or if it is empty.
2728
*/
2829
export function globalIgnores(ignorePatterns, name) {
2930
if (!Array.isArray(ignorePatterns)) {

packages/object-schema/src/object-schema.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ import { ValidationStrategy } from "./validation-strategy.js";
2525
* @param {string} name The name of the key this strategy is for.
2626
* @param {PropertyDefinition} definition The strategy for the object key.
2727
* @returns {void}
28-
* @throws {Error} When the strategy is missing a name.
29-
* @throws {Error} When the strategy is missing a merge() method.
30-
* @throws {Error} When the strategy is missing a validate() method.
28+
* @throws {TypeError} When the strategy is missing a name.
29+
* @throws {TypeError} When the strategy is missing a merge() method.
30+
* @throws {TypeError} When the strategy is missing a validate() method.
3131
*/
3232
function validateDefinition(name, definition) {
3333
let hasSchema = false;
@@ -152,6 +152,7 @@ export class ObjectSchema {
152152
/**
153153
* Creates a new instance.
154154
* @param {ObjectDefinition} definitions The schema definitions.
155+
* @throws {Error} When the definitions are missing or invalid.
155156
*/
156157
constructor(definitions) {
157158
if (!definitions) {
@@ -221,7 +222,7 @@ export class ObjectSchema {
221222
* strategy.
222223
* @param {...Object} objects The objects to merge.
223224
* @returns {Object} A new object with a mix of all objects' keys.
224-
* @throws {Error} If any object is invalid.
225+
* @throws {TypeError} If any object is invalid.
225226
*/
226227
merge(...objects) {
227228
// double check arguments

packages/plugin-kit/src/source-code.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ export class TextSourceCodeBase {
255255
* Returns the loc information for the given node or token.
256256
* @param {Options['SyntaxElementWithLoc']} nodeOrToken The node or token to get the loc information for.
257257
* @returns {SourceLocation} The loc information for the node or token.
258+
* @throws {Error} If the node or token does not have loc information.
258259
*/
259260
getLoc(nodeOrToken) {
260261
if (hasESTreeStyleLoc(nodeOrToken)) {
@@ -274,6 +275,7 @@ export class TextSourceCodeBase {
274275
* Returns the range information for the given node or token.
275276
* @param {Options['SyntaxElementWithLoc']} nodeOrToken The node or token to get the range information for.
276277
* @returns {SourceRange} The range information for the node or token.
278+
* @throws {Error} If the node or token does not have range information.
277279
*/
278280
getRange(nodeOrToken) {
279281
if (hasESTreeStyleRange(nodeOrToken)) {
@@ -297,6 +299,7 @@ export class TextSourceCodeBase {
297299
* Returns the parent of the given node.
298300
* @param {Options['SyntaxElementWithLoc']} node The node to get the parent of.
299301
* @returns {Options['SyntaxElementWithLoc']|undefined} The parent of the node.
302+
* @throws {Error} If the method is not implemented in the subclass.
300303
*/
301304
getParent(node) {
302305
throw new Error("Not implemented.");

0 commit comments

Comments
 (0)