Skip to content

Commit eb3496d

Browse files
committed
Test against more specs
1 parent 94a37a0 commit eb3496d

File tree

512 files changed

+20630
-83
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

512 files changed

+20630
-83
lines changed

python/formate_js/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ def javascript_hook(
6868
if "indent" in (formate_global_config or {}):
6969
indent_setting = formate_global_config["indent"]
7070
if indent_setting == '\t':
71-
kwargs["use_tabs"] = True
71+
if "indent_width" not in kwargs:
72+
kwargs["use_tabs"] = True
73+
kwargs["indent_width"] = 4
7274
else:
7375
kwargs["use_tabs"] = False
7476
if set(indent_setting) == {' '}:

src/configuration.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -973,6 +973,7 @@ const USE_BRACES_DEFAULT: &str = "whenNotSingleLine";
973973
const PREFER_HANGING_DEFAULT: bool = false;
974974
const PREFER_HANGING_GRANULAR_DEFAULT: &str = "never";
975975
const PREFER_SINGLE_LINE_DEFAULT: bool = false;
976+
const METHOD_SPACE_BEFORE_PARENTHESES_DEFAULT: bool = false;
976977
const SPACE_SURROUNDING_PROPERTIES_DEFAULT: bool = true;
977978
const TYPE_LITERAL_SEPARATOR_KIND_DEFAULT: &str = "semiColon";
978979
const QUOTE_STYLE_DEFAULT: &str = "alwaysDouble";
@@ -1180,7 +1181,7 @@ impl PyConfiguration {
11801181
import_declaration_space_surrounding_named_imports: "bool" = IMPORT_DECLARATION_SPACE_SURROUNDING_NAMED_IMPORTS_DEFAULT,
11811182
jsx_expression_container_space_surrounding_expression: "bool" = JSX_EXPRESSION_CONTAINER_SPACE_SURROUNDING_EXPRESSION_DEFAULT,
11821183
jsx_self_closing_element_space_before_slash: "bool" = JSX_SELF_CLOSING_ELEMENT_SPACE_BEFORE_SLASH_DEFAULT,
1183-
method_space_before_parentheses: "bool" = SPACE_SURROUNDING_PROPERTIES_DEFAULT,
1184+
method_space_before_parentheses: "bool" = METHOD_SPACE_BEFORE_PARENTHESES_DEFAULT,
11841185
object_expression_space_surrounding_properties: "bool" = SPACE_SURROUNDING_PROPERTIES_DEFAULT,
11851186
object_pattern_space_surrounding_properties: "bool" = SPACE_SURROUNDING_PROPERTIES_DEFAULT,
11861187
set_accessor_space_before_parentheses: "bool" = SET_ACCESSOR_SPACE_BEFORE_PARENTHESES_DEFAULT,
@@ -2320,7 +2321,7 @@ impl PyConfiguration {
23202321
dict_set_item!(
23212322
"method_space_before_parentheses",
23222323
self.method_space_before_parentheses,
2323-
SPACE_SURROUNDING_PROPERTIES_DEFAULT
2324+
METHOD_SPACE_BEFORE_PARENTHESES_DEFAULT
23242325
);
23252326
dict_set_item!(
23262327
"object_expression_space_surrounding_properties",

tests/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ pytest>=6.0.0
55
pytest-cov>=2.8.1
66
pytest-randomly>=3.7.0
77
pytest-timeout>=1.4.2
8+
regex>=2024.11.6
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
~~ catchClause.spaceAround: true ~~
2+
== should output without param ==
3+
try{
4+
a;
5+
} catch
6+
{
7+
b;
8+
}
9+
10+
[expect]
11+
try {
12+
a;
13+
} catch {
14+
b;
15+
}
16+
17+
== should output with param ==
18+
try{
19+
a;
20+
}
21+
catch(ex){
22+
b;
23+
}
24+
25+
[expect]
26+
try {
27+
a;
28+
} catch ( ex ) {
29+
b;
30+
}
31+
32+
== should output with type on param ==
33+
try {
34+
a
35+
} catch ( ex :unknown ) {
36+
}
37+
38+
[expect]
39+
try {
40+
a;
41+
} catch ( ex: unknown ) {
42+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
~~ commentLine.forceSpaceAfterSlashes: false ~~
2+
== should not force a space after a double slash ==
3+
//test
4+
// test
5+
// test
6+
7+
[expect]
8+
//test
9+
// test
10+
// test
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
~~ ignoreNodeCommentText: my-ignore-comment, ignoreFileCommentText: my-ignore-file-comment ~~
2+
== should ignore formatting a node marked with a custom ignore comment ==
3+
// my-ignore-comment
4+
call(5, 6, 7,
5+
8, 9, 10);
6+
7+
[expect]
8+
// my-ignore-comment
9+
call(5, 6, 7,
10+
8, 9, 10);
11+
12+
== should not ignore when a comment block ==
13+
/* my-ignore-comment */
14+
[
15+
5, 6, 7,
16+
8, 9, 10,
17+
11, 12, 13
18+
];
19+
20+
[expect]
21+
/* my-ignore-comment */
22+
[
23+
5, 6, 7,
24+
8, 9, 10,
25+
11, 12, 13
26+
];
27+
28+
== should not ignore when ignore word has extra characters on the end ==
29+
/* my-ignore-commente */
30+
[
31+
5, 6, 7
32+
]
33+
34+
[expect]
35+
/* my-ignore-commente */
36+
[
37+
5,
38+
6,
39+
7,
40+
];
41+
42+
== should ignore when there is a colon after (or some other non word character) ==
43+
/* my-ignore-comment: Some explanation */
44+
[
45+
5, 6, 7
46+
]
47+
48+
[expect]
49+
/* my-ignore-comment: Some explanation */
50+
[
51+
5, 6, 7
52+
]
53+
54+
== should ignore a custom file ignore comment ==
55+
// my-ignore-file-comment
56+
// test
57+
[
58+
5, 6
59+
];
60+
[1,
61+
9]
62+
63+
[expect]
64+
// my-ignore-file-comment
65+
// test
66+
[
67+
5, 6
68+
];
69+
[1,
70+
9]
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
-- file.tsx --
2+
== should ignore element after ignore comment in an element ==
3+
const t = (
4+
<Element>
5+
{/* dprint-ignore */}
6+
<Test />
7+
</Element>
8+
);
9+
10+
[expect]
11+
const t = (
12+
<Element>
13+
{/* dprint-ignore */}
14+
<Test />
15+
</Element>
16+
);
17+
18+
== should ignore element after ignore comment in a fragment ==
19+
const t = (
20+
<>
21+
{/* dprint-ignore */}
22+
<Test />
23+
</>
24+
);
25+
26+
[expect]
27+
const t = (
28+
<>
29+
{/* dprint-ignore */}
30+
<Test />
31+
</>
32+
);
33+
34+
== should ignore element after ignore comment in a previous empty element ==
35+
const t = (
36+
<Element>
37+
{/* dprint-ignore */}
38+
{/* deno-lint-ignore */}
39+
<Test />
40+
</Element>
41+
);
42+
43+
[expect]
44+
const t = (
45+
<Element>
46+
{/* dprint-ignore */}
47+
{/* deno-lint-ignore */}
48+
<Test />
49+
</Element>
50+
);
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
-- file.d.ts --
2+
== should format a declaration file ==
3+
declare namespace someModule {
4+
interface Test {
5+
prop: string;
6+
}
7+
}
8+
9+
declare module "test" {
10+
class Test {
11+
myMethod(): void;
12+
}
13+
}
14+
15+
global {
16+
interface GlobalTest {
17+
prop: number;
18+
}
19+
}
20+
21+
declare function someFunc(): string;
22+
export = someFunc;
23+
24+
[expect]
25+
declare namespace someModule {
26+
interface Test {
27+
prop: string;
28+
}
29+
}
30+
31+
declare module "test" {
32+
class Test {
33+
myMethod(): void;
34+
}
35+
}
36+
37+
global {
38+
interface GlobalTest {
39+
prop: number;
40+
}
41+
}
42+
43+
declare function someFunc(): string;
44+
export = someFunc;
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
~~ trailingCommas: always, lineWidth: 40 ~~
2+
== should not do a trailing comma in rest parameters ==
3+
function foo(
4+
a: A,
5+
b: B,
6+
...c: C
7+
): void {}
8+
9+
[expect]
10+
function foo(
11+
a: A,
12+
b: B,
13+
...c: C
14+
): void {}
15+
16+
== should not do a trailing comma in array patterns ==
17+
const [a, b] = [1, 2, 3];
18+
const [a, ...b] = [1, 2, 3];
19+
20+
[expect]
21+
const [a, b,] = [1, 2, 3,];
22+
const [a, ...b] = [1, 2, 3,];
23+
24+
== should not do a trailing comma in object patterns ==
25+
const { a, b } = {};
26+
const { a, ...b } = {};
27+
28+
[expect]
29+
const { a, b, } = {};
30+
const { a, ...b } = {};
31+
32+
== should not use trailing commas on a dynamic import ==
33+
const ttttesssttt = import("testttttttt");
34+
35+
[expect]
36+
const ttttesssttt = import(
37+
"testttttttt"
38+
);
39+
40+
== should not use trailing commas in a rest param in arrow functions ==
41+
const test = (
42+
a: A,
43+
b: B,
44+
...c: C
45+
): void => {
46+
test;
47+
};
48+
49+
[expect]
50+
const test = (
51+
a: A,
52+
b: B,
53+
...c: C
54+
): void => {
55+
test;
56+
};
57+
58+
== should not use trailing comma in type argument in class decl ==
59+
export class DocumentCollection<
60+
T extends object = any,
61+
> extends BaseCollection<
62+
T
63+
> {}
64+
65+
[expect]
66+
export class DocumentCollection<
67+
T extends object = any,
68+
> extends BaseCollection<
69+
T
70+
> {}
71+
72+
== should not use trailing comma in type argument in class expr ==
73+
const t = class DocumentCollection<
74+
T extends object = any,
75+
> extends BaseCollection<
76+
T
77+
> {}
78+
79+
[expect]
80+
const t = class DocumentCollection<
81+
T extends object = any,
82+
> extends BaseCollection<
83+
T
84+
> {};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
~~ useTabs: true, indentWidth: 4, lineWidth: 40 ~~
2+
== should use the specified indent width for the tab size ==
3+
const test = testingThisOutt + testtt + testingThisOut + testingthi + outt;
4+
5+
[expect]
6+
const test = testingThisOutt + testtt
7+
+ testingThisOut + testingthi
8+
+ outt;

0 commit comments

Comments
 (0)