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

feat(support-info): add options field #3433

Merged
merged 17 commits into from Dec 31, 2017
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions package.json
Expand Up @@ -21,6 +21,7 @@
"cjk-regex": "1.0.2",
"cosmiconfig": "3.1.0",
"dashify": "0.2.2",
"dedent": "0.7.0",
"diff": "3.2.0",
"editorconfig": "0.14.2",
"editorconfig-to-prettier": "0.0.5",
Expand Down Expand Up @@ -77,6 +78,7 @@
"rollup-plugin-node-resolve": "2.0.0",
"rollup-plugin-replace": "1.2.1",
"shelljs": "0.7.8",
"snapshot-diff": "0.2.2",
"strip-ansi": "4.0.0",
"sw-toolbox": "3.6.0",
"uglify-es": "3.0.28",
Expand Down
44 changes: 20 additions & 24 deletions src/cli-constant.js
@@ -1,6 +1,7 @@
"use strict";

const camelCase = require("camelcase");
const dedent = require("dedent");

const CATEGORY_CONFIG = "Config";
const CATEGORY_EDITOR = "Editor";
Expand Down Expand Up @@ -132,10 +133,10 @@ const detailedOptions = normalizeDetailedOptions({
},
{
value: "prefer-file",
description: dedent(`
description: dedent`
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.
`)
`
}
],
description:
Expand All @@ -146,10 +147,10 @@ const detailedOptions = normalizeDetailedOptions({
category: CATEGORY_EDITOR,
exception: -1,
forwardToApi: true,
description: dedent(`
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.
`)
`
},
"debug-check": {
type: "boolean"
Expand Down Expand Up @@ -180,10 +181,10 @@ const detailedOptions = normalizeDetailedOptions({
help: {
type: "flag",
alias: "h",
description: dedent(`
description: dedent`
Show CLI usage, or details about the given flag.
Example: --help write
`)
`
},
"ignore-path": {
type: "path",
Expand All @@ -194,9 +195,9 @@ const detailedOptions = normalizeDetailedOptions({
"insert-pragma": {
type: "boolean",
forwardToApi: true,
description: dedent(`
description: dedent`
Insert @format pragma into file's first docblock comment.
`)
`
},
"jsx-bracket-same-line": {
type: "boolean",
Expand Down Expand Up @@ -263,29 +264,29 @@ const detailedOptions = normalizeDetailedOptions({
category: CATEGORY_EDITOR,
forwardToApi: true,
exception: Infinity,
description: dedent(`
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.
`)
`
},
"range-start": {
type: "int",
category: CATEGORY_EDITOR,
forwardToApi: true,
description: dedent(`
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.
`)
`
},
"require-pragma": {
type: "boolean",
forwardToApi: true,
description: dedent(`
description: dedent`
Require either '@prettier' or '@format' to be present in the file's first docblock comment
in order for it to be formatted.
`)
`
},
semi: {
type: "boolean",
Expand Down Expand Up @@ -386,17 +387,12 @@ const minimistOptions = {
)
};

const usageSummary = `
Usage: prettier [options] [file/glob ...]
const usageSummary = dedent`
Usage: prettier [options] [file/glob ...]

By default, output is written to stdout.
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();
}
By default, output is written to stdout.
Stdin is read if it is piped to Prettier and no files are given.
`;

function normalizeDetailedOptions(rawDetailedOptions) {
const names = Object.keys(rawDetailedOptions).sort();
Expand Down
4 changes: 2 additions & 2 deletions src/options.js
Expand Up @@ -4,7 +4,7 @@ const path = require("path");

const validate = require("jest-validate").validate;
const deprecatedConfig = require("./deprecated");
const supportTable = require("./support").supportTable;
const supportLanguages = require("./support").supportLanguages;

const defaults = {
cursorOffset: -1,
Expand Down Expand Up @@ -43,7 +43,7 @@ function normalize(options) {
const extension = path.extname(filepath);
const filename = path.basename(filepath).toLowerCase();

const language = supportTable.find(
const language = supportLanguages.find(
language =>
typeof language.since === "string" &&
(language.extensions.indexOf(extension) > -1 ||
Expand Down