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

only check version once #912

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion src/common/printer-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const printComments = (node, path, options, filter = () => true) => {
// since it depends on the version of Prettier being used.
// Mocking the behaviour will introduce a lot of maintenance in the tests.
/* c8 ignore start */
return isPrettier2()
return isPrettier2
? document.parts // Prettier V2
: document; // Prettier V3
/* c8 ignore stop */
Expand Down
8 changes: 4 additions & 4 deletions src/common/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@ import { util, version } from 'prettier';
import satisfies from 'semver/functions/satisfies.js';

export const prettierVersionSatisfies = (range) => satisfies(version, range);
export const isPrettier2 = () => prettierVersionSatisfies('^2.3.0');
export const isPrettier2 = prettierVersionSatisfies('^2.3.0');

// The following functions will never be 100% covered in a single run
// since it depends on the version of Prettier being used.
// Mocking the behaviour will introduce a lot of maintenance in the tests.
/* c8 ignore start */
export function isNextLineEmpty(text, startIndex) {
return isPrettier2()
return isPrettier2
? util.isNextLineEmptyAfterIndex(text, startIndex)
: util.isNextLineEmpty(text, startIndex); // V3 deprecated `isNextLineEmptyAfterIndex`
}

export function getNextNonSpaceNonCommentCharacterIndex(text, node, locEnd) {
return isPrettier2()
return isPrettier2
? util.getNextNonSpaceNonCommentCharacterIndex(text, node, locEnd)
: util.getNextNonSpaceNonCommentCharacterIndex(text, locEnd(node)); // V3 signature changed
}

export function getNextNonSpaceNonCommentCharacter(text, node, locEnd) {
return isPrettier2()
return isPrettier2
? text.charAt(
util.getNextNonSpaceNonCommentCharacterIndex(text, node, locEnd)
)
Expand Down