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

Fix for Prettier 2 #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
15 changes: 14 additions & 1 deletion src/printer.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,23 @@ const {
breakParent,
} = require("prettier").doc.builders;
const { willBreak } = require("prettier").doc.utils;
const { makeString, isNextLineEmpty } = require("prettier").util;
const {
makeString,
isNextLineEmpty: _isNextLineEmpty,
} = require("prettier").util;
const { isValidIdentifier, isExpression } = require("./util");
const { printDanglingComments, isDanglingComment } = require("./comments");

const prettierVersion = require("prettier").version;

function lookupIfPrettier2(options, prop) {
return parseInt(prettierVersion[0]) > 1 ? options[prop] : options;
Comment on lines +26 to +29
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This way, the version check won’t break on Prettier 10 – Prettier 19:

Suggested change
const prettierVersion = require("prettier").version;
function lookupIfPrettier2(options, prop) {
return parseInt(prettierVersion[0]) > 1 ? options[prop] : options;
const [prettierVersionMajor] = require("prettier").version.split(".", 1);
function lookupIfPrettier2(options, prop) {
return parseInt(prettierVersionMajor) > 1 ? options[prop] : options;

}

function isNextLineEmpty(text, node, options) {
return _isNextLineEmpty(text, node, lookupIfPrettier2(options, "locEnd"));
}

function printNoParens(path, options, print) {
const node = path.getValue();

Expand Down