Skip to content

Commit

Permalink
Copy phpstan config into tool dir (#1482)
Browse files Browse the repository at this point in the history
Similar to eslint, phpstan config files also load dependencies relative
to config file path, so we should copy the phpstan configs into tool
directory where we install the packages.
  • Loading branch information
marschattha authored Feb 7, 2025
1 parent 932c210 commit b7ea577
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
14 changes: 14 additions & 0 deletions qlty-check/src/executor/invocation_script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub fn compute_invocation_script(plan: &InvocationPlan) -> Result<String> {

// Autoload script first in case it has variables that need to be interpolated
base_script = replace_autoload_script(plan, base_script);
base_script = replace_config_script(plan, base_script);
base_script = plan.tool.interpolate_variables(&base_script);
base_script = replace_target_variable(plan, base_script);
base_script = replace_tmpfile_variable(plan, base_script);
Expand All @@ -39,6 +40,19 @@ fn replace_autoload_script(plan: &InvocationPlan, script: String) -> String {
}
}

fn replace_config_script(plan: &InvocationPlan, script: String) -> String {
if script.contains("${config_script}") {
if !plan.plugin_configs.is_empty() {
let config_script = plan.driver.config_script.as_deref().unwrap_or("");
script.replace("${config_script}", config_script)
} else {
script.replace("${config_script}", "")
}
} else {
script
}
}

fn replace_target_variable(plan: &InvocationPlan, script: String) -> String {
if script.contains("${target}") {
let targets_list = plan_target_list(plan);
Expand Down
3 changes: 3 additions & 0 deletions qlty-config/src/config/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ pub struct DriverDef {

#[serde(default)]
pub autoload_script: Option<String>,

#[serde(default)]
pub config_script: Option<String>,
}

fn default_driver_timeout() -> u64 {
Expand Down
4 changes: 3 additions & 1 deletion qlty-plugins/plugins/linters/phpstan/plugin.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ description = "PHP code linter"
suggested = "targets"

[plugins.definitions.phpstan.drivers.lint]
script = "php -d memory_limit=-1 ${linter}/phpstan analyze ${target} --error-format=json --level=9 ${autoload_script}"
script = "php -d memory_limit=-1 ${linter}/phpstan analyze ${target} --error-format=json --level=9 ${autoload_script} ${config_script}"
autoload_script = "--autoload-file=${linter}/vendor/autoload.php"
config_script = "--configuration=${config_file}"
success_codes = [0, 1]
output = "stdout"
output_format = "phpstan"
cache_results = true
batch = true
suggested = "targets"
output_missing = "parse"
copy_configs_into_tool_install = true

0 comments on commit b7ea577

Please sign in to comment.