Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

fix(rome_cli): Respect formatter/linter enabled from configuration #3591

Merged
merged 1 commit into from
Nov 9, 2022
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
8 changes: 6 additions & 2 deletions crates/rome_cli/src/commands/ci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,17 @@ pub(crate) fn ci(mut session: CliSession) -> Result<(), Termination> {
.formatter
.get_or_insert_with(FormatterConfiguration::default);

formatter.enabled = formatter_enabled.unwrap_or(true);
if let Some(formatter_enabled) = formatter_enabled {
formatter.enabled = formatter_enabled;
}

let linter = configuration
.linter
.get_or_insert_with(LinterConfiguration::default);

linter.enabled = linter_enabled.unwrap_or(true);
if let Some(linter_enabled) = linter_enabled {
linter.enabled = linter_enabled;
}

// no point in doing the traversal if all the checks have been disabled
if configuration.is_formatter_disabled() && configuration.is_linter_disabled() {
Expand Down
37 changes: 21 additions & 16 deletions crates/rome_cli/tests/commands/ci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,29 +160,32 @@ fn ci_does_not_run_formatter() {
let mut fs = MemoryFileSystem::default();
let mut console = BufferConsole::default();

let file_path = Path::new("rome.json");
fs.insert(file_path.into(), CONFIG_DISABLED_FORMATTER.as_bytes());
fs.insert(
PathBuf::from("rome.json"),
CONFIG_DISABLED_FORMATTER.as_bytes(),
);

let file_path = Path::new("file.js");
fs.insert(file_path.into(), UNFORMATTED_AND_INCORRECT.as_bytes());
let input_file = Path::new("file.js");

fs.insert(input_file.into(), UNFORMATTED.as_bytes());

let result = run_cli(
DynRef::Borrowed(&mut fs),
DynRef::Borrowed(&mut console),
Arguments::from_vec(vec![OsString::from("ci"), file_path.as_os_str().into()]),
Arguments::from_vec(vec![OsString::from("ci"), input_file.as_os_str().into()]),
);

assert!(result.is_err(), "run_cli returned {result:?}");
assert!(result.is_ok(), "run_cli returned {result:?}");

let mut file = fs
.open(file_path)
.open(input_file)
.expect("formatting target file was removed by the CLI");

let mut content = String::new();
file.read_to_string(&mut content)
.expect("failed to read file from memory FS");

assert_eq!(content, UNFORMATTED_AND_INCORRECT);
assert_eq!(content, UNFORMATTED);

drop(file);
assert_cli_snapshot(SnapshotPayload::new(
Expand All @@ -199,30 +202,30 @@ fn ci_does_not_run_formatter_via_cli() {
let mut fs = MemoryFileSystem::default();
let mut console = BufferConsole::default();

let file_path = Path::new("file.js");
fs.insert(file_path.into(), UNFORMATTED_AND_INCORRECT.as_bytes());
let input_file = Path::new("file.js");
fs.insert(input_file.into(), UNFORMATTED.as_bytes());

let result = run_cli(
DynRef::Borrowed(&mut fs),
DynRef::Borrowed(&mut console),
Arguments::from_vec(vec![
OsString::from("ci"),
OsString::from("--formatter-enabled=false"),
file_path.as_os_str().into(),
input_file.as_os_str().into(),
]),
);

assert!(result.is_err(), "run_cli returned {result:?}");
assert!(result.is_ok(), "run_cli returned {result:?}");

let mut file = fs
.open(file_path)
.open(input_file)
.expect("formatting target file was removed by the CLI");

let mut content = String::new();
file.read_to_string(&mut content)
.expect("failed to read file from memory FS");

assert_eq!(content, UNFORMATTED_AND_INCORRECT);
assert_eq!(content, UNFORMATTED);

drop(file);
assert_cli_snapshot(SnapshotPayload::new(
Expand All @@ -239,8 +242,10 @@ fn ci_does_not_run_linter() {
let mut fs = MemoryFileSystem::default();
let mut console = BufferConsole::default();

let file_path = Path::new("rome.json");
fs.insert(file_path.into(), CONFIG_LINTER_DISABLED.as_bytes());
fs.insert(
PathBuf::from("rome.json"),
CONFIG_LINTER_DISABLED.as_bytes(),
);

let file_path = Path::new("file.js");
fs.insert(file_path.into(), CUSTOM_FORMAT_BEFORE.as_bytes());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,9 @@ expression: content
## `file.js`

```js
statement( ) ; let a = !b || !c;
```

# Termination Message

```block
errors where emitted while running checks
statement( )
```

# Emitted Messages

```block
file.js:1:27 lint/complexity/useSimplifiedLogicExpression FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

× Logical expression contains unnecessary complexity.

> 1 │ statement( ) ; let a = !b || !c;
│ ^^^^^^^^

i Suggested fix: Reduce the complexity of the logical expression.

- statement(····)·;·let·a·=·!b·||·!c;
+ statement(····)·;·let·a·=·!(b·&&·c);


```


Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,9 @@ expression: content
## `file.js`

```js
statement( ) ; let a = !b || !c;
```

# Termination Message

```block
errors where emitted while running checks
statement( )
```

# Emitted Messages

```block
file.js:1:27 lint/complexity/useSimplifiedLogicExpression FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

× Logical expression contains unnecessary complexity.

> 1 │ statement( ) ; let a = !b || !c;
│ ^^^^^^^^

i Suggested fix: Reduce the complexity of the logical expression.

- statement(····)·;·let·a·=·!b·||·!c;
+ statement(····)·;·let·a·=·!(b·&&·c);


```