2017-12-26 04:23:50 +03:00
|
|
|
"use strict";
|
|
|
|
|
2017-12-31 07:34:37 +03:00
|
|
|
const dedent = require("dedent");
|
2017-12-26 04:23:50 +03:00
|
|
|
|
2018-04-25 19:29:35 +03:00
|
|
|
const CATEGORY_CONFIG = "Config";
|
|
|
|
const CATEGORY_EDITOR = "Editor";
|
|
|
|
const CATEGORY_FORMAT = "Format";
|
|
|
|
const CATEGORY_OTHER = "Other";
|
|
|
|
const CATEGORY_OUTPUT = "Output";
|
2017-12-31 07:34:37 +03:00
|
|
|
const CATEGORY_GLOBAL = "Global";
|
|
|
|
const CATEGORY_SPECIAL = "Special";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @typedef {Object} OptionInfo
|
2019-10-25 19:25:15 +03:00
|
|
|
* @property {string} [since] - available since version
|
2017-12-31 07:34:37 +03:00
|
|
|
* @property {string} category
|
|
|
|
* @property {'int' | 'boolean' | 'choice' | 'path'} type
|
2019-10-25 19:25:15 +03:00
|
|
|
* @property {boolean} [array] - indicate it's an array of the specified type
|
|
|
|
* @property {OptionValueInfo} [default]
|
|
|
|
* @property {OptionRangeInfo} [range] - for type int
|
2017-12-31 07:34:37 +03:00
|
|
|
* @property {string} description
|
2019-10-25 19:25:15 +03:00
|
|
|
* @property {string} [deprecated] - deprecated since version
|
|
|
|
* @property {OptionRedirectInfo} [redirect] - redirect deprecated option
|
|
|
|
* @property {(value: any) => boolean} [exception]
|
|
|
|
* @property {OptionChoiceInfo[]} [choices] - for type choice
|
|
|
|
* @property {string} [cliName]
|
|
|
|
* @property {string} [cliCategory]
|
|
|
|
* @property {string} [cliDescription]
|
2017-12-31 07:34:37 +03:00
|
|
|
*
|
|
|
|
* @typedef {number | boolean | string} OptionValue
|
2018-01-18 10:26:27 +03:00
|
|
|
* @typedef {OptionValue | [{ value: OptionValue[] }] | Array<{ since: string, value: OptionValue}>} OptionValueInfo
|
2017-12-31 07:34:37 +03:00
|
|
|
*
|
|
|
|
* @typedef {Object} OptionRedirectInfo
|
|
|
|
* @property {string} option
|
|
|
|
* @property {OptionValue} value
|
|
|
|
*
|
|
|
|
* @typedef {Object} OptionRangeInfo
|
|
|
|
* @property {number} start - recommended range start
|
|
|
|
* @property {number} end - recommended range end
|
|
|
|
* @property {number} step - recommended range step
|
|
|
|
*
|
|
|
|
* @typedef {Object} OptionChoiceInfo
|
|
|
|
* @property {boolean | string} value - boolean for the option that is originally boolean type
|
2019-10-25 19:25:15 +03:00
|
|
|
* @property {string} description
|
|
|
|
* @property {string} [since] - undefined if available since the first version of the option
|
|
|
|
* @property {string} [deprecated] - deprecated since version
|
|
|
|
* @property {OptionValueInfo} [redirect] - redirect deprecated value
|
2017-12-31 07:34:37 +03:00
|
|
|
*/
|
2019-10-25 19:25:15 +03:00
|
|
|
|
|
|
|
/** @type {{ [name: string]: OptionInfo }} */
|
2018-04-25 19:29:35 +03:00
|
|
|
const options = {
|
2017-12-31 07:34:37 +03:00
|
|
|
cursorOffset: {
|
|
|
|
since: "1.4.0",
|
|
|
|
category: CATEGORY_SPECIAL,
|
|
|
|
type: "int",
|
|
|
|
default: -1,
|
|
|
|
range: { start: -1, end: Infinity, step: 1 },
|
|
|
|
description: dedent`
|
|
|
|
Print (to stderr) where a cursor at the given position would move to after formatting.
|
|
|
|
This option cannot be used with --range-start and --range-end.
|
2018-01-27 19:24:25 +03:00
|
|
|
`,
|
2018-04-25 19:29:35 +03:00
|
|
|
cliCategory: CATEGORY_EDITOR
|
2017-12-31 07:34:37 +03:00
|
|
|
},
|
2018-11-06 17:47:13 +03:00
|
|
|
endOfLine: {
|
|
|
|
since: "1.15.0",
|
|
|
|
category: CATEGORY_GLOBAL,
|
|
|
|
type: "choice",
|
|
|
|
default: "auto",
|
|
|
|
description: "Which end of line characters to apply.",
|
|
|
|
choices: [
|
|
|
|
{
|
|
|
|
value: "auto",
|
|
|
|
description: dedent`
|
|
|
|
Maintain existing
|
|
|
|
(mixed values within one file are normalised by looking at what's used after the first line)
|
|
|
|
`
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: "lf",
|
|
|
|
description:
|
|
|
|
"Line Feed only (\\n), common on Linux and macOS as well as inside git repos"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: "crlf",
|
|
|
|
description:
|
|
|
|
"Carriage Return + Line Feed characters (\\r\\n), common on Windows"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: "cr",
|
|
|
|
description: "Carriage Return character only (\\r), used very rarely"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
2017-12-31 07:34:37 +03:00
|
|
|
filepath: {
|
|
|
|
since: "1.4.0",
|
|
|
|
category: CATEGORY_SPECIAL,
|
|
|
|
type: "path",
|
|
|
|
description:
|
2018-01-27 19:24:25 +03:00
|
|
|
"Specify the input filepath. This will be used to do parser inference.",
|
|
|
|
cliName: "stdin-filepath",
|
2018-04-25 19:29:35 +03:00
|
|
|
cliCategory: CATEGORY_OTHER,
|
2018-01-27 19:24:25 +03:00
|
|
|
cliDescription: "Path to the file to pretend that stdin comes from."
|
2017-12-31 07:34:37 +03:00
|
|
|
},
|
|
|
|
insertPragma: {
|
|
|
|
since: "1.8.0",
|
|
|
|
category: CATEGORY_SPECIAL,
|
|
|
|
type: "boolean",
|
|
|
|
default: false,
|
2018-01-27 19:24:25 +03:00
|
|
|
description: "Insert @format pragma into file's first docblock comment.",
|
2018-04-25 19:29:35 +03:00
|
|
|
cliCategory: CATEGORY_OTHER
|
2017-12-31 07:34:37 +03:00
|
|
|
},
|
|
|
|
parser: {
|
|
|
|
since: "0.0.10",
|
|
|
|
category: CATEGORY_GLOBAL,
|
|
|
|
type: "choice",
|
2018-05-23 22:55:06 +03:00
|
|
|
default: [
|
|
|
|
{ since: "0.0.10", value: "babylon" },
|
|
|
|
{ since: "1.13.0", value: undefined }
|
|
|
|
],
|
2017-12-31 07:34:37 +03:00
|
|
|
description: "Which parser to use.",
|
2018-01-18 10:26:27 +03:00
|
|
|
exception: value =>
|
|
|
|
typeof value === "string" || typeof value === "function",
|
2017-12-31 07:34:37 +03:00
|
|
|
choices: [
|
|
|
|
{ value: "flow", description: "Flow" },
|
2018-12-27 16:05:19 +03:00
|
|
|
{
|
|
|
|
value: "babylon",
|
|
|
|
description: "JavaScript",
|
|
|
|
deprecated: "1.16.0",
|
|
|
|
redirect: "babel"
|
|
|
|
},
|
|
|
|
{ value: "babel", since: "1.16.0", description: "JavaScript" },
|
2018-12-29 16:35:47 +03:00
|
|
|
{ value: "babel-flow", since: "1.16.0", description: "Flow" },
|
2017-12-31 07:34:37 +03:00
|
|
|
{ value: "typescript", since: "1.4.0", description: "TypeScript" },
|
|
|
|
{ value: "css", since: "1.7.1", description: "CSS" },
|
|
|
|
{
|
|
|
|
value: "postcss",
|
|
|
|
since: "1.4.0",
|
|
|
|
description: "CSS/Less/SCSS",
|
|
|
|
deprecated: "1.7.1",
|
|
|
|
redirect: "css"
|
|
|
|
},
|
|
|
|
{ value: "less", since: "1.7.1", description: "Less" },
|
|
|
|
{ value: "scss", since: "1.7.1", description: "SCSS" },
|
|
|
|
{ value: "json", since: "1.5.0", description: "JSON" },
|
2018-04-25 17:10:22 +03:00
|
|
|
{ value: "json5", since: "1.13.0", description: "JSON5" },
|
2018-05-14 04:12:25 +03:00
|
|
|
{
|
|
|
|
value: "json-stringify",
|
|
|
|
since: "1.13.0",
|
|
|
|
description: "JSON.stringify"
|
|
|
|
},
|
2017-12-31 07:34:37 +03:00
|
|
|
{ value: "graphql", since: "1.5.0", description: "GraphQL" },
|
2018-01-18 10:26:27 +03:00
|
|
|
{ value: "markdown", since: "1.8.0", description: "Markdown" },
|
2018-08-13 17:23:09 +03:00
|
|
|
{ value: "mdx", since: "1.15.0", description: "MDX" },
|
2018-06-21 05:29:42 +03:00
|
|
|
{ value: "vue", since: "1.10.0", description: "Vue" },
|
2018-08-01 10:44:37 +03:00
|
|
|
{ value: "yaml", since: "1.14.0", description: "YAML" },
|
|
|
|
{
|
|
|
|
value: "glimmer",
|
|
|
|
since: null,
|
|
|
|
description: "Handlebars"
|
2018-09-19 04:19:18 +03:00
|
|
|
},
|
2018-11-04 18:03:07 +03:00
|
|
|
{ value: "html", since: "1.15.0", description: "HTML" },
|
2019-02-01 08:58:50 +03:00
|
|
|
{ value: "angular", since: "1.15.0", description: "Angular" },
|
|
|
|
{ value: "lwc", since: "1.17.0", description: "Lightning Web Components" }
|
2017-12-31 07:34:37 +03:00
|
|
|
]
|
|
|
|
},
|
2018-01-18 10:26:27 +03:00
|
|
|
plugins: {
|
|
|
|
since: "1.10.0",
|
|
|
|
type: "path",
|
|
|
|
array: true,
|
|
|
|
default: [{ value: [] }],
|
|
|
|
category: CATEGORY_GLOBAL,
|
|
|
|
description:
|
|
|
|
"Add a plugin. Multiple plugins can be passed as separate `--plugin`s.",
|
2018-01-27 19:24:25 +03:00
|
|
|
exception: value => typeof value === "string" || typeof value === "object",
|
|
|
|
cliName: "plugin",
|
2018-04-25 19:29:35 +03:00
|
|
|
cliCategory: CATEGORY_CONFIG
|
2018-01-18 10:26:27 +03:00
|
|
|
},
|
2018-05-09 14:17:12 +03:00
|
|
|
pluginSearchDirs: {
|
|
|
|
since: "1.13.0",
|
|
|
|
type: "path",
|
|
|
|
array: true,
|
|
|
|
default: [{ value: [] }],
|
|
|
|
category: CATEGORY_GLOBAL,
|
|
|
|
description: dedent`
|
|
|
|
Custom directory that contains prettier plugins in node_modules subdirectory.
|
|
|
|
Overrides default behavior when plugins are searched relatively to the location of Prettier.
|
|
|
|
Multiple values are accepted.
|
|
|
|
`,
|
|
|
|
exception: value => typeof value === "string" || typeof value === "object",
|
|
|
|
cliName: "plugin-search-dir",
|
|
|
|
cliCategory: CATEGORY_CONFIG
|
|
|
|
},
|
2017-12-31 07:34:37 +03:00
|
|
|
printWidth: {
|
|
|
|
since: "0.0.0",
|
|
|
|
category: CATEGORY_GLOBAL,
|
|
|
|
type: "int",
|
|
|
|
default: 80,
|
|
|
|
description: "The line length where Prettier will try wrap.",
|
|
|
|
range: { start: 0, end: Infinity, step: 1 }
|
|
|
|
},
|
|
|
|
rangeEnd: {
|
|
|
|
since: "1.4.0",
|
|
|
|
category: CATEGORY_SPECIAL,
|
|
|
|
type: "int",
|
|
|
|
default: Infinity,
|
|
|
|
range: { start: 0, end: Infinity, step: 1 },
|
|
|
|
description: dedent`
|
|
|
|
Format code ending at a given character offset (exclusive).
|
|
|
|
The range will extend forwards to the end of the selected statement.
|
|
|
|
This option cannot be used with --cursor-offset.
|
2018-01-27 19:24:25 +03:00
|
|
|
`,
|
2018-04-25 19:29:35 +03:00
|
|
|
cliCategory: CATEGORY_EDITOR
|
2017-12-31 07:34:37 +03:00
|
|
|
},
|
|
|
|
rangeStart: {
|
|
|
|
since: "1.4.0",
|
|
|
|
category: CATEGORY_SPECIAL,
|
|
|
|
type: "int",
|
|
|
|
default: 0,
|
|
|
|
range: { start: 0, end: Infinity, step: 1 },
|
|
|
|
description: dedent`
|
|
|
|
Format code starting at a given character offset.
|
|
|
|
The range will extend backwards to the start of the first line containing the selected statement.
|
|
|
|
This option cannot be used with --cursor-offset.
|
2018-01-27 19:24:25 +03:00
|
|
|
`,
|
2018-04-25 19:29:35 +03:00
|
|
|
cliCategory: CATEGORY_EDITOR
|
2017-12-31 07:34:37 +03:00
|
|
|
},
|
|
|
|
requirePragma: {
|
|
|
|
since: "1.7.0",
|
|
|
|
category: CATEGORY_SPECIAL,
|
|
|
|
type: "boolean",
|
|
|
|
default: false,
|
|
|
|
description: dedent`
|
|
|
|
Require either '@prettier' or '@format' to be present in the file's first docblock comment
|
|
|
|
in order for it to be formatted.
|
2018-01-27 19:24:25 +03:00
|
|
|
`,
|
2018-04-25 19:29:35 +03:00
|
|
|
cliCategory: CATEGORY_OTHER
|
2017-12-31 07:34:37 +03:00
|
|
|
},
|
|
|
|
tabWidth: {
|
|
|
|
type: "int",
|
|
|
|
category: CATEGORY_GLOBAL,
|
|
|
|
default: 2,
|
|
|
|
description: "Number of spaces per indentation level.",
|
|
|
|
range: { start: 0, end: Infinity, step: 1 }
|
|
|
|
},
|
|
|
|
useFlowParser: {
|
|
|
|
since: "0.0.0",
|
|
|
|
category: CATEGORY_GLOBAL,
|
|
|
|
type: "boolean",
|
2018-08-31 06:26:07 +03:00
|
|
|
default: [
|
|
|
|
{ since: "0.0.0", value: false },
|
|
|
|
{ since: "1.15.0", value: undefined }
|
|
|
|
],
|
2017-12-31 07:34:37 +03:00
|
|
|
deprecated: "0.0.10",
|
|
|
|
description: "Use flow parser.",
|
2018-01-27 19:24:25 +03:00
|
|
|
redirect: { option: "parser", value: "flow" },
|
|
|
|
cliName: "flow-parser"
|
2017-12-31 07:34:37 +03:00
|
|
|
},
|
|
|
|
useTabs: {
|
|
|
|
since: "1.0.0",
|
|
|
|
category: CATEGORY_GLOBAL,
|
|
|
|
type: "boolean",
|
|
|
|
default: false,
|
|
|
|
description: "Indent with tabs instead of spaces."
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-12-26 04:23:50 +03:00
|
|
|
module.exports = {
|
2018-04-25 19:29:35 +03:00
|
|
|
CATEGORY_CONFIG,
|
|
|
|
CATEGORY_EDITOR,
|
|
|
|
CATEGORY_FORMAT,
|
|
|
|
CATEGORY_OTHER,
|
|
|
|
CATEGORY_OUTPUT,
|
|
|
|
CATEGORY_GLOBAL,
|
|
|
|
CATEGORY_SPECIAL,
|
|
|
|
options
|
2017-12-26 04:23:50 +03:00
|
|
|
};
|