ast-grep-cli 0.45.2__tar.gz → 0.45.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/Cargo.lock +14 -15
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/Cargo.toml +8 -8
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/PKG-INFO +1 -1
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/cli/src/config.rs +1 -1
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/cli/src/scan.rs +7 -1
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/cli/src/utils/args.rs +9 -1
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/cli/src/utils/debug_query.rs +9 -1
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/cli/src/utils/rule_overwrite.rs +28 -5
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/cli/tests/run_test.rs +34 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/cli/tests/scan_test.rs +128 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/config/src/combined.rs +40 -1
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/config/src/rule_config.rs +20 -3
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/core/src/replacer/template.rs +29 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/core/src/tree_sitter/mod.rs +1 -1
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/outline/src/default_rule.rs +2 -0
- ast_grep_cli-0.45.3/crates/outline/src/default_rules/markdown.yml +31 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/outline/src/extractor.rs +111 -4
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/outline/tests/default_outline_rules.rs +1 -0
- ast_grep_cli-0.45.3/crates/outline/tests/fixtures/markdown_headings.md +18 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/outline/tests/javascript_outline_rules.rs +19 -0
- ast_grep_cli-0.45.3/crates/outline/tests/markdown_outline_rules.rs +24 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/outline/tests/typescript_outline_rules.rs +19 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/pyproject.toml +1 -1
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/LICENSE +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/README.md +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/cli/Cargo.toml +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/cli/README.md +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/cli/src/bin/alias.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/cli/src/completions.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/cli/src/lang/injection.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/cli/src/lang/lang_globs.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/cli/src/lang/mod.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/cli/src/lib.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/cli/src/lsp.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/cli/src/main.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/cli/src/new.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/cli/src/outline/extract.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/cli/src/outline/options.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/cli/src/outline/output/tests.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/cli/src/outline/output.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/cli/src/outline.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/cli/src/print/cloud_print.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/cli/src/print/colored_print/markdown.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/cli/src/print/colored_print/match_merger.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/cli/src/print/colored_print/styles.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/cli/src/print/colored_print/test.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/cli/src/print/colored_print.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/cli/src/print/file_name_printer.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/cli/src/print/interactive_print.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/cli/src/print/json_print.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/cli/src/print/mod.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/cli/src/run.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/cli/src/utils/error_context.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/cli/src/utils/inspect.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/cli/src/utils/mod.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/cli/src/utils/print_diff.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/cli/src/utils/worker.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/cli/src/verify/case_result.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/cli/src/verify/find_file.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/cli/src/verify/reporter.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/cli/src/verify/snapshot.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/cli/src/verify/test_case.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/cli/src/verify.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/cli/tests/common/mod.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/cli/tests/help_test.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/cli/tests/verify_test.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/config/Cargo.toml +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/config/src/check_var.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/config/src/fixer.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/config/src/label.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/config/src/lib.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/config/src/maybe.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/config/src/rewriter.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/config/src/rule/deserialize_env.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/config/src/rule/mod.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/config/src/rule/nth_child.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/config/src/rule/parameterized_util.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/config/src/rule/range.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/config/src/rule/referent_rule.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/config/src/rule/relational_rule.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/config/src/rule/selector.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/config/src/rule/stop_by.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/config/src/rule_collection.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/config/src/rule_core.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/config/src/transform/mod.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/config/src/transform/parse.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/config/src/transform/rewrite.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/config/src/transform/string_case.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/config/src/transform/trans.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/core/Cargo.toml +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/core/src/language.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/core/src/lib.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/core/src/match_tree/match_node.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/core/src/match_tree/mod.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/core/src/match_tree/strictness.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/core/src/matcher/kind.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/core/src/matcher/node_match.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/core/src/matcher/pattern.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/core/src/matcher/text.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/core/src/matcher.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/core/src/meta_var.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/core/src/node.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/core/src/ops.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/core/src/pinned.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/core/src/replacer/indent.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/core/src/replacer/structural.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/core/src/replacer.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/core/src/source.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/core/src/tree_sitter/traversal.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/dynamic/Cargo.toml +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/dynamic/src/custom_lang.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/dynamic/src/lib.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/language/Cargo.toml +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/language/src/bash.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/language/src/cpp.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/language/src/csharp.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/language/src/css.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/language/src/dart.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/language/src/elixir.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/language/src/go.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/language/src/haskell.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/language/src/hcl.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/language/src/html.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/language/src/json.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/language/src/kotlin.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/language/src/lib.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/language/src/lua.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/language/src/markdown.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/language/src/nix.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/language/src/parsers.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/language/src/php.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/language/src/python.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/language/src/ruby.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/language/src/rust.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/language/src/scala.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/language/src/solidity.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/language/src/swift.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/language/src/yaml.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/lsp/Cargo.toml +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/lsp/src/lib.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/lsp/src/utils.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/lsp/tests/basic.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/outline/Cargo.toml +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/outline/src/combined_extractor.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/outline/src/default_rules/c.yml +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/outline/src/default_rules/cpp.yml +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/outline/src/default_rules/csharp.yml +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/outline/src/default_rules/go.yml +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/outline/src/default_rules/java.yml +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/outline/src/default_rules/javascript.yml +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/outline/src/default_rules/kotlin.yml +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/outline/src/default_rules/php.yml +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/outline/src/default_rules/python.yml +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/outline/src/default_rules/ruby.yml +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/outline/src/default_rules/rust.yml +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/outline/src/default_rules/swift.yml +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/outline/src/default_rules/typescript.yml +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/outline/src/lib.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/outline/src/model.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/outline/src/options.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/outline/tests/c_family_outline_rules.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/outline/tests/common/mod.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/outline/tests/jvm_swift_outline_rules.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/outline/tests/python_go_outline_rules.rs +0 -0
- {ast_grep_cli-0.45.2 → ast_grep_cli-0.45.3}/crates/outline/tests/ruby_php_outline_rules.rs +0 -0
|
@@ -103,7 +103,7 @@ dependencies = [
|
|
|
103
103
|
|
|
104
104
|
[[package]]
|
|
105
105
|
name = "ast-grep"
|
|
106
|
-
version = "0.45.
|
|
106
|
+
version = "0.45.3"
|
|
107
107
|
dependencies = [
|
|
108
108
|
"ansi_term",
|
|
109
109
|
"anyhow",
|
|
@@ -139,7 +139,7 @@ dependencies = [
|
|
|
139
139
|
|
|
140
140
|
[[package]]
|
|
141
141
|
name = "ast-grep-config"
|
|
142
|
-
version = "0.45.
|
|
142
|
+
version = "0.45.3"
|
|
143
143
|
dependencies = [
|
|
144
144
|
"ast-grep-core",
|
|
145
145
|
"bit-set",
|
|
@@ -155,7 +155,7 @@ dependencies = [
|
|
|
155
155
|
|
|
156
156
|
[[package]]
|
|
157
157
|
name = "ast-grep-core"
|
|
158
|
-
version = "0.45.
|
|
158
|
+
version = "0.45.3"
|
|
159
159
|
dependencies = [
|
|
160
160
|
"bit-set",
|
|
161
161
|
"regex",
|
|
@@ -166,7 +166,7 @@ dependencies = [
|
|
|
166
166
|
|
|
167
167
|
[[package]]
|
|
168
168
|
name = "ast-grep-dynamic"
|
|
169
|
-
version = "0.45.
|
|
169
|
+
version = "0.45.3"
|
|
170
170
|
dependencies = [
|
|
171
171
|
"ast-grep-core",
|
|
172
172
|
"ignore",
|
|
@@ -180,7 +180,7 @@ dependencies = [
|
|
|
180
180
|
|
|
181
181
|
[[package]]
|
|
182
182
|
name = "ast-grep-language"
|
|
183
|
-
version = "0.45.
|
|
183
|
+
version = "0.45.3"
|
|
184
184
|
dependencies = [
|
|
185
185
|
"ast-grep-core",
|
|
186
186
|
"ignore",
|
|
@@ -217,7 +217,7 @@ dependencies = [
|
|
|
217
217
|
|
|
218
218
|
[[package]]
|
|
219
219
|
name = "ast-grep-lsp"
|
|
220
|
-
version = "0.45.
|
|
220
|
+
version = "0.45.3"
|
|
221
221
|
dependencies = [
|
|
222
222
|
"anyhow",
|
|
223
223
|
"ast-grep-config",
|
|
@@ -235,7 +235,7 @@ dependencies = [
|
|
|
235
235
|
|
|
236
236
|
[[package]]
|
|
237
237
|
name = "ast-grep-napi"
|
|
238
|
-
version = "0.45.
|
|
238
|
+
version = "0.45.3"
|
|
239
239
|
dependencies = [
|
|
240
240
|
"ast-grep-config",
|
|
241
241
|
"ast-grep-core",
|
|
@@ -251,7 +251,7 @@ dependencies = [
|
|
|
251
251
|
|
|
252
252
|
[[package]]
|
|
253
253
|
name = "ast-grep-outline"
|
|
254
|
-
version = "0.45.
|
|
254
|
+
version = "0.45.3"
|
|
255
255
|
dependencies = [
|
|
256
256
|
"ast-grep-config",
|
|
257
257
|
"ast-grep-core",
|
|
@@ -265,7 +265,7 @@ dependencies = [
|
|
|
265
265
|
|
|
266
266
|
[[package]]
|
|
267
267
|
name = "ast-grep-py"
|
|
268
|
-
version = "0.45.
|
|
268
|
+
version = "0.45.3"
|
|
269
269
|
dependencies = [
|
|
270
270
|
"anyhow",
|
|
271
271
|
"ast-grep-config",
|
|
@@ -2100,13 +2100,12 @@ dependencies = [
|
|
|
2100
2100
|
|
|
2101
2101
|
[[package]]
|
|
2102
2102
|
name = "tree-sitter"
|
|
2103
|
-
version = "0.
|
|
2103
|
+
version = "0.27.0"
|
|
2104
2104
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
2105
|
-
checksum = "
|
|
2105
|
+
checksum = "2038684e0058edba0d17302619f62eabce4a8e11c6ac59506996a8d79848851d"
|
|
2106
2106
|
dependencies = [
|
|
2107
2107
|
"cc",
|
|
2108
2108
|
"regex",
|
|
2109
|
-
"regex-syntax",
|
|
2110
2109
|
"serde_json",
|
|
2111
2110
|
"streaming-iterator",
|
|
2112
2111
|
"tree-sitter-language",
|
|
@@ -2264,9 +2263,9 @@ dependencies = [
|
|
|
2264
2263
|
|
|
2265
2264
|
[[package]]
|
|
2266
2265
|
name = "tree-sitter-language"
|
|
2267
|
-
version = "0.1.
|
|
2266
|
+
version = "0.1.8"
|
|
2268
2267
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
2269
|
-
checksum = "
|
|
2268
|
+
checksum = "ca0d1bf6fdd806e43ae5198f82f527056d359def39e54e67a0f478ac09dac081"
|
|
2270
2269
|
|
|
2271
2270
|
[[package]]
|
|
2272
2271
|
name = "tree-sitter-lua"
|
|
@@ -2487,7 +2486,7 @@ checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b"
|
|
|
2487
2486
|
|
|
2488
2487
|
[[package]]
|
|
2489
2488
|
name = "wasm"
|
|
2490
|
-
version = "0.45.
|
|
2489
|
+
version = "0.45.3"
|
|
2491
2490
|
dependencies = [
|
|
2492
2491
|
"ast-grep-config",
|
|
2493
2492
|
"ast-grep-core",
|
|
@@ -6,7 +6,7 @@ resolver = "2"
|
|
|
6
6
|
lto = true
|
|
7
7
|
|
|
8
8
|
[workspace.package]
|
|
9
|
-
version = "0.45.
|
|
9
|
+
version = "0.45.3"
|
|
10
10
|
authors = ["Herrington Darkholme <2883231+HerringtonDarkholme@users.noreply.github.com>"]
|
|
11
11
|
edition = "2024"
|
|
12
12
|
license = "MIT"
|
|
@@ -17,12 +17,12 @@ rust-version = "1.88.0"
|
|
|
17
17
|
readme = "README.md"
|
|
18
18
|
|
|
19
19
|
[workspace.dependencies]
|
|
20
|
-
ast-grep-core = { path = "crates/core", version = "0.45.
|
|
21
|
-
ast-grep-config = { path = "crates/config", version = "0.45.
|
|
22
|
-
ast-grep-dynamic = { path = "crates/dynamic", version = "0.45.
|
|
23
|
-
ast-grep-language = { path = "crates/language", version = "0.45.
|
|
24
|
-
ast-grep-lsp = { path = "crates/lsp", version = "0.45.
|
|
25
|
-
ast-grep-outline = { path = "crates/outline", version = "0.45.
|
|
20
|
+
ast-grep-core = { path = "crates/core", version = "0.45.3", default-features = false }
|
|
21
|
+
ast-grep-config = { path = "crates/config", version = "0.45.3" }
|
|
22
|
+
ast-grep-dynamic = { path = "crates/dynamic", version = "0.45.3" }
|
|
23
|
+
ast-grep-language = { path = "crates/language", version = "0.45.3" }
|
|
24
|
+
ast-grep-lsp = { path = "crates/lsp", version = "0.45.3" }
|
|
25
|
+
ast-grep-outline = { path = "crates/outline", version = "0.45.3" }
|
|
26
26
|
|
|
27
27
|
bit-set = { version = "0.11.0" }
|
|
28
28
|
ignore = { version = "0.4.22" }
|
|
@@ -30,7 +30,7 @@ regex = { version = "1.10.4" }
|
|
|
30
30
|
serde = { version = "1.0.200", features = ["derive"] }
|
|
31
31
|
serde_regex = "1.2.0"
|
|
32
32
|
serde_yaml = "0.9.33"
|
|
33
|
-
tree-sitter = { version = "0.
|
|
33
|
+
tree-sitter = { version = "0.27.0" }
|
|
34
34
|
thiserror = "2.0.0"
|
|
35
35
|
schemars = "1.0.0"
|
|
36
36
|
anyhow = "1.0.82"
|
|
@@ -103,7 +103,7 @@ impl ProjectConfig {
|
|
|
103
103
|
custom_language_outline_rules(&project_dir, sg_config.custom_languages.as_ref());
|
|
104
104
|
let config = ProjectConfig {
|
|
105
105
|
project_dir,
|
|
106
|
-
rule_dirs: sg_config.rule_dirs
|
|
106
|
+
rule_dirs: std::mem::take(&mut sg_config.rule_dirs),
|
|
107
107
|
outline_rules,
|
|
108
108
|
test_configs: sg_config.test_configs.take(),
|
|
109
109
|
util_dirs: sg_config.util_dirs.take(),
|
|
@@ -217,6 +217,7 @@ fn no_suppress_all_rule_config(overwrite: &RuleOverwrite) -> RuleConfig<SgLang>
|
|
|
217
217
|
.find(NO_SUPPRESS_ALL_ID)
|
|
218
218
|
.severity
|
|
219
219
|
.unwrap_or(Severity::Off);
|
|
220
|
+
let severity = overwrite.apply_min_severity(severity);
|
|
220
221
|
CombinedScan::no_suppress_all_config(severity, SupportLang::Rust.into())
|
|
221
222
|
}
|
|
222
223
|
|
|
@@ -225,6 +226,7 @@ fn unused_suppression_rule_config(arg: &ScanArg, overwrite: &RuleOverwrite) -> R
|
|
|
225
226
|
.find(UNUSED_SUPPRESSION_ID)
|
|
226
227
|
.severity
|
|
227
228
|
.unwrap_or_else(|| default_unused_suppression_rule_severity(arg));
|
|
229
|
+
let severity = overwrite.apply_min_severity(severity);
|
|
228
230
|
CombinedScan::unused_config(severity, SupportLang::Rust.into())
|
|
229
231
|
}
|
|
230
232
|
|
|
@@ -356,7 +358,10 @@ impl StdInWorker for ScanStdin {
|
|
|
356
358
|
processor: &P::Processor,
|
|
357
359
|
) -> Result<Vec<P::Processed>> {
|
|
358
360
|
use ast_grep_core::tree_sitter::LanguageExt;
|
|
359
|
-
let
|
|
361
|
+
let Some(first_rule) = self.rules.first() else {
|
|
362
|
+
return Ok(vec![]);
|
|
363
|
+
};
|
|
364
|
+
let lang = first_rule.language;
|
|
360
365
|
let combined = CombinedScan::new(self.rules.iter().collect());
|
|
361
366
|
let grep = lang.ast_grep(src);
|
|
362
367
|
let path = Path::new("STDIN");
|
|
@@ -476,6 +481,7 @@ rule:
|
|
|
476
481
|
},
|
|
477
482
|
overwrite: OverwriteArgs {
|
|
478
483
|
filter: None,
|
|
484
|
+
min_severity: Severity::Off,
|
|
479
485
|
error: None,
|
|
480
486
|
warning: None,
|
|
481
487
|
info: None,
|
|
@@ -4,6 +4,7 @@ use crate::utils::ErrorContext as EC;
|
|
|
4
4
|
use crate::utils::Granularity;
|
|
5
5
|
|
|
6
6
|
use anyhow::{Context, Result};
|
|
7
|
+
use ast_grep_config::Severity;
|
|
7
8
|
use clap::{Args, ValueEnum};
|
|
8
9
|
use ignore::{
|
|
9
10
|
WalkBuilder, WalkParallel,
|
|
@@ -300,6 +301,13 @@ pub struct OverwriteArgs {
|
|
|
300
301
|
/// set of rule definitions within a project.
|
|
301
302
|
#[clap(long, conflicts_with = "rule", value_name = "REGEX")]
|
|
302
303
|
pub filter: Option<Regex>,
|
|
304
|
+
|
|
305
|
+
/// Set the minimum severity of rules to scan.
|
|
306
|
+
///
|
|
307
|
+
/// Rules with severity lower than the specified value will be ignored.
|
|
308
|
+
#[clap(long, value_name = "SEVERITY", default_value = "off")]
|
|
309
|
+
pub min_severity: Severity,
|
|
310
|
+
|
|
303
311
|
/// Set rule severity to error
|
|
304
312
|
///
|
|
305
313
|
/// This flag sets the specified RULE_ID's severity to error. You can specify multiple rules by using the flag multiple times,
|
|
@@ -340,7 +348,7 @@ pub struct OverwriteArgs {
|
|
|
340
348
|
impl OverwriteArgs {
|
|
341
349
|
/// Returns true if none rule is turned off on CLI nor filtered out
|
|
342
350
|
pub fn include_all_rules(&self) -> bool {
|
|
343
|
-
self.filter.is_none() && self.off.is_none()
|
|
351
|
+
self.filter.is_none() && self.off.is_none() && self.min_severity == Severity::Off
|
|
344
352
|
}
|
|
345
353
|
}
|
|
346
354
|
|
|
@@ -19,7 +19,15 @@ pub enum DebugFormat {
|
|
|
19
19
|
|
|
20
20
|
fn get_mapping(lang: SgLang) -> impl Fn(u16) -> Option<Cow<'static, str>> {
|
|
21
21
|
let ts_lang = lang.get_ts_language();
|
|
22
|
-
move |kind_id: u16|
|
|
22
|
+
move |kind_id: u16| {
|
|
23
|
+
// tree-sitter is doing shitty lifetime for the fuck sake of wasm
|
|
24
|
+
// the lifetime here does NOT reflect the actual tslanguage, tslanguage is Copy
|
|
25
|
+
// change lifetime to ts_lang's does NOT solve the problem, ts_lang is used as local var too many times
|
|
26
|
+
// https://github.com/tree-sitter/tree-sitter/commit/c68605f18d0e46a653f2ed89b02a6fab93dffac0
|
|
27
|
+
ts_lang
|
|
28
|
+
.node_kind_for_id(kind_id)
|
|
29
|
+
.map(|s| Cow::Owned(s.to_owned()))
|
|
30
|
+
}
|
|
23
31
|
}
|
|
24
32
|
|
|
25
33
|
impl DebugFormat {
|
|
@@ -14,6 +14,7 @@ pub struct RuleOverwrite {
|
|
|
14
14
|
default_severity: Option<Severity>,
|
|
15
15
|
by_rule_id: HashMap<String, Severity>,
|
|
16
16
|
rule_filter: Option<Regex>,
|
|
17
|
+
min_severity: Severity,
|
|
17
18
|
}
|
|
18
19
|
|
|
19
20
|
fn read_severity(
|
|
@@ -42,6 +43,7 @@ impl RuleOverwrite {
|
|
|
42
43
|
},
|
|
43
44
|
by_rule_id: HashMap::new(),
|
|
44
45
|
rule_filter: filter.cloned(),
|
|
46
|
+
min_severity: Severity::Off,
|
|
45
47
|
}
|
|
46
48
|
}
|
|
47
49
|
pub fn new(cli: &OverwriteArgs) -> Result<Self> {
|
|
@@ -81,6 +83,7 @@ impl RuleOverwrite {
|
|
|
81
83
|
default_severity,
|
|
82
84
|
by_rule_id,
|
|
83
85
|
rule_filter: cli.filter.clone(),
|
|
86
|
+
min_severity: cli.min_severity.clone(),
|
|
84
87
|
})
|
|
85
88
|
}
|
|
86
89
|
|
|
@@ -88,18 +91,30 @@ impl RuleOverwrite {
|
|
|
88
91
|
&self,
|
|
89
92
|
configs: Vec<RuleConfig<SgLang>>,
|
|
90
93
|
) -> Result<Vec<RuleConfig<SgLang>>> {
|
|
91
|
-
let
|
|
94
|
+
let configs = if let Some(filter) = &self.rule_filter {
|
|
92
95
|
filter_rule_by_regex(configs, filter)?
|
|
93
96
|
} else {
|
|
94
97
|
configs
|
|
95
98
|
};
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
99
|
+
let configs = configs
|
|
100
|
+
.into_iter()
|
|
101
|
+
.filter_map(|config| self.process_one_config(config))
|
|
102
|
+
.collect();
|
|
100
103
|
Ok(configs)
|
|
101
104
|
}
|
|
102
105
|
|
|
106
|
+
fn process_one_config(&self, mut config: RuleConfig<SgLang>) -> Option<RuleConfig<SgLang>> {
|
|
107
|
+
// overwrite severity
|
|
108
|
+
let overwrite = self.find(&config.id);
|
|
109
|
+
overwrite.overwrite(&mut config);
|
|
110
|
+
// remove rules that are below min_severity
|
|
111
|
+
if config.severity >= self.min_severity {
|
|
112
|
+
Some(config)
|
|
113
|
+
} else {
|
|
114
|
+
None
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
103
118
|
pub fn find(&self, id: &str) -> OverwriteResult {
|
|
104
119
|
let severity = self
|
|
105
120
|
.by_rule_id
|
|
@@ -108,6 +123,14 @@ impl RuleOverwrite {
|
|
|
108
123
|
.or_else(|| self.default_severity.clone());
|
|
109
124
|
OverwriteResult { severity }
|
|
110
125
|
}
|
|
126
|
+
|
|
127
|
+
pub fn apply_min_severity(&self, severity: Severity) -> Severity {
|
|
128
|
+
if severity >= self.min_severity {
|
|
129
|
+
severity
|
|
130
|
+
} else {
|
|
131
|
+
Severity::Off
|
|
132
|
+
}
|
|
133
|
+
}
|
|
111
134
|
}
|
|
112
135
|
|
|
113
136
|
fn filter_rule_by_regex(
|
|
@@ -137,6 +137,40 @@ export function greet(name: string) {
|
|
|
137
137
|
Ok(())
|
|
138
138
|
}
|
|
139
139
|
|
|
140
|
+
#[test]
|
|
141
|
+
fn test_outline_markdown_headings() -> Result<()> {
|
|
142
|
+
let dir = create_test_files([(
|
|
143
|
+
"guide.md",
|
|
144
|
+
r#"# Introduction
|
|
145
|
+
|
|
146
|
+
Usage
|
|
147
|
+
=====
|
|
148
|
+
|
|
149
|
+
###### Details
|
|
150
|
+
|
|
151
|
+
References
|
|
152
|
+
----------
|
|
153
|
+
|
|
154
|
+
```markdown
|
|
155
|
+
# Not a heading
|
|
156
|
+
```
|
|
157
|
+
"#,
|
|
158
|
+
)])?;
|
|
159
|
+
|
|
160
|
+
Command::new(cargo_bin!())
|
|
161
|
+
.current_dir(dir.path())
|
|
162
|
+
.args(["outline", "guide.md", "--json=compact"])
|
|
163
|
+
.assert()
|
|
164
|
+
.success()
|
|
165
|
+
.stdout(contains(r#""language":"Markdown""#))
|
|
166
|
+
.stdout(contains(r#""name":"Introduction""#))
|
|
167
|
+
.stdout(contains(r#""name":"Usage""#))
|
|
168
|
+
.stdout(contains(r#""name":"Details""#))
|
|
169
|
+
.stdout(contains(r#""name":"References""#))
|
|
170
|
+
.stdout(contains(r#""name":"Not a heading""#).not());
|
|
171
|
+
Ok(())
|
|
172
|
+
}
|
|
173
|
+
|
|
140
174
|
#[test]
|
|
141
175
|
fn test_rewrite_js_in_html() -> Result<()> {
|
|
142
176
|
let dir = create_test_files([("a.html", "<script>alert(1)</script>")])?;
|
|
@@ -34,6 +34,32 @@ rule:
|
|
|
34
34
|
pattern: Some($A)
|
|
35
35
|
";
|
|
36
36
|
|
|
37
|
+
const SEVERITY_RULES: &str = "
|
|
38
|
+
id: hint-rule
|
|
39
|
+
message: hint rule
|
|
40
|
+
severity: hint
|
|
41
|
+
language: TypeScript
|
|
42
|
+
rule: { pattern: Some($A) }
|
|
43
|
+
---
|
|
44
|
+
id: info-rule
|
|
45
|
+
message: info rule
|
|
46
|
+
severity: info
|
|
47
|
+
language: TypeScript
|
|
48
|
+
rule: { pattern: Some($A) }
|
|
49
|
+
---
|
|
50
|
+
id: warning-rule
|
|
51
|
+
message: warning rule
|
|
52
|
+
severity: warning
|
|
53
|
+
language: TypeScript
|
|
54
|
+
rule: { pattern: Some($A) }
|
|
55
|
+
---
|
|
56
|
+
id: error-rule
|
|
57
|
+
message: error rule
|
|
58
|
+
severity: error
|
|
59
|
+
language: TypeScript
|
|
60
|
+
rule: { pattern: Some($A) }
|
|
61
|
+
";
|
|
62
|
+
|
|
37
63
|
const FIXABLE_JS_RULE: &str = "
|
|
38
64
|
id: no-var
|
|
39
65
|
message: use let
|
|
@@ -299,6 +325,108 @@ fn test_severity_override() -> Result<()> {
|
|
|
299
325
|
Ok(())
|
|
300
326
|
}
|
|
301
327
|
|
|
328
|
+
#[test]
|
|
329
|
+
fn test_severity_threshold_filters_output_and_rule_tally() -> Result<()> {
|
|
330
|
+
let dir = create_test_files([
|
|
331
|
+
("sgconfig.yml", CONFIG),
|
|
332
|
+
("rules/severity.yml", SEVERITY_RULES),
|
|
333
|
+
("test.ts", "Some(123)"),
|
|
334
|
+
])?;
|
|
335
|
+
Command::new(cargo_bin!())
|
|
336
|
+
.current_dir(dir.path())
|
|
337
|
+
.args([
|
|
338
|
+
"scan",
|
|
339
|
+
"--min-severity",
|
|
340
|
+
"warning",
|
|
341
|
+
"--color=never",
|
|
342
|
+
"--report-style=short",
|
|
343
|
+
"--inspect=summary",
|
|
344
|
+
])
|
|
345
|
+
.assert()
|
|
346
|
+
.failure()
|
|
347
|
+
.stdout(contains("error-rule"))
|
|
348
|
+
.stdout(contains("warning-rule"))
|
|
349
|
+
.stdout(contains("info-rule").not())
|
|
350
|
+
.stdout(contains("hint-rule").not())
|
|
351
|
+
.stderr(contains("effectiveRuleCount=2,skippedRuleCount=2"))
|
|
352
|
+
.stderr(contains("1 error(s) found in code"));
|
|
353
|
+
Ok(())
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
#[test]
|
|
357
|
+
fn test_severity_threshold_uses_overwritten_severity() -> Result<()> {
|
|
358
|
+
let dir = create_test_files([
|
|
359
|
+
("sgconfig.yml", CONFIG),
|
|
360
|
+
("rules/severity.yml", SEVERITY_RULES),
|
|
361
|
+
("test.ts", "Some(123)"),
|
|
362
|
+
])?;
|
|
363
|
+
|
|
364
|
+
Command::new(cargo_bin!())
|
|
365
|
+
.current_dir(dir.path())
|
|
366
|
+
.args([
|
|
367
|
+
"scan",
|
|
368
|
+
"--min-severity=error",
|
|
369
|
+
"--warning=error-rule",
|
|
370
|
+
"--json=compact",
|
|
371
|
+
])
|
|
372
|
+
.assert()
|
|
373
|
+
.success()
|
|
374
|
+
.stdout(contains("error-rule").not());
|
|
375
|
+
Ok(())
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
#[test]
|
|
379
|
+
fn test_min_severity_filters_all_stdin_rules() -> Result<()> {
|
|
380
|
+
let inline_rule =
|
|
381
|
+
"{id: hint-rule, severity: hint, language: ts, rule: {pattern: console.log($A)}}";
|
|
382
|
+
Command::new(cargo_bin!())
|
|
383
|
+
.args([
|
|
384
|
+
"scan",
|
|
385
|
+
"--stdin",
|
|
386
|
+
"--min-severity=warning",
|
|
387
|
+
"--inline-rules",
|
|
388
|
+
inline_rule,
|
|
389
|
+
"--json=compact",
|
|
390
|
+
])
|
|
391
|
+
.write_stdin("console.log(123)")
|
|
392
|
+
.assert()
|
|
393
|
+
.success()
|
|
394
|
+
.stdout(predicate::eq("[]\n"));
|
|
395
|
+
Ok(())
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
#[test]
|
|
399
|
+
fn test_min_severity_filters_builtin_rules() -> Result<()> {
|
|
400
|
+
let unused = create_test_files([
|
|
401
|
+
("sgconfig.yml", CONFIG),
|
|
402
|
+
("rules/rule.yml", RULE1),
|
|
403
|
+
("test.ts", "None(123) // ast-grep-ignore"),
|
|
404
|
+
])?;
|
|
405
|
+
Command::new(cargo_bin!())
|
|
406
|
+
.current_dir(unused.path())
|
|
407
|
+
.args([
|
|
408
|
+
"scan",
|
|
409
|
+
"--min-severity=warning",
|
|
410
|
+
"--hint=unused-suppression",
|
|
411
|
+
])
|
|
412
|
+
.assert()
|
|
413
|
+
.success()
|
|
414
|
+
.stdout(contains("unused-suppression").not());
|
|
415
|
+
|
|
416
|
+
let suppress_all = create_test_files([
|
|
417
|
+
("sgconfig.yml", CONFIG),
|
|
418
|
+
("rules/rule.yml", RULE1),
|
|
419
|
+
("test.ts", "Some(123) // ast-grep-ignore"),
|
|
420
|
+
])?;
|
|
421
|
+
Command::new(cargo_bin!())
|
|
422
|
+
.current_dir(suppress_all.path())
|
|
423
|
+
.args(["scan", "--min-severity=error", "--warning=no-suppress-all"])
|
|
424
|
+
.assert()
|
|
425
|
+
.success()
|
|
426
|
+
.stdout(contains("no-suppress-all").not());
|
|
427
|
+
Ok(())
|
|
428
|
+
}
|
|
429
|
+
|
|
302
430
|
#[test]
|
|
303
431
|
fn test_severity_override_with_rule_path() -> Result<()> {
|
|
304
432
|
let dir = setup()?;
|
|
@@ -65,8 +65,21 @@ enum SuppressKind {
|
|
|
65
65
|
Line(usize),
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
+
fn is_suppression_comment(node: &Node<'_, impl Doc>) -> bool {
|
|
69
|
+
if !node.kind().contains("comment") {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
let text: &str = &node.text();
|
|
73
|
+
// ast-grep-ignore must be the first alphabetic text
|
|
74
|
+
// otherwise it is considered prose
|
|
75
|
+
let Some(start) = text.find(|c: char| c.is_alphabetic()) else {
|
|
76
|
+
return false;
|
|
77
|
+
};
|
|
78
|
+
text[start..].starts_with(IGNORE_TEXT)
|
|
79
|
+
}
|
|
80
|
+
|
|
68
81
|
fn get_suppression_kind(node: &Node<'_, impl Doc>) -> Option<SuppressKind> {
|
|
69
|
-
if !
|
|
82
|
+
if !is_suppression_comment(node) {
|
|
70
83
|
return None;
|
|
71
84
|
}
|
|
72
85
|
let line = node.start_pos().line();
|
|
@@ -559,6 +572,32 @@ language: Tsx",
|
|
|
559
572
|
});
|
|
560
573
|
}
|
|
561
574
|
|
|
575
|
+
#[test]
|
|
576
|
+
fn test_suppression_in_prose_is_not_reported_as_unused() {
|
|
577
|
+
let source = r#"
|
|
578
|
+
// This comment mentions ast-grep-ignore: as prose
|
|
579
|
+
console.log('must still match')
|
|
580
|
+
"#;
|
|
581
|
+
test_scan_unused(source, |scanned| {
|
|
582
|
+
assert_eq!(scanned.len(), 1);
|
|
583
|
+
assert_eq!(scanned[0].0.id, "test");
|
|
584
|
+
assert_eq!(scanned[0].1[0].text(), "console.log('must still match')");
|
|
585
|
+
});
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
#[test]
|
|
589
|
+
fn test_suppression_in_prose_does_not_suppress_matching_rule() {
|
|
590
|
+
let source = r#"
|
|
591
|
+
// This comment mentions ast-grep-ignore: test as prose
|
|
592
|
+
console.log('must still match')
|
|
593
|
+
"#;
|
|
594
|
+
test_scan_unused(source, |scanned| {
|
|
595
|
+
assert_eq!(scanned.len(), 1);
|
|
596
|
+
assert_eq!(scanned[0].0.id, "test");
|
|
597
|
+
assert_eq!(scanned[0].1[0].text(), "console.log('must still match')");
|
|
598
|
+
});
|
|
599
|
+
}
|
|
600
|
+
|
|
562
601
|
#[test]
|
|
563
602
|
fn test_file_suppression() {
|
|
564
603
|
let source = r#"// ast-grep-ignore: test
|
|
@@ -22,10 +22,15 @@ use thiserror::Error;
|
|
|
22
22
|
use std::borrow::Cow;
|
|
23
23
|
use std::collections::HashMap;
|
|
24
24
|
use std::ops::{Deref, DerefMut};
|
|
25
|
+
use std::str::FromStr;
|
|
25
26
|
|
|
26
|
-
#[derive(
|
|
27
|
+
#[derive(
|
|
28
|
+
Serialize, Deserialize, Clone, Default, JsonSchema, Debug, PartialOrd, Ord, PartialEq, Eq,
|
|
29
|
+
)]
|
|
27
30
|
#[serde(rename_all = "camelCase")]
|
|
28
31
|
pub enum Severity {
|
|
32
|
+
/// Turns off the rule.
|
|
33
|
+
Off,
|
|
29
34
|
#[default]
|
|
30
35
|
/// A kind reminder for code with potential improvement.
|
|
31
36
|
Hint,
|
|
@@ -35,8 +40,20 @@ pub enum Severity {
|
|
|
35
40
|
Warning,
|
|
36
41
|
/// An error that code produces bugs or has logic errors.
|
|
37
42
|
Error,
|
|
38
|
-
|
|
39
|
-
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
impl FromStr for Severity {
|
|
46
|
+
type Err = String;
|
|
47
|
+
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
|
48
|
+
match s.to_lowercase().as_str() {
|
|
49
|
+
"hint" => Ok(Severity::Hint),
|
|
50
|
+
"info" => Ok(Severity::Info),
|
|
51
|
+
"warning" => Ok(Severity::Warning),
|
|
52
|
+
"error" => Ok(Severity::Error),
|
|
53
|
+
"off" => Ok(Severity::Off),
|
|
54
|
+
_ => Err(format!("Invalid severity level: {}", s)),
|
|
55
|
+
}
|
|
56
|
+
}
|
|
40
57
|
}
|
|
41
58
|
|
|
42
59
|
#[derive(Debug, Error)]
|
|
@@ -35,6 +35,20 @@ impl TemplateFix {
|
|
|
35
35
|
};
|
|
36
36
|
template.vars.iter().map(|v| v.0.used_var()).collect()
|
|
37
37
|
}
|
|
38
|
+
|
|
39
|
+
/// Returns the node-backed metavariable when it is the entire template.
|
|
40
|
+
pub fn exact_node_var(&self) -> Option<&str> {
|
|
41
|
+
let TemplateFix::WithMetaVar(template) = self else {
|
|
42
|
+
return None;
|
|
43
|
+
};
|
|
44
|
+
if template.vars.len() != 1 {
|
|
45
|
+
return None;
|
|
46
|
+
}
|
|
47
|
+
match &template.vars[0].0 {
|
|
48
|
+
MetaVarExtract::Single(name) | MetaVarExtract::Multiple(name) => Some(name),
|
|
49
|
+
MetaVarExtract::Transformed(_) => None,
|
|
50
|
+
}
|
|
51
|
+
}
|
|
38
52
|
}
|
|
39
53
|
|
|
40
54
|
impl<D: Doc> Replacer<D> for TemplateFix {
|
|
@@ -326,6 +340,21 @@ if (true) {
|
|
|
326
340
|
assert_eq!(tf.used_vars(), ["B", "C"].into_iter().collect());
|
|
327
341
|
}
|
|
328
342
|
|
|
343
|
+
#[test]
|
|
344
|
+
fn test_exact_node_var() {
|
|
345
|
+
let exact = TemplateFix::try_new("$A", &Tsx).expect("ok");
|
|
346
|
+
assert_eq!(exact.exact_node_var(), Some("A"));
|
|
347
|
+
let exact_multi = TemplateFix::try_new("$$$A", &Tsx).expect("ok");
|
|
348
|
+
assert_eq!(exact_multi.exact_node_var(), Some("A"));
|
|
349
|
+
|
|
350
|
+
let surrounded = TemplateFix::try_new("prefix $A", &Tsx).expect("ok");
|
|
351
|
+
assert_eq!(surrounded.exact_node_var(), Some("A"));
|
|
352
|
+
let multiple = TemplateFix::try_new("$A$B", &Tsx).expect("ok");
|
|
353
|
+
assert_eq!(multiple.exact_node_var(), None);
|
|
354
|
+
let transformed = TemplateFix::with_transform("$A", &Tsx, &["A".to_string()]);
|
|
355
|
+
assert_eq!(transformed.exact_node_var(), None);
|
|
356
|
+
}
|
|
357
|
+
|
|
329
358
|
// GH #641
|
|
330
359
|
#[test]
|
|
331
360
|
fn test_multi_row_replace() {
|