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

Long type references are broken up into multiple lines incorrectly with leading pipe character #181

Closed
pahund opened this issue Dec 28, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@pahund
Copy link

pahund commented Dec 28, 2022

Before formatting, by JSDoc for a return statement looks like this:

/**
 * Gets a configuration object assembled from environment variables and .env configuration files.
 *
 * @memberof Config
 * @function getEnvConfig
 * @returns {Config.SomeConfiguration | Config.SomeOtherConfiguration | Config.AnotherConfiguration | Config.YetAnotherConfiguration } The environment configuration
 */
export default () => configurator.config;

After running Prettier, the JSDoc comment is formatted like this:

/**
 * Gets a configuration object assembled from environment variables and .env configuration files.
 *
 * @memberof Config
 * @function getEnvConfig
 * @returns {| Config.SomeConfiguration
 *   | Config.SomeOtherConfiguration
 *   | Config.AnotherConfiguration
 *   | Config.YetAnotherConfiguration}
 *   The environment configuration
 */
export default () => configurator.config;

Running JSDoc, this causes the following error:

ERROR: Unable to parse a tag's type expression for source file /Users/patrick.hund/IdeaProjects/code-kraken/src/config/getEnvConfig.mjs in line 41 with tag title "returns" and text "{| Config.SomeConfiguration
  | Config.SomeOtherConfiguration
  | Config.AnotherConfiguration
  | Config.YetAnotherConfiguration}
  The environment configuration": Invalid type expression "| Config.SomeConfiguration
  | Config.SomeOtherConfiguration
  | Config.AnotherConfiguration
  | Config.YetAnotherConfiguration": Expected "!", "$", "'", "(", "*", ".", "...", "0", "?", "@", "Function", "\"", "\\", "_", "break", "case", "catch", "class", "const", "continue", "debugger", "default", "delete", "do", "else", "enum", "export", "extends", "false", "finally", "for", "function", "if", "implements", "import", "in", "instanceof", "interface", "let", "new", "null", "package", "private", "protected", "public", "return", "static", "super", "switch", "this", "throw", "true", "try", "typeof", "undefined", "var", "void", "while", "with", "yield", "{", Unicode letter number, Unicode lowercase letter, Unicode modifier letter, Unicode other letter, Unicode titlecase letter, Unicode uppercase letter, or [1-9] but "|" found.

The culprit is the pipe character before Config.SomeConfiguration. If I manually format the JSDoc code like this, removing the pipe character, the syntax error does not happen:

/**
 * Gets a configuration object assembled from environment variables and .env configuration files.
 *
 * @memberof Config
 * @function getEnvConfig
 * @returns {Config.SomeConfiguration
 *   | Config.SomeOtherConfiguration
 *   | Config.AnotherConfiguration
 *   | Config.YetAnotherConfiguration}
 *   The environment configuration
 */
export default () => configurator.config;
@hosseinmd hosseinmd added the bug Something isn't working label Dec 30, 2022
hosseinmd added a commit that referenced this issue Oct 5, 2023
@hosseinmd
Copy link
Owner

fixed: v1.0.5

@pahund
Copy link
Author

pahund commented May 21, 2024

Thanks @hosseinmd!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants