Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

challenge(formatter): sloppy mode tests #801

Merged
merged 1 commit into from
Nov 20, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 21 additions & 2 deletions crates/biome_js_formatter/tests/prettier_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{env, path::Path};
use biome_formatter::IndentStyle;
use biome_formatter_test::test_prettier_snapshot::{PrettierSnapshot, PrettierTestFile};
use biome_js_formatter::context::JsFormatOptions;
use biome_js_syntax::JsFileSource;
use biome_js_syntax::{JsFileSource, ModuleKind};

mod language;

Expand All @@ -18,7 +18,7 @@ fn test_snapshot(input: &'static str, _: &str, _: &str, _: &str) {
));

let test_file = PrettierTestFile::new(input, root_path);
let source_type = {
let mut source_type = {
// Prettier testing suite uses JSX tags inside JS files.
// As there's no way to know in advance which files have JSX syntax, we
// change the source type only here
Expand All @@ -31,12 +31,31 @@ fn test_snapshot(input: &'static str, _: &str, _: &str, _: &str) {
}
};

if is_non_strict_mode(root_path, test_file.input_file()) {
source_type = source_type.with_module_kind(ModuleKind::Script)
}

let options = JsFormatOptions::new(source_type)
.with_indent_style(IndentStyle::Space)
.with_indent_width(2.into());

let language = language::JsTestFormatLanguage::new(source_type);

let snapshot = PrettierSnapshot::new(test_file, language, options);

snapshot.test()
}

victor-teles marked this conversation as resolved.
Show resolved Hide resolved
fn is_non_strict_mode(root_path: &Path, file_path: &Path) -> bool {
let test_cases_paths = [
"js/with",
"js/sloppy-mode",
"js/identifier/parentheses/const.js",
];

victor-teles marked this conversation as resolved.
Show resolved Hide resolved
test_cases_paths.iter().any(|path| {
file_path
.strip_prefix(root_path)
.is_ok_and(|file| file.starts_with(path))
})
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ while (false) function foo(){}
```
function-declaration-in-while.js:1:15 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

× In strict mode code, functions can only be declared at top level or inside a block
× In non-strict mode code, functions can only be declared at top level, inside a block, or as the body of an if or labelled statement

> 1 │ while (false) function foo(){}
│ ^^^^^^^^^^^^^^^^
Expand Down

This file was deleted.