Repository navigation
fix(analyser): check fixes of statements with placeholders with parameters - #1037
Merged
Merged
Conversation
…eters The guard from #906 parsed the fixed statement as written, so a statement with a psql variable (:name, :'name', :"name", $name) never parsed and lost all of its fixes. It now converts the placeholders to parameters first, like the statement itself is parsed. The spec harness parses the same way.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Since #906,
Analyser::analyseonly keeps a fix if the fixed statement still parses. The check parsed the statement as written. The linter itself first converts placeholders to parameters (pgls_lexer::convert_to_positional_params, which the workspace runs before parsing each statement). So a statement with a psql variable never passed the check, and lost every fix:keeps_statement_validnow parses the fixed statement with its placeholders converted, the same way the statement was parsed. The conversion keeps the text length, so the edits apply unchanged. The placeholders stay as written in the fixed file, because the fix is applied to the source, not to the converted text.pgls_lexermoves from a dev-dependency ofpgls_analyserto a normal dependency. It depends only on the tokenizer and the text crates, so there's no cycle, and the WASM build already pulls it in through the workspace.The spec harness (
rules_tests.rs) now parses statements the way the workspace does: placeholders converted, withwith_identifier_parametersset. Its "a fix must keep the input valid" assertion uses the same conversion, so specs can contain psql variables. No existing snapshot changes.Tests
fixes_of_statements_with_placeholders_are_checked_with_parameters::name,:'name',$nameand:"name". A valid fix is kept and a broken one is still dropped.requireConcurrentIndexCreation/fix_psql_variables(value placeholders in aWHERE) andconstraintMissingNotValid/fix_psql_variables(an identifier placeholder as the schema). Both now show the fix.test_fix_file_fixes_statements_with_psql_variables:fix_fileaddsCONCURRENTLYand keeps:"schema",:'tenant'and$planas written.cargo test -p pgls_analyser -p pgls_workspace(including the Postgres regression test),cargo clippy -p pgls_analyser -p pgls_workspace --all-targets -- -D warnings.Not covered
${...}expansions only exist with feat(workspace): analyse goose ENVSUB expansions as parameters #949, which isn't merged, so there's no test for them here. With feat(workspace): analyse goose ENVSUB expansions as parameters #949, the document already replaces an expansion with a$NAMEplaceholder before parsing, so this change would let those statements get fixes again. feat(workspace): analyse goose ENVSUB expansions as parameters #949 also drops fixes that edit inside an expansion, and itstest_goose_envsub_expansions_stay_as_writtenexpects no fixes at all. Whichever PR merges second needs to update that test and the line in the migrations guide.Update: merged main after #1044, which replaced
keeps_statement_validwithkeeps_sql_valid. Both of its paths now parse with placeholders converted, through a smallparseshelper: the fix applied to the statement, and for a fix that edits after its statement, the file text with and without the fix. Before, a file with a placeholder never passed the "parses without the fix" guard, so such fixes were kept unchecked. New tests: unitfixes_after_statements_with_placeholders_are_checked_with_parameters, and specbanUncommittedTransaction/no_semicolon_at_the_end_psql_variables(the invalidcommit;fix is dropped; without the conversion in the guard, the harness fails with "produces invalid SQL"). This also covers the L1 point under "Not covered".