Skip to content

Commit

Permalink
feat: 🎸 add option noSingleQuote
Browse files Browse the repository at this point in the history
  • Loading branch information
shufo committed Aug 21, 2023
1 parent a336e6f commit 1342e94
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 1 deletion.
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@
"default": false,
"markdownDescription": "Indent \\<head\\> and \\<body\\> tag sections in html"
},
"bladeFormatter.format.noSingleQuote": {
"type": "boolean",
"default": false,
"markdownDescription": "Use double quotes instead of single quotes for php expression."
},
"bladeFormatter.misc.dontShowNewVersionMessage": {
"type": "boolean",
"default": false,
Expand Down Expand Up @@ -199,7 +204,7 @@
},
"dependencies": {
"ajv": "^8.12.0",
"blade-formatter": "^1.37.0",
"blade-formatter": "link:../../blade-formatter21",
"find-config": "^1.0.0",
"ignore": "^5.2.4",
"sucrase": "^3.34.0",
Expand Down
1 change: 1 addition & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export function activate(context: ExtensionContext) {
noMultipleEmptyLines: extConfig.noMultipleEmptyLines,
noPhpSyntaxCheck: extConfig.noPhpSyntaxCheck,
indentInnerHtml: extConfig.indentInnerHtml,
noSingleQuote: extConfig.noSingleQuote,
...runtimeConfig, // override all settings by runtime config
...tailwindConfig,
};
Expand Down
2 changes: 2 additions & 0 deletions src/runtimeConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface RuntimeConfig {
tailwindcssConfigPath?: string;
noMultipleEmptyLines?: boolean;
noPhpSyntaxCheck?: boolean;
noSingleQuote?: boolean;
}

const configFileNames = [".bladeformatterrc.json", ".bladeformatterrc"];
Expand Down Expand Up @@ -61,6 +62,7 @@ export function readRuntimeConfig(filePath: string): RuntimeConfig | undefined {
tailwindcssConfigPath: { type: "string" },
noMultipleEmptyLines: { type: "boolean" },
noPhpSyntaxCheck: { type: "boolean" },
noSingleQuote: { type: "boolean" },
},
additionalProperties: true,
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"noSingleQuote": true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@if ($array["it_should_be_keep_double_quote"])
foo
@endif
@include("common.header")
@include("common.navbar")
@yield("content")
<div class='{{ auth($user["key"]) }}'>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@if ($array["it_should_be_keep_double_quote"])
foo
@endif
@include('common.header')
@include('common.navbar')
@yield('content')
<div class='{{ auth($user['key']) }}'>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@if ($array["it_should_be_keep_double_quote"])
foo
@endif
@include("common.header")
@include("common.navbar")
@yield("content")
<div class='{{ auth($user["key"]) }}'>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@if ($array["it_should_be_keep_double_quote"])
foo
@endif
@include('common.header')
@include('common.navbar')
@yield('content')
<div class='{{ auth($user['key']) }}'>
</div>
25 changes: 25 additions & 0 deletions src/test/suite/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,31 @@ suite("Extension Test Suite", () => {
await config.update("indentInnerHtml", undefined, true);
});

test("Should format file with runtime config / noSingleQuote", async function (this: any) {
this.timeout(20000);
await formatSameAsBladeFormatter(
"withConfig/noSingleQuote/index.blade.php",
"withConfig/noSingleQuote/formatted.index.blade.php",
);
});

test("Should format file without runtime config / noSingleQuote", async function (this: any) {
this.timeout(20000);
const config = vscode.workspace.getConfiguration(
"bladeFormatter.format",
);
await config.update(
"noSingleQuote",
true,
true,
);
await formatSameAsBladeFormatter(
"withoutConfig/noSingleQuote/index.blade.php",
"withoutConfig/noSingleQuote/formatted.index.blade.php",
);
await config.update("noSingleQuote", undefined, true);
});

test("Format command exists in command list", async function () {
const commands = await vscode.commands.getCommands();
assert(commands.includes(ExtensionConstants.formatCommandKey));
Expand Down

1 comment on commit 1342e94

@mrkaluzny
Copy link

Choose a reason for hiding this comment

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

@shufo I think this option is broken, it always ignores single quotes

Please sign in to comment.