dweiss commented on code in PR #14812:
URL: https://github.com/apache/lucene/pull/14812#discussion_r2156296401


##########
gradle/validation/ast-grep/rules/java-patterns.yml:
##########
@@ -0,0 +1,24 @@
+# Banned Lucene source patterns
+# Historically implemented as regexes which are more difficult
+---
+# yaml-language-server: 
$schema=https://raw.githubusercontent.com/ast-grep/ast-grep/refs/heads/main/schemas/java_rule.json
+id: java-lang-import
+language: java
+rule:
+  pattern: import java.lang.$REF
+  kind: import_declaration
+fix: ""
+severity: error
+message: unnecessary import of `$REF` from java.lang
+note: classes in java.lang are implicitly imported
+---
+# yaml-language-server: 
$schema=https://raw.githubusercontent.com/ast-grep/ast-grep/refs/heads/main/schemas/java_rule.json
+id: impossible-type-inference
+language: java
+# does the javac compiler allow this? did it ever?
+rule:
+  pattern: var $$$ = new $$$<>($$$)
+  kind: local_variable_declaration

Review Comment:
   I think this can actually be valid code, as in:
   ```
       var list = new ArrayList<String>();
       var foo = new ArrayList<>(list);
   ```
   which compiles just fine but breaks the rule. This pattern doesn't exist 
anywhere in Lucene - I'm actually surprised it doesn't - I use this quite a lot 
elsewhere.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org

Reply via email to