501 Commits

Author SHA1 Message Date
Danny Mösch faa5859155 Introduce guarded filepath provider for file collection (#6435) 2026-01-14 18:06:13 -05:00
Danny Mösch 35e3d0c6f4 Mark directories as such to enforce a new hierarchy (#6434) 2026-01-13 21:25:22 +01:00
Danny Mösch 2e78f40e54 Use directory enumerator to collect and exclude files at the same time (#6366) 2025-12-17 19:47:21 +01:00
Saleem Abdulrasool 562ec8f369 Correct incorrect handling of file paths (#6355)
`URL.path` is not a usable rendering of the path. `URL.path` represents
the URI path. If the path is meant to be consumable as a file path, the
file system representation (aka FSR) must be retrieved.

This improves the file path handling and makes additional tests now
pass.

Co-authored-by: Danny Mösch <danny.moesch@icloud.com>
2025-12-01 22:02:12 +01:00
Danny Mösch 4065fc8437 Enable upcoming feature MemberImportVisibility (#6286) 2025-10-08 08:12:05 +02:00
Danny Mösch c1ffdfe891 Enable prefer_condition_list rule (#6163) 2025-07-12 09:41:00 -04:00
Danny Mösch a6c4fd98bc Move files from SwiftLintCore to SwiftLintFramework
Ideally, SwiftLintCore would some day only contain components
that are needed to define rules. Consequently, it would be the
only bundle required to import for (external) rule development.
2024-12-23 12:51:43 +01:00
JP Simard a7bc9e20c7 Move built-in rules to new SwiftLintBuiltInRules module (#4950) 2023-04-27 11:16:01 -04:00
JP Simard 86d60400c1 Move core SwiftLint functionality to new SwiftLintCore module
Over the years, SwiftLintFramework had become a fairly massive monolith,
containing over 400 source files with both core infrastructure and
rules.

Architecturally, the rules should rely on the core infrastructure but
not the other way around. There are two exceptions to this:
`custom_rules` and `superfluous_disable_command` which need special
integration with the linter infrastructure.

Now the time has come to formalize this architecture and one way to do
that is to move the core SwiftLint functionality out of
SwiftLintFramework and into a new SwiftLintCore module that the rules
can depend on.

Beyond enforcing architectural patterns, this also has the advantage of
speeding up incremental compilation by skipping rebuilding the core
functionality when iterating on rules.

Because the core functionality is always useful when building rules, I'm
opting to import SwiftLintCore in SwiftLintFramework as `@_exported` so
that it's implicitly available to all files in SwiftLintFramework
without needing to import it directly.

In a follow-up I'll also split the built-in rules and the extra rules
into their own modules. More modularization is possible from there, but
not planned.

The bulk of this PR just moves files from `Source/SwiftLintFramework/*`
to `Source/SwiftLintCore/*`. There are some other changes that can't be
split up into their own PRs:

* Change jazzy to document the SwiftLintCore module instead of
  SwiftLintFramework.
* Change imports in unit tests to reflect where code was moved to.
* Update `sourcery` make rule to reflect where code was moved to.
* Create a new `coreRules` array and register those rules with the
  registry. This allows the `custom_rules` and
  `superfluous_disable_command` rule implementations to remain internal
  to the SwiftLintCore module, preventing more implementation details
  from leaking across architectural layers.
* Move `RuleRegistry.registerAllRulesOnce()` out of the type declaration
  and up one level so it can access rules defined downstream from
  SwiftLintCore.
2023-04-26 21:10:19 -04:00
JP Simard 3a2bb15ca3 Make some SwiftLintFramework declarations public (#4945)
* Make some SwiftLintFramework declarations public

If built-in rules depend on them.

This will allow separating the rules from the core infrastructure in
separate modules in an upcoming PR.

It also helps formalize the API contract for what should be accessible
to rule implementations.

* Exclude extensions from jazzy
2023-04-26 16:37:25 -04:00
JP Simard ea56405983 Rename Request.cursorInfo() to cursorInfoWithoutSymbolGraph() (#4943)
To avoid conflicting with the `cursorInfo` declared in
SourceKittenFramework.
2023-04-26 18:28:24 +00:00
JP Simard 165172e0fa Introduce a "rule registry" concept
This will allow for registering rules that aren't compiled as part of
SwiftLintFramework.

Specifically this will allow us to split the built-in and extra rules
into separate modules, leading to faster incremental compilation when
working on rules since the rest of the framework won't need to be
rebuilt on every compilation.
2023-04-25 12:28:50 -04:00
JP Simard 70a56a1420 Update SwiftSyntax to 04-10 snapshot (#4887)
https://github.com/apple/swift-syntax/releases/tag/509.0.0-swift-5.9-DEVELOPMENT-SNAPSHOT-2023-04-10-a
2023-04-13 14:04:43 -04:00
Martin Redington ca43d2359b Fix unit test configuration (#4847) 2023-03-30 22:46:31 +02:00
Danny Mösch 7ac128c83d Enable direct_return rule in the repository 2023-03-12 14:36:07 +01:00
Danny Mösch 1bf2f25e40 Get rid of some disabled commands (#4807) 2023-03-11 08:20:47 -05:00
Martin Redington 31510b662e Use all optin rules facility for SwiftLint's own .swiftlint.yml (#4800) 2023-03-11 11:59:05 +01:00
Martin Redington 0bd8a7aba6 Add new blanket_disable_command rule (#4731) 2023-03-07 21:43:53 +01:00
Martin Redington 1c3c62e422 Add new invalid_swiftlint_command rule (#4546) 2023-03-04 13:53:27 +01:00
Martin Redington d6e3bbb64d Add "all" pseudo-rule which enables all opt-in rules (#4544) 2023-03-04 13:49:00 +01:00
Danny Mösch c9b1b961f5 Fix some issues in direct_return rule (#4783) 2023-02-25 02:48:31 -05:00
JP Simard 2f0e537f9b Update SwiftSyntax to latest development snapshot (#4759)
* Merge `spacedBinaryOperator` and `unspacedBinaryOperator`

* New contextual keyword enums

* Update for removed `UnavailabilityConditionSyntax`

* Handle how attributes are now defined

This partially reverts commit 325d0ee1e4.

* Handle removal of `TokenListSyntax`

* Update `Package.swift`

* Extract some SwiftSyntax helpers

* Update to `0.50900.0-swift-DEVELOPMENT-SNAPSHOT-2023-02-06-a`

* Skip attributes with keypath arguments in `attributes` rule

To preserve the rule's existing behavior.

* Limit unowned_variable_capture violations to capture lists

* Add changelog entries
2023-02-20 10:51:31 -05:00
Danny Mösch f3e5557de9 Stop triggering strict_fileprivate rule on protocol implementations (#4705) 2023-02-18 13:23:26 +01:00
Marcelo Fabri 0163ffd328 Cache folded syntax tree (#4744) 2023-02-06 10:39:36 -08:00
Danny Mösch 5eed8fe91b Enable if_let_shadowing rule and fix all violations (#4247) 2023-01-31 22:31:38 +01:00
JP Simard 0750d5d465 Extract EnumDeclSyntax.supportsRawValues helper (#4727)
I'll want to use this elsewhere shortly.

Also adds `CGFloat` to the raw value types since we were missing that
one.
2023-01-27 16:46:54 -05:00
JP Simard 84c6d200b6 Clean up unused initializers (#4726)
Found with the upcoming improve dead code detection.
2023-01-27 16:31:56 -05:00
Jimmy Arts eda0d92f44 Make forceExclude work with directly specified files (#4609) 2022-12-22 21:15:08 +01:00
Julio Carrettoni 3745704c03 Add rule for single space after period on comments (#4624) 2022-12-15 23:27:33 +01:00
Danny Mösch 4adabd8e4b Print a warning for Analyzer rules misplaced in the configuration (#4620) 2022-12-05 18:03:54 -05:00
Martin Redington 7a8b2d1dab Add test_parent_class option to more test rules (#4262) 2022-12-01 18:56:13 +01:00
Ryan Aveo 92304cdd98 Fix building tests in Xcode (#4607)
Co-authored-by: JP Simard <jp@jpsim.com>
2022-11-30 10:33:33 -05:00
JP Simard 4ccf9eebb4 Fix line count calculation for multiline string literals (#4587)
Fixes https://github.com/realm/SwiftLint/issues/4585

Update body length rule thresholds for SwiftLint
2022-11-24 16:40:51 +00:00
JP Simard ba8899714d Reduce visibility of custom rules (#4553) 2022-11-16 16:14:50 -05:00
JP Simard 18f9a0e3a6 Write some docs for internal APIs (#4550)
These should be useful when writing rules, but also may become public
API in the future.
2022-11-16 13:58:55 -05:00
JP Simard 04d1184904 Remove structure cache (#4541) 2022-11-10 14:53:16 -05:00
Danny Mösch 1edef5ebdc Trigger prefer_self_in_static_references rule on constructor calls (#4519) 2022-11-06 14:55:28 +01:00
Danny Mösch 7e8a3ae2ac Introduce onlyElement property on Collection (#4518) 2022-11-06 07:37:44 -05:00
Marcelo Fabri 45ac3dcdff Rewrite required_enum_case with SwiftSyntax (#4521) 2022-11-06 01:26:11 -08:00
JP Simard e97119efec Migrate orphaned_doc_comment to use SwiftSyntax classifications (#4461) 2022-11-02 15:55:47 +00:00
JP Simard f1f6a3c4a0 Add ByteSourceRange.toSourceKittenByteRange() helper (#4500)
This will be useful for other rules too.
2022-11-01 14:13:29 -04:00
Marcelo Fabri 20bfe264f5 Rewrite overridden_super_call and prohibited_super_call with SwiftSyntax (#4493)
* Rewrite `overridden_super_call` with SwiftSyntax

* Rewrite `prohibited_super_call` too
2022-10-30 20:28:25 -07:00
JP Simard d551cb8c16 Update SwiftSyntax (#4480)
Moves syntax classifications to a new IDEUtils module.
2022-10-28 09:23:06 -04:00
JP Simard 1b59a3f168 Cache location converters (#4481)
This is 2%-12% faster according to OSSCheck
2022-10-26 12:37:16 -04:00
Marcelo Fabri c1f2b615e2 Rewrite redundant_optional_initialization with SwiftSyntax (#4409) 2022-10-23 20:30:29 -04:00
Marcelo Fabri 53752f58ad Rewrite redundant_set_access_control with SwiftSyntax (#4395) 2022-10-23 15:30:01 -07:00
JP Simard cb79584c7d Migrate comment_spacing to use SwiftSyntax classifications (#4460) 2022-10-23 17:39:38 -04:00
JP Simard 1ee5154687 Update SwiftSyntax to fa7ff05 (#4455)
There's a new SwiftParserDiagnostics module and the rewriter visit
function signatures changed.
2022-10-23 11:56:22 -04:00
Marcelo Fabri cee4af098f Migrate prefer_zero_over_explicit_init to SwiftSyntax (#4448) 2022-10-23 04:53:00 -07:00
Marcelo Fabri 9c8708bc01 Extract common SwiftSyntax extensions (#4445) 2022-10-23 00:54:18 -07:00