Skip to content

Commit 8e76d49

Browse files
feat: added an option to files - maxSize see [#5295](#5295)
1 parent 4a5ef84 commit 8e76d49

File tree

17 files changed

+478
-7
lines changed

17 files changed

+478
-7
lines changed

.changeset/open-oranges-sell.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@biomejs/biome": minor
3+
---
4+
5+
Addressed [#5295](https://github.com/biomejs/biome/issues/5295): option to allow overrides of files.maxSize

crates/biome_cli/tests/cases/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ mod linter_groups_plain;
1919
mod migrate_v2;
2020
mod overrides_formatter;
2121
mod overrides_linter;
22+
mod overrides_max_file_size;
2223
mod overrides_organize_imports;
2324
mod protected_files;
2425
mod reporter_github;
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
use crate::run_cli;
2+
use crate::snap_test::{SnapshotPayload, assert_cli_snapshot};
3+
use biome_cli::CliDiagnostic;
4+
use biome_console::BufferConsole;
5+
use biome_fs::MemoryFileSystem;
6+
use bpaf::Args;
7+
use camino::Utf8Path;
8+
9+
const FORMATTED: &str = "statement();\n";
10+
const TEST_FILE: &str = "test.js";
11+
const CLI_COMMANDS: [&str; 2] = ["check", "format"];
12+
13+
fn setup_test(
14+
includes: &str,
15+
max_size: u64,
16+
cli_command: &str,
17+
) -> (MemoryFileSystem, BufferConsole, Result<(), CliDiagnostic>) {
18+
assert!(
19+
CLI_COMMANDS.contains(&cli_command),
20+
"Command must be one of {:?}",
21+
CLI_COMMANDS.join(", ")
22+
);
23+
24+
let mut console = BufferConsole::default();
25+
let mut fs = MemoryFileSystem::default();
26+
let file_path = Utf8Path::new("biome.json");
27+
28+
fs.insert(
29+
file_path.into(),
30+
format!(
31+
r#"{{
32+
"files": {{
33+
"maxSize": 1024
34+
}},
35+
"overrides": [
36+
{{
37+
"includes": [
38+
"{}"
39+
],
40+
"files": {{ "maxSize": {} }}
41+
}}
42+
]
43+
}}"#,
44+
includes, max_size
45+
)
46+
.as_bytes(),
47+
);
48+
49+
let test_file = Utf8Path::new(TEST_FILE);
50+
fs.insert(test_file.into(), FORMATTED.as_bytes());
51+
52+
let (fs, result) = run_cli(
53+
fs,
54+
&mut console,
55+
Args::from([cli_command, test_file.as_str()].as_slice()),
56+
);
57+
58+
(fs, console, result)
59+
}
60+
61+
#[test]
62+
fn overrides_files_max_size_option_pass() {
63+
for cli_command in CLI_COMMANDS {
64+
let (fs, console, result) = setup_test(TEST_FILE, 1024, cli_command);
65+
66+
assert!(result.is_ok(), "run_cli returned {result:?}");
67+
68+
assert_cli_snapshot(SnapshotPayload::new(
69+
module_path!(),
70+
"overrides_files_max_size_option_pass",
71+
fs,
72+
console,
73+
result,
74+
));
75+
}
76+
}
77+
78+
#[test]
79+
fn overrides_files_max_size_option_invalid_value() {
80+
for cli_command in CLI_COMMANDS {
81+
let (fs, console, result) = setup_test(TEST_FILE, 0, cli_command);
82+
83+
assert!(result.is_err(), "run_cli returned {result:?}");
84+
85+
assert_cli_snapshot(SnapshotPayload::new(
86+
module_path!(),
87+
"overrides_files_max_size_option_invalid_value",
88+
fs,
89+
console,
90+
result,
91+
));
92+
}
93+
}
94+
95+
#[test]
96+
fn overrides_files_max_size_too_large_limit() {
97+
for cli_command in CLI_COMMANDS {
98+
let (fs, console, result) = setup_test(TEST_FILE, 1, cli_command);
99+
100+
assert!(result.is_err(), "run_cli returned {result:?}");
101+
102+
assert_cli_snapshot(SnapshotPayload::new(
103+
module_path!(),
104+
format!("overrides_files_max_size_too_large_limit_{}", cli_command).as_str(),
105+
fs,
106+
console,
107+
result,
108+
));
109+
}
110+
}
111+
112+
#[test]
113+
fn overrides_files_max_size_ignored_includes_does_not_match_filename() {
114+
for cli_command in CLI_COMMANDS {
115+
let (fs, console, result) = setup_test("invalidFile.js", 1, cli_command);
116+
117+
assert!(result.is_ok(), "run_cli returned {result:?}");
118+
119+
assert_cli_snapshot(SnapshotPayload::new(
120+
module_path!(),
121+
"overrides_files_max_size_ignored_includes_does_not_match_filename",
122+
fs,
123+
console,
124+
result,
125+
));
126+
}
127+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
source: crates/biome_cli/tests/snap_test.rs
3+
assertion_line: 432
4+
expression: redactor(content)
5+
---
6+
## `biome.json`
7+
8+
```json
9+
{
10+
"files": {
11+
"maxSize": 1024
12+
},
13+
"overrides": [
14+
{
15+
"includes": ["invalidFile.js"],
16+
"files": { "maxSize": 1 }
17+
}
18+
]
19+
}
20+
```
21+
22+
## `test.js`
23+
24+
```js
25+
statement();
26+
27+
```
28+
29+
# Emitted Messages
30+
31+
```block
32+
Checked 1 file in <TIME>. No fixes applied.
33+
```
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
---
2+
source: crates/biome_cli/tests/snap_test.rs
3+
assertion_line: 432
4+
expression: redactor(content)
5+
---
6+
## `biome.json`
7+
8+
```json
9+
{
10+
"files": {
11+
"maxSize": 1024
12+
},
13+
"overrides": [
14+
{
15+
"includes": ["test.js"],
16+
"files": { "maxSize": 0 }
17+
}
18+
]
19+
}
20+
```
21+
22+
## `test.js`
23+
24+
```js
25+
statement();
26+
27+
```
28+
29+
# Termination Message
30+
31+
```block
32+
configuration ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
33+
34+
× Biome exited because the configuration resulted in errors. Please fix them.
35+
36+
37+
38+
```
39+
40+
# Emitted Messages
41+
42+
```block
43+
biome.json:10:47 deserialize ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
44+
45+
× The number should be an integer between 1 and 18446744073709551615.
46+
47+
8 │ "test.js"
48+
9 │ ],
49+
> 10 │ "files": { "maxSize": 0 }
50+
│ ^
51+
11 │ }
52+
12 │ ]
53+
54+
55+
```
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
source: crates/biome_cli/tests/snap_test.rs
3+
assertion_line: 432
4+
expression: redactor(content)
5+
---
6+
## `biome.json`
7+
8+
```json
9+
{
10+
"files": {
11+
"maxSize": 1024
12+
},
13+
"overrides": [
14+
{
15+
"includes": ["test.js"],
16+
"files": { "maxSize": 1024 }
17+
}
18+
]
19+
}
20+
```
21+
22+
## `test.js`
23+
24+
```js
25+
statement();
26+
27+
```
28+
29+
# Emitted Messages
30+
31+
```block
32+
Checked 1 file in <TIME>. No fixes applied.
33+
```
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
---
2+
source: crates/biome_cli/tests/snap_test.rs
3+
assertion_line: 432
4+
expression: redactor(content)
5+
---
6+
## `biome.json`
7+
8+
```json
9+
{
10+
"files": {
11+
"maxSize": 1024
12+
},
13+
"overrides": [
14+
{
15+
"includes": ["test.js"],
16+
"files": { "maxSize": 1 }
17+
}
18+
]
19+
}
20+
```
21+
22+
## `test.js`
23+
24+
```js
25+
statement();
26+
27+
```
28+
29+
# Termination Message
30+
31+
```block
32+
check ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
33+
34+
× No files were processed in the specified paths.
35+
36+
i Check your biome.json or biome.jsonc to ensure the paths are not ignored by the configuration.
37+
38+
i These paths were provided but ignored:
39+
40+
- test.js
41+
42+
43+
44+
```
45+
46+
# Emitted Messages
47+
48+
```block
49+
test.js check ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
50+
51+
i The size of the file is 13 B, which exceeds the configured maximum of 1 B for this project.
52+
Use the `files.maxSize` configuration to change the maximum size of files processed, or `files.ignore` to ignore the file.
53+
54+
55+
```
56+
57+
```block
58+
Checked 0 files in <TIME>. No fixes applied.
59+
```
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
---
2+
source: crates/biome_cli/tests/snap_test.rs
3+
assertion_line: 432
4+
expression: redactor(content)
5+
---
6+
## `biome.json`
7+
8+
```json
9+
{
10+
"files": {
11+
"maxSize": 1024
12+
},
13+
"overrides": [
14+
{
15+
"includes": ["test.js"],
16+
"files": { "maxSize": 1 }
17+
}
18+
]
19+
}
20+
```
21+
22+
## `test.js`
23+
24+
```js
25+
statement();
26+
27+
```
28+
29+
# Termination Message
30+
31+
```block
32+
format ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
33+
34+
× No files were processed in the specified paths.
35+
36+
i Check your biome.json or biome.jsonc to ensure the paths are not ignored by the configuration.
37+
38+
i These paths were provided but ignored:
39+
40+
- test.js
41+
42+
43+
44+
```
45+
46+
# Emitted Messages
47+
48+
```block
49+
test.js format ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
50+
51+
i The size of the file is 13 B, which exceeds the configured maximum of 1 B for this project.
52+
Use the `files.maxSize` configuration to change the maximum size of files processed, or `files.ignore` to ignore the file.
53+
54+
55+
```
56+
57+
```block
58+
Checked 0 files in <TIME>. No fixes applied.
59+
```

crates/biome_configuration/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ pub use html::{HtmlConfiguration, html_configuration};
5757
pub use javascript::{JsConfiguration, js_configuration};
5858
pub use json::{JsonConfiguration, json_configuration};
5959
pub use overrides::{
60-
OverrideAssistConfiguration, OverrideFormatterConfiguration, OverrideGlobs,
61-
OverrideLinterConfiguration, OverridePattern, Overrides,
60+
OverrideAssistConfiguration, OverrideFilesConfiguration, OverrideFormatterConfiguration,
61+
OverrideGlobs, OverrideLinterConfiguration, OverridePattern, Overrides,
6262
};
6363
use plugins::Plugins;
6464
use regex::Regex;

0 commit comments

Comments
 (0)