Skip to content
Merged
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
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ tracing-subscriber = "0.3.22" # Tracing implementation
ureq = { version = "3.1.4", default-features = false } # HTTP client
url = { version = "2.5.8" } # URL parsing
walkdir = "2.5.0" # Directory traversal
editorconfig-parser = "0.0.3"
editorconfig-parser = "0.0.4"
natord = "1.0.9"
oxfmt = { path = "apps/oxfmt" }
sort-package-json = "0.0.12"
Expand Down
2 changes: 2 additions & 0 deletions apps/oxfmt/src-js/config.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ export interface Oxfmtrc {
* For JSX, you can set the `jsxSingleQuote` option.
*
* - Default: `false`
* - Overrides `.editorconfig.quote_type`
*/
singleQuote?: boolean;
/**
Expand Down Expand Up @@ -435,6 +436,7 @@ export interface FormatConfig {
* For JSX, you can set the `jsxSingleQuote` option.
*
* - Default: `false`
* - Overrides `.editorconfig.quote_type`
*/
singleQuote?: boolean;
/**
Expand Down
17 changes: 16 additions & 1 deletion apps/oxfmt/src/core/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::path::{Path, PathBuf};

use editorconfig_parser::{
EditorConfig, EditorConfigProperties, EditorConfigProperty, EndOfLine, IndentStyle,
MaxLineLength,
MaxLineLength, QuoteType,
};
use fast_glob::glob_match;
use serde_json::Value;
Expand Down Expand Up @@ -613,6 +613,7 @@ fn load_editorconfig(
/// - indent_size
/// - tab_width
/// - insert_final_newline
/// - quote_type
fn has_editorconfig_overrides(editorconfig: &EditorConfig, path: &Path) -> bool {
let sections = editorconfig.sections();

Expand All @@ -635,6 +636,7 @@ fn has_editorconfig_overrides(editorconfig: &EditorConfig, path: &Path) -> bool
|| resolved.indent_size != root.indent_size
|| resolved.tab_width != root.tab_width
|| resolved.insert_final_newline != root.insert_final_newline
|| resolved.quote_type != root.quote_type
}
// No `[*]` section means any resolved property is an override
None => {
Expand All @@ -644,6 +646,7 @@ fn has_editorconfig_overrides(editorconfig: &EditorConfig, path: &Path) -> bool
|| resolved.indent_size != EditorConfigProperty::Unset
|| resolved.tab_width != EditorConfigProperty::Unset
|| resolved.insert_final_newline != EditorConfigProperty::Unset
|| resolved.quote_type != EditorConfigProperty::Unset
}
}
}
Expand Down Expand Up @@ -697,4 +700,16 @@ fn apply_editorconfig(config: &mut FormatConfig, props: &EditorConfigProperties)
{
config.insert_final_newline = Some(v);
}

if config.single_quote.is_none() {
match props.quote_type {
EditorConfigProperty::Value(QuoteType::Single) => {
config.single_quote = Some(true);
}
EditorConfigProperty::Value(QuoteType::Double) => {
config.single_quote = Some(false);
}
_ => {}
}
}
}
1 change: 1 addition & 0 deletions apps/oxfmt/src/core/oxfmtrc/format_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ pub struct FormatConfig {
/// For JSX, you can set the `jsxSingleQuote` option.
///
/// - Default: `false`
/// - Overrides `.editorconfig.quote_type`
#[serde(skip_serializing_if = "Option::is_none")]
pub single_quote: Option<bool>,
/// Use single quotes instead of double quotes in JSX.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,20 @@ nested/deep/test.json
--------------------"
`;

exports[`editorconfig > quote_type maps to singleQuote 1`] = `
"--- FILE -----------
test.js
--- BEFORE ---------
const a = "hello";
const b = "world";

--- AFTER ----------
const a = 'hello';
const b = 'world';

--------------------"
`;

exports[`editorconfig > tab_width fallback when indent_size is not set 1`] = `
"--- FILE -----------
test.js
Expand Down
11 changes: 11 additions & 0 deletions apps/oxfmt/test/cli/editorconfig/editorconfig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,17 @@ describe("editorconfig", () => {
expect(snapshot).toMatchSnapshot();
});

// .editorconfig:
// [*] quote_type=single
//
// Expected: singleQuote=true
// - String literals should use single quotes instead of double quotes
it("quote_type maps to singleQuote", async () => {
const cwd = join(fixturesDir, "quote_type");
const snapshot = await runWriteModeAndSnapshot(cwd, ["test.js"]);
expect(snapshot).toMatchSnapshot();
});

// .editorconfig: (empty file)
//
// Expected: default settings (useTabs=false, tabWidth=2)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[*]
quote_type = single
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const a = "hello";
const b = "world";
8 changes: 4 additions & 4 deletions npm/oxfmt/configuration_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@
"markdownDescription": "Enforce single attribute per line in HTML, Vue, and JSX.\n\n- Default: `false`"
},
"singleQuote": {
"description": "Use single quotes instead of double quotes.\n\nFor JSX, you can set the `jsxSingleQuote` option.\n\n- Default: `false`",
"description": "Use single quotes instead of double quotes.\n\nFor JSX, you can set the `jsxSingleQuote` option.\n\n- Default: `false`\n- Overrides `.editorconfig.quote_type`",
"type": "boolean",
"markdownDescription": "Use single quotes instead of double quotes.\n\nFor JSX, you can set the `jsxSingleQuote` option.\n\n- Default: `false`"
"markdownDescription": "Use single quotes instead of double quotes.\n\nFor JSX, you can set the `jsxSingleQuote` option.\n\n- Default: `false`\n- Overrides `.editorconfig.quote_type`"
},
"sortImports": {
"description": "Sort import statements.\n\nUsing the similar algorithm as [eslint-plugin-perfectionist/sort-imports](https://perfectionist.dev/rules/sort-imports).\nFor details, see each field's documentation.\n\nPass `true` or an object to enable with defaults, or omit/set `false` to disable.\n\n- Default: Disabled",
Expand Down Expand Up @@ -359,9 +359,9 @@
"markdownDescription": "Enforce single attribute per line in HTML, Vue, and JSX.\n\n- Default: `false`"
},
"singleQuote": {
"description": "Use single quotes instead of double quotes.\n\nFor JSX, you can set the `jsxSingleQuote` option.\n\n- Default: `false`",
"description": "Use single quotes instead of double quotes.\n\nFor JSX, you can set the `jsxSingleQuote` option.\n\n- Default: `false`\n- Overrides `.editorconfig.quote_type`",
"type": "boolean",
"markdownDescription": "Use single quotes instead of double quotes.\n\nFor JSX, you can set the `jsxSingleQuote` option.\n\n- Default: `false`"
"markdownDescription": "Use single quotes instead of double quotes.\n\nFor JSX, you can set the `jsxSingleQuote` option.\n\n- Default: `false`\n- Overrides `.editorconfig.quote_type`"
},
"sortImports": {
"description": "Sort import statements.\n\nUsing the similar algorithm as [eslint-plugin-perfectionist/sort-imports](https://perfectionist.dev/rules/sort-imports).\nFor details, see each field's documentation.\n\nPass `true` or an object to enable with defaults, or omit/set `false` to disable.\n\n- Default: Disabled",
Expand Down
8 changes: 4 additions & 4 deletions tasks/website_formatter/src/snapshots/schema_json.snap
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ expression: json
"markdownDescription": "Enforce single attribute per line in HTML, Vue, and JSX.\n\n- Default: `false`"
},
"singleQuote": {
"description": "Use single quotes instead of double quotes.\n\nFor JSX, you can set the `jsxSingleQuote` option.\n\n- Default: `false`",
"description": "Use single quotes instead of double quotes.\n\nFor JSX, you can set the `jsxSingleQuote` option.\n\n- Default: `false`\n- Overrides `.editorconfig.quote_type`",
"type": "boolean",
"markdownDescription": "Use single quotes instead of double quotes.\n\nFor JSX, you can set the `jsxSingleQuote` option.\n\n- Default: `false`"
"markdownDescription": "Use single quotes instead of double quotes.\n\nFor JSX, you can set the `jsxSingleQuote` option.\n\n- Default: `false`\n- Overrides `.editorconfig.quote_type`"
},
"sortImports": {
"description": "Sort import statements.\n\nUsing the similar algorithm as [eslint-plugin-perfectionist/sort-imports](https://perfectionist.dev/rules/sort-imports).\nFor details, see each field's documentation.\n\nPass `true` or an object to enable with defaults, or omit/set `false` to disable.\n\n- Default: Disabled",
Expand Down Expand Up @@ -363,9 +363,9 @@ expression: json
"markdownDescription": "Enforce single attribute per line in HTML, Vue, and JSX.\n\n- Default: `false`"
},
"singleQuote": {
"description": "Use single quotes instead of double quotes.\n\nFor JSX, you can set the `jsxSingleQuote` option.\n\n- Default: `false`",
"description": "Use single quotes instead of double quotes.\n\nFor JSX, you can set the `jsxSingleQuote` option.\n\n- Default: `false`\n- Overrides `.editorconfig.quote_type`",
"type": "boolean",
"markdownDescription": "Use single quotes instead of double quotes.\n\nFor JSX, you can set the `jsxSingleQuote` option.\n\n- Default: `false`"
"markdownDescription": "Use single quotes instead of double quotes.\n\nFor JSX, you can set the `jsxSingleQuote` option.\n\n- Default: `false`\n- Overrides `.editorconfig.quote_type`"
},
"sortImports": {
"description": "Sort import statements.\n\nUsing the similar algorithm as [eslint-plugin-perfectionist/sort-imports](https://perfectionist.dev/rules/sort-imports).\nFor details, see each field's documentation.\n\nPass `true` or an object to enable with defaults, or omit/set `false` to disable.\n\n- Default: Disabled",
Expand Down
2 changes: 2 additions & 0 deletions tasks/website_formatter/src/snapshots/schema_markdown.snap
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,7 @@ Use single quotes instead of double quotes.
For JSX, you can set the `jsxSingleQuote` option.

- Default: `false`
- Overrides `.editorconfig.quote_type`


##### overrides[n].options.sortImports
Expand Down Expand Up @@ -1073,6 +1074,7 @@ Use single quotes instead of double quotes.
For JSX, you can set the `jsxSingleQuote` option.

- Default: `false`
- Overrides `.editorconfig.quote_type`


## sortImports
Expand Down
Loading