feat(support-info): add `options` field (#3433)
* refactor: rename supportTable with supportLanguages * refactor: use `dedent` * test: reduce unnecessary data * feat(support-info): add `options` field * add `showDeprecated` option * add `showUnreleased` option * test: snapshot diff * fix(support): add missing `since` * fix: add missing `category` * refactor: use template tag * fix: `trailingComma:true` should redirect to `trailingComma:es5` * refactor: reorder parser * refactor: fix linting * refactor: move options * refactor: move options to printersmaster
parent
800a1cf9d4
commit
6c0dd74518
|
@ -22,6 +22,7 @@
|
||||||
"cjk-regex": "1.0.2",
|
"cjk-regex": "1.0.2",
|
||||||
"cosmiconfig": "3.1.0",
|
"cosmiconfig": "3.1.0",
|
||||||
"dashify": "0.2.2",
|
"dashify": "0.2.2",
|
||||||
|
"dedent": "0.7.0",
|
||||||
"diff": "3.2.0",
|
"diff": "3.2.0",
|
||||||
"editorconfig": "0.14.2",
|
"editorconfig": "0.14.2",
|
||||||
"editorconfig-to-prettier": "0.0.6",
|
"editorconfig-to-prettier": "0.0.6",
|
||||||
|
@ -80,6 +81,7 @@
|
||||||
"rollup-plugin-node-resolve": "2.0.0",
|
"rollup-plugin-node-resolve": "2.0.0",
|
||||||
"rollup-plugin-replace": "1.2.1",
|
"rollup-plugin-replace": "1.2.1",
|
||||||
"shelljs": "0.7.8",
|
"shelljs": "0.7.8",
|
||||||
|
"snapshot-diff": "0.2.2",
|
||||||
"strip-ansi": "4.0.0",
|
"strip-ansi": "4.0.0",
|
||||||
"sw-toolbox": "3.6.0",
|
"sw-toolbox": "3.6.0",
|
||||||
"uglify-es": "3.0.28",
|
"uglify-es": "3.0.28",
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const camelCase = require("camelcase");
|
const camelCase = require("camelcase");
|
||||||
|
const dedent = require("dedent");
|
||||||
|
|
||||||
const CATEGORY_CONFIG = "Config";
|
const CATEGORY_CONFIG = "Config";
|
||||||
const CATEGORY_EDITOR = "Editor";
|
const CATEGORY_EDITOR = "Editor";
|
||||||
|
@ -135,10 +136,10 @@ const detailedOptions = normalizeDetailedOptions({
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: "prefer-file",
|
value: "prefer-file",
|
||||||
description: dedent(`
|
description: dedent`
|
||||||
If a config file is found will evaluate it and ignore other CLI options.
|
If a config file is found will evaluate it and ignore other CLI options.
|
||||||
If no config file is found CLI options will evaluate as normal.
|
If no config file is found CLI options will evaluate as normal.
|
||||||
`)
|
`
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
description:
|
description:
|
||||||
|
@ -149,10 +150,10 @@ const detailedOptions = normalizeDetailedOptions({
|
||||||
category: CATEGORY_EDITOR,
|
category: CATEGORY_EDITOR,
|
||||||
exception: -1,
|
exception: -1,
|
||||||
forwardToApi: true,
|
forwardToApi: true,
|
||||||
description: dedent(`
|
description: dedent`
|
||||||
Print (to stderr) where a cursor at the given position would move to after formatting.
|
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.
|
This option cannot be used with --range-start and --range-end.
|
||||||
`)
|
`
|
||||||
},
|
},
|
||||||
"debug-check": {
|
"debug-check": {
|
||||||
type: "boolean"
|
type: "boolean"
|
||||||
|
@ -183,10 +184,10 @@ const detailedOptions = normalizeDetailedOptions({
|
||||||
help: {
|
help: {
|
||||||
type: "flag",
|
type: "flag",
|
||||||
alias: "h",
|
alias: "h",
|
||||||
description: dedent(`
|
description: dedent`
|
||||||
Show CLI usage, or details about the given flag.
|
Show CLI usage, or details about the given flag.
|
||||||
Example: --help write
|
Example: --help write
|
||||||
`)
|
`
|
||||||
},
|
},
|
||||||
"ignore-path": {
|
"ignore-path": {
|
||||||
type: "path",
|
type: "path",
|
||||||
|
@ -197,9 +198,9 @@ const detailedOptions = normalizeDetailedOptions({
|
||||||
"insert-pragma": {
|
"insert-pragma": {
|
||||||
type: "boolean",
|
type: "boolean",
|
||||||
forwardToApi: true,
|
forwardToApi: true,
|
||||||
description: dedent(`
|
description: dedent`
|
||||||
Insert @format pragma into file's first docblock comment.
|
Insert @format pragma into file's first docblock comment.
|
||||||
`)
|
`
|
||||||
},
|
},
|
||||||
"jsx-bracket-same-line": {
|
"jsx-bracket-same-line": {
|
||||||
type: "boolean",
|
type: "boolean",
|
||||||
|
@ -276,29 +277,29 @@ const detailedOptions = normalizeDetailedOptions({
|
||||||
category: CATEGORY_EDITOR,
|
category: CATEGORY_EDITOR,
|
||||||
forwardToApi: true,
|
forwardToApi: true,
|
||||||
exception: Infinity,
|
exception: Infinity,
|
||||||
description: dedent(`
|
description: dedent`
|
||||||
Format code ending at a given character offset (exclusive).
|
Format code ending at a given character offset (exclusive).
|
||||||
The range will extend forwards to the end of the selected statement.
|
The range will extend forwards to the end of the selected statement.
|
||||||
This option cannot be used with --cursor-offset.
|
This option cannot be used with --cursor-offset.
|
||||||
`)
|
`
|
||||||
},
|
},
|
||||||
"range-start": {
|
"range-start": {
|
||||||
type: "int",
|
type: "int",
|
||||||
category: CATEGORY_EDITOR,
|
category: CATEGORY_EDITOR,
|
||||||
forwardToApi: true,
|
forwardToApi: true,
|
||||||
description: dedent(`
|
description: dedent`
|
||||||
Format code starting at a given character offset.
|
Format code starting at a given character offset.
|
||||||
The range will extend backwards to the start of the first line containing the selected statement.
|
The range will extend backwards to the start of the first line containing the selected statement.
|
||||||
This option cannot be used with --cursor-offset.
|
This option cannot be used with --cursor-offset.
|
||||||
`)
|
`
|
||||||
},
|
},
|
||||||
"require-pragma": {
|
"require-pragma": {
|
||||||
type: "boolean",
|
type: "boolean",
|
||||||
forwardToApi: true,
|
forwardToApi: true,
|
||||||
description: dedent(`
|
description: dedent`
|
||||||
Require either '@prettier' or '@format' to be present in the file's first docblock comment
|
Require either '@prettier' or '@format' to be present in the file's first docblock comment
|
||||||
in order for it to be formatted.
|
in order for it to be formatted.
|
||||||
`)
|
`
|
||||||
},
|
},
|
||||||
semi: {
|
semi: {
|
||||||
type: "boolean",
|
type: "boolean",
|
||||||
|
@ -399,17 +400,12 @@ const minimistOptions = {
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
const usageSummary = `
|
const usageSummary = dedent`
|
||||||
Usage: prettier [options] [file/glob ...]
|
Usage: prettier [options] [file/glob ...]
|
||||||
|
|
||||||
By default, output is written to stdout.
|
By default, output is written to stdout.
|
||||||
Stdin is read if it is piped to Prettier and no files are given.
|
Stdin is read if it is piped to Prettier and no files are given.
|
||||||
`.trim();
|
`;
|
||||||
|
|
||||||
function dedent(str) {
|
|
||||||
const spaces = str.match(/\n^( +)/m)[1].length;
|
|
||||||
return str.replace(new RegExp(`^ {${spaces}}`, "gm"), "").trim();
|
|
||||||
}
|
|
||||||
|
|
||||||
function normalizeDetailedOptions(rawDetailedOptions) {
|
function normalizeDetailedOptions(rawDetailedOptions) {
|
||||||
const names = Object.keys(rawDetailedOptions).sort();
|
const names = Object.keys(rawDetailedOptions).sort();
|
||||||
|
|
|
@ -1,17 +1,225 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
const util = require("./util");
|
||||||
|
const dedent = require("dedent");
|
||||||
const semver = require("semver");
|
const semver = require("semver");
|
||||||
const currentVersion = require("../../package.json").version;
|
const currentVersion = require("../../package.json").version;
|
||||||
const loadPlugins = require("./load-plugins");
|
const loadPlugins = require("./load-plugins");
|
||||||
|
|
||||||
function getSupportInfo(version, options) {
|
const CATEGORY_GLOBAL = "Global";
|
||||||
|
const CATEGORY_SPECIAL = "Special";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {Object} OptionInfo
|
||||||
|
* @property {string} since - available since version
|
||||||
|
* @property {string} category
|
||||||
|
* @property {'int' | 'boolean' | 'choice' | 'path'} type
|
||||||
|
* @property {boolean?} deprecated - deprecated since version
|
||||||
|
* @property {OptionRedirectInfo?} redirect - redirect deprecated option
|
||||||
|
* @property {string} description
|
||||||
|
* @property {string?} oppositeDescription - for `false` option
|
||||||
|
* @property {OptionValueInfo} default
|
||||||
|
* @property {OptionRangeInfo?} range - for type int
|
||||||
|
* @property {OptionChoiceInfo?} choices - for type choice
|
||||||
|
*
|
||||||
|
* @typedef {number | boolean | string} OptionValue
|
||||||
|
* @typedef {OptionValue | Array<{ since: string, value: OptionValue}>} OptionValueInfo
|
||||||
|
*
|
||||||
|
* @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
|
||||||
|
* @property {string?} description - undefined if redirect
|
||||||
|
* @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
|
||||||
|
*/
|
||||||
|
/** @type {{ [name: string]: OptionInfo } */
|
||||||
|
const supportOptions = {
|
||||||
|
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.
|
||||||
|
`
|
||||||
|
},
|
||||||
|
filepath: {
|
||||||
|
since: "1.4.0",
|
||||||
|
category: CATEGORY_SPECIAL,
|
||||||
|
type: "path",
|
||||||
|
default: undefined,
|
||||||
|
description:
|
||||||
|
"Specify the input filepath. This will be used to do parser inference."
|
||||||
|
},
|
||||||
|
insertPragma: {
|
||||||
|
since: "1.8.0",
|
||||||
|
category: CATEGORY_SPECIAL,
|
||||||
|
type: "boolean",
|
||||||
|
default: false,
|
||||||
|
description: "Insert @format pragma into file's first docblock comment."
|
||||||
|
},
|
||||||
|
parser: {
|
||||||
|
since: "0.0.10",
|
||||||
|
category: CATEGORY_GLOBAL,
|
||||||
|
type: "choice",
|
||||||
|
default: "babylon",
|
||||||
|
description: "Which parser to use.",
|
||||||
|
choices: [
|
||||||
|
{ value: "babylon", description: "JavaScript" },
|
||||||
|
{ value: "flow", description: "Flow" },
|
||||||
|
{ 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" },
|
||||||
|
{ value: "graphql", since: "1.5.0", description: "GraphQL" },
|
||||||
|
{ value: "markdown", since: "1.8.0", description: "Markdown" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
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.
|
||||||
|
`
|
||||||
|
},
|
||||||
|
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.
|
||||||
|
`
|
||||||
|
},
|
||||||
|
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.
|
||||||
|
`
|
||||||
|
},
|
||||||
|
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",
|
||||||
|
default: false,
|
||||||
|
deprecated: "0.0.10",
|
||||||
|
description: "Use flow parser.",
|
||||||
|
redirect: { option: "parser", value: "flow" }
|
||||||
|
},
|
||||||
|
useTabs: {
|
||||||
|
since: "1.0.0",
|
||||||
|
category: CATEGORY_GLOBAL,
|
||||||
|
type: "boolean",
|
||||||
|
default: false,
|
||||||
|
description: "Indent with tabs instead of spaces."
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
function getSupportInfo(version, opts) {
|
||||||
|
opts = opts || {};
|
||||||
|
|
||||||
if (!version) {
|
if (!version) {
|
||||||
version = currentVersion;
|
version = currentVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const plugins = loadPlugins();
|
||||||
|
|
||||||
|
const options = util
|
||||||
|
.arrayify(
|
||||||
|
Object.assign(
|
||||||
|
plugins
|
||||||
|
.reduce(
|
||||||
|
(currentPrinters, plugin) =>
|
||||||
|
currentPrinters.concat(
|
||||||
|
Object.keys(plugin.printers).map(
|
||||||
|
printerName => plugin.printers[printerName]
|
||||||
|
)
|
||||||
|
),
|
||||||
|
[]
|
||||||
|
)
|
||||||
|
.reduce(
|
||||||
|
(currentOptions, printer) =>
|
||||||
|
Object.assign(currentOptions, printer.options),
|
||||||
|
{}
|
||||||
|
),
|
||||||
|
supportOptions
|
||||||
|
),
|
||||||
|
"name"
|
||||||
|
)
|
||||||
|
.sort((a, b) => (a.name === b.name ? 0 : a.name < b.name ? -1 : 1))
|
||||||
|
.filter(filterSince)
|
||||||
|
.filter(filterDeprecated)
|
||||||
|
.map(mapDeprecated)
|
||||||
|
.map(option => {
|
||||||
|
const newOption = Object.assign({}, option);
|
||||||
|
|
||||||
|
if (Array.isArray(newOption.default)) {
|
||||||
|
newOption.default = newOption.default
|
||||||
|
.filter(filterSince)
|
||||||
|
.sort((info1, info2) =>
|
||||||
|
semver.compare(info2.since, info1.since)
|
||||||
|
)[0].value;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Array.isArray(newOption.choices)) {
|
||||||
|
newOption.choices = newOption.choices
|
||||||
|
.filter(filterSince)
|
||||||
|
.filter(filterDeprecated)
|
||||||
|
.map(mapDeprecated);
|
||||||
|
}
|
||||||
|
|
||||||
|
return newOption;
|
||||||
|
});
|
||||||
|
|
||||||
const usePostCssParser = semver.lt(version, "1.7.1");
|
const usePostCssParser = semver.lt(version, "1.7.1");
|
||||||
|
|
||||||
const languages = loadPlugins(options)
|
const languages = plugins
|
||||||
.reduce((all, plugin) => all.concat(plugin.languages), [])
|
.reduce((all, plugin) => all.concat(plugin.languages), [])
|
||||||
.filter(language => language.since && semver.gte(version, language.since))
|
.filter(language => language.since && semver.gte(version, language.since))
|
||||||
.map(language => {
|
.map(language => {
|
||||||
|
@ -35,7 +243,31 @@ function getSupportInfo(version, options) {
|
||||||
return language;
|
return language;
|
||||||
});
|
});
|
||||||
|
|
||||||
return { languages };
|
return { languages, options };
|
||||||
|
|
||||||
|
function filterSince(object) {
|
||||||
|
return (
|
||||||
|
opts.showUnreleased ||
|
||||||
|
!("since" in object) ||
|
||||||
|
(object.since && semver.gte(version, object.since))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
function filterDeprecated(object) {
|
||||||
|
return (
|
||||||
|
opts.showDeprecated ||
|
||||||
|
!("deprecated" in object) ||
|
||||||
|
(object.deprecated && semver.lt(version, object.deprecated))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
function mapDeprecated(object) {
|
||||||
|
if (!object.deprecated || opts.showDeprecated) {
|
||||||
|
return object;
|
||||||
|
}
|
||||||
|
const newObject = Object.assign({}, object);
|
||||||
|
delete newObject.deprecated;
|
||||||
|
delete newObject.redirect;
|
||||||
|
return newObject;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
|
@ -805,7 +805,16 @@ function hasNodeIgnoreComment(node) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function arrayify(object, keyName) {
|
||||||
|
return Object.keys(object).reduce(
|
||||||
|
(array, key) =>
|
||||||
|
array.concat(Object.assign({ [keyName]: key }, object[key])),
|
||||||
|
[]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
arrayify,
|
||||||
punctuationRegex,
|
punctuationRegex,
|
||||||
punctuationCharRange,
|
punctuationCharRange,
|
||||||
getStringWidth,
|
getStringWidth,
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
const jsOptions = require("../language-js/options");
|
||||||
|
|
||||||
|
// format based on https://github.com/prettier/prettier/blob/master/src/common/support.js
|
||||||
|
module.exports = {
|
||||||
|
singleQuote: jsOptions.singleQuote
|
||||||
|
};
|
|
@ -12,6 +12,7 @@ const softline = docBuilders.softline;
|
||||||
const group = docBuilders.group;
|
const group = docBuilders.group;
|
||||||
const fill = docBuilders.fill;
|
const fill = docBuilders.fill;
|
||||||
const indent = docBuilders.indent;
|
const indent = docBuilders.indent;
|
||||||
|
const printerOptions = require("./options");
|
||||||
|
|
||||||
const removeLines = doc.utils.removeLines;
|
const removeLines = doc.utils.removeLines;
|
||||||
|
|
||||||
|
@ -535,6 +536,7 @@ function maybeToLowerCase(value) {
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
options: printerOptions,
|
||||||
print: genericPrint,
|
print: genericPrint,
|
||||||
hasPrettierIgnore: util.hasIgnoreComment,
|
hasPrettierIgnore: util.hasIgnoreComment,
|
||||||
massageAstNode: clean
|
massageAstNode: clean
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
const jsOptions = require("../language-js/options");
|
||||||
|
|
||||||
|
// format based on https://github.com/prettier/prettier/blob/master/src/common/support.js
|
||||||
|
module.exports = {
|
||||||
|
bracketSpacing: jsOptions.bracketSpacing
|
||||||
|
};
|
|
@ -9,6 +9,7 @@ const softline = docBuilders.softline;
|
||||||
const group = docBuilders.group;
|
const group = docBuilders.group;
|
||||||
const indent = docBuilders.indent;
|
const indent = docBuilders.indent;
|
||||||
const ifBreak = docBuilders.ifBreak;
|
const ifBreak = docBuilders.ifBreak;
|
||||||
|
const printerOptions = require("./options");
|
||||||
|
|
||||||
const util = require("../common/util");
|
const util = require("../common/util");
|
||||||
|
|
||||||
|
@ -555,6 +556,7 @@ function printComment(commentPath) {
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
options: printerOptions,
|
||||||
print: genericPrint,
|
print: genericPrint,
|
||||||
hasPrettierIgnore: util.hasIgnoreComment,
|
hasPrettierIgnore: util.hasIgnoreComment,
|
||||||
printComment,
|
printComment,
|
||||||
|
|
|
@ -0,0 +1,80 @@
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
const CATEGORY_JAVASCRIPT = "JavaScript";
|
||||||
|
|
||||||
|
// format based on https://github.com/prettier/prettier/blob/master/src/common/support.js
|
||||||
|
module.exports = {
|
||||||
|
arrowParens: {
|
||||||
|
since: "1.9.0",
|
||||||
|
category: CATEGORY_JAVASCRIPT,
|
||||||
|
type: "choice",
|
||||||
|
default: "avoid",
|
||||||
|
description: "Include parentheses around a sole arrow function parameter.",
|
||||||
|
choices: [
|
||||||
|
{
|
||||||
|
value: "avoid",
|
||||||
|
description: "Omit parens when possible. Example: `x => x`"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: "always",
|
||||||
|
description: "Always include parens. Example: `(x) => x`"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
bracketSpacing: {
|
||||||
|
since: "0.0.0",
|
||||||
|
category: CATEGORY_JAVASCRIPT,
|
||||||
|
type: "boolean",
|
||||||
|
default: true,
|
||||||
|
description: "Print spaces between brackets.",
|
||||||
|
oppositeDescription: "Do not print spaces between brackets."
|
||||||
|
},
|
||||||
|
jsxBracketSameLine: {
|
||||||
|
since: "0.17.0",
|
||||||
|
category: CATEGORY_JAVASCRIPT,
|
||||||
|
type: "boolean",
|
||||||
|
default: false,
|
||||||
|
description: "Put > on the last line instead of at a new line."
|
||||||
|
},
|
||||||
|
semi: {
|
||||||
|
since: "1.0.0",
|
||||||
|
category: CATEGORY_JAVASCRIPT,
|
||||||
|
type: "boolean",
|
||||||
|
default: true,
|
||||||
|
description: "Print semicolons.",
|
||||||
|
oppositeDescription:
|
||||||
|
"Do not print semicolons, except at the beginning of lines which may need them."
|
||||||
|
},
|
||||||
|
singleQuote: {
|
||||||
|
since: "0.0.0",
|
||||||
|
category: CATEGORY_JAVASCRIPT,
|
||||||
|
type: "boolean",
|
||||||
|
default: false,
|
||||||
|
description: "Use single quotes instead of double quotes."
|
||||||
|
},
|
||||||
|
trailingComma: {
|
||||||
|
since: "0.0.0",
|
||||||
|
category: CATEGORY_JAVASCRIPT,
|
||||||
|
type: "choice",
|
||||||
|
default: [
|
||||||
|
{ since: "0.0.0", value: false },
|
||||||
|
{ since: "0.19.0", value: "none" }
|
||||||
|
],
|
||||||
|
description: "Print trailing commas wherever possible when multi-line.",
|
||||||
|
choices: [
|
||||||
|
{ value: "none", description: "No trailing commas." },
|
||||||
|
{
|
||||||
|
value: "es5",
|
||||||
|
description:
|
||||||
|
"Trailing commas where valid in ES5 (objects, arrays, etc.)"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: "all",
|
||||||
|
description:
|
||||||
|
"Trailing commas wherever possible (including function arguments)."
|
||||||
|
},
|
||||||
|
{ value: true, deprecated: "0.19.0", redirect: "es5" },
|
||||||
|
{ value: false, deprecated: "0.19.0", redirect: "none" }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
};
|
|
@ -6,6 +6,7 @@ const comments = require("../main/comments");
|
||||||
const util = require("../common/util");
|
const util = require("../common/util");
|
||||||
const isIdentifierName = require("esutils").keyword.isIdentifierNameES6;
|
const isIdentifierName = require("esutils").keyword.isIdentifierNameES6;
|
||||||
const embed = require("./embed");
|
const embed = require("./embed");
|
||||||
|
const printerOptions = require("./options");
|
||||||
const clean = require("./clean");
|
const clean = require("./clean");
|
||||||
|
|
||||||
const doc = require("../doc");
|
const doc = require("../doc");
|
||||||
|
@ -5236,6 +5237,7 @@ function printJsDocComment(comment) {
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
options: printerOptions,
|
||||||
print: genericPrint,
|
print: genericPrint,
|
||||||
embed,
|
embed,
|
||||||
massageAstNode: clean,
|
massageAstNode: clean,
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
const jsOptions = require("../language-js/options");
|
||||||
|
|
||||||
|
const CATEGORY_MARKDOWN = "Markdown";
|
||||||
|
|
||||||
|
// format based on https://github.com/prettier/prettier/blob/master/src/common/support.js
|
||||||
|
module.exports = {
|
||||||
|
proseWrap: {
|
||||||
|
since: "1.8.2",
|
||||||
|
category: CATEGORY_MARKDOWN,
|
||||||
|
type: "choice",
|
||||||
|
default: [
|
||||||
|
{ since: "1.8.2", value: true },
|
||||||
|
{ since: "1.9.0", value: "preserve" }
|
||||||
|
],
|
||||||
|
description: "How to wrap prose. (markdown)",
|
||||||
|
choices: [
|
||||||
|
{
|
||||||
|
since: "1.9.0",
|
||||||
|
value: "always",
|
||||||
|
description: "Wrap prose if it exceeds the print width."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
since: "1.9.0",
|
||||||
|
value: "never",
|
||||||
|
description: "Do not wrap prose."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
since: "1.9.0",
|
||||||
|
value: "preserve",
|
||||||
|
description: "Wrap prose as-is."
|
||||||
|
},
|
||||||
|
{ value: false, deprecated: "1.9.0", redirect: "never" },
|
||||||
|
{ value: true, deprecated: "1.9.0", redirect: "always" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
singleQuote: jsOptions.singleQuote
|
||||||
|
};
|
|
@ -12,6 +12,7 @@ const softline = docBuilders.softline;
|
||||||
const fill = docBuilders.fill;
|
const fill = docBuilders.fill;
|
||||||
const align = docBuilders.align;
|
const align = docBuilders.align;
|
||||||
const printDocToString = doc.printer.printDocToString;
|
const printDocToString = doc.printer.printDocToString;
|
||||||
|
const printerOptions = require("./options");
|
||||||
|
|
||||||
const SINGLE_LINE_NODE_TYPES = [
|
const SINGLE_LINE_NODE_TYPES = [
|
||||||
"heading",
|
"heading",
|
||||||
|
@ -670,6 +671,7 @@ function clean(ast, newObj) {
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
options: printerOptions,
|
||||||
print: genericPrint,
|
print: genericPrint,
|
||||||
embed,
|
embed,
|
||||||
massageAstNode: clean,
|
massageAstNode: clean,
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -2,29 +2,66 @@
|
||||||
|
|
||||||
const prettier = require("../../tests_config/require_prettier");
|
const prettier = require("../../tests_config/require_prettier");
|
||||||
const runPrettier = require("../runPrettier");
|
const runPrettier = require("../runPrettier");
|
||||||
|
const snapshotDiff = require("snapshot-diff");
|
||||||
|
|
||||||
describe("API getSupportInfo()", () => {
|
describe("API getSupportInfo()", () => {
|
||||||
test("no arguments", () => {
|
const testVersions = [
|
||||||
expect(prettier.getSupportInfo()).toMatchSnapshot();
|
"0.0.0",
|
||||||
});
|
"1.0.0",
|
||||||
|
"1.4.0",
|
||||||
|
"1.5.0",
|
||||||
|
"1.7.1",
|
||||||
|
"1.8.0",
|
||||||
|
"1.8.2",
|
||||||
|
undefined
|
||||||
|
];
|
||||||
|
|
||||||
const testVersions = ["0.0.0", "1.0.0", "1.4.0", "1.5.0", "1.7.1", "1.8.0"];
|
testVersions.forEach((version, index) => {
|
||||||
|
const info = getCoreInfo(version);
|
||||||
testVersions.forEach(version => {
|
if (index === 0) {
|
||||||
test(`with version ${version}`, () => {
|
test(`with version ${version}`, () => {
|
||||||
expect(
|
expect(info).toMatchSnapshot();
|
||||||
prettier
|
});
|
||||||
.getSupportInfo(version)
|
} else {
|
||||||
.languages.reduce(
|
const previousVersion = testVersions[index - 1];
|
||||||
(obj, language) =>
|
const previousInfo = getCoreInfo(previousVersion);
|
||||||
Object.assign({ [language.name]: language.parsers }, obj),
|
test(`with version ${previousVersion} -> ${version}`, () => {
|
||||||
{}
|
expect(snapshotDiff(previousInfo, info)).toMatchSnapshot();
|
||||||
)
|
});
|
||||||
).toMatchSnapshot();
|
}
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("CLI --support-info", () => {
|
describe("CLI --support-info", () => {
|
||||||
runPrettier("cli", "--support-info").test({ status: 0 });
|
runPrettier("cli", "--support-info").test({ status: 0 });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function getCoreInfo(version) {
|
||||||
|
const supportInfo = prettier.getSupportInfo(version);
|
||||||
|
const languages = supportInfo.languages.reduce(
|
||||||
|
(obj, language) =>
|
||||||
|
Object.assign({ [language.name]: language.parsers }, obj),
|
||||||
|
{}
|
||||||
|
);
|
||||||
|
const options = supportInfo.options.reduce(
|
||||||
|
(obj, option) =>
|
||||||
|
Object.assign(
|
||||||
|
{
|
||||||
|
[option.name]: Object.assign(
|
||||||
|
{
|
||||||
|
type: option.type,
|
||||||
|
default: option.default
|
||||||
|
},
|
||||||
|
option.type === "int"
|
||||||
|
? { range: option.range }
|
||||||
|
: option.type === "choice"
|
||||||
|
? { choices: option.choices.map(choice => choice.value) }
|
||||||
|
: null
|
||||||
|
)
|
||||||
|
},
|
||||||
|
obj
|
||||||
|
),
|
||||||
|
{}
|
||||||
|
);
|
||||||
|
return { languages, options };
|
||||||
|
}
|
||||||
|
|
73
yarn.lock
73
yarn.lock
|
@ -112,7 +112,7 @@ ansi-escapes@^3.0.0:
|
||||||
version "3.0.0"
|
version "3.0.0"
|
||||||
resolved "https://registry.yarnpkg.com/ansi-escapes/-/ansi-escapes-3.0.0.tgz#ec3e8b4e9f8064fc02c3ac9b65f1c275bda8ef92"
|
resolved "https://registry.yarnpkg.com/ansi-escapes/-/ansi-escapes-3.0.0.tgz#ec3e8b4e9f8064fc02c3ac9b65f1c275bda8ef92"
|
||||||
|
|
||||||
ansi-regex@^2.0.0:
|
ansi-regex@^2.0.0, ansi-regex@^2.1.1:
|
||||||
version "2.1.1"
|
version "2.1.1"
|
||||||
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-2.1.1.tgz#c3b33ab5ee360d86e0e628f0468ae7ef27d654df"
|
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-2.1.1.tgz#c3b33ab5ee360d86e0e628f0468ae7ef27d654df"
|
||||||
|
|
||||||
|
@ -124,18 +124,18 @@ ansi-styles@^2.2.1:
|
||||||
version "2.2.1"
|
version "2.2.1"
|
||||||
resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-2.2.1.tgz#b432dd3358b634cf75e1e4664368240533c1ddbe"
|
resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-2.2.1.tgz#b432dd3358b634cf75e1e4664368240533c1ddbe"
|
||||||
|
|
||||||
|
ansi-styles@^3.0.0, ansi-styles@^3.2.0:
|
||||||
|
version "3.2.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-3.2.0.tgz#c159b8d5be0f9e5a6f346dab94f16ce022161b88"
|
||||||
|
dependencies:
|
||||||
|
color-convert "^1.9.0"
|
||||||
|
|
||||||
ansi-styles@^3.1.0:
|
ansi-styles@^3.1.0:
|
||||||
version "3.1.0"
|
version "3.1.0"
|
||||||
resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-3.1.0.tgz#09c202d5c917ec23188caa5c9cb9179cd9547750"
|
resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-3.1.0.tgz#09c202d5c917ec23188caa5c9cb9179cd9547750"
|
||||||
dependencies:
|
dependencies:
|
||||||
color-convert "^1.0.0"
|
color-convert "^1.0.0"
|
||||||
|
|
||||||
ansi-styles@^3.2.0:
|
|
||||||
version "3.2.0"
|
|
||||||
resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-3.2.0.tgz#c159b8d5be0f9e5a6f346dab94f16ce022161b88"
|
|
||||||
dependencies:
|
|
||||||
color-convert "^1.9.0"
|
|
||||||
|
|
||||||
anymatch@^1.3.0:
|
anymatch@^1.3.0:
|
||||||
version "1.3.0"
|
version "1.3.0"
|
||||||
resolved "https://registry.yarnpkg.com/anymatch/-/anymatch-1.3.0.tgz#a3e52fa39168c825ff57b0248126ce5a8ff95507"
|
resolved "https://registry.yarnpkg.com/anymatch/-/anymatch-1.3.0.tgz#a3e52fa39168c825ff57b0248126ce5a8ff95507"
|
||||||
|
@ -1337,6 +1337,10 @@ decamelize@^1.0.0, decamelize@^1.1.1, decamelize@^1.1.2:
|
||||||
version "1.2.0"
|
version "1.2.0"
|
||||||
resolved "https://registry.yarnpkg.com/decamelize/-/decamelize-1.2.0.tgz#f6534d15148269b20352e7bee26f501f9a191290"
|
resolved "https://registry.yarnpkg.com/decamelize/-/decamelize-1.2.0.tgz#f6534d15148269b20352e7bee26f501f9a191290"
|
||||||
|
|
||||||
|
dedent@0.7.0:
|
||||||
|
version "0.7.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/dedent/-/dedent-0.7.0.tgz#2495ddbaf6eb874abb0e1be9df22d2e5a544326c"
|
||||||
|
|
||||||
deep-extend@~0.4.0:
|
deep-extend@~0.4.0:
|
||||||
version "0.4.2"
|
version "0.4.2"
|
||||||
resolved "https://registry.yarnpkg.com/deep-extend/-/deep-extend-0.4.2.tgz#48b699c27e334bf89f10892be432f6e4c7d34a7f"
|
resolved "https://registry.yarnpkg.com/deep-extend/-/deep-extend-0.4.2.tgz#48b699c27e334bf89f10892be432f6e4c7d34a7f"
|
||||||
|
@ -2538,6 +2542,15 @@ jest-config@^21.2.1:
|
||||||
jest-validate "^21.2.1"
|
jest-validate "^21.2.1"
|
||||||
pretty-format "^21.2.1"
|
pretty-format "^21.2.1"
|
||||||
|
|
||||||
|
jest-diff@21.3.0-beta.15, jest-diff@test:
|
||||||
|
version "21.3.0-beta.15"
|
||||||
|
resolved "https://registry.yarnpkg.com/jest-diff/-/jest-diff-21.3.0-beta.15.tgz#13efca4723fc2f452f8143fe0df5515c5128c672"
|
||||||
|
dependencies:
|
||||||
|
chalk "^2.0.1"
|
||||||
|
diff "^3.2.0"
|
||||||
|
jest-get-type "21.3.0-beta.15"
|
||||||
|
pretty-format "21.3.0-beta.15"
|
||||||
|
|
||||||
jest-diff@^21.2.1:
|
jest-diff@^21.2.1:
|
||||||
version "21.2.1"
|
version "21.2.1"
|
||||||
resolved "https://registry.yarnpkg.com/jest-diff/-/jest-diff-21.2.1.tgz#46cccb6cab2d02ce98bc314011764bb95b065b4f"
|
resolved "https://registry.yarnpkg.com/jest-diff/-/jest-diff-21.2.1.tgz#46cccb6cab2d02ce98bc314011764bb95b065b4f"
|
||||||
|
@ -2572,6 +2585,10 @@ jest-environment-node@^21.2.1:
|
||||||
jest-mock "^21.2.0"
|
jest-mock "^21.2.0"
|
||||||
jest-util "^21.2.1"
|
jest-util "^21.2.1"
|
||||||
|
|
||||||
|
jest-get-type@21.3.0-beta.15:
|
||||||
|
version "21.3.0-beta.15"
|
||||||
|
resolved "https://registry.yarnpkg.com/jest-get-type/-/jest-get-type-21.3.0-beta.15.tgz#d5a510c32683124576eaba69b66a1ba3c25ed67c"
|
||||||
|
|
||||||
jest-get-type@^21.0.2:
|
jest-get-type@^21.0.2:
|
||||||
version "21.0.2"
|
version "21.0.2"
|
||||||
resolved "https://registry.yarnpkg.com/jest-get-type/-/jest-get-type-21.0.2.tgz#304e6b816dd33cd1f47aba0597bcad258a509fc6"
|
resolved "https://registry.yarnpkg.com/jest-get-type/-/jest-get-type-21.0.2.tgz#304e6b816dd33cd1f47aba0597bcad258a509fc6"
|
||||||
|
@ -2604,6 +2621,14 @@ jest-jasmine2@^21.2.1:
|
||||||
jest-snapshot "^21.2.1"
|
jest-snapshot "^21.2.1"
|
||||||
p-cancelable "^0.3.0"
|
p-cancelable "^0.3.0"
|
||||||
|
|
||||||
|
jest-matcher-utils@21.3.0-beta.15:
|
||||||
|
version "21.3.0-beta.15"
|
||||||
|
resolved "https://registry.yarnpkg.com/jest-matcher-utils/-/jest-matcher-utils-21.3.0-beta.15.tgz#b033ee41f9d60c5bf338928b36e8e612fe19d54f"
|
||||||
|
dependencies:
|
||||||
|
chalk "^2.0.1"
|
||||||
|
jest-get-type "21.3.0-beta.15"
|
||||||
|
pretty-format "21.3.0-beta.15"
|
||||||
|
|
||||||
jest-matcher-utils@^21.2.1:
|
jest-matcher-utils@^21.2.1:
|
||||||
version "21.2.1"
|
version "21.2.1"
|
||||||
resolved "https://registry.yarnpkg.com/jest-matcher-utils/-/jest-matcher-utils-21.2.1.tgz#72c826eaba41a093ac2b4565f865eb8475de0f64"
|
resolved "https://registry.yarnpkg.com/jest-matcher-utils/-/jest-matcher-utils-21.2.1.tgz#72c826eaba41a093ac2b4565f865eb8475de0f64"
|
||||||
|
@ -2690,6 +2715,17 @@ jest-snapshot@^21.2.1:
|
||||||
natural-compare "^1.4.0"
|
natural-compare "^1.4.0"
|
||||||
pretty-format "^21.2.1"
|
pretty-format "^21.2.1"
|
||||||
|
|
||||||
|
jest-snapshot@test:
|
||||||
|
version "21.3.0-beta.15"
|
||||||
|
resolved "https://registry.yarnpkg.com/jest-snapshot/-/jest-snapshot-21.3.0-beta.15.tgz#7f07a6efaee9d62d1befa60e39fa03f775e30707"
|
||||||
|
dependencies:
|
||||||
|
chalk "^2.0.1"
|
||||||
|
jest-diff "21.3.0-beta.15"
|
||||||
|
jest-matcher-utils "21.3.0-beta.15"
|
||||||
|
mkdirp "^0.5.1"
|
||||||
|
natural-compare "^1.4.0"
|
||||||
|
pretty-format "21.3.0-beta.15"
|
||||||
|
|
||||||
jest-util@^21.2.1:
|
jest-util@^21.2.1:
|
||||||
version "21.2.1"
|
version "21.2.1"
|
||||||
resolved "https://registry.yarnpkg.com/jest-util/-/jest-util-21.2.1.tgz#a274b2f726b0897494d694a6c3d6a61ab819bb78"
|
resolved "https://registry.yarnpkg.com/jest-util/-/jest-util-21.2.1.tgz#a274b2f726b0897494d694a6c3d6a61ab819bb78"
|
||||||
|
@ -3521,6 +3557,20 @@ prettier@1.9.2:
|
||||||
version "1.9.2"
|
version "1.9.2"
|
||||||
resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.9.2.tgz#96bc2132f7a32338e6078aeb29727178c6335827"
|
resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.9.2.tgz#96bc2132f7a32338e6078aeb29727178c6335827"
|
||||||
|
|
||||||
|
pretty-format@21.3.0-beta.15:
|
||||||
|
version "21.3.0-beta.15"
|
||||||
|
resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-21.3.0-beta.15.tgz#702708a64be53619b2c10138dc5a594056fd1569"
|
||||||
|
dependencies:
|
||||||
|
ansi-regex "^3.0.0"
|
||||||
|
ansi-styles "^3.2.0"
|
||||||
|
|
||||||
|
pretty-format@^20.0.3:
|
||||||
|
version "20.0.3"
|
||||||
|
resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-20.0.3.tgz#020e350a560a1fe1a98dc3beb6ccffb386de8b14"
|
||||||
|
dependencies:
|
||||||
|
ansi-regex "^2.1.1"
|
||||||
|
ansi-styles "^3.0.0"
|
||||||
|
|
||||||
pretty-format@^21.1.0:
|
pretty-format@^21.1.0:
|
||||||
version "21.1.0"
|
version "21.1.0"
|
||||||
resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-21.1.0.tgz#557428254323832ee8b7c971cb613442bea67f61"
|
resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-21.1.0.tgz#557428254323832ee8b7c971cb613442bea67f61"
|
||||||
|
@ -4091,6 +4141,15 @@ slice-ansi@0.0.4:
|
||||||
version "0.0.4"
|
version "0.0.4"
|
||||||
resolved "https://registry.yarnpkg.com/slice-ansi/-/slice-ansi-0.0.4.tgz#edbf8903f66f7ce2f8eafd6ceed65e264c831b35"
|
resolved "https://registry.yarnpkg.com/slice-ansi/-/slice-ansi-0.0.4.tgz#edbf8903f66f7ce2f8eafd6ceed65e264c831b35"
|
||||||
|
|
||||||
|
snapshot-diff@0.2.2:
|
||||||
|
version "0.2.2"
|
||||||
|
resolved "https://registry.yarnpkg.com/snapshot-diff/-/snapshot-diff-0.2.2.tgz#26f836f5da8baad46e2986cec75799758eb83210"
|
||||||
|
dependencies:
|
||||||
|
jest-diff test
|
||||||
|
jest-snapshot test
|
||||||
|
pretty-format "^20.0.3"
|
||||||
|
strip-ansi "^4.0.0"
|
||||||
|
|
||||||
sntp@1.x.x:
|
sntp@1.x.x:
|
||||||
version "1.0.9"
|
version "1.0.9"
|
||||||
resolved "https://registry.yarnpkg.com/sntp/-/sntp-1.0.9.tgz#6541184cc90aeea6c6e7b35e2659082443c66198"
|
resolved "https://registry.yarnpkg.com/sntp/-/sntp-1.0.9.tgz#6541184cc90aeea6c6e7b35e2659082443c66198"
|
||||||
|
|
Loading…
Reference in New Issue