org.sonar.l10n.delphi.rules.community-delphi.ImportSpecificity.html Maven / Gradle / Ivy
Why is this an issue?
The interface uses clause should only contain imports that are required for the interface section.
Imports that are only used in the implementation section should be moved there.
Importing a unit in the interface section declares a compilation dependency on that unit.
Units cannot have mutual (circular) dependencies in their interface sections, and a unit must be
recompiled whenever a unit imported in its interface section is changed. Because of this,
interface imports increase the time the compiler takes to resolve and validate dependencies.
Implementation section imports do not have these limitations. If an import in the interface
section doesn't need to be there, these costs are being incurred for no benefit.
It also encapsulates implementation details where they belong - in the implementation section.
How to fix it
Move the import into the implementation uses clause:
unit Unit1;
interface
uses System.IOUtils;
procedure Run;
implementation
procedure Run;
begin
TFile.WriteAllText('myfile.txt', 'Hello world');
end;
unit Unit1;
interface
procedure Run;
implementation
uses System.IOUtils;
procedure Run;
begin
TFile.WriteAllText('myfile.txt', 'Hello world');
end;
Resources