Commit Graph

3313 Commits

Author SHA1 Message Date
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 740572f049 Move Version.swift to SwiftLintCore 2023-04-26 21:10:19 -04:00
JP Simard 39a05f2c35 Re-export SwiftLintCore import in SwiftLintFramework
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.
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 a7e3909c6a Improve StyleViolation reason formatting validation (#4946)
So it checks violations for all rules in the registry, not just the
built-in rules.
2023-04-26 18:54:44 +00: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 8a21549ca9 Change Reachability to an enum (#4941)
Since it's already acting as a namespace, might as well make it so it
can't be instantiated and can't have instance properties.
2023-04-26 13:55:17 -04:00
JP Simard 603fff9a82 Make Correction and CorrectableRule declarations public (#4937)
The CLI target shouldn't be importing SwiftLintFramework with
`@_spi(TestHelper)`. If the CLI target needs to access something in
SwiftLintFramework, that declaration should be `public`.
2023-04-26 12:17:10 -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 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 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 1b0f37c6f6 Pin Sourcery version to 2.0.2 (#4888)
By adding a `tools/sourcery` script that downloads and runs Sourcery via
Bazel.

Previously, unrelated changes might include modifications to the
generated comment headers because contributors' local versions of
Sourcery would be used, which we don't control.

Also move the CI job to Buildkite where the bazel server is usually
already warmed up and running.
2023-04-13 20:09:26 +00: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 7dad240ea7 Add a reporters subcommand (#4836) 2023-03-31 08:09:01 +02:00
Martin Redington ca43d2359b Fix unit test configuration (#4847) 2023-03-30 22:46:31 +02:00
JP Simard eb85125a5f release 0.51.0 2023-03-27 11:44:47 -04:00
Martin Redington 5a91b1e392 Fixed display of optin and correctable (#4841)
Co-authored-by: Martin Redington <mildm8nnered@gmail.com>
2023-03-27 07:48:51 +02:00
JP Simard efc5afd5d5 Apply small formatting fixes (#4840)
* Trim excess trailing and vertical whitespace
* Move `SwiftyTextTable` dependency into `frameworkDependencies`
* Adjust wording in README around analyzer rules in the `opt_in_rules`
  section, since analyzer rules can only go in the `analyzer_rules`
  section.
2023-03-26 16:09:43 -04:00
Martin Redington f2d15355be Add a summary table reporter (#4820) 2023-03-25 08:28:42 +01: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