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 basic embedded overrides support #22

Merged
merged 2 commits into from
Nov 21, 2023
Merged

Add basic embedded overrides support #22

merged 2 commits into from
Nov 21, 2023

Conversation

Sec-ant
Copy link
Owner

@Sec-ant Sec-ant commented Oct 30, 2023

This is a preliminary attempt to add option overrides support for embedded languages, see #16 (comment)

  • Add a new option embeddedOverrides. This option accepts a stringified json string or an absolute json file path as its value.
  • The value should be in the following form, an example 👇:
    [
      {
        "identifiers": [
          "sql"
        ],
        "options": {
          "keywordCase": "lower",
          "indentStyle": "tabularRight"
        }
      },
      {
        "identifiers": [
          "mysql"
        ],
        "options": {
          "keywordCase": "upper"
        }
      }
    ]

Note: Not all options are supported for overriding. Check the interface definition:

export interface EmbeddedOverride {
  identifiers: AutocompleteStringList<EmbeddedDefaultIdentifier[]>;
  options: Omit<
    // native prettier options
    Omit<Options, keyof PrettierPluginEmbedOptions> &
      // prettier-plugin-embed options
      // except for "embedded<Language>Identifiers"
      // and global options
      // (they should be set globally, not in overrides)
      Omit<
        PrettierPluginEmbedOptions,
        | keyof PrettierPluginGlobalOptions
        | ReturnType<typeof makeIdentifiersOptionName<EmbeddedLanguage>>
      >,
    // these options are used in `printDocToString`,
    // we cannot override them because plugins can only affect ast and doc generation at most
    // check: https://github.com/prettier/prettier/blob/7aecca5d6473d73f562ca3af874831315f8f2581/src/document/printer.js
    | "printWidth"
    | "endOfLine"
    | "useTabs"
    | "tabWidth"
    // some other options we don't want to expose to the users or don't make sense to override
    | "parser"
    | "filepath"
    | "embeddedLanguageFormatting"
    | `__${string}`
  >;
}

@Sec-ant Sec-ant merged commit dc1c543 into main Nov 21, 2023
3 checks passed
@Sec-ant Sec-ant deleted the embedded-overrides branch November 21, 2023 04:00
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.

1 participant