-
Notifications
You must be signed in to change notification settings - Fork 116
fix: Исправлены ложные срабатывания диагностик MagicNumber и MagicDate при работе со структурами #3542
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
WalkthroughAdds "Exceptions" documentation for MagicDate and MagicNumber; suppresses diagnostics for structure property assignments and certain structure method calls; enhances MagicDate diagnostic with stricter date validation, configuration handling, AST/symbol helpers and tests; adds findAssignmentContext helper in AbstractVisitorDiagnostic. Changes
Sequence Diagram(s)sequenceDiagram
participant V as Diagnostic Visitor
participant L as Literal / Expression
participant A as Assignment Finder
participant S as SymbolTree / Resolver
participant R as Reporter
V->>L: visitConstValue / visitString
V->>A: findAssignmentContext(ctx)
A-->>V: AssignmentContext or null
V->>S: resolve symbol/type (isVariableOfStructureType?)
alt structure property assignment or structure method call
V->>R: suppress diagnostic
Note right of R#DFF0D8: suppressed (structure-related)
else not structure-related
V->>V: validate literal (isValidDate / authorized/excluded)
alt valid & not excluded
V->>R: report diagnostic
Note right of R#F8E7D6: reported magic date/number
else
V->>R: no diagnostic
end
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (5 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnostic.java (1)
201-217: Consider simplifying the null-safety checks.The implementation correctly identifies structure property assignments by checking for
acceptor.accessProperty(). However, thelValue.isEmpty()check on line 212 may be redundant since an empty lValue would result in a null acceptor, which is already handled by theObjects::nonNullfilter on line 214.Consider this minor simplification:
private static boolean insideStructurePropertyAssignment(Optional<BSLParser.ExpressionContext> expression) { return expression .map(BSLParserRuleContext::getParent) // callParam .filter(context -> context.getChildCount() == 1) .map(BSLParserRuleContext::getParent) // callParamList .filter(context -> context.getChildCount() == 1) .map(BSLParserRuleContext::getParent) // doCall .map(BSLParserRuleContext::getParent) // assignment .filter(BSLParser.AssignmentContext.class::isInstance) .map(BSLParser.AssignmentContext.class::cast) .map(BSLParser.AssignmentContext::lValue) - .filter(lValue -> lValue != null && !lValue.isEmpty()) + .filter(Objects::nonNull) .map(BSLParser.LValueContext::acceptor) .filter(Objects::nonNull) .map(acceptor -> acceptor.accessProperty() != null) .orElse(false); }
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (7)
docs/diagnostics/MagicDate.md(1 hunks)docs/diagnostics/MagicNumber.md(2 hunks)docs/en/diagnostics/MagicDate.md(1 hunks)docs/en/diagnostics/MagicNumber.md(1 hunks)src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnostic.java(3 hunks)src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicNumberDiagnostic.java(1 hunks)src/main/resources/com/github/_1c_syntax/bsl/languageserver/configuration/schema.json(2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (12)
- GitHub Check: build (23, windows-latest)
- GitHub Check: build (21, ubuntu-latest)
- GitHub Check: build (23, ubuntu-latest)
- GitHub Check: build (23, macOS-latest)
- GitHub Check: build (21, macOS-latest)
- GitHub Check: build (17, ubuntu-latest)
- GitHub Check: build (21, windows-latest)
- GitHub Check: build (17, macOS-latest)
- GitHub Check: build (17, windows-latest)
- GitHub Check: build
- GitHub Check: Analyse
- GitHub Check: Benchmark
🔇 Additional comments (8)
src/main/resources/com/github/_1c_syntax/bsl/languageserver/configuration/schema.json (1)
924-929: LGTM! Formatting improvement.The enum arrays have been reformatted from single-line to multi-line for better readability. No semantic changes.
Also applies to: 933-939, 943-947, 978-983
docs/diagnostics/MagicNumber.md (1)
34-56: LGTM! Clear documentation of exception cases.The new "Exceptions" section effectively documents when the diagnostic does not trigger, with clear code examples for structure property assignments and method calls.
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnostic.java (2)
37-37: LGTM! Necessary import added.The
Objectsimport is used for the null-safety check in the newinsideStructurePropertyAssignmentmethod.
98-98: The implementation is incomplete and does not cover direct property assignments.My verification confirms the original review comment's concern. The
insideStructurePropertyAssignmentmethod traverses throughcallParam → callParamList → doCall → assignment, which only suppresses diagnostics when the magic date is inside a method call. However, it does not handle direct property assignments likeStructure.Property = '20240101'.Evidence:
- The implementation specifically requires
doCall(method call context) in the traversal path- Direct property assignments lack this intermediate node structure
- Test data file contains no test cases for direct property assignments
- The method only detects assignments where the RHS contains a method/function invocation, not bare value assignments
This gap means direct property assignments to structure properties will still trigger the diagnostic, contrary to what the review comment verified.
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicNumberDiagnostic.java (1)
129-160: Implementation is sound, but verify it's used correctly.The helper methods
isStructurePropertyAssignmentandfindAssignmentContextare well-implemented:
findAssignmentContextcorrectly traverses up the AST to find the nearestAssignmentContextisStructurePropertyAssignmentproperly checks for structure property access viaacceptor.accessProperty()However, the usage of this method in
isWrongExpression(line 121) may be incorrect. See the related comment on lines 118-123.docs/en/diagnostics/MagicDate.md (1)
39-60: LGTM! Clear exception documentation.The Exceptions section clearly documents the cases where the diagnostic does not trigger, with helpful code examples for both structure property assignments and method calls.
docs/diagnostics/MagicDate.md (1)
39-60: LGTM! Comprehensive exception documentation.The Exceptions section effectively documents when the MagicDate diagnostic does not trigger, with clear Russian code examples for structure property assignments and method calls.
docs/en/diagnostics/MagicNumber.md (1)
34-56: LGTM! Helpful exception documentation.The Exceptions section clearly describes the non-trigger scenarios with appropriate code examples for both structure property assignments and method calls.
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicNumberDiagnostic.java
Show resolved
Hide resolved
0643789 to
a73b562
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
♻️ Duplicate comments (1)
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnostic.java (1)
202-230: Code duplication: identical helpers in MagicNumberDiagnostic.These methods are duplicated in
MagicNumberDiagnostic.java(lines 137-163). See the refactoring suggestion in that file to extract shared logic to a common utility class.
🧹 Nitpick comments (2)
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicNumberDiagnostic.java (1)
137-163: Consider extracting shared helper methods to a common utility class.Both
isStructurePropertyAssignmentandfindAssignmentContexthave identical implementations inMagicDateDiagnostic.java(lines 202-230). Extracting these to a shared utility class would improve maintainability and reduce duplication.For example, create a utility class in the diagnostics package:
package com.github._1c_syntax.bsl.languageserver.diagnostics; public final class StructureAssignmentHelper { private StructureAssignmentHelper() { // utility class } public static boolean isStructurePropertyAssignment(BSLParser.ExpressionContext expression) { var assignment = findAssignmentContext(expression); if (assignment == null) { return false; } var lValue = assignment.lValue(); if (lValue == null || lValue.isEmpty()) { return false; } var acceptor = lValue.acceptor(); return acceptor != null && acceptor.accessProperty() != null; } public static BSLParser.AssignmentContext findAssignmentContext(BSLParserRuleContext ctx) { var current = ctx.getParent(); while (current != null) { if (current instanceof BSLParser.AssignmentContext assignmentContext) { return assignmentContext; } current = current.getParent(); } return null; } }src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnostic.java (1)
37-37: Remove unused import.The
java.util.Objectsimport added on line 37 is not used anywhere in the file.Apply this diff:
-import java.util.Objects;
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
src/test/resources/diagnostics/MagicNumberDiagnostic.bslis excluded by!src/test/resources/**
📒 Files selected for processing (6)
docs/diagnostics/MagicDate.md(1 hunks)docs/diagnostics/MagicNumber.md(2 hunks)docs/en/diagnostics/MagicDate.md(1 hunks)docs/en/diagnostics/MagicNumber.md(1 hunks)src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnostic.java(3 hunks)src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicNumberDiagnostic.java(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
- docs/en/diagnostics/MagicDate.md
- docs/diagnostics/MagicDate.md
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (12)
- GitHub Check: Analyse
- GitHub Check: build
- GitHub Check: build (21, macOS-latest)
- GitHub Check: build (23, macOS-latest)
- GitHub Check: build (21, ubuntu-latest)
- GitHub Check: build (23, windows-latest)
- GitHub Check: build (17, macOS-latest)
- GitHub Check: build (23, ubuntu-latest)
- GitHub Check: build (21, windows-latest)
- GitHub Check: build (17, windows-latest)
- GitHub Check: build (17, ubuntu-latest)
- GitHub Check: Benchmark
🔇 Additional comments (4)
docs/diagnostics/MagicNumber.md (2)
34-56: Well-documented exceptions align with the fix.The new "Exceptions" section clearly explains when the diagnostic does not trigger, using concrete, representative examples that match the reported issue. The examples correctly show structure property assignments and method calls as exception cases. The formatting and Russian description are clear and consistent with the documentation style.
34-56: Verify whether English documentation requires parallel updates.The PR checklist mentions descriptions should be filled for both Russian and English versions (though English translation can be omitted). Please confirm whether a corresponding English documentation file (likely
docs/diagnostics/MagicNumber.mdor similar without language qualifier) needs to be updated with equivalent exception documentation.docs/en/diagnostics/MagicNumber.md (1)
34-56: LGTM! Clear documentation of exceptions.The new Exceptions section clearly documents when the diagnostic should not trigger, with helpful examples that align with the PR objectives.
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicNumberDiagnostic.java (1)
118-131: Logic is correct - false positive issue properly addressed.Contrary to the previous review comment, the current implementation correctly excludes structure property assignments. The early return with
falseon line 123 ensures the filter rejects structure property assignments, making the Optional empty and causingisWrongExpressionto return false, which prevents the diagnostic from firing.Logic flow:
- If
isStructurePropertyAssignment→ filter returnsfalse→ Optional empty →isPresent()returnsfalse→ diagnostic does NOT fire ✓The code has been updated since the previous review and now implements the correct behavior.
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnostic.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnostic.java (1)
37-37: Remove unused import.The
java.util.Objectsimport is not used anywhere in this file.Apply this diff to remove the unused import:
-import java.util.Objects;
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnostic.java(3 hunks)src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicNumberDiagnostic.java(1 hunks)src/test/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnosticTest.java(2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicNumberDiagnostic.java
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (12)
- GitHub Check: Analyse
- GitHub Check: build
- GitHub Check: build (23, ubuntu-latest)
- GitHub Check: build (23, macOS-latest)
- GitHub Check: build (21, ubuntu-latest)
- GitHub Check: build (21, macOS-latest)
- GitHub Check: build (17, macOS-latest)
- GitHub Check: build (23, windows-latest)
- GitHub Check: build (17, windows-latest)
- GitHub Check: build (21, windows-latest)
- GitHub Check: build (17, ubuntu-latest)
- GitHub Check: Benchmark
🔇 Additional comments (4)
src/test/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnosticTest.java (2)
42-42: LGTM! Test expectation correctly updated.The reduction from 18 to 17 diagnostics reflects the new suppression logic for structure property assignments.
72-72: LGTM! Test expectation correctly updated.The reduction from 10 to 9 diagnostics confirms the suppression logic works correctly with custom configuration.
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnostic.java (2)
97-100: LGTM! Past review concern successfully addressed.The diagnostic condition now correctly includes the
insideStructurePropertyAssignmentcheck, resolving the critical issue flagged in the previous review where this method was defined but not called.
203-226: LGTM! Logic correctly detects structure property assignments.The method properly traverses the AST to find assignments with property accessors, successfully identifying patterns like
structure.property = value. Null safety is appropriately handled at each step.
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnostic.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/AbstractVisitorDiagnostic.java(2 hunks)src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnostic.java(2 hunks)src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicNumberDiagnostic.java(1 hunks)src/test/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnosticTest.java(2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnostic.java
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-04-18T22:46:43.245Z
Learnt from: nixel2007
PR: 1c-syntax/bsl-language-server#3449
File: src/main/java/com/github/_1c_syntax/bsl/languageserver/utils/expressiontree/ExpressionTreeBuildingVisitor.java:192-203
Timestamp: 2025-04-18T22:46:43.245Z
Learning: В проекте bsl-language-server класс BSLParser.ExpressionContext наследуется от BSLParserRuleContext, а не напрямую от ParserRuleContext. При работе с ним нужно учитывать специфичные методы BSLParserRuleContext.
Applied to files:
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/AbstractVisitorDiagnostic.java
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (12)
- GitHub Check: Analyse
- GitHub Check: build
- GitHub Check: build (23, macOS-latest)
- GitHub Check: build (23, ubuntu-latest)
- GitHub Check: build (17, ubuntu-latest)
- GitHub Check: build (17, macOS-latest)
- GitHub Check: build (21, windows-latest)
- GitHub Check: build (17, windows-latest)
- GitHub Check: build (21, macOS-latest)
- GitHub Check: build (23, windows-latest)
- GitHub Check: build (21, ubuntu-latest)
- GitHub Check: Analyze the repo with CodeSee
🔇 Additional comments (4)
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicNumberDiagnostic.java (2)
118-131: LGTM! Logic correctly excludes structure property assignments.The filter logic is correct: when
isStructurePropertyAssignmentreturnstrue, the filter returnsfalse, making the Optional empty, soisPresent()returnsfalseand the diagnostic does not fire. This aligns with the PR objective to suppress false positives for structure property assignments.
143-162: No code duplication found. The method correctly uses the inherited implementation from AbstractVisitorDiagnostic.The verification confirms that
MagicNumberDiagnosticextendsAbstractVisitorDiagnosticand the call tofindAssignmentContextat line 150 correctly resolves to the inheritedprotected staticmethod defined in the base class. There is no private duplicate implementation inMagicNumberDiagnostic, so no refactoring is needed.src/test/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnosticTest.java (1)
42-60: LGTM! Test expectations updated correctly.The diagnostic count adjustments (18→17 and 10→9) correctly reflect the new behavior where structure property assignments no longer trigger the MagicDate diagnostic.
Also applies to: 72-82
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/AbstractVisitorDiagnostic.java (1)
52-67: Code verified—shared implementation is properly reused.The search confirms that both
MagicNumberDiagnosticandMagicDateDiagnosticare calling the sharedfindAssignmentContext()method fromAbstractVisitorDiagnostic(lines 150 and 209 respectively). No duplicate private implementations exist in the subclasses. The refactoring successfully eliminated code duplication.
src/test/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnosticTest.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
♻️ Duplicate comments (1)
src/test/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnosticTest.java (1)
86-180: Refactor or remove redundant test methods.These six test methods repeat the same pattern from past reviews: all call
getDiagnostics()on the default fixture and verify different subsets of the same 17 diagnostics. They don't isolate specific behaviors with dedicated test inputs.For example:
testValidDateFormatsclaims to test various date formats but doesn't create test code with different format variationstestReturnSimpleDateclaims to verify return statement suppression but doesn't create a focused test case with only return statementstestStructurePropertyAssignmentclaims to test structure property suppression but doesn't create test code demonstrating structure property assignmentsThese tests don't add value beyond the main
test()method. Consider:
- Removing these tests entirely, or
- Refactoring each to test focused scenarios with custom test code via
getDocumentContext(testCode):@Test void testStructurePropertyAssignment() { var testCode = """ Структура = Новый Структура(); Структура.Свойство = "00020101"; // Should NOT trigger diagnostic Переменная = "00020101"; // SHOULD trigger diagnostic """; var diagnostics = getDiagnostics(getDocumentContext(testCode)); assertThat(diagnostics).hasSize(1); assertThat(diagnostics, true).hasRange(2, ...); // Only line 2 }Based on past review comments.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/test/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnosticTest.java(3 hunks)
src/test/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnosticTest.java
Outdated
Show resolved
Hide resolved
src/test/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnosticTest.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnostic.java (1)
139-156: Time bounds are too permissive (can accept 24:60:60).Use canonical ranges to avoid false positives on invalid date strings.
Apply this diff:
- return hh <= 24 && mm <= 60 && ss <= 60; + return hh >= 0 && hh < 24 && mm >= 0 && mm < 60 && ss >= 0 && ss < 60;
♻️ Duplicate comments (1)
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnostic.java (1)
298-307: Duplicate helper: extract or reuse base implementation.findAssignmentContext(...) appears here and (likely) in related diagnostics. Prefer a single protected static helper in AbstractVisitorDiagnostic; remove duplicates and call the shared one.
Apply this diff (assuming base now provides it):
- private static BSLParser.AssignmentContext findAssignmentContext(BSLParserRuleContext ctx) { - var current = ctx.getParent(); - while (current != null) { - if (current instanceof BSLParser.AssignmentContext assignmentContext) { - return assignmentContext; - } - current = current.getParent(); - } - return null; - }If not yet extracted, move this implementation to AbstractVisitorDiagnostic and adjust usages accordingly.
🧹 Nitpick comments (3)
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnostic.java (3)
83-89: Normalize configured authorizedDates to digits‑only and validate length.isExcluded() strips non‑digits from candidate values; mirror that normalization here to ensure matches and reduce surprises.
Apply this diff:
- Set<String> authD = Arrays.stream(authorizedDatesString.split(",")) - .map(String::trim) - .collect(Collectors.toSet()); + Set<String> authD = Arrays.stream(authorizedDatesString.split(",")) + .map(String::trim) + .map(s -> nonNumberPattern.matcher(s).replaceAll("")) + .filter(s -> !s.isEmpty() && (s.length() == 8 || s.length() == 12 || s.length() == 14)) + .collect(Collectors.toSet());
118-131: 12‑digit format gap vs defaults.DEFAULT_AUTHORIZED_DATES contains "000101010000" (12 digits), but string validation accepts only 8/14 digits. If 12‑digit "YYYYMMDDHHMM" strings are valid inputs in this context, extend the validator accordingly.
- Update validator to handle 12‑digit strings:
- if (strDate.length() == 8) { + if (strDate.length() == 8) { return true; } - var hh = parseInt(strDate.substring(8, 10)); - var mm = parseInt(strDate.substring(10, 12)); - var ss = parseInt(strDate.substring(12, 14)); - return hh <= 24 && mm <= 60 && ss <= 60; + if (strDate.length() == 12) { + var hh = parseInt(strDate.substring(8, 10)); + var mm = parseInt(strDate.substring(10, 12)); + return hh >= 0 && hh < 24 && mm >= 0 && mm < 60; + } + var hh = parseInt(strDate.substring(8, 10)); + var mm = parseInt(strDate.substring(10, 12)); + var ss = parseInt(strDate.substring(12, 14)); + return hh >= 0 && hh < 24 && mm >= 0 && mm < 60 && ss >= 0 && ss < 60;
- If 12‑digit strings are intended, also broaden paramPattern to include 12 digits:
""[0123]{1}\d{7}"|"[0123]{1}\d{11}"|"[0123]{1}\d{13}"
195-209: getExpression() brittleness (strict childCount==1 hops).This can miss valid trees with extra trivia nodes. Consider a more tolerant climb (e.g., walk parents until ExpressionContext) or reuse a central AST utility.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnostic.java(9 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
- GitHub Check: Analyse
- GitHub Check: build (23, windows-latest)
- GitHub Check: build (23, macOS-latest)
- GitHub Check: build (17, ubuntu-latest)
- GitHub Check: build (21, macOS-latest)
- GitHub Check: build (21, ubuntu-latest)
- GitHub Check: build (21, windows-latest)
- GitHub Check: build (23, ubuntu-latest)
- GitHub Check: build (17, windows-latest)
🔇 Additional comments (1)
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnostic.java (1)
107-111: Structure‑property suppression is correctly wired.The added check prevents false positives for structure property assignments as intended. LGTM.
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnostic.java
Show resolved
Hide resolved
198a942 to
f17fa5d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
♻️ Duplicate comments (3)
src/test/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnosticTest.java (2)
85-167: Remove or refactor superficial test methods.These five test methods (
testValidDateFormats,testExcludedDates,testSimpleDateAssignment,testReturnSimpleDate,testAssignmentWithDateMethod) all perform identical operations—callinggetDiagnostics()and asserting size/ranges—without isolating or verifying the specific private methods they claim to test. Past review feedback already identified this issue with similar tests.Consider either removing these redundant tests or refactoring them to create focused test cases that exercise specific validation logic (e.g., dedicated fixtures for date format validation, exclusion lists, or assignment contexts).
169-198: Misleading test—correct the comment and add focused structure property assignment test cases.The comment at lines 175-176 incorrectly identifies line 30 as a structure property assignment when it's actually an
Execute()call. Past review confirmed this discrepancy. Additionally, the test doesn't demonstrate actual structure property assignment suppression (e.g.,Структура.Свойство = "00020101"orСтруктура.Вставить("Ключ", "00020101")).Required fixes:
- Remove or correct the misleading comment.
- Add dedicated test cases with actual structure property assignments to verify the suppression feature works as intended.
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnostic.java (1)
281-291: Consider narrowing suppression to Structure type only.The current implementation suppresses diagnostics for all property assignments (e.g.,
Obj.Property = "00020101"), regardless of whether the base object is aСтруктура/Structure. Past review identified this over-broad suppression concern.To align precisely with the PR objective, consider using
documentContext.getSymbolTree()(available to diagnostics) to verify the base expression type isСтруктура/Structurebefore suppressing. This would prevent unintended suppression for non-Structure property assignments and ensure test coverage includes such cases.
🧹 Nitpick comments (1)
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicNumberDiagnostic.java (1)
149-162: Consider narrowing suppression to Structure type only.The current implementation suppresses diagnostics for all property assignments (e.g.,
Obj.Property = 20), regardless of whether the base object is actually aСтруктура/Structure. This matches the over-broad suppression concern raised in theMagicDateDiagnosticpast review.To align with the PR objective (suppress for structure properties specifically), consider using
documentContext.getSymbolTree()to verify the base expression type isСтруктура/Structurebefore suppressing. This refinement would prevent unintended suppression for non-Structure property assignments.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
src/test/resources/diagnostics/MagicNumberDiagnostic.bslis excluded by!src/test/resources/**
📒 Files selected for processing (8)
docs/diagnostics/MagicDate.md(1 hunks)docs/diagnostics/MagicNumber.md(2 hunks)docs/en/diagnostics/MagicDate.md(1 hunks)docs/en/diagnostics/MagicNumber.md(1 hunks)src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/AbstractVisitorDiagnostic.java(2 hunks)src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnostic.java(10 hunks)src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicNumberDiagnostic.java(1 hunks)src/test/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnosticTest.java(2 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
- docs/diagnostics/MagicDate.md
- docs/en/diagnostics/MagicDate.md
- docs/diagnostics/MagicNumber.md
- docs/en/diagnostics/MagicNumber.md
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-04-18T22:46:43.245Z
Learnt from: nixel2007
PR: 1c-syntax/bsl-language-server#3449
File: src/main/java/com/github/_1c_syntax/bsl/languageserver/utils/expressiontree/ExpressionTreeBuildingVisitor.java:192-203
Timestamp: 2025-04-18T22:46:43.245Z
Learning: В проекте bsl-language-server класс BSLParser.ExpressionContext наследуется от BSLParserRuleContext, а не напрямую от ParserRuleContext. При работе с ним нужно учитывать специфичные методы BSLParserRuleContext.
Applied to files:
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/AbstractVisitorDiagnostic.java
🔇 Additional comments (4)
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/AbstractVisitorDiagnostic.java (1)
52-67: LGTM! Well-placed helper to eliminate duplication.The
findAssignmentContextmethod correctly walks up the AST to locate the nearest enclosingAssignmentContext. Extracting this logic to the base class eliminates duplication betweenMagicDateDiagnosticandMagicNumberDiagnostic, improving maintainability.src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicNumberDiagnostic.java (1)
118-131: LGTM! Structure property assignment suppression logic is correct.The early-return pattern at lines 122-124 correctly suppresses the diagnostic when
isStructurePropertyAssignmentreturnstrue. The flow ensures structure property assignments (e.g.,Структура.Свойство = 20) do not trigger MagicNumber diagnostics, aligning with the PR objectives.src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnostic.java (2)
108-111: LGTM! Structure property assignment check correctly integrated.The addition of
insideStructurePropertyAssignmentat line 111 correctly suppresses the diagnostic for structure property assignments, resolving the critical issue from past reviews. The condition chain now properly handles all intended exclusion contexts.
77-273: LGTM! Well-documented validation and context detection methods.The new and updated methods (
configure,isValidDate,parseInt,isAccepted,isExcluded,getExpression, and various context-checking helpers) are well-structured with clear Javadoc comments. The validation logic for date formats and context detection is straightforward and appropriate for the diagnostic's purpose.
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnostic.java
Show resolved
Hide resolved
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnostic.java
Outdated
Show resolved
Hide resolved
...ain/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/AbstractVisitorDiagnostic.java
Outdated
Show resolved
Hide resolved
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnostic.java
Outdated
Show resolved
Hide resolved
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnostic.java
Outdated
Show resolved
Hide resolved
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicNumberDiagnostic.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
♻️ Duplicate comments (1)
src/test/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnosticTest.java (1)
85-174: Remove or refactor superficial test methods that don't add meaningful coverage.These five test methods (
testValidDateFormats,testExcludedDates,testSimpleDateAssignment,testReturnSimpleDate,testAssignmentWithDateMethod) all callgetDiagnostics()on the same fixture and assert subsets of the same 17 diagnostics. They claim to test specific scenarios (various date formats, excluded dates, simple assignments, return statements, Date() method usage) but don't isolate or demonstrate those behaviors—they simply repeat assertions on the same integration test output.These tests were flagged as redundant in previous review rounds and haven't been meaningfully improved. Consider either:
- Removing them entirely (recommended), or
- Creating focused test fixtures that isolate each scenario:
- Create separate
.bslfiles with specific test cases for each scenario- Use dedicated configuration where relevant (e.g., for excluded dates)
- Assert the specific behavior being tested (e.g., for
testExcludedDates, configure authorized dates and verify those specific dates don't generate diagnostics)
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/test/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnosticTest.java(2 hunks)
🔇 Additional comments (1)
src/test/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnosticTest.java (1)
42-42: Diagnostic count reduction is correct and properly implemented.The test counts were reduced (18→17 and 10→9) due to newly added logic in
MagicDateDiagnostic.insideStructurePropertyAssignment()that suppresses magic date diagnostics when they appear in structure property assignments.Verification confirms:
- The diagnostic implementation includes the
insideStructurePropertyAssignment()method (lines 280-293) that checks if a magic date is on the right-hand side of a structure property assignment- The method is correctly called in
visitConstValue()as part of the suppression chain- Fixture line 32 (
ОтборЭлемента.ПравоеЗначение = Новый СтандартнаяДатаНачала(Дата('19800101000000'));) contains exactly this pattern: a structure property assignment with a magic date inside a Date() constructor- This is the suppressed diagnostic causing the count reduction from 18→17 (first test) and 10→9 (second test)
The change is intentional and appropriate—it reduces false positives by not flagging magic dates in structure property assignments where the property name itself provides semantic context.
src/test/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnosticTest.java
Show resolved
Hide resolved
2762463 to
5db7b11
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
♻️ Duplicate comments (2)
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicNumberDiagnostic.java (1)
122-122: Remove redundant class name qualifier.As noted in the past review, the explicit
MagicNumberDiagnostic.qualifier is unnecessary when calling a static method from within the same class.Apply this diff:
- if (MagicNumberDiagnostic.isStructurePropertyAssignment(expression)) { + if (isStructurePropertyAssignment(expression)) {src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnostic.java (1)
421-451: Over-broad suppression remains unaddressed: matches any property assignment.The implementation suppresses diagnostics for all property assignments (e.g.,
Obj.Date = "20250101"), not just Structure properties. The past review flagged this concern and suggested usingdocumentContext.getSymbolTree()to verify the base type is actually "Структура"/"Structure", but this type validation was not implemented.This means cases like:
ОтборЭлемента.ПравоеЗначение = "19800101" // Not a Structure, but suppressedwill incorrectly suppress the diagnostic.
Consider either:
- Adding type checking via the symbol tree to verify the base object is a Structure type, or
- Documenting this limitation if type information is unavailable or the broader suppression is intentional
🧹 Nitpick comments (2)
src/test/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnosticTest.java (2)
191-221: Clarify test expectations for return statement suppression.The Javadoc states "Проверяет, что возврат дат из функций НЕ генерирует диагностики" (verifies that returning dates from functions does NOT generate diagnostics), but the test expects 19 diagnostics—the same count as the main test.
If return statements are being suppressed, we'd expect either:
- Fewer diagnostics than the baseline test, or
- Assertions that specifically verify return statement lines are absent from the diagnostic list
The current test doesn't demonstrate that return statement suppression is working. Consider adding explicit checks using
assertNoDiagnosticOnLinefor specific return statement lines to verify suppression.
259-270: Make edge case test more specific.The test claims to verify "пустые строки, null значения, некорректные форматы" (empty strings, null values, incorrect formats) but only asserts that diagnostics are not empty, without verifying specific edge case behavior. Consider adding explicit test cases or assertions for each claimed edge case scenario.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (2)
src/test/resources/diagnostics/MagicDateDiagnostic.bslis excluded by!src/test/resources/**src/test/resources/diagnostics/MagicNumberDiagnostic.bslis excluded by!src/test/resources/**
📒 Files selected for processing (8)
docs/diagnostics/MagicDate.md(1 hunks)docs/diagnostics/MagicNumber.md(2 hunks)docs/en/diagnostics/MagicDate.md(1 hunks)docs/en/diagnostics/MagicNumber.md(1 hunks)src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/AbstractVisitorDiagnostic.java(2 hunks)src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnostic.java(7 hunks)src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicNumberDiagnostic.java(1 hunks)src/test/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnosticTest.java(1 hunks)
✅ Files skipped from review due to trivial changes (1)
- docs/diagnostics/MagicDate.md
🚧 Files skipped from review as they are similar to previous changes (3)
- docs/en/diagnostics/MagicDate.md
- docs/en/diagnostics/MagicNumber.md
- docs/diagnostics/MagicNumber.md
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (12)
- GitHub Check: Analyse
- GitHub Check: build (17, windows-latest)
- GitHub Check: build (23, ubuntu-latest)
- GitHub Check: build (23, windows-latest)
- GitHub Check: build (23, macOS-latest)
- GitHub Check: build (17, macOS-latest)
- GitHub Check: build (21, ubuntu-latest)
- GitHub Check: build (21, windows-latest)
- GitHub Check: build (21, macOS-latest)
- GitHub Check: build (17, ubuntu-latest)
- GitHub Check: build
- GitHub Check: Benchmark
🔇 Additional comments (2)
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/AbstractVisitorDiagnostic.java (1)
56-68: LGTM!The helper method is well-implemented, uses the appropriate
Trees.getRootParentutility as suggested in past reviews, and is correctly scoped for reuse by diagnostic subclasses.src/test/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnosticTest.java (1)
239-257: LGTM! Core feature verification is correct.This test properly verifies the PR's main objective: suppressing MagicDate diagnostics for structure property assignments while still generating them for simple variable assignments. The use of line-specific assertions clearly demonstrates the expected behavior.
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnostic.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnostic.java (1)
434-487: Consider adding type verification to structure property assignments.There's an asymmetry in how structure detection works:
isStructureMethodCall(lines 466-487): Verifies the object is actually a Structure type viaisVariableOfStructureTypebefore suppressingisStructurePropertyAssignment(lines 434-457): Only checks foraccessProperty()without type verificationThis means
NonStructureObject.Property = "00020101"would be incorrectly suppressed even though the object isn't a Structure.For consistency and correctness, consider extracting the base object name from the
acceptorinisStructurePropertyAssignmentand callingisVariableOfStructureTypeto verify it's actually a Structure, similar to howisStructureMethodCallhandles it.Example approach:
private static boolean isStructurePropertyAssignment(BSLParser.ExpressionContext expr) { if (expr == null) { return false; } var assignment = (BSLParser.AssignmentContext) Trees.getRootParent((BSLParserRuleContext) expr, BSLParser.RULE_assignment); if (assignment == null) { return false; } var lValue = assignment.lValue(); if (lValue == null || lValue.isEmpty()) { return false; } var acceptor = lValue.acceptor(); if (acceptor == null) { return false; } var accessProperty = acceptor.accessProperty(); - return accessProperty != null; + if (accessProperty == null) { + return false; + } + + // Extract base object name and verify it's a Structure type + String objectName = extractObjectName(acceptor); + return objectName != null && isVariableOfStructureType(objectName); }Note: You'll need to make
isVariableOfStructureTypenon-private (protected or package-private) and implementextractObjectNameto parse the object identifier from the acceptor context.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
src/test/resources/diagnostics/MagicDateDiagnostic.bslis excluded by!src/test/resources/**
📒 Files selected for processing (2)
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnostic.java(7 hunks)src/test/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnosticTest.java(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnostic.java (1)
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicNumberDiagnostic.java (1)
DiagnosticMetadata(40-164)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (12)
- GitHub Check: Analyse
- GitHub Check: build
- GitHub Check: build (23, ubuntu-latest)
- GitHub Check: build (21, ubuntu-latest)
- GitHub Check: build (23, macOS-latest)
- GitHub Check: build (17, macOS-latest)
- GitHub Check: build (23, windows-latest)
- GitHub Check: build (21, windows-latest)
- GitHub Check: build (17, windows-latest)
- GitHub Check: build (21, macOS-latest)
- GitHub Check: build (17, ubuntu-latest)
- GitHub Check: Benchmark
🔇 Additional comments (4)
src/test/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnosticTest.java (1)
27-336: Excellent test coverage and structure!The test file demonstrates strong engineering practices:
- Helper methods (lines 67-96) eliminate duplication and provide clear, reusable assertions
- Line number constants (lines 40-50) make tests maintainable and self-documenting
- Comprehensive scenarios: covers configuration, date formats, exclusions, assignments, structure handling, edge cases, and bilingual support
- Clear documentation: Javadoc comments explain what each test verifies
The test suite thoroughly validates the PR objectives around suppressing diagnostics for structure property assignments while ensuring normal cases still trigger.
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnostic.java (3)
47-68: Outstanding documentation!The class-level Javadoc comprehensively documents:
- Purpose and behavior
- Supported date formats
- Suppression scenarios (structure properties, method calls, returns, etc.)
- Configuration options
This makes the diagnostic's behavior crystal clear to users and maintainers.
205-218: Well-designed centralized decision logic.The
shouldGenerateDiagnosticmethod consolidates all suppression checks into a single, testable decision point. This improves maintainability and makes the diagnostic's behavior easier to understand and modify.The optimization note about minimizing AST tree traversals shows attention to performance.
515-569: Robust structure type detection with graceful fallback.The implementation demonstrates good engineering:
- Primary path: Uses
SymbolTreefor accurate type resolution (lines 528-544)- Fallback: Heuristic name-based detection when symbol tree unavailable (lines 554-569)
- Bilingual support: Handles both Russian and English naming conventions
The heuristic approach is pragmatic—while not perfect, it provides reasonable coverage for common naming patterns when formal type information isn't available.
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnostic.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnostic.java (1)
514-568: Symbol resolution with sensible heuristic fallback.The
isVariableOfStructureTypemethod correctly prioritizes symbol tree lookup with description analysis, falling back to name-based heuristics when symbol information is unavailable. The heuristic keywords (структура, structure, стр, str, данные, data, параметры, params) are reasonable for typical 1C:Enterprise code patterns.Note: The heuristic at lines 560-567 could have false positives (e.g., a variable named
"строка"would match"стр"), but this trade-off is acceptable given the fallback nature and difficulty of perfect type inference without full semantic analysis.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnostic.java(8 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnostic.java (2)
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicNumberDiagnostic.java (1)
DiagnosticMetadata(40-164)src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/RewriteMethodParameterDiagnostic.java (1)
DiagnosticMetadata(54-197)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (11)
- GitHub Check: Analyse
- GitHub Check: build (17, windows-latest)
- GitHub Check: build (23, macOS-latest)
- GitHub Check: build
- GitHub Check: build (21, ubuntu-latest)
- GitHub Check: build (23, ubuntu-latest)
- GitHub Check: build (21, macOS-latest)
- GitHub Check: build (17, macOS-latest)
- GitHub Check: build (21, windows-latest)
- GitHub Check: build (23, windows-latest)
- GitHub Check: build (17, ubuntu-latest)
🔇 Additional comments (7)
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnostic.java (7)
24-25: VariableSymbol import is correctly used.Despite a past review comment flagging this import as unused, it's actually required at line 532 where
symbolTree.getVariableSymbol()returnsOptional<VariableSymbol>. The import should remain.
46-67: Excellent documentation.The comprehensive JavaDoc clearly explains the diagnostic's purpose, suppression scenarios, and supported date formats. This aligns perfectly with the PR objectives and helps future maintainers understand the intended behavior.
108-147: Robust configuration handling.The enhanced configuration logic with null checks, empty-string filtering, and date validation (
isValidDateString) prevents configuration errors and ensures only valid dates are authorized. This defensive approach improves reliability.
149-193: Excellent refactoring with centralized gating.Both
visitStringandvisitConstValuenow route throughshouldGenerateDiagnostic, eliminating code duplication and ensuring consistent suppression logic across all entry points. The flow is clear: validate → get context → gate → report.
195-217: Core fix correctly implemented.The centralized
shouldGenerateDiagnosticmethod properly implements the PR objective by suppressing diagnostics for structure property assignments and method calls (line 211), while preserving other suppression conditions. The boolean logic is correct: diagnostics are generated only when none of the suppression conditions are met.
225-283: Enhanced date validation is solid.The improved validation logic correctly handles both date formats (YYYYMMDD and YYYYMMDDHHMMSS), validates component ranges, and aligns with 1C platform limits (year 1-9999). The
parseInthelper safely handles leading zeros and exceptions. Note: day validation doesn't enforce month-specific limits (e.g., February 30), but this is acceptable for magic-number detection heuristics.
427-486: Structure detection logic is well-implemented.The methods correctly identify structure property assignments and method calls:
isStructurePropertyAssignmentuses AST traversal to detectObj.Property = valuepatternsisStructureMethodCalluses the bilingualSTRUCTURE_METHOD_PATTERNto match both"Вставить"and"Insert"(case-insensitive)- Text parsing in
isStructureObjectCallis reasonable given AST constraintsThis addresses the PR objective and past review feedback about bilingual support.
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnostic.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnostic.java (2)
86-90: Fix paramPattern: excludes valid dates (years starting with 4–9).The pattern forces the first digit to [0–3], so strings like "99991231" and "40010101" are never checked. This causes false negatives.
Apply:
- private static final Pattern paramPattern = CaseInsensitivePattern.compile( - "\"[0123]{1}\\d{7}\"|\"[0123]{1}\\d{13}\"" - ); + private static final Pattern paramPattern = CaseInsensitivePattern.compile( + "\"\\d{8}\"|\"\\d{14}\"" + );
80-82: Remove unsupported 12-digit default date from authorized list.DEFAULT_AUTHORIZED_DATES includes "000101010000" (12 digits) while supported lengths are 8 or 14; configure() filters it out anyway, creating a misleading default.
- private static final String DEFAULT_AUTHORIZED_DATES = "00010101,00010101000000,000101010000"; + private static final String DEFAULT_AUTHORIZED_DATES = "00010101,00010101000000";Also update docs mentioning supported formats.
♻️ Duplicate comments (1)
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnostic.java (1)
433-456: Structure property suppression matches any property; add type check.isStructurePropertyAssignment() returns true for all property assignments (Obj.Prop = "..."), not only Structure. This suppresses diagnostics in non-Structure contexts.
- private static boolean isStructurePropertyAssignment(BSLParser.ExpressionContext expr) { + private boolean isStructurePropertyAssignment(BSLParser.ExpressionContext expr) { if (expr == null) { return false; } @@ - var accessProperty = acceptor.accessProperty(); - return accessProperty != null; + var accessProperty = acceptor.accessProperty(); + if (accessProperty == null) { + return false; + } + // LHS like Var.Property — verify Var is a Structure + String lhs = acceptor.getText(); + int dot = lhs.indexOf('.'); + if (dot <= 0) { + return false; + } + String baseName = lhs.substring(0, dot).trim(); + return isVariableOfStructureType(baseName); }Add a test ensuring non-Structure property assignments (e.g., ОтборЭлемента.ПравоеЗначение = "00020101") still produce diagnostics.
🧹 Nitpick comments (8)
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnostic.java (3)
95-99: Redundant inline (?i) with CaseInsensitivePattern.CaseInsensitivePattern.compile already sets case-insensitive mode; the embedded "(?i)" is redundant.
- private static final Pattern STRUCTURE_METHOD_PATTERN = CaseInsensitivePattern.compile( - "(?i)Вставить|Insert" - ); + private static final Pattern STRUCTURE_METHOD_PATTERN = CaseInsensitivePattern.compile( + "Вставить|Insert" + );
313-321: Duplicate expression-mapping helpers; consider unifying.getExpression(Optional) and getExpressionFromString(StringContext) are identical apart from parameter type.
Extract a single private method accepting BSLParserRuleContext (or a generic mapper) to reduce duplication.
Also applies to: 329-337
404-424: Fragile multi-parent walk; prefer direct AST queries.The deep parent chain in insideAssignmentWithDateMethodForSimpleDate() is brittle. Use Trees.getRootParent(expr, RULE_assignment) and then inspect the RHS for GlobalMethodCallContext with methodPattern, or traverse with Trees.findFirst(...).
If you want, I can draft a helper that finds a GlobalMethodCallContext under an assignment’s rValue.
src/test/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnosticTest.java (5)
195-225: Test intent vs assertions mismatch (return/assignment cases).Docstrings say “return does NOT generate diagnostics” and “assignment with Date() generates diagnostics,” yet assertions don’t verify absence on return lines and rely on global counts/ranges.
- Add assertNoDiagnosticOnLine for return lines.
- For Date() assignment, assert presence on the specific lines; for returns, assert absence.
If line numbers aren’t constant, assert by message substring or by locating the exact Range from the fixture.
268-276: Weak “isNotEmpty” tests — refactor to focused assertions.testEdgeCases, testEdgeCasesExtended, and testStringLiterals only check non-empty diagnostics. Replace with targeted expectations (presence/absence on specific lines or counts) or remove to reduce noise.
Also applies to: 338-350, 369-376
324-336: Latin method coverage: also assert non-Structure Insert still reports.Great that you check DataStructure.Insert. Add a counterexample where Insert is called on a non-Structure to ensure no over-suppression.
131-150: Configuration tests: add assertions that invalid/empty/null authorizedDates don’t break filtering.Since configure() filters invalid dates, assert that:
- invalid dates are not included (e.g., "invalid" doesn’t prevent "00020101" from reporting),
- null/empty reverts to defaults,
- duplicates are handled (Set semantics).
If helpful, assert the diagnostic count difference before/after configuration.
Also applies to: 382-408, 414-424
247-261: Test coverage incomplete: non-Structure property assignments not verified.The test method
testStructurePropertyAssignment()validates Structure property suppression and simple variable reporting, but lacks explicit coverage for non-Structure object properties (e.g.,ОтборЭлемента.ПравоеЗначение = "00020101"). While the current assertions indirectly cover this viaSIMPLE_ASSIGNMENT_LINE, adding an explicit assertion for a non-Structure property assignment would strengthen test coverage.Two approaches:
- Extend the fixture to include
ОтборЭлемента.ПравоеЗначение = "00020101"and add a corresponding assertion.- Create an alternate fixture using
getDiagnostics(String simpleFileName)(supported by the harness).The current test is functionally adequate but incomplete.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
src/test/resources/diagnostics/MagicDateDiagnostic.bslis excluded by!src/test/resources/**
📒 Files selected for processing (2)
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnostic.java(8 hunks)src/test/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnosticTest.java(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnostic.java (1)
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicNumberDiagnostic.java (1)
DiagnosticMetadata(40-164)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (11)
- GitHub Check: build
- GitHub Check: build (21, macOS-latest)
- GitHub Check: build (23, windows-latest)
- GitHub Check: build (23, macOS-latest)
- GitHub Check: build (17, macOS-latest)
- GitHub Check: build (21, windows-latest)
- GitHub Check: build (21, ubuntu-latest)
- GitHub Check: build (23, ubuntu-latest)
- GitHub Check: build (17, windows-latest)
- GitHub Check: build (17, ubuntu-latest)
- GitHub Check: Analyse
🔇 Additional comments (2)
src/test/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnosticTest.java (1)
39-47: No off-by-one errors found.Line constants in the test match the actual fixture exactly (lines 73, 74, 76, 84, 85 for the respective constant values). The original review's concern about off-by-one shifts is incorrect.
Likely an incorrect or invalid review comment.
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnostic.java (1)
522-544: No changes needed; review comment is based on unavailable APIs.The VariableSymbol API does not expose type predicates like getType(), typeOf(), or getTypeName(). The available methods are:
getKind()→ VariableKind (scope: LOCAL, PARAMETER, DYNAMIC, etc.—not value type)getDescription()→ Optional (text metadata from comments, no type fields)The current implementation at lines 522-544 already uses the only viable approach: parsing description text for structure keywords plus name-based heuristics. There are no "actual type predicates" available to replace this logic.
Likely an incorrect or invalid review comment.
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnostic.java
Show resolved
Hide resolved
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnostic.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnostic.java (2)
86-88: Critical: paramPattern excludes valid dates (years 4000–9999).
"[0123]{1}\\d{7}"and"[0123]{1}\\d{13}"wrongly reject strings starting with 4–9, so"90010101"and"99991231235959"are ignored entirely.Apply:
- private static final Pattern paramPattern = CaseInsensitivePattern.compile( - "\"[0123]{1}\\d{7}\"|\"[0123]{1}\\d{13}\"" - ); + private static final Pattern paramPattern = Pattern.compile( + "\"\\d{8}\"|\"\\d{14}\"" + );Optionally, drop the pre-filter and rely on isValidDate(String) for correctness.
80-85: Default config includes unsupported 12‑digit date.
DEFAULT_AUTHORIZED_DATEScontains000101010000(12 digits), but validators accept only 8 or 14 digits. Afterconfigure(), this entry is silently discarded, creating inconsistent behavior between defaults and configured state.Choose one:
- Align defaults with validators (recommended):
- private static final String DEFAULT_AUTHORIZED_DATES = "00010101,00010101000000,000101010000"; + private static final String DEFAULT_AUTHORIZED_DATES = "00010101,00010101000000";
- Or add 12‑digit support consistently:
- Allow 12 in isValidDateString and isValidDate (parse HHMM without seconds).
♻️ Duplicate comments (1)
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnostic.java (1)
421-444: Over-broad suppression: property assignment matches any object, not only Structure.
accessProperty() != nullis true for arbitrary object properties, so diagnostics can be suppressed outside Structures (e.g.,Obj.Prop = "00020101"). Re-opened; still present in current code.Tighten by verifying the base object is a Structure (symbol/type when available; heuristic fallback). Also make the method non-static so it can use
documentContext.- private static boolean isStructurePropertyAssignment(BSLParser.ExpressionContext expr) { + private boolean isStructurePropertyAssignment(BSLParser.ExpressionContext expr) { if (expr == null) { return false; } @@ - var accessProperty = acceptor.accessProperty(); - return accessProperty != null; + var accessProperty = acceptor.accessProperty(); + if (accessProperty == null) { + return false; + } + // Extract base object from "Base.Property[.Sub...]" + String acceptorText = acceptor.getText(); + int dotIdx = acceptorText.indexOf('.'); + if (dotIdx <= 0) { + return false; + } + String baseName = acceptorText.substring(0, dotIdx).trim(); + return isVariableOfStructureType(baseName); }Add a test ensuring a non‑Structure property assignment still reports MagicDate. Example (fixture snippet):
ОтборЭлемента.ПравоеЗначение = "00020101"; // should report
🧹 Nitpick comments (4)
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnostic.java (2)
453-474: Prefer AST for receiver/method instead of parsing call text.
isStructureMethodCall/isStructureObjectCallparsecallTextand split on the first '.', which breaks on chains likeObj.Sub.Insert(...)and is locale/format fragile.
- Extract the receiver from the parser nodes (e.g., member/access nodes) and resolve its type via
SymbolTree.- Keep the bilingual method check via
STRUCTURE_METHOD_PATTERN, but match against the actual method identifier node, notStringtext. This reduces false positives/negatives in nested expressions.Also applies to: 483-500
203-216: Duplicate checks for simple date assignment.
insideSimpleDateAssignment(...)ends up delegating toinsideAssignmentWithDateMethodForSimpleDate(...), andshouldGenerateDiagnostic(...)evaluates both, duplicating work.
- Remove
isSimpleAssignmentfromshouldGenerateDiagnosticand rely onisDateMethod, or inline a single helper to avoid repeated AST walks.Also applies to: 346-359
src/test/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnosticTest.java (2)
244-255: Add negative check: non‑Structure property assignment must still report.Great that structure property/method cases are suppressed. Add an explicit non‑Structure property assignment in the fixture and assert that it DOES produce a diagnostic to guard against over-broad suppression.
Example to add to fixture:
ОбъектНеСтруктура.Свойство = "00020101"; // should reportThen assert presence on that line.
318-340: Consolidate superficial “isNotEmpty” tests or make them assertive.Several tests only assert
isNotEmpty(). Either merge them into one sanity test or add precise expectations (ranges/lines) to increase value.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
src/test/resources/diagnostics/MagicDateDiagnostic.bslis excluded by!src/test/resources/**
📒 Files selected for processing (2)
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnostic.java(8 hunks)src/test/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnosticTest.java(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnostic.java (2)
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicNumberDiagnostic.java (1)
DiagnosticMetadata(40-164)src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/RewriteMethodParameterDiagnostic.java (1)
DiagnosticMetadata(54-197)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (11)
- GitHub Check: build (17, macOS-latest)
- GitHub Check: build (23, macOS-latest)
- GitHub Check: build (23, ubuntu-latest)
- GitHub Check: build (23, windows-latest)
- GitHub Check: build (21, macOS-latest)
- GitHub Check: build (21, windows-latest)
- GitHub Check: build (21, ubuntu-latest)
- GitHub Check: build (17, windows-latest)
- GitHub Check: build (17, ubuntu-latest)
- GitHub Check: build
- GitHub Check: Analyse
🔇 Additional comments (2)
src/test/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnosticTest.java (2)
39-47: Fix off-by-one error in SIMPLE_ASSIGNMENT_LINE constant; verify Latin constants manually.Based on fixture inspection:
SIMPLE_ASSIGNMENT_LINE = 76is off-by-one; the actual assignmentПростаяПеременная = "00040101";is on line 77, not 76.STRUCTURE_INSERT_LINE,STRUCTURE_PROPERTY_LINE,STRUCTURE2_INSERT_LINE, andSTRUCTURE2_PROPERTY_LINEconstants are correct.- Please confirm
LATIN_INSERT_LINE = 93andLATIN_INSERT_CYRILLIC_LINE = 94against the fixture file, as the Latin section in the fixture begins after line 107.
128-147: Incorrect premise about the map mutation concern.The review comment states that
getDefaultConfiguration()"may return a shared map," but this is inaccurate. The method creates a newMapon each invocation viaCollectors.toMap()inDiagnosticInfo.javaline 272-274, so mutations to the local configuration variable intestConfigure()do not leak through that mechanism.However, there is a legitimate test isolation concern:
MagicDateDiagnosticTestlacks@DirtiesContextwhile many peer diagnostic test classes in the codebase explicitly use it (e.g.,MetadataObjectNameLengthDiagnosticTest,TimeoutsInExternalResourcesDiagnosticTest). The real risk is thatdiagnosticInstancestate mutations intestConfigure()could affect subsequent test methods if the bean is reused across the test context. The appropriate fix would be to add@DirtiesContextat the class level, consistent with other diagnostic tests, rather than wrapping the configuration map.Likely an incorrect or invalid review comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
src/test/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnosticTest.java (2)
257-440: Many test methods only assertisNotEmpty()without verifying specific behavior.Several test methods (
testEdgeCases,testEdgeCasesExtended,testStringLiterals,testVisitStringMethod,testInvalidDateFormats,testStructureMethodCallEdgeCases,testSymbolResolutionEdgeCases) only callgetDiagnostics()and assertisNotEmpty(). These don't verify specific edge cases or behavior—they're essentially duplicates of the main test.Consider either removing these or refactoring them to assert specific scenarios (e.g., specific input patterns, expected diagnostic locations, or configuration behaviors). Tests should validate distinct behavior rather than repeat generic checks.
272-396: Minor test duplication: null configuration tested twice.Both
testInvalidConfiguration(line 280) andtestNullConfiguration(lines 372-381) test the null configuration scenario. Consider consolidating related configuration tests to reduce duplication.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/AbstractVisitorDiagnostic.java(2 hunks)src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnostic.java(8 hunks)src/test/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnosticTest.java(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnostic.java (1)
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicNumberDiagnostic.java (1)
DiagnosticMetadata(40-164)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (11)
- GitHub Check: Analyse
- GitHub Check: build (23, macOS-latest)
- GitHub Check: build (21, ubuntu-latest)
- GitHub Check: build (23, ubuntu-latest)
- GitHub Check: build (21, macOS-latest)
- GitHub Check: build (17, windows-latest)
- GitHub Check: build (21, windows-latest)
- GitHub Check: build (17, ubuntu-latest)
- GitHub Check: build (23, windows-latest)
- GitHub Check: build (17, macOS-latest)
- GitHub Check: build
🔇 Additional comments (11)
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/AbstractVisitorDiagnostic.java (1)
55-64: LGTM! Helper method correctly extracts shared AST traversal logic.The
findAssignmentContexthelper properly usesTrees.getRootParentto locate the assignment context, eliminating duplication between MagicDateDiagnostic and MagicNumberDiagnostic. The protected static visibility makes it accessible to diagnostic subclasses.Based on past review comments
src/test/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnosticTest.java (2)
49-93: LGTM! Helper methods improve test readability.The three helper methods (
hasDiagnosticOnLine,assertNoDiagnosticOnLine,assertHasDiagnosticOnLine) provide clear, reusable utilities for verifying diagnostic presence on specific lines. Good Javadoc documentation.
244-255: LGTM! Test correctly verifies structure property assignment suppression.The test properly validates the PR's core feature: diagnostics are suppressed for structure property assignments (
Структура.Вставить,Структура.СвойствоДаты) but still fire for simple variable assignments. Good use of helper methods for clear assertions.src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnostic.java (8)
46-67: LGTM! Comprehensive class documentation.The Javadoc clearly documents when the diagnostic is suppressed (structure property assignments, structure method calls, simple date assignments, returns, authorized dates) and lists supported date formats. This helps users understand the diagnostic's behavior.
107-132: LGTM! Enhanced configuration handling with proper validation.The configure method now includes null checks, validates date strings with
isValidDateString, and filters out invalid entries. This prevents configuration errors from breaking the diagnostic.
194-216: LGTM! Centralized suppression logic.The
shouldGenerateDiagnosticmethod consolidates all suppression checks in one place, making the logic clear and maintainable. Properly checks for structure property assignments, structure method calls, returns, and date method assignments.
233-267: LGTM! Date validation with correct bounds.The validation properly uses
MAX_YEAR_BY_1Cconstant for year bounds and strict inequalities for time components (hh < 24,mm < 60,ss < 60). Handles both 8-digit (date only) and 14-digit (date+time) formats correctly.
446-474: LGTM! Bilingual structure method detection with type checking.The method now uses
STRUCTURE_METHOD_PATTERNto match bothВставитьandInsert(case-insensitive), and delegates toisStructureObjectCallfor proper type verification via the symbol tree. This addresses previous concerns about language limitations and over-broad suppression.Based on past review comments
502-530: LGTM! Symbol tree-based type detection with safe fallback.The method properly uses
SymbolTreeto resolve variable types and checks the description for structure indicators. Returns false if the symbol tree is unavailable or the variable isn't found, which is a safe default that avoids false suppression.
338-359: LGTM! Refactored to use AST-based detection.The method now properly delegates to
insideAssignmentWithDateMethodForSimpleDatefor precise AST-based checking, eliminating the previous text-based heuristic that caused false positives. Correctly excludes structure property assignments and method calls first.Based on past review comments
414-444: Property assignment suppression remains over-broad without type checking.The method suppresses diagnostics for any property assignment (e.g.,
Obj.Property = "00020101") without verifying thatObjis actually a Structure. WhileisVariableOfStructureTypeexists (line 510) and is correctly used inisStructureObjectCallfor method calls, it is not used inisStructurePropertyAssignmentfor property assignments.This means property assignments to non-Structure objects—or even undefined variables like
ОтборЭлемента.ПравоеЗначениеon line 32—are also suppressed, creating an asymmetry with method call handling. Either add type checking toisStructurePropertyAssignmentsimilar toisStructureObjectCall, or document why all property assignments are intentionally suppressed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnostic.java (1)
80-81: Remove the unsupported 12-digit value from DEFAULT_AUTHORIZED_DATES.The constant includes "000101010000" (12 digits), but the isValidDateString method only accepts 8 or 14 digit strings (line 141). During configuration, this 12-digit value is silently filtered out (lines 124–131), contradicting the documented supported formats. Remove the 12-digit value to eliminate the confusing inconsistency:
- private static final String DEFAULT_AUTHORIZED_DATES = "00010101,00010101000000,000101010000"; + private static final String DEFAULT_AUTHORIZED_DATES = "00010101,00010101000000";
♻️ Duplicate comments (1)
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnostic.java (1)
417-440: Over-broad suppression: property assignment without Structure type check.isStructurePropertyAssignment() suppresses diagnostics for any property assignment, not only Structure properties. This masks cases like Obj.Date = "20250101". Add a Structure-type check using the base identifier of the lValue, consistent with isStructureMethodCall/isVariableOfStructureType.
Apply:
private static boolean isStructurePropertyAssignment(BSLParser.ExpressionContext expr) { @@ - var accessProperty = acceptor.accessProperty(); - return accessProperty != null; + var accessProperty = acceptor.accessProperty(); + if (accessProperty == null) { + return false; + } + // Verify base object is Structure: <Base>.<Property> = ... + var lValueText = lValue.getText(); + int dot = lValueText.indexOf('.'); + if (dot <= 0) { + return false; + } + var objectName = lValueText.substring(0, dot); + // Delegate to existing resolver + return new MagicDateDiagnostic().isVariableOfStructureType(objectName); }Note: if calling a non-static method from static context is undesired, move isVariableOfStructureType to static or a shared util.
🧹 Nitpick comments (5)
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnostic.java (3)
199-212: Redundant checks: isSimpleAssignment duplicates isDateMethod.insideSimpleDateAssignment now delegates to insideAssignmentWithDateMethodForSimpleDate; you also compute isDateMethod. Drop one to reduce AST traversals.
- boolean isDateMethod = insideAssignmentWithDateMethodForSimpleDate(expressionContext); - boolean isSimpleAssignment = insideSimpleDateAssignment(expressionContext); - - return !isStructureProperty && !isReturn && !isDateMethod && !isSimpleAssignment; + boolean isDateMethod = insideAssignmentWithDateMethodForSimpleDate(expressionContext); + return !isStructureProperty && !isReturn && !isDateMethod;Optionally remove insideSimpleDateAssignment if no longer used.
388-408: Deep parent-walk is brittle; prefer Trees.getRootParent.insideAssignmentWithDateMethodForSimpleDate chains multiple parent hops. Use Trees.getRootParent to reach GlobalMethodCall and Assignment for clarity and resilience.
- return expression - .map(BSLParserRuleContext::getParent) - .filter(context -> context.getChildCount() == 1) - .map(BSLParserRuleContext::getParent) - .filter(context -> context.getChildCount() == 1) - .map(BSLParserRuleContext::getParent) - .map(BSLParserRuleContext::getParent) - .filter(BSLParser.GlobalMethodCallContext.class::isInstance) - .map(BSLParser.GlobalMethodCallContext.class::cast) - .filter(context -> methodPattern.matcher(context.methodName().getText()).matches()) - .map(BSLParserRuleContext::getParent) - .filter(context -> context.getChildCount() == 1) - .map(BSLParserRuleContext::getParent) - .filter(context -> context.getChildCount() == 1) - .map(BSLParserRuleContext::getParent) - .filter(context -> context.getChildCount() == 1) - .map(BSLParserRuleContext::getParent) - .filter(BSLParser.AssignmentContext.class::isInstance) - .isPresent(); + return expression + .map(expr -> (BSLParser.GlobalMethodCallContext) + Trees.getRootParent((BSLParserRuleContext) expr, BSLParser.RULE_globalMethodCall)) + .filter(ctx -> methodPattern.matcher(ctx.methodName().getText()).matches()) + .map(ctx -> Trees.getRootParent(ctx, BSLParser.RULE_assignment)) + .filter(BSLParser.AssignmentContext.class::isInstance) + .isPresent();
324-332: Duplicate expression-extraction helpers.getExpressionFromString duplicates getExpression logic. Consider extracting a common helper accepting BSLParserRuleContext and reusing it.
Also applies to: 308-316
src/test/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnosticTest.java (2)
95-122: Brittle golden-count and dense range assertions.Hard-coding hasSize(40) and many ranges ties tests to fixture editing. Prefer focused scenario tests: assert on specific lines of interest (helpers already exist) and avoid global counts.
257-266: Superficial tests asserting only non-empty diagnostics.Several tests only check isNotEmpty(), adding little value and increasing noise. Consolidate or rewrite to assert precise suppression/triggering for specific lines.
Also applies to: 318-327, 402-407, 414-418, 425-429, 436-440
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (2)
src/test/resources/diagnostics/MagicDateDiagnostic.bslis excluded by!src/test/resources/**src/test/resources/diagnostics/MagicNumberDiagnostic.bslis excluded by!src/test/resources/**
📒 Files selected for processing (2)
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnostic.java(8 hunks)src/test/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnosticTest.java(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnostic.java (2)
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicNumberDiagnostic.java (1)
DiagnosticMetadata(40-164)src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/FunctionOutParameterDiagnostic.java (1)
DiagnosticMetadata(41-87)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (11)
- GitHub Check: Analyse
- GitHub Check: build (17, macOS-latest)
- GitHub Check: build (23, windows-latest)
- GitHub Check: build (21, macOS-latest)
- GitHub Check: build (23, ubuntu-latest)
- GitHub Check: build (17, windows-latest)
- GitHub Check: build (21, ubuntu-latest)
- GitHub Check: build (17, ubuntu-latest)
- GitHub Check: build (23, macOS-latest)
- GitHub Check: build (21, windows-latest)
- GitHub Check: build
🔇 Additional comments (2)
src/test/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnosticTest.java (2)
128-147: Configured authorizedDates include unsupported 12-digit format.testConfigure passes "000101010000" (12 digits), which the validator now rejects. Align the test with supported formats or extend validation to include 12-digit DATETIME.
39-48: The proposed changes in the review comment are incorrect and should not be applied.The constants STRUCTURE_INSERT_LINE, STRUCTURE_PROPERTY_LINE, STRUCTURE2_INSERT_LINE, and STRUCTURE2_PROPERTY_LINE are all correct as currently written. The fixture file confirms:
- Line 73:
Структура.Вставить()✓- Line 74:
Структура.СвойствоДаты =✓- Line 84:
ПеремСтрДаты.Вставить()✓- Line 85:
ПеремСтрДаты.СвойствоДаты =✓However, there are actual line number errors elsewhere:
- SIMPLE_ASSIGNMENT_LINE = 76 should be 77 (fixture line 77 has the magic date assignment)
- LATIN_INSERT_LINE = 93 should be 111 (fixture line 111 has
DataStructure.Insert())- LATIN_INSERT_CYRILLIC_LINE = 94 should be 112 (fixture line 112 has the Cyrillic version)
Likely an incorrect or invalid review comment.
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnostic.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (2)
src/test/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnosticTest.java (1)
322-327: Consider strengthening assertions in edge-case and coverage tests.Several test methods (
testEdgeCasesExtended,testStringLiterals,testInvalidDateFormats,testStructureMethodCallEdgeCases,testSymbolResolutionEdgeCases) only assertisNotEmpty()without verifying specific behavior or diagnostic locations.While these may improve code coverage metrics, they don't validate correctness. Consider either:
- Adding specific assertions about which lines should/shouldn't have diagnostics
- Consolidating these into a single smoke test if they're just ensuring no crashes
Also applies to: 346-351, 403-420, 426-431
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnostic.java (1)
383-406: Consider adding type validation for property assignments.The method suppresses diagnostics for any property assignment (e.g.,
Obj.Date = "00020101"), regardless of whetherObjis actually a Structure type. WhileisStructureMethodCall()validates types viaisVariableOfStructureType(), property assignments lack this check.This broader suppression may be acceptable if the semantic context of any property name is deemed sufficient, but for consistency with the PR objective ("при присваивании значений к свойствам структуры"), consider using
isVariableOfStructureType()to validate the base object type.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
src/test/resources/diagnostics/MagicDateDiagnostic.bslis excluded by!src/test/resources/**
📒 Files selected for processing (2)
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnostic.java(8 hunks)src/test/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnosticTest.java(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnostic.java (1)
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicNumberDiagnostic.java (1)
DiagnosticMetadata(40-164)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (11)
- GitHub Check: build
- GitHub Check: build (23, macOS-latest)
- GitHub Check: build (21, windows-latest)
- GitHub Check: build (23, windows-latest)
- GitHub Check: build (17, macOS-latest)
- GitHub Check: build (21, macOS-latest)
- GitHub Check: build (17, ubuntu-latest)
- GitHub Check: build (17, windows-latest)
- GitHub Check: build (23, ubuntu-latest)
- GitHub Check: build (21, ubuntu-latest)
- GitHub Check: Analyse
🔇 Additional comments (8)
src/test/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnosticTest.java (1)
64-93: LGTM: Well-structured test helpers.The helper methods provide clear, focused assertions for checking diagnostics on specific lines. The use of descriptive error messages improves test failure diagnostics.
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnostic.java (7)
46-67: Excellent documentation.The Javadoc clearly describes the diagnostic's purpose, suppression contexts, and supported date formats. This will help users understand when false positives are expected vs. real issues.
86-97: LGTM: Patterns correctly support validation and bilingual detection.The
paramPatternnow accepts any 8- or 14-digit date (delegating validation toisValidDate()), andSTRUCTURE_METHOD_PATTERNproperly handles both Russian and English method names case-insensitively.
107-132: LGTM: Robust configuration handling.The method properly handles null configuration, validates date strings, and filters invalid entries. The defensive programming approach prevents configuration errors from causing runtime issues.
180-193: LGTM: Centralized suppression logic improves maintainability.The
shouldGenerateDiagnostic()method consolidates all suppression conditions in one place, making the logic transparent and reducing the risk of inconsistent checks across different code paths.
216-244: LGTM: Date validation is now correct.The validation properly uses
MAX_YEAR_BY_1Cconstant, enforces strict time component bounds (< 24/60/60), and handles both 8- and 14-digit date formats correctly.
300-321: LGTM: Precise AST-based detection.The method correctly delegates to
insideAssignmentWithDateMethodForSimpleDate()for accurate detection, and explicitly excludes structure-related contexts to avoid false suppressions.
415-494: LGTM: Robust structure method validation with type checking.The implementation properly:
- Detects structure method calls bilingually via pattern matching
- Extracts the base object identifier
- Uses
SymbolTreeto resolve and validate the variable is actually a Structure type- Handles null cases defensively throughout
This precise type checking reduces false positives effectively.
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnostic.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnostic.java (1)
458-487: Consider adding type verification for consistency with method call checking.The method
isStructurePropertyAssignment()suppresses diagnostics for ANY property assignment (e.g.,Object.Property = value) without verifying the object is actually a Structure type. In contrast,isStructureMethodCall()(lines 500-597) usesisVariableOfStructureType()to verify the object type via symbol tree before suppressing.This inconsistency could lead to over-broad suppression. For example,
ОтборЭлемента.ПравоеЗначение = "00020101"would be suppressed even ifОтборЭлементаis not a Structure.Suggestion: Add type verification similar to
isStructureMethodCall():private static boolean isStructurePropertyAssignment(BSLParser.ExpressionContext expr) { if (expr == null) { return false; } var assignment = getRootParent(expr, BSLParser.RULE_assignment); if (!(assignment instanceof BSLParser.AssignmentContext)) { return false; } var assignmentContext = (BSLParser.AssignmentContext) assignment; var lValue = assignmentContext.lValue(); if (lValue == null || lValue.isEmpty()) { return false; } var acceptor = lValue.acceptor(); if (acceptor == null) { return false; } var accessProperty = acceptor.accessProperty(); - return accessProperty != null; + if (accessProperty == null) { + return false; + } + + // Extract object name and verify it's a Structure type + String objectName = acceptor.getText(); + if (objectName != null) { + int dotIndex = objectName.indexOf('.'); + if (dotIndex > 0) { + objectName = objectName.substring(0, dotIndex); + return isVariableOfStructureType(objectName); + } + } + return false; }Note: This would require making
isVariableOfStructureType()accessible (currently it requiresdocumentContext, so the method signature would need adjustment).Alternatively, if the intent is to suppress diagnostics for ALL property assignments (not just structures), consider renaming the method to
isAnyPropertyAssignment()to reflect its actual behavior.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnostic.java(6 hunks)src/test/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnosticTest.java(1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-04-18T22:46:43.245Z
Learnt from: nixel2007
PR: 1c-syntax/bsl-language-server#3449
File: src/main/java/com/github/_1c_syntax/bsl/languageserver/utils/expressiontree/ExpressionTreeBuildingVisitor.java:192-203
Timestamp: 2025-04-18T22:46:43.245Z
Learning: В проекте bsl-language-server класс BSLParser.ExpressionContext наследуется от BSLParserRuleContext, а не напрямую от ParserRuleContext. При работе с ним нужно учитывать специфичные методы BSLParserRuleContext.
Applied to files:
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnostic.java
🧬 Code graph analysis (1)
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnostic.java (2)
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicNumberDiagnostic.java (1)
DiagnosticMetadata(40-164)src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/RewriteMethodParameterDiagnostic.java (1)
DiagnosticMetadata(54-197)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (11)
- GitHub Check: build
- GitHub Check: Analyse
- GitHub Check: build (23, macOS-latest)
- GitHub Check: build (21, windows-latest)
- GitHub Check: build (21, ubuntu-latest)
- GitHub Check: build (23, ubuntu-latest)
- GitHub Check: build (23, windows-latest)
- GitHub Check: build (17, macOS-latest)
- GitHub Check: build (21, macOS-latest)
- GitHub Check: build (17, windows-latest)
- GitHub Check: build (17, ubuntu-latest)
🔇 Additional comments (10)
src/test/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnosticTest.java (3)
27-93: LGTM! Well-structured test infrastructure.The helper methods and constants significantly improve test readability and maintainability. The Collections import is correctly used at line 274.
95-255: Excellent test coverage for core functionality.The tests properly verify:
- Structure property assignments are suppressed (lines 248-252)
- Structure method calls (Insert/Вставить) are suppressed (lines 248, 251)
- Simple variable assignments still generate diagnostics (line 254)
This aligns perfectly with the PR objectives.
257-431: Comprehensive edge case coverage.The tests effectively cover:
- Bilingual method support (Вставить/Insert)
- Invalid/null/empty configurations
- Different structure variable names
- Symbol resolution scenarios
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnostic.java (7)
24-31: LGTM! All imports are properly used.The imports for SymbolTree, VariableSymbol, and Trees are correctly utilized in the type resolution logic.
45-108: Excellent documentation and bilingual pattern support.The Javadoc clearly documents suppression contexts, and the updated
paramPatterncorrectly allows all valid 1C years (1-9999). The bilingualSTRUCTURE_METHOD_PATTERNproperly supports both Russian and English code.
116-151: Robust configuration validation.The null guards and
isValidDateString()filtering ensure the diagnostic handles invalid configurations gracefully.
154-220: Well-architected central diagnostic logic.The
shouldGenerateDiagnostic()method effectively centralizes suppression logic, making the code more maintainable and reducing duplication betweenvisitConstValue()andvisitString().
243-286: Date validation logic is correct.The time bounds correctly allow 0-23 hours, 0-59 minutes, and 0-59 seconds. The
parseInt()method safely handles leading zeros and invalid inputs.
362-455: AST navigation logic is well-implemented.The refactored
insideSimpleDateAssignment()correctly delegates to AST-based checking, avoiding the text-based false positives mentioned in past reviews. ThenavigateToParent()helper provides safe traversal with proper null checks.
500-597: Excellent implementation with proper type verification.The structure method call detection correctly:
- Uses symbol tree resolution to verify object types
- Supports bilingual method names (Вставить/Insert)
- Handles edge cases with comprehensive null checks
- Gracefully degrades when symbol information is unavailable
This implementation properly addresses past review feedback about over-broad suppression.
- Added detailed validation for magic dates in the MagicDateDiagnostic, including checks for valid date formats and context exclusions. - Introduced new methods to improve the detection of structure property assignments and method calls within the MagicNumberDiagnostic. - Updated diagnostic logic to minimize false positives and ensure accurate detection of magic numbers and dates in various contexts.
- Added multiple test cases for MagicDateDiagnostic to validate various date formats, structure property assignments, and edge cases. - Introduced tests for handling authorized dates, invalid configurations, and different structure names. - Enhanced assertions to ensure accurate detection of diagnostics in various contexts, including support for Latin structure methods and string literals.
…r diagnostics - Introduced an "Exceptions" section in both MagicDate and MagicNumber documentation to clarify scenarios where diagnostics do not trigger. - Included examples for structure property assignments and method calls that do not activate the diagnostics, enhancing user understanding of the limitations.
7c807eb to
8a7f27c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/test/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnosticTest.java (1)
257-266: Consider adding specific assertions to edge case tests.Several test methods (
testEdgeCases,testEdgeCasesExtended,testStringLiterals,testStructureMethodCallEdgeCases,testSymbolResolutionEdgeCases) only assert that diagnostics are not empty without verifying specific behavior.Consider enhancing these tests with targeted assertions that verify the actual edge cases they claim to test (e.g., specific line numbers, expected diagnostic messages, or absence of diagnostics in certain scenarios).
Also applies to: 318-327, 342-351, 410-420, 422-431
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (2)
src/test/resources/diagnostics/MagicDateDiagnostic.bslis excluded by!src/test/resources/**src/test/resources/diagnostics/MagicNumberDiagnostic.bslis excluded by!src/test/resources/**
📒 Files selected for processing (8)
docs/diagnostics/MagicDate.md(1 hunks)docs/diagnostics/MagicNumber.md(2 hunks)docs/en/diagnostics/MagicDate.md(1 hunks)docs/en/diagnostics/MagicNumber.md(1 hunks)src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/AbstractVisitorDiagnostic.java(2 hunks)src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnostic.java(6 hunks)src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicNumberDiagnostic.java(1 hunks)src/test/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnosticTest.java(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
- src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicNumberDiagnostic.java
- docs/diagnostics/MagicDate.md
- docs/diagnostics/MagicNumber.md
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-04-18T22:46:43.245Z
Learnt from: nixel2007
PR: 1c-syntax/bsl-language-server#3449
File: src/main/java/com/github/_1c_syntax/bsl/languageserver/utils/expressiontree/ExpressionTreeBuildingVisitor.java:192-203
Timestamp: 2025-04-18T22:46:43.245Z
Learning: В проекте bsl-language-server класс BSLParser.ExpressionContext наследуется от BSLParserRuleContext, а не напрямую от ParserRuleContext. При работе с ним нужно учитывать специфичные методы BSLParserRuleContext.
Applied to files:
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnostic.java
🧬 Code graph analysis (1)
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnostic.java (2)
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicNumberDiagnostic.java (1)
DiagnosticMetadata(40-164)src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/RewriteMethodParameterDiagnostic.java (1)
DiagnosticMetadata(54-197)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (11)
- GitHub Check: Analyse
- GitHub Check: build
- GitHub Check: build (23, windows-latest)
- GitHub Check: build (21, macOS-latest)
- GitHub Check: build (23, ubuntu-latest)
- GitHub Check: build (23, macOS-latest)
- GitHub Check: build (21, windows-latest)
- GitHub Check: build (21, ubuntu-latest)
- GitHub Check: build (17, ubuntu-latest)
- GitHub Check: build (17, windows-latest)
- GitHub Check: build (17, macOS-latest)
🔇 Additional comments (6)
docs/en/diagnostics/MagicNumber.md (1)
33-56: LGTM! Clear documentation of exception cases.The new "Exceptions" section effectively documents when the diagnostic is suppressed for structure property assignments and method calls. The examples are clear and align with the PR objectives.
docs/en/diagnostics/MagicDate.md (1)
38-60: LGTM! Consistent documentation with clear examples.The "Exceptions" section mirrors the MagicNumber documentation structure and provides clear examples specific to date literals. Well done.
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/AbstractVisitorDiagnostic.java (1)
55-64: LGTM! Good refactoring to eliminate duplication.Extracting the
findAssignmentContexthelper to the base class is the right approach. The method is correctly implemented usingTrees.getRootParentand will be shared by both MagicNumber and MagicDate diagnostics.src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnostic.java (2)
45-66: Excellent refactoring with centralized suppression logic.The comprehensive Javadoc (lines 45-66) clearly documents the diagnostic's purpose and exception cases. The
shouldGenerateDiagnosticmethod (lines 200-220) nicely centralizes all suppression checks in one place, making the logic easy to understand and maintain. The implementation successfully addresses the PR objectives of suppressing false positives for structure property assignments.Also applies to: 200-220
567-597: No issues found with the double.getDescription()call—it's correct API usage.The chain is intentional:
VariableSymbol.getDescription()returnsOptional<VariableDescription>, and the inner.map(description -> description.getDescription())calls theSourceDefinedSymbolDescription.getDescription()method (which returnsString) on eachVariableDescriptionobject. This is proper Optional chaining.The type-checking logic via
SymbolTreeis sound and properly prevents false positives.src/test/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/MagicDateDiagnosticTest.java (1)
240-255: LGTM! Well-structured test for the core feature.The
testStructurePropertyAssignmentmethod effectively verifies the PR's main objective: suppressing diagnostics for structure property assignments while still triggering for simple variable assignments. The helper methods provide clear, descriptive assertions.
|


Описание
Исправлены ложные срабатывания диагностик MagicNumber и MagicDate при работе со структурами. Теперь диагностики не срабатывают при присваивании значений к свойствам структуры, так как имя свойства уже дает смысл значению.
Связанные задачи
Closes #3496
Чеклист
Общие
Для диагностик
Дополнительно
Summary by CodeRabbit
Documentation
Bug Fixes
Tests