refactor: rename formatOption with forwardToApi
This commit is contained in:
1 parent
eaafbb77aa
commit
0f9bb5b971
2 files changed
+19
-19
No files matched your search
+17
-17
@@ -4,7 +4,7 @@ const detailOptions = normalizeDetailOptions({
|
|||||||
"bracket-spacing": {
|
"bracket-spacing": {
|
||||||
type: "boolean",
|
type: "boolean",
|
||||||
category: "format",
|
category: "format",
|
||||||
formatOption: true,
|
forwardToApi: true,
|
||||||
hidden: true
|
hidden: true
|
||||||
},
|
},
|
||||||
color: {
|
color: {
|
||||||
@@ -39,7 +39,7 @@ const detailOptions = normalizeDetailOptions({
|
|||||||
"cursor-offset": {
|
"cursor-offset": {
|
||||||
type: "int",
|
type: "int",
|
||||||
exception: -1,
|
exception: -1,
|
||||||
formatOption: 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
|
||||||
@@ -83,7 +83,7 @@ const detailOptions = normalizeDetailOptions({
|
|||||||
"jsx-bracket-same-line": {
|
"jsx-bracket-same-line": {
|
||||||
type: "boolean",
|
type: "boolean",
|
||||||
category: "format",
|
category: "format",
|
||||||
formatOption: true,
|
forwardToApi: true,
|
||||||
description: "Put > on the last line instead of at a new line."
|
description: "Put > on the last line instead of at a new line."
|
||||||
},
|
},
|
||||||
"list-different": {
|
"list-different": {
|
||||||
@@ -115,7 +115,7 @@ const detailOptions = normalizeDetailOptions({
|
|||||||
parser: {
|
parser: {
|
||||||
type: "choice",
|
type: "choice",
|
||||||
category: "format",
|
category: "format",
|
||||||
formatOption: true,
|
forwardToApi: true,
|
||||||
exception: value => typeof value === "string", // allow path to a parser module
|
exception: value => typeof value === "string", // allow path to a parser module
|
||||||
choices: ["flow", "babylon", "typescript", "postcss", "json", "graphql"],
|
choices: ["flow", "babylon", "typescript", "postcss", "json", "graphql"],
|
||||||
description: "Specify which parse to use. Defaults to babylon.",
|
description: "Specify which parse to use. Defaults to babylon.",
|
||||||
@@ -124,14 +124,14 @@ const detailOptions = normalizeDetailOptions({
|
|||||||
"print-width": {
|
"print-width": {
|
||||||
type: "int",
|
type: "int",
|
||||||
category: "format",
|
category: "format",
|
||||||
formatOption: true,
|
forwardToApi: true,
|
||||||
description:
|
description:
|
||||||
"Specify the length of line that the printer will wrap on. Defaults to 80."
|
"Specify the length of line that the printer will wrap on. Defaults to 80."
|
||||||
},
|
},
|
||||||
"range-end": {
|
"range-end": {
|
||||||
type: "int",
|
type: "int",
|
||||||
category: "format",
|
category: "format",
|
||||||
formatOption: 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).
|
||||||
@@ -143,7 +143,7 @@ const detailOptions = normalizeDetailOptions({
|
|||||||
"range-start": {
|
"range-start": {
|
||||||
type: "int",
|
type: "int",
|
||||||
category: "format",
|
category: "format",
|
||||||
formatOption: 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.
|
||||||
@@ -154,13 +154,13 @@ const detailOptions = normalizeDetailOptions({
|
|||||||
semi: {
|
semi: {
|
||||||
type: "boolean",
|
type: "boolean",
|
||||||
category: "format",
|
category: "format",
|
||||||
formatOption: true,
|
forwardToApi: true,
|
||||||
hidden: true
|
hidden: true
|
||||||
},
|
},
|
||||||
"single-quote": {
|
"single-quote": {
|
||||||
type: "boolean",
|
type: "boolean",
|
||||||
category: "format",
|
category: "format",
|
||||||
formatOption: true,
|
forwardToApi: true,
|
||||||
description: "Use single quotes instead of double quotes."
|
description: "Use single quotes instead of double quotes."
|
||||||
},
|
},
|
||||||
stdin: {
|
stdin: {
|
||||||
@@ -169,20 +169,20 @@ const detailOptions = normalizeDetailOptions({
|
|||||||
},
|
},
|
||||||
"stdin-filepath": {
|
"stdin-filepath": {
|
||||||
type: "path",
|
type: "path",
|
||||||
formatOption: "filepath",
|
forwardToApi: "filepath",
|
||||||
description: "Path to the file used to read from stdin."
|
description: "Path to the file used to read from stdin."
|
||||||
},
|
},
|
||||||
"tab-width": {
|
"tab-width": {
|
||||||
type: "int",
|
type: "int",
|
||||||
category: "format",
|
category: "format",
|
||||||
formatOption: true,
|
forwardToApi: true,
|
||||||
description:
|
description:
|
||||||
"Specify the number of spaces per indentation-level. Defaults to 2."
|
"Specify the number of spaces per indentation-level. Defaults to 2."
|
||||||
},
|
},
|
||||||
"trailing-comma": {
|
"trailing-comma": {
|
||||||
type: "choice",
|
type: "choice",
|
||||||
category: "format",
|
category: "format",
|
||||||
formatOption: true,
|
forwardToApi: true,
|
||||||
choices: [
|
choices: [
|
||||||
"none",
|
"none",
|
||||||
"es5",
|
"es5",
|
||||||
@@ -195,7 +195,7 @@ const detailOptions = normalizeDetailOptions({
|
|||||||
"use-tabs": {
|
"use-tabs": {
|
||||||
type: "boolean",
|
type: "boolean",
|
||||||
category: "format",
|
category: "format",
|
||||||
formatOption: true,
|
forwardToApi: true,
|
||||||
description: "Indent lines with tabs instead of spaces."
|
description: "Indent lines with tabs instead of spaces."
|
||||||
},
|
},
|
||||||
version: {
|
version: {
|
||||||
@@ -263,10 +263,10 @@ function normalizeDetailOptions(rawDetailOptions) {
|
|||||||
const option = rawDetailOptions[name];
|
const option = rawDetailOptions[name];
|
||||||
return Object.assign({}, option, {
|
return Object.assign({}, option, {
|
||||||
name,
|
name,
|
||||||
formatOption:
|
forwardToApi:
|
||||||
option.formatOption &&
|
option.forwardToApi &&
|
||||||
(typeof option.formatOption === "string"
|
(typeof option.forwardToApi === "string"
|
||||||
? option.formatOption
|
? option.forwardToApi
|
||||||
: kebabToCamel(name)),
|
: kebabToCamel(name)),
|
||||||
choices:
|
choices:
|
||||||
option.choices &&
|
option.choices &&
|
||||||
|
|||||||
+2
-2
@@ -19,10 +19,10 @@ const apiDefaultOptions = require("./options").defaults;
|
|||||||
|
|
||||||
function getOptions(argv) {
|
function getOptions(argv) {
|
||||||
return constant.detailOptions
|
return constant.detailOptions
|
||||||
.filter(option => option.formatOption)
|
.filter(option => option.forwardToApi)
|
||||||
.reduce(
|
.reduce(
|
||||||
(current, option) =>
|
(current, option) =>
|
||||||
Object.assign(current, { [option.formatOption]: argv[option.name] }),
|
Object.assign(current, { [option.forwardToApi]: argv[option.name] }),
|
||||||
{}
|
{}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user