Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 0 additions & 32 deletions MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
- [Enumerations](#enumerations)
- [Assign-only Properties](#assign-only-properties)
- [Redundant Public Accessibility](#redundant-public-accessibility)
- [Redundant Internal Accessibility](#redundant-internal-accessibility)
- [Redundant Fileprivate Accessibility](#redundant-fileprivate-accessibility)
- [Unused Imports](#unused-imports)
- [Objective-C](#objective-c)
- [Codable](#codable)
Expand Down Expand Up @@ -293,6 +295,18 @@ Declarations that are marked `public` yet are not referenced from outside their

This analysis can be disabled with `--disable-redundant-public-analysis`.

### Redundant Internal Accessibility

Declarations that are marked `internal` (or are unmarked, since this is Swift's default access level), yet are not referenced outside the file they're defined in are identified as having redundant internal accessibility. In this scenario, the declaration could be marked `private` or `fileprivate`. Reducing the visibility of declarations — encapsulation — helps with code maintainability and can improve compilation performance.

This analysis can be disabled with `--disable-redundant-internal-analysis`.

### Redundant Fileprivate Accessibility

Declarations that are marked `fileprivate` yet are not accessed from other types within the same file are identified as having redundant fileprivate accessibility. If a `fileprivate` declaration is only used within its own type, it should be marked `private` instead. Reducing the visibility of declarations helps with code maintainability and makes access boundaries clearer.

This analysis can be disabled with `--disable-redundant-fileprivate-analysis`.

### Unused Imports

Periphery can only detect unused imports of targets it has scanned. It cannot detect unused imports of other targets because the Swift source files are unavailable and uses of `@_exported` cannot be observed. `@_exported` is problematic because it changes the public interface of a target such that the declarations exported by the target are no longer necessarily declared by the imported target. For example, the `Foundation` target exports `Dispatch`, among other targets. If any given source file imports `Foundation` and references `DispatchQueue` but no other declarations from `Foundation`, then the `Foundation` import cannot be removed as it would also make the `DispatchQueue` type unavailable. To avoid false positives, therefore, Periphery only detects unused imports of targets it has scanned.
Expand Down
3 changes: 3 additions & 0 deletions Sources/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ swift_library(
"SourceGraph/Mutators/ProtocolConformanceReferenceBuilder.swift",
"SourceGraph/Mutators/ProtocolExtensionReferenceBuilder.swift",
"SourceGraph/Mutators/PubliclyAccessibleRetainer.swift",
"SourceGraph/Mutators/RedundantAccessibilityMarkerShared.swift",
"SourceGraph/Mutators/RedundantExplicitPublicAccessibilityMarker.swift",
"SourceGraph/Mutators/RedundantFilePrivateAccessibilityMarker.swift",
"SourceGraph/Mutators/RedundantInternalAccessibilityMarker.swift",
"SourceGraph/Mutators/RedundantProtocolMarker.swift",
"SourceGraph/Mutators/ResultBuilderRetainer.swift",
"SourceGraph/Mutators/StringInterpolationAppendInterpolationRetainer.swift",
Expand Down
14 changes: 12 additions & 2 deletions Sources/Configuration/Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@ public final class Configuration {
@Setting(key: "disable_redundant_public_analysis", defaultValue: false)
public var disableRedundantPublicAnalysis: Bool

@Setting(key: "disable_redundant_internal_analysis", defaultValue: false)
public var disableRedundantInternalAnalysis: Bool

@Setting(key: "disable_redundant_fileprivate_analysis", defaultValue: false)
public var disableRedundantFilePrivateAnalysis: Bool

@Setting(key: "show_nested_redundant_accessibility", defaultValue: false)
public var showNestedRedundantAccessibility: Bool

@Setting(key: "disable_unused_import_analysis", defaultValue: false)
public var disableUnusedImportAnalysis: Bool

Expand Down Expand Up @@ -224,10 +233,11 @@ public final class Configuration {

// MARK: - Private

lazy var settings: [any AbstractSetting] = [
private lazy var settings: [any AbstractSetting] = [
$project, $schemes, $excludeTargets, $excludeTests, $indexExclude, $reportExclude, $reportInclude, $outputFormat,
$retainPublic, $noRetainSPI, $retainFiles, $retainAssignOnlyProperties, $retainAssignOnlyPropertyTypes, $retainObjcAccessible,
$retainObjcAnnotated, $retainUnusedProtocolFuncParams, $retainSwiftUIPreviews, $disableRedundantPublicAnalysis,
$disableRedundantInternalAnalysis, $disableRedundantFilePrivateAnalysis, $showNestedRedundantAccessibility,
$disableUnusedImportAnalysis, $superfluousIgnoreComments, $retainUnusedImportedModules,
$externalEncodableProtocols, $externalCodableProtocols, $externalTestCaseClasses, $verbose, $quiet, $color,
$disableUpdateCheck, $strict, $indexStorePath,
Expand Down Expand Up @@ -256,7 +266,7 @@ public final class Configuration {
}
}

protocol AbstractSetting {
private protocol AbstractSetting {
associatedtype Value

var key: String { get }
Expand Down
Loading
Loading