Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions 5 src/conditionals.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { concat, hardline, group, ifBreak, indent, softline } = require("prettier").doc.builders;
const { breakParent, concat, hardline, group, ifBreak, indent, softline } = require("prettier").doc.builders;

const printWithAddition = (keyword, path, print) => concat([
`${keyword} `,
Expand All @@ -13,7 +13,7 @@ const printTernaryConditions = (keyword, truthyValue, falsyValue) => {
return keyword === "if" ? parts : parts.reverse();
};

const printConditional = keyword => (path, print) => {
const printConditional = keyword => (path, options, print) => {
const [_predicate, _statements, addition] = path.getValue().body;

// If the addition is not an elsif or an else, then it's the second half of a
Expand Down Expand Up @@ -62,6 +62,7 @@ const printConditional = keyword => (path, print) => {
concat([softline, "end"])
]),
concat([
options.inlineConditionals ? "" : breakParent,
path.call(print, "body", 1),
` ${keyword} `,
path.call(print, "body", 0)
Expand Down
14 changes: 14 additions & 0 deletions 14 src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,20 @@ module.exports = {
print
}
},
options: {
inlineConditionals: {
type: "boolean",
category: "Global",
default: true,
description: "When it fits on one line, allow if and unless statements to use the modifier form."
},
inlineLoops: {
type: "boolean",
category: "Global",
default: true,
description: "When it fits on one line, allow while and until statements to use the modifier form."
}
},
defaultOptions: {
printWidth: 80,
tabWidth: 2
Expand Down
7 changes: 4 additions & 3 deletions 7 src/loops.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
const { concat, group, hardline, ifBreak, indent, softline } = require("prettier").doc.builders;
const { breakParent, concat, group, hardline, ifBreak, indent, softline } = require("prettier").doc.builders;

const printLoop = keyword => (path, print) => group(ifBreak(
const printLoop = keyword => (path, options, print) => group(ifBreak(
concat([
concat([`${keyword} `, path.call(print, "body", 0)]),
indent(concat([softline, path.call(print, "body", 1)])),
concat([softline, "end"])
]),
concat([
options.inlineLoops ? "" : breakParent,
path.call(print, "body", 1),
` ${keyword} `,
path.call(print, "body", 0)
])
));

const printFor = (path, print) => group(concat([
const printFor = (path, options, print) => group(concat([
path.call(print, "body", 1),
".each do |",
path.call(print, "body", 0),
Expand Down
6 changes: 3 additions & 3 deletions 6 src/params.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
const { concat, group, join } = require("prettier").doc.builders;

const printKwargRestParam = (path, print) => (
const printKwargRestParam = (path, options, print) => (
concat(["**", path.call(print, "body", 0)])
);

const printRestParam = (path, print) => (
const printRestParam = (path, options, print) => (
concat(["*", path.call(print, "body", 0)])
);

const printParams = (path, print) => {
const printParams = (path, options, print) => {
const [reqs, opts, rest, post, kwargs, kwarg_rest, block] = path.getValue().body;
let parts = [];

Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.