(filePath: string)
| 37 | const configFileNames = [".bladeformatterrc.json", ".bladeformatterrc"]; |
| 38 | |
| 39 | export function readRuntimeConfig(filePath: string): RuntimeConfig | undefined { |
| 40 | const configFilePath: string | null = findConfigFile(filePath); |
| 41 | |
| 42 | if (configFilePath === null) { |
| 43 | return undefined; |
| 44 | } |
| 45 | |
| 46 | const configFileContent = fs.readFileSync(configFilePath).toString(); |
| 47 | const schema: JTDSchemaType<RuntimeConfig> = { |
| 48 | optionalProperties: { |
| 49 | indentSize: { type: "int32" }, |
| 50 | indentInnerHtml: { type: "boolean" }, |
| 51 | wrapLineLength: { type: "int32" }, |
| 52 | wrapAttributes: { |
| 53 | enum: [ |
| 54 | "auto", |
| 55 | "force", |
| 56 | "force-aligned ", |
| 57 | "force-expand-multiline", |
| 58 | "aligned-multiple", |
| 59 | "preserve", |
| 60 | "preserve-aligned", |
| 61 | ], |
| 62 | }, |
| 63 | wrapAttributesMinAttrs: { type: "int32" }, |
| 64 | endWithNewline: { type: "boolean" }, |
| 65 | useTabs: { type: "boolean" }, |
| 66 | sortTailwindcssClasses: { type: "boolean" }, |
| 67 | sortHtmlAttributes: { type: "string" }, |
| 68 | customHtmlAttributesOrder: { type: "string" }, |
| 69 | tailwindcssConfigPath: { type: "string" }, |
| 70 | noMultipleEmptyLines: { type: "boolean" }, |
| 71 | noPhpSyntaxCheck: { type: "boolean" }, |
| 72 | noSingleQuote: { type: "boolean" }, |
| 73 | noTrailingCommaPhp: { type: "boolean" }, |
| 74 | componentPrefix: { elements: { type: "string" } }, |
| 75 | phpVersion: { type: "string" }, |
| 76 | }, |
| 77 | additionalProperties: true, |
| 78 | }; |
| 79 | const parse = ajv.compileParser(schema); |
| 80 | return parse(configFileContent); |
| 81 | } |
| 82 | |
| 83 | export function findConfigFile(filePath: string): string | null { |
| 84 | for (let i = 0; i < configFileNames.length; i++) { |
no test coverage detected