drccrd commented on PR #4083:
URL: 
https://github.com/apache/incubator-kie-tools/pull/4083#issuecomment-6977538833

   Thanks for picking up #3711, the stable codes are exactly the prerequisite 
the issue needed. Below are scope notes from me as the issue author, a 
structural suggestion, and bugs, each reproduced against the branch head 
(c9c83cc).
   
   ### Scope
   
   **Deprecation warnings should be suppressible too.** #3711 predates the 
deprecated-syntax lint (#4006), which is why it only names `drools-lint` and 
`drools-type`. To cover `drools-deprecated`:
   - Give each deprecation family a stable code, for example 
`deprecated-half-constraint`, `deprecated-pattern-connective`, 
`deprecated-connective-annotation`, `deprecated-agenda-group`, 
`deprecated-custom-operator`. `DeprecatedConstructs` sets no codes today, so 
only a directive without codes could match them.
   - Expose its source constant 
([DeprecatedConstructs.java#L67](https://github.com/apache/incubator-kie-tools/blob/c9c83cc60bcd3442c4c1b81b2bf62939ab77399e/packages/drools-lsp/drools-completion/src/main/java/org/drools/completion/DeprecatedConstructs.java#L67))
 and include it in the suppressible sources.
   - These diagnostics are produced inside `DRLDiagnosticHelper.parse`, which 
neither `lint()` nor `lintUnknownTypes()` sees, so they need the central filter 
described below.
   - A suppressed deprecation should simply disappear. It must not bring back 
the parse errors it replaced, which is what `drools.lsp.lint.deprecated: off` 
does.
   
   **Keeping `disable-next-line` and the `disable`/`enable` regions is fine.** 
They go beyond the issue but look useful. Bugs 2 and 7 below are the two things 
they need fixed.
   
   ### Structure: reuse the parse instead of re-scanning the text
   
   `DRLLintSuppression` re-implements parsing that already exists:
   - `RULE_KEYWORD`, `DECLARE_KEYWORD`, `END_AT_START` and `END_AT_END` are 
copied from `DRLLintHelper`, and `findRuleBoundaries` re-implements the 
`lintMissingRuleEnds` scan, but tracks one open rule where the original uses a 
stack (bug 4).
   - `SuppressionIndex.parse` re-runs `DRLLintHelper.sanitize`, which `lint()` 
already ran, and `blankStrings` hand-rolls string detection.
   - The directive regex matches anywhere on a line, not only inside comments.
   
   `DRLDiagnosticHelper.parse` already lexes the whole document 
([L92-L94](https://github.com/apache/incubator-kie-tools/blob/c9c83cc60bcd3442c4c1b81b2bf62939ab77399e/packages/drools-lsp/drools-completion/src/main/java/org/drools/completion/DRLDiagnosticHelper.java#L92-L94)),
 and every comment is a typed token there: `LINE_COMMENT` in the header and 
LHS, `RHS_LINE_COMMENT` and `RHS_COMMENT` inside consequences. String contents 
are separate `*_STRING_LITERAL` tokens, and a block comment token knows its end 
line. Suggestion:
   1. Read directives from those comment tokens (exposed through `Parsed`). 
That removes `blankStrings` and fixes bugs 3 and 6.
   2. Build one suppression index per validation in 
`DroolsLspDocumentService.validate()` 
([L233-L250](https://github.com/apache/incubator-kie-tools/blob/c9c83cc60bcd3442c4c1b81b2bf62939ab77399e/packages/drools-lsp/drools-lsp-server/src/main/java/org/drools/lsp/server/DroolsLspDocumentService.java#L233-L250)),
 the one place where syntax, deprecation, lint and unknown-type diagnostics are 
combined. Pass it into the lint passes so they skip suppressed findings before 
counting toward their caps (bug 1), and into `mvelPropertyAccessEdits` (bug 5).
   3. For `disable-rule` ranges, extract the stack-based scanner from 
`lintMissingRuleEnds` and share it (bug 4). It works on broken text, which is 
exactly when `missing-end` fires.
   
   ### Bugs
   
   1. **Suppressed findings use up the per-pass cap.** The passes stop at 
`MAX_DIAGNOSTICS_PER_PASS` (20) and `MAX_UNKNOWN_TYPE_DIAGNOSTICS` (50) before 
`filter` runs 
([DRLLintHelper.java#L159](https://github.com/apache/incubator-kie-tools/blob/c9c83cc60bcd3442c4c1b81b2bf62939ab77399e/packages/drools-lsp/drools-completion/src/main/java/org/drools/completion/DRLLintHelper.java#L159),
 
[#L861](https://github.com/apache/incubator-kie-tools/blob/c9c83cc60bcd3442c4c1b81b2bf62939ab77399e/packages/drools-lsp/drools-completion/src/main/java/org/drools/completion/DRLLintHelper.java#L861)).
 A `disable missing-semicolon` region over a rule with 25 missing `;`, then 
`enable` and a new rule with one real missing `;`: `lint()` returns nothing. 
Likewise 55 suppressed unknown types hide the unknown type in the next rule.
   2. **A misspelled action opens a region to the end of the file.** `\b` 
matches between `disable` and `-` 
([L55-L56](https://github.com/apache/incubator-kie-tools/blob/c9c83cc60bcd3442c4c1b81b2bf62939ab77399e/packages/drools-lsp/drools-completion/src/main/java/org/drools/completion/DRLLintSuppression.java#L55-L56)),
 so `// @drl-lsp-lint:disable-lines missing-semicolon` parses as `disable` and 
hides every later missing `;` in the file. Misspelled codes such as 
`missing-semicolons` are also accepted silently. Please anchor the action 
(followed by whitespace, `*/` or the end of the comment) and report unknown 
actions and codes.
   3. **Directive detection is not comment-aware** (this is also the Copilot 
comment). `insert(p) // can't fix yet @drl-lsp-lint:disable-line 
missing-semicolon` still reports, because the apostrophe opens a pseudo-string 
that blanks the rest of the line. In the other direction, `insert(p) 
@drl-lsp-lint:disable-line` written as plain code is honoured. And `#` is not a 
comment in DRL10: the lexer produces `HASH`, `AT` and identifier tokens, and 
parsing the input of `alternateCommentSyntaxesAndDescriptions` reports 
`mismatched input '#'` at line 0. The test passes only because the lint never 
parses. I'd drop `#` support.
   4. **`disable-rule` binds to the wrong rule.** `findRuleBoundaries` 
overwrites `currentRuleStart` without recording an unclosed rule 
([L351-L353](https://github.com/apache/incubator-kie-tools/blob/c9c83cc60bcd3442c4c1b81b2bf62939ab77399e/packages/drools-lsp/drools-completion/src/main/java/org/drools/completion/DRLLintSuppression.java#L351-L353)):
 `disable-rule missing-end` above an unclosed rule A followed by rule B keeps 
A's `missing-end` and suppresses B instead. Separately, the case-insensitive 
`^\s*(rule|query)\b` treats a consequence line `Rule r = drools.getRule();` as 
a new rule, and `disable-rule missing-semicolon` above such a rule then 
suppresses neither of its missing `;`.
   5. **Quick fixes ignore suppression.** `buildPropertyAccessActions` 
recomputes its edits with `mvelPropertyAccessEdits(text)` 
([DroolsLspDocumentService.java#L760](https://github.com/apache/incubator-kie-tools/blob/c9c83cc60bcd3442c4c1b81b2bf62939ab77399e/packages/drools-lsp/drools-lsp-server/src/main/java/org/drools/lsp/server/DroolsLspDocumentService.java#L760)).
 With `mvelPropertyAccess` on, `Person( getName() == "x" ) // 
@drl-lsp-lint:disable-line mvel-property-access` shows no diagnostic, but 
"Convert all getter calls in this file" still rewrites it.
   6. **`disable-next-line` in a multi-line block comment** targets the line 
after the directive, which is the ` */` line 
([L257-L263](https://github.com/apache/incubator-kie-tools/blob/c9c83cc60bcd3442c4c1b81b2bf62939ab77399e/packages/drools-lsp/drools-completion/src/main/java/org/drools/completion/DRLLintSuppression.java#L257-L263)),
 so the statement after the comment is still reported.
   7. **`enable <code>` inside a wildcard region** replaces `*` with the 
hand-kept `ALL_LINT_CODES` 
([L282-L292](https://github.com/apache/incubator-kie-tools/blob/c9c83cc60bcd3442c4c1b81b2bf62939ab77399e/packages/drools-lsp/drools-completion/src/main/java/org/drools/completion/DRLLintSuppression.java#L282-L292)).
 Any code missing from that list, such as the deprecation codes above, 
reappears inside the region. Keeping the region as "everything except the 
re-enabled codes" removes the need for the list.
   
   ### Smaller points
   
   - Diagnostic sources: the PR adds `CODE_*` constants, but `"drools-lint"` 
and `"drools-type"` stay literals in eight `setSource` calls, in 
`isSuppressibleSource` and in `DroolsLspDocumentService` 
([#L696](https://github.com/apache/incubator-kie-tools/blob/c9c83cc60bcd3442c4c1b81b2bf62939ab77399e/packages/drools-lsp/drools-lsp-server/src/main/java/org/drools/lsp/server/DroolsLspDocumentService.java#L696)).
 The filter only works while those strings match, so `SOURCE_*` constants next 
to the codes would tie producers, filter and code actions together, as 
`CompileDiagnostics.SOURCE` and `DeprecatedConstructs.SOURCE` already do.
   - README: the lint section documents every lint setting but not the 
directives, their scopes, the `-- note` form or the code names users have to 
type.
   - `SuppressionIndex.parse` lowercases a copy of the whole document on every 
call, even without directives. `DIRECTIVE_PATTERN.matcher(text).find()` avoids 
the copy, and the question goes away if directives come from comment tokens.
   - Unused code: the `rawArgs == null` branch in `parseCodes` is unreachable, 
`t.trim()` after splitting on `[,\s]+` does nothing, `hasAnySuppression` can be 
derived from the two collections, and `java.util.Collections` is unused (as are 
`ArrayList`, `Collections` and `DiagnosticSeverity` in the test).
   


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

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to