2553 Commits

Author SHA1 Message Date
Danny Mösch 67e98911fc Get rid of @testable import 2025-10-18 00:19:05 +02:00
Danny Mösch aa67f5ac13 Adopt typed throws where possible (#5922) 2025-09-27 19:11:46 +02:00
Martin Redington 13c0c235eb only rule should work for individual custom rules (#6057) 2025-09-18 10:21:47 +01:00
Danny Mösch 77050e8c40 Enable a fully statically linked Linux executable (#6211)
If SwiftLint is built from this state using the Swift SDK, we'll get a
large self-contained Linux executable that runs without loading SourceKit.
It can do that by disabling any rule that requires SourceKit.

With `SWIFTLINT_DISABLE_SOURCEKIT` set on a normally (dynamically linked)
binary, the behavior is the same. That's different from the previously
reported more serious warnings.
2025-08-30 10:02:38 -04:00
Danny Mösch 7624586c18 Maintain SourceKit-mode as long as custom rules don't support SwiftSyntax (#6212) 2025-08-30 09:42:52 +02:00
JP Simard f6c9633087 Add RegexConfiguration.ExecutionMode (#6128)
* Add `RegexConfiguration.ExecutionMode`

To help migrate custom rules to SwiftSyntax. Not wired up yet, just the
configuration parsing and defaults. Will wire it up in the next PR.

The diff looks big, but it's 500+ lines of tests, with ~45 lines of
actually new code.

* Docs

* Address PR feedback

- Add `default` case to ExecutionMode enum instead of using optional
- Change configuration key from `mode` to `execution_mode` for consistency
- Move default execution mode logic to runtime instead of configuration time
- Refactor test functions to use throws instead of do-catch
2025-06-22 10:19:14 -04:00
JP Simard 3a922d41f9 Add ConditionallySourceKitFree to migrate custom rules to SwiftSyntax (#6127)
The protocol will be used to tag rules that may or may not require
SourceKit depending on its configuration. I only expect this to be used
for custom rules as utility to help transition to a fully SwiftSyntax
based approach.
2025-06-21 15:54:56 -04:00
Danny Mösch ec35f95786 Fix strict concurrency warnings in SwiftLintCore 2024-12-23 16:52:10 +01: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 eaf34d7204 Move extra rules into its own module (#4949)
This will decouple building extra rules from built-in rules so that
making changes in one of those modules doesn't rebuild the other.
2023-04-27 10:37:30 -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 72c2a5488d Re-order CustomRules.swift (#4944)
For consistency with other files in this project, which usually have
private extensions at the bottom of the file.
2023-04-26 18:37:40 +00: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 9c414932d8 Add more documentation comments (#4942)
In preparation for these declarations to become public.
2023-04-26 14:18:13 -04:00
JP Simard 2544dc79d3 Move CustomRuleTimer to its own file (#4938)
And add docs.
2023-04-26 15:56:04 +00:00
Benny Wong 172b8b8a94 Remove else else typo (#4933) 2023-04-25 18:03:25 +00:00
JP Simard 3f52acd0a2 Make UnitTestRuleConfiguration internal (#4931) 2023-04-25 13:28:28 +00:00
JP Simard 817de197d5 Clean up MARK comments 2023-04-24 15:13:44 -04:00
Danny Mösch c241935635 Introduce basic Stack type (#4922) 2023-04-23 09:12:35 +00:00
Danny Mösch 69fadb6918 Remove no-op initializers from structs (#4912) 2023-04-20 11:59:37 +02:00
JP Simard 21dc766c93 Exclude new XCTSpecificMatcherRule examples from documentation (#4907) 2023-04-18 21:45:51 +00:00
JP Simard fbbccf9db8 Allow configuring xct_specific_matcher with matchers (#4905)
So that either `one-argument-asserts` or `two-argument-asserts` or both
can be enabled.

The following configuration effectively reverts back to the rule
behavior prior to https://github.com/realm/SwiftLint/pull/3858:

```yaml
xct_specific_matcher:
  matchers:
    - two-argument-asserts
```
2023-04-18 20:50:58 +00:00
JP Simard c22d60fac0 Update UnusedImportRuleExamples for Swift 5.8 (#4903) 2023-04-18 17:58:40 +00:00
Andrew Montgomery 41290a23d3 Remove checks for setUp/tearDown from overridden_super_call rule (#4875) 2023-04-17 20:18:41 +00:00
Danny Mösch 5aed7ce95c Check first argument label in reduce_boolean rule (#4895) 2023-04-16 09:58:27 +02:00
Martin Redington 97fd216455 Skip unit tests in no_magic_numbers rule (#4897) 2023-04-16 09:07:54 +02:00
Danny Mösch f127ba14dd Ignore block comments in let_var_whitespace rule (#4889) 2023-04-16 00:10:03 +02:00
JP Simard 5226725689 Fix extra space before member access 2023-04-13 15:12:37 -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
Danny Mösch bb11e6a0a7 Extract examples to separate file 2023-04-04 20:10:59 +02:00
Danny Mösch eee97a7b2b Trigger prefer_self_in_static_references rule on types 2023-04-04 20:10:59 +02:00
Danny Mösch cf1e2e27dc Use is instead of as for simple type checks 2023-04-04 20:10:59 +02:00
Sven Münnich a2facce70c Fix false positives related to multiline strings in indentation_width rule (#4862) 2023-04-04 19:27:16 +02:00
Danny Mösch bd444fcd77 Fix lower_acl_than_parent rule rewriter by preserving leading whitespace (#4861) 2023-04-03 20:26:46 +00:00
Danny Mösch ee849bcb10 Remove unused imports (#4856) 2023-04-03 19:26:59 +02:00
Danny Mösch 6d4bc78cb4 Add new superfluous_else rule (#4696) 2023-04-02 12:32:40 +02:00
Danny Mösch 16e2bb0f18 Extend xct_specific_matcher rule to check for boolean asserts on (un)equal comparisons (#3858) 2023-04-02 12:30:21 +02:00
Kim de Vos b0cbb440c3 Add new sorted_enum_cases rule (#4845) 2023-04-02 11:33:20 +02:00
Danny Mösch 58a07eb452 Update SwiftSyntax (#4852) 2023-03-31 23:12:31 +02:00
Danny Mösch 3d15419adb Fix warnings in Swift 5.8/Xcode 14.3 (#4850) 2023-03-31 22:13:20 +02:00
Martin Redington 6a09af169e Fix crash when parsing apple/swift (#4828) 2023-03-31 20:59:47 +02:00
Martin Redington 6983c813c8 Fix rewriter of trailing_semicolon rule wrongly removing trailing comments (#4818) 2023-03-13 22:23:35 +00:00
Danny Mösch fb89ab2fb5 Stop triggering unused_capture_list on variables referenced in optional bindings 2023-03-12 14:38:10 +01:00
Danny Mösch 7ac128c83d Enable direct_return rule in the repository 2023-03-12 14:36:07 +01:00
Danny Mösch 06578e5d91 Get rid of some more disabled commands 2023-03-12 00:03:02 +01:00
Danny Mösch 1940e0e2d2 Make custom rule rule_id more specific 2023-03-12 00:03:02 +01:00
Danny Mösch bd77cbcf6e Add example verifying that trailing_semicolon works with trailing comments (#4808) 2023-03-11 13:29:38 +00:00
Martin Redington 31510b662e Use all optin rules facility for SwiftLint's own .swiftlint.yml (#4800) 2023-03-11 11:59:05 +01:00