Make ESLint catch category typos
parent
f53eab9b8d
commit
c2847d90cd
|
@ -1,5 +1,10 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
const CATEGORY_COMMAND = "Command";
|
||||||
|
const CATEGORY_CONFIG = "Config";
|
||||||
|
const CATEGORY_FORMAT = "Format";
|
||||||
|
const CATEGORY_OTHER = "Other";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {
|
* {
|
||||||
* [name]: {
|
* [name]: {
|
||||||
|
@ -45,7 +50,7 @@
|
||||||
const detailOptions = normalizeDetailOptions({
|
const detailOptions = normalizeDetailOptions({
|
||||||
"bracket-spacing": {
|
"bracket-spacing": {
|
||||||
type: "boolean",
|
type: "boolean",
|
||||||
category: "format",
|
category: CATEGORY_FORMAT,
|
||||||
forwardToApi: true,
|
forwardToApi: true,
|
||||||
oppositeDescription: "Do not print spaces between brackets."
|
oppositeDescription: "Do not print spaces between brackets."
|
||||||
},
|
},
|
||||||
|
@ -60,14 +65,14 @@ const detailOptions = normalizeDetailOptions({
|
||||||
},
|
},
|
||||||
config: {
|
config: {
|
||||||
type: "path",
|
type: "path",
|
||||||
category: "config",
|
category: CATEGORY_CONFIG,
|
||||||
description:
|
description:
|
||||||
"Path to a prettier configuration file (.prettierrc, package.json, prettier.config.js).",
|
"Path to a prettier configuration file (.prettierrc, package.json, prettier.config.js).",
|
||||||
oppositeDescription: "Do not look for a configuration file."
|
oppositeDescription: "Do not look for a configuration file."
|
||||||
},
|
},
|
||||||
"config-precedence": {
|
"config-precedence": {
|
||||||
type: "choice",
|
type: "choice",
|
||||||
category: "config",
|
category: CATEGORY_CONFIG,
|
||||||
default: "cli-override",
|
default: "cli-override",
|
||||||
choices: ["cli-override", "file-override", "prefer-file"],
|
choices: ["cli-override", "file-override", "prefer-file"],
|
||||||
description: dedent(`
|
description: dedent(`
|
||||||
|
@ -96,25 +101,25 @@ const detailOptions = normalizeDetailOptions({
|
||||||
},
|
},
|
||||||
"find-config-path": {
|
"find-config-path": {
|
||||||
type: "path",
|
type: "path",
|
||||||
category: "command",
|
category: CATEGORY_COMMAND,
|
||||||
description:
|
description:
|
||||||
"Finds and prints the path to a configuration file for a given input file."
|
"Finds and prints the path to a configuration file for a given input file."
|
||||||
},
|
},
|
||||||
"flow-parser": {
|
"flow-parser": {
|
||||||
// Deprecated in 0.0.10
|
// Deprecated in 0.0.10
|
||||||
type: "boolean",
|
type: "boolean",
|
||||||
category: "format",
|
category: CATEGORY_FORMAT,
|
||||||
deprecated: "Use `--parser flow` instead."
|
deprecated: "Use `--parser flow` instead."
|
||||||
},
|
},
|
||||||
help: {
|
help: {
|
||||||
type: "boolean",
|
type: "boolean",
|
||||||
category: "command",
|
category: CATEGORY_COMMAND,
|
||||||
alias: "h",
|
alias: "h",
|
||||||
description: "Show help."
|
description: "Show help."
|
||||||
},
|
},
|
||||||
"ignore-path": {
|
"ignore-path": {
|
||||||
type: "path",
|
type: "path",
|
||||||
category: "config",
|
category: CATEGORY_CONFIG,
|
||||||
default: ".prettierignore",
|
default: ".prettierignore",
|
||||||
description: dedent(`
|
description: dedent(`
|
||||||
Path to a file containing patterns that describe files to ignore.
|
Path to a file containing patterns that describe files to ignore.
|
||||||
|
@ -123,20 +128,20 @@ const detailOptions = normalizeDetailOptions({
|
||||||
},
|
},
|
||||||
"jsx-bracket-same-line": {
|
"jsx-bracket-same-line": {
|
||||||
type: "boolean",
|
type: "boolean",
|
||||||
category: "format",
|
category: CATEGORY_FORMAT,
|
||||||
forwardToApi: 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": {
|
||||||
type: "boolean",
|
type: "boolean",
|
||||||
category: "command",
|
category: CATEGORY_COMMAND,
|
||||||
alias: "l",
|
alias: "l",
|
||||||
description:
|
description:
|
||||||
"Print filenames of files that are different from Prettier formatting."
|
"Print filenames of files that are different from Prettier formatting."
|
||||||
},
|
},
|
||||||
parser: {
|
parser: {
|
||||||
type: "choice",
|
type: "choice",
|
||||||
category: "format",
|
category: CATEGORY_FORMAT,
|
||||||
forwardToApi: 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"],
|
||||||
|
@ -145,14 +150,14 @@ const detailOptions = normalizeDetailOptions({
|
||||||
},
|
},
|
||||||
"print-width": {
|
"print-width": {
|
||||||
type: "int",
|
type: "int",
|
||||||
category: "format",
|
category: CATEGORY_FORMAT,
|
||||||
forwardToApi: 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: CATEGORY_FORMAT,
|
||||||
forwardToApi: true,
|
forwardToApi: true,
|
||||||
exception: Infinity,
|
exception: Infinity,
|
||||||
description: dedent(`
|
description: dedent(`
|
||||||
|
@ -164,7 +169,7 @@ const detailOptions = normalizeDetailOptions({
|
||||||
},
|
},
|
||||||
"range-start": {
|
"range-start": {
|
||||||
type: "int",
|
type: "int",
|
||||||
category: "format",
|
category: CATEGORY_FORMAT,
|
||||||
forwardToApi: true,
|
forwardToApi: true,
|
||||||
description: dedent(`
|
description: dedent(`
|
||||||
Format code starting at a given character offset.
|
Format code starting at a given character offset.
|
||||||
|
@ -175,14 +180,14 @@ const detailOptions = normalizeDetailOptions({
|
||||||
},
|
},
|
||||||
semi: {
|
semi: {
|
||||||
type: "boolean",
|
type: "boolean",
|
||||||
category: "format",
|
category: CATEGORY_FORMAT,
|
||||||
forwardToApi: true,
|
forwardToApi: true,
|
||||||
oppositeDescription:
|
oppositeDescription:
|
||||||
"Do not print semicolons, except at the beginning of lines which may need them."
|
"Do not print semicolons, except at the beginning of lines which may need them."
|
||||||
},
|
},
|
||||||
"single-quote": {
|
"single-quote": {
|
||||||
type: "boolean",
|
type: "boolean",
|
||||||
category: "format",
|
category: CATEGORY_FORMAT,
|
||||||
forwardToApi: true,
|
forwardToApi: true,
|
||||||
description: "Use single quotes instead of double quotes."
|
description: "Use single quotes instead of double quotes."
|
||||||
},
|
},
|
||||||
|
@ -197,14 +202,14 @@ const detailOptions = normalizeDetailOptions({
|
||||||
},
|
},
|
||||||
"tab-width": {
|
"tab-width": {
|
||||||
type: "int",
|
type: "int",
|
||||||
category: "format",
|
category: CATEGORY_FORMAT,
|
||||||
forwardToApi: 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: CATEGORY_FORMAT,
|
||||||
forwardToApi: true,
|
forwardToApi: true,
|
||||||
choices: [
|
choices: [
|
||||||
"none",
|
"none",
|
||||||
|
@ -217,24 +222,24 @@ const detailOptions = normalizeDetailOptions({
|
||||||
},
|
},
|
||||||
"use-tabs": {
|
"use-tabs": {
|
||||||
type: "boolean",
|
type: "boolean",
|
||||||
category: "format",
|
category: CATEGORY_FORMAT,
|
||||||
forwardToApi: true,
|
forwardToApi: true,
|
||||||
description: "Indent lines with tabs instead of spaces."
|
description: "Indent lines with tabs instead of spaces."
|
||||||
},
|
},
|
||||||
version: {
|
version: {
|
||||||
type: "boolean",
|
type: "boolean",
|
||||||
category: "command",
|
category: CATEGORY_COMMAND,
|
||||||
alias: "v",
|
alias: "v",
|
||||||
description: "Print Prettier version."
|
description: "Print Prettier version."
|
||||||
},
|
},
|
||||||
"with-node-modules": {
|
"with-node-modules": {
|
||||||
type: "boolean",
|
type: "boolean",
|
||||||
category: "config",
|
category: CATEGORY_CONFIG,
|
||||||
description: "Process files inside 'node_modules' directory."
|
description: "Process files inside 'node_modules' directory."
|
||||||
},
|
},
|
||||||
write: {
|
write: {
|
||||||
type: "boolean",
|
type: "boolean",
|
||||||
category: "command",
|
category: CATEGORY_COMMAND,
|
||||||
description: "Edit the file in-place. (Beware!)"
|
description: "Edit the file in-place. (Beware!)"
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -284,7 +289,7 @@ function normalizeDetailOptions(rawDetailOptions) {
|
||||||
const option = rawDetailOptions[name];
|
const option = rawDetailOptions[name];
|
||||||
return Object.assign({}, option, {
|
return Object.assign({}, option, {
|
||||||
name,
|
name,
|
||||||
category: option.category || "other",
|
category: option.category || CATEGORY_OTHER,
|
||||||
forwardToApi:
|
forwardToApi:
|
||||||
option.forwardToApi &&
|
option.forwardToApi &&
|
||||||
(typeof option.forwardToApi === "string"
|
(typeof option.forwardToApi === "string"
|
||||||
|
@ -308,6 +313,10 @@ const detailOptionMap = detailOptions.reduce(
|
||||||
);
|
);
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
CATEGORY_COMMAND,
|
||||||
|
CATEGORY_CONFIG,
|
||||||
|
CATEGORY_FORMAT,
|
||||||
|
CATEGORY_OTHER,
|
||||||
minimistOptions,
|
minimistOptions,
|
||||||
detailOptions,
|
detailOptions,
|
||||||
detailOptionMap
|
detailOptionMap
|
||||||
|
|
|
@ -343,7 +343,7 @@ function createUsage() {
|
||||||
.filter(Boolean);
|
.filter(Boolean);
|
||||||
|
|
||||||
const groupedOptions = flattenedOptions.reduce((current, option) => {
|
const groupedOptions = flattenedOptions.reduce((current, option) => {
|
||||||
const category = capitalize(option.category);
|
const category = option.category;
|
||||||
const group = (current[category] = current[category] || []);
|
const group = (current[category] = current[category] || []);
|
||||||
group.push(option);
|
group.push(option);
|
||||||
return current;
|
return current;
|
||||||
|
@ -351,8 +351,12 @@ function createUsage() {
|
||||||
|
|
||||||
const usageSummary = "Usage: prettier [opts] [filename ...]";
|
const usageSummary = "Usage: prettier [opts] [filename ...]";
|
||||||
|
|
||||||
const firstCategories = ["Command", "Format", "Config"];
|
const firstCategories = [
|
||||||
const lastCategories = ["Other"];
|
constant.CATEGORY_COMMAND,
|
||||||
|
constant.CATEGORY_FORMAT,
|
||||||
|
constant.CATEGORY_CONFIG
|
||||||
|
];
|
||||||
|
const lastCategories = [constant.CATEGORY_OTHER];
|
||||||
const allCategories = firstCategories.concat(
|
const allCategories = firstCategories.concat(
|
||||||
Object.keys(groupedOptions).filter(
|
Object.keys(groupedOptions).filter(
|
||||||
category =>
|
category =>
|
||||||
|
@ -405,10 +409,6 @@ function createOptionUsage(option, threshold) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function capitalize(str) {
|
|
||||||
return str.replace(/^[a-z]/, char => char.toUpperCase());
|
|
||||||
}
|
|
||||||
|
|
||||||
function indent(str, spaces) {
|
function indent(str, spaces) {
|
||||||
return str.replace(/^/gm, " ".repeat(spaces));
|
return str.replace(/^/gm, " ".repeat(spaces));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue