Draft
Conversation
Contributor
|
Thanks for your pull request and interest in making D better, @gorsing! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub run digger -- build "master + dmd#22840" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Currently, developers rely on external tools like D-Scanner to catch semantic anti-patterns and style issues. However, external AST-based linters lack access to the compiler's symbol table and type resolution, which leads to false positives/negatives for complex semantic rules.
At the same time, introducing new semantic checks as compiler warnings (
-w) has historically been rejected because it breaks existing codebases and CI pipelines.Solution
This PR introduces a dedicated, strictly opt-in linter infrastructure integrated directly into the frontend via
pragma(lint).ErrorKind.lintdiagnostic that strictly does not incrementglobal.errorsorglobal.warnings. Compiling with-wor-wewill never fail if a lint rule is triggered.pragma(lint, ruleName)integrates tightly withScopeand applies lexically. It can be toggled on/off (none,all) per-module, per-aggregate, or per-function, respecting D's philosophy of explicit control.SARIFoutput, making it ready for modern IDEs and CI/CD environments.Proof of Concept Rule (
constSpecial)To demonstrate the infrastructure, this PR includes one zero-false-positive rule:
constSpecial. It emits a lint message when special struct methods (opEquals,toHash,opCmp,toString) are declared withoutconst. Since this check sits insemantic3.d(visit(FuncDeclaration)), it leverages the compiler's perfect knowledge of types and correctly ignores compiler-generated thunks (!funcdecl.isGenerated()).Example usage:
Proof of Concept Rule (unusedParams)
Example usage:
Future Impact
If accepted, this lays the groundwork for migrating highly requested, semantically heavy checks (e.g., unused parameters, redundant expressions, catching base
Exceptionor UnusedParams) directly into the compiler, without disrupting the ecosystem or forcing warnings on users who don't want them.