Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin' into p/module-import
Browse files Browse the repository at this point in the history
  • Loading branch information
leaysgur committed Jan 23, 2025
2 parents b93ae75 + 3be0392 commit 413052c
Show file tree
Hide file tree
Showing 30 changed files with 1,006 additions and 971 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

19 changes: 18 additions & 1 deletion apps/oxlint/src/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use oxc_linter::{
LintFilter, LintOptions, LintService, LintServiceOptions, Linter, Oxlintrc,
};
use oxc_span::VALID_EXTENSIONS;
use serde_json::Value;

use crate::{
cli::{CliRunResult, LintCommand, LintResult, MiscOptions, Runner, WarningOptions},
Expand Down Expand Up @@ -132,7 +133,23 @@ impl Runner for LintRunner {
if misc_options.print_config {
return CliRunResult::PrintConfigResult { config_file };
} else if basic_options.init {
match fs::write(Self::DEFAULT_OXLINTRC, config_file) {
let schema_relative_path = "node_modules/oxlint/configuration_schema.json";
let configuration = if self.cwd.join(schema_relative_path).is_file() {
let mut config_json: Value = serde_json::from_str(&config_file).unwrap();
if let Value::Object(ref mut obj) = config_json {
let mut json_object = serde_json::Map::new();
json_object.insert(
"$schema".to_string(),
format!("./{schema_relative_path}").into(),
);
json_object.extend(obj.clone());
*obj = json_object;
}
serde_json::to_string_pretty(&config_json).unwrap()
} else {
config_file
};
match fs::write(Self::DEFAULT_OXLINTRC, configuration) {
Ok(()) => {
return CliRunResult::ConfigFileInitResult {
message: "Configuration file created".to_string(),
Expand Down
4 changes: 2 additions & 2 deletions apps/oxlint/src/output_formatter/checkstyle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ fn format_checkstyle(diagnostics: &[Error]) -> String {
let messages = infos
.iter()
.fold(String::new(), |mut acc, info| {
let Info { line, column, message, severity, rule_id, .. } = info;
let Info { start, message, severity, rule_id, .. } = info;
let severity = match severity {
Severity::Error => "error",
_ => "warning",
};
let message = rule_id.as_ref().map_or_else(|| xml_escape(message), |rule_id| Cow::Owned(format!("{} ({rule_id})", xml_escape(message))));
let source = rule_id.as_ref().map_or_else(|| Cow::Borrowed(""), |rule_id| Cow::Owned(format!("eslint.rules.{rule_id}")));
let line = format!(r#"<error line="{line}" column="{column}" severity="{severity}" message="{message}" source="{source}" />"#);
let line = format!(r#"<error line="{}" column="{}" severity="{severity}" message="{message}" source="{source}" />"#, start.line, start.column);
acc.push_str(&line);
acc
});
Expand Down
10 changes: 7 additions & 3 deletions apps/oxlint/src/output_formatter/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl DiagnosticReporter for GithubReporter {
}

fn format_github(diagnostic: &Error) -> String {
let Info { line, column, filename, message, severity, rule_id } = Info::new(diagnostic);
let Info { start, end, filename, message, severity, rule_id } = Info::new(diagnostic);
let severity = match severity {
Severity::Error => "error",
Severity::Warning | miette::Severity::Advice => "warning",
Expand All @@ -44,7 +44,11 @@ fn format_github(diagnostic: &Error) -> String {
let filename = escape_property(&filename);
let message = escape_data(&message);
format!(
"::{severity} file={filename},line={line},endLine={line},col={column},endColumn={column},title={title}::{message}\n"
"::{severity} file={filename},line={},endLine={},col={},endColumn={},title={title}::{message}\n",
start.line,
end.line,
start.column,
end.column
)
}

Expand Down Expand Up @@ -108,6 +112,6 @@ mod test {
let result = reporter.render_error(error);

assert!(result.is_some());
assert_eq!(result.unwrap(), "::warning file=file%3A//test.ts,line=1,endLine=1,col=1,endColumn=1,title=oxlint::error message\n");
assert_eq!(result.unwrap(), "::warning file=file%3A//test.ts,line=1,endLine=1,col=1,endColumn=9,title=oxlint::error message\n");
}
}
2 changes: 1 addition & 1 deletion apps/oxlint/src/output_formatter/stylish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ fn format_stylish(diagnostics: &[Error]) -> String {
let mut grouped: FxHashMap<String, Vec<&Error>> = FxHashMap::default();
let mut sorted = diagnostics.iter().collect::<Vec<_>>();

sorted.sort_by_key(|diagnostic| Info::new(diagnostic).line);
sorted.sort_by_key(|diagnostic| Info::new(diagnostic).start.line);

for diagnostic in sorted {
let info = Info::new(diagnostic);
Expand Down
4 changes: 2 additions & 2 deletions apps/oxlint/src/output_formatter/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ impl DiagnosticReporter for UnixReporter {

/// <https://github.com/fregante/eslint-formatters/tree/ae1fd9748596447d1fd09625c33d9e7ba9a3d06d/packages/eslint-formatter-unix>
fn format_unix(diagnostic: &Error) -> String {
let Info { line, column, filename, message, severity, rule_id } = Info::new(diagnostic);
let Info { start, end: _, filename, message, severity, rule_id } = Info::new(diagnostic);
let severity = match severity {
Severity::Error => "Error",
_ => "Warning",
};
let rule_id =
rule_id.map_or_else(|| Cow::Borrowed(""), |rule_id| Cow::Owned(format!("/{rule_id}")));
format!("{filename}:{line}:{column}: {message} [{severity}{rule_id}]\n")
format!("{filename}:{}:{}: {message} [{severity}{rule_id}]\n", start.line, start.column)
}

#[cfg(test)]
Expand Down
Loading

0 comments on commit 413052c

Please sign in to comment.