How to use the prettier.hasNewlineInRange function in prettier

To help you get started, we’ve selected a few prettier examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github prettier / plugin-php / src / printer.js View on Github external
//   [,] === $arr;
      //   [1,] === $arr;
      //   [1,,] === $arr;
      //
      // Note that getLast returns null if the array is empty, but
      // we already check for an empty array just above so we are safe
      const needsForcedTrailingComma = lastElem && lastElem.kind === "noop";

      const [firstProperty] = node.items
        .filter((node) => node.kind !== "noop")
        .sort((a, b) => options.locStart(a) - options.locStart(b));
      const isAssociative = !!(firstProperty && firstProperty.key);
      const shouldBreak =
        isAssociative &&
        firstProperty &&
        hasNewlineInRange(
          options.originalText,
          options.locStart(node),
          options.locStart(firstProperty)
        );

      return group(
        concat([
          open,
          indent(concat([softline, printArrayItems(path, options, print)])),
          needsForcedTrailingComma ? "," : "",
          ifBreak(
            !needsForcedTrailingComma && shouldPrintComma(options, "5.0")
              ? concat([
                  lastElem && shouldPrintHardlineBeforeTrailingComma(lastElem)
                    ? hardline
                    : "",
github prettier / plugin-php / src / comments.js View on Github external
function handleRetifComments(
  enclosingNode,
  precedingNode,
  followingNode,
  comment,
  text,
  options
) {
  const isSameLineAsPrecedingNode =
    precedingNode &&
    !hasNewlineInRange(
      text,
      options.locEnd(precedingNode),
      options.locStart(comment)
    );

  if (
    (!precedingNode || !isSameLineAsPrecedingNode) &&
    enclosingNode &&
    enclosingNode.kind === "retif" &&
    followingNode
  ) {
    addLeadingComment(followingNode, comment);
    return true;
  }
  return false;
}
github prettier / plugin-php / src / printer.js View on Github external
]);

      const shortEcho =
        firstNode && firstNode.kind === "echo" && firstNode.shortForm;
      parts.push(concat([shortEcho ? "");

    if (hasEndTag) {
      const lastNode = getLast(node.children);
      const beforeCloseTag = lastNode
        ? concat([
            hasNewlineInRange(
              options.originalText,
              options.locEnd(lastNode),
              options.locEnd(node)
            )
              ? hardline
              : " ",
            isNextLineEmpty(options.originalText, lastNode, options)
              ? hardline
              : "",
          ])
        : node.comments
        ? hardline
        : "";

      parts.push(lineSuffix(concat([beforeCloseTag, "?>"])));
    }