Skip to content

Commit

Permalink
feat: 🎸 add option --php-version
Browse files Browse the repository at this point in the history
  • Loading branch information
shufo committed Oct 9, 2023
1 parent d44f402 commit a57f9ef
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,22 @@ export const options = {
description: "If set to false, no trailing commas are printed for php expression.",
since: "1.10.0",
},
phpVersion: {
type: "string",
category: "Blade",
default: "8.1",
description: "The version of PHP to use for formatting.",
since: "1.13.0",
},
};

/**
* Parses a PHP version string and returns a floating point number.
*
* @param {string} version - The PHP version string to parse.
* @returns {number} The parsed PHP version as a floating point number.
* @since 1.0.0
*/
export function parsePhpVersion(version: string): number {
return parseFloat(version);
}
5 changes: 4 additions & 1 deletion src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ import { Parser, ParserOptions, resolveConfigFile } from "prettier";
import { FormatterOption } from "blade-formatter";
import { Formatter } from "blade-formatter";
import path from "path";
import { parsePhpVersion } from "./options";

export const parse = async (
text: string,
parsers: { [parserName: string]: Parser },
opts: ParserOptions & FormatterOption,
) => {
const phpVersion = parsePhpVersion(opts["phpVersion"]);

const formatterOptions: FormatterOption = {
indentSize: opts["tabWidth"],
wrapLineLength: opts["printWidth"],
Expand All @@ -25,7 +28,7 @@ export const parse = async (
noMultipleEmptyLines: true,
noPhpSyntaxCheck: opts["noPhpSyntaxCheck"],
noSingleQuote: !opts["singleQuote"],
noTrailingCommaPhp: !opts["trailingCommaPHP"],
noTrailingCommaPhp: phpVersion < 7.2 || !opts["trailingCommaPHP"],
customHtmlAttributesOrder: opts["customHtmlAttributesOrder"],
indentInnerHtml: opts["indentInnerHtml"],
// @ts-ignore
Expand Down

0 comments on commit a57f9ef

Please sign in to comment.