Commit Graph

30 Commits

Author SHA1 Message Date
JP Simard 48604d35e3 Update Sourcery to 2.1.2 (#5318) 2023-10-31 20:34:49 +00:00
Danny Mösch f62411e002 Stop generating tests for core rules (#5225) 2023-09-17 22:13:10 +00:00
Danny Mösch 9f927e9d9b Add new non_overridable_class_declaration rule (#5160) 2023-08-28 13:34:09 -04:00
Matt Thompson 0537f3af75 Add new private_swiftui_state_property rule (#4769) 2023-07-28 16:08:00 -04:00
Keith Smiley b3189aa2d7 Add unneeded_override rule (#5139)
This rule flags functions where the only thing they do is call their
super function and therefore could be omitted. For example:

```swift
override func foo() {
    super.foo()
}
```

This can get pretty complex since there are a lot of slight variations
the subclasses' functions can call the superclasses' functions with, but
this covers many of the cases. Ideally this would handle variable
overrides too but it doesn't currently.
2023-07-26 15:36:30 -04:00
Martin Redington 0693d547b0 Add new unneeded_synthesized_initializer rule (#4812) 2023-06-21 22:15:02 +02:00
woxtu f1d5a55658 Fix typo (#5044) 2023-06-10 23:50:49 +02:00
Kyle Bashour 8822d40687 Add unhandled_throwing_task rule (#4958)
This rule will check Task's that are not explicitly annotated with success and
failure types for unhandled try expressions. These trys will silently fail if an
error is thrown.

See this forum thread for more details:
https://forums.swift.org/t/task-initializer-with-throwing-closure-swallows-error/56066
2023-05-10 14:03:01 -04:00
Danny Mösch 6a2e973de3 Add new redundant_self_in_closure rule (#4911) 2023-05-05 21:14:14 +02: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 3541ef4d02 Import SwiftLintCore in generated tests
In preparation for it containing the `superfluous_disable_command` rule.
2023-04-26 21:10:19 -04:00
JP Simard 4c04cdafa7 Introduce SwiftLintTestCase
To consistently set up rules before tests
2023-04-25 12:28:50 -04: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
Danny Mösch 6d4bc78cb4 Add new superfluous_else rule (#4696) 2023-04-02 12:32:40 +02:00
Kim de Vos b0cbb440c3 Add new sorted_enum_cases rule (#4845) 2023-04-02 11:33:20 +02:00
Martin Redington 7dad240ea7 Add a reporters subcommand (#4836) 2023-03-31 08:09:01 +02:00
Martin Redington 0bd8a7aba6 Add new blanket_disable_command rule (#4731) 2023-03-07 21:43:53 +01:00
1in1 4fee8e6a0c Add new duplicate_conditions rule (#4771) 2023-03-05 11:05:23 +01:00
Martin Redington 1c3c62e422 Add new invalid_swiftlint_command rule (#4546) 2023-03-04 13:53:27 +01:00
Danny Mösch 393318d903 Add new direct_return opt-in rule (#4717) 2023-02-19 13:09:41 +01:00
Danny Mösch cc44c989b7 Check every used internal violation reason for a pending period 2023-01-10 22:29:13 +01:00
Julio Carrettoni 3745704c03 Add rule for single space after period on comments (#4624) 2022-12-15 23:27:33 +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 fd502b4526 Add new local_doc_comment rule (#4581)
Moving the validation of doc comments in local scopes out of
`orphaned_doc_comment` and into a new opt-in `local_doc_comment` rule.

Addresses https://github.com/realm/SwiftLint/issues/4573.
2022-11-23 17:50:18 -05:00
JP Simard 4bd7da32ea Reduce visibility of rules to be internal (#4533)
There's no reason to expose these publicly and this will make it nicer
to move to a new module outside of the core SwiftLint functionality.
2022-11-09 11:01:26 -05:00
Henry 63c043664d Add new no_magic_numbers rule (#4265) 2022-10-30 15:28:20 +01:00
Marcelo Fabri 59ad84f6e9 Add ns_number_init_as_function_reference rule (#4414) 2022-10-20 09:15:17 -07:00
Danny Mösch a7ff8a8d76 Rename if_let_shadowing rule to shorthand_optional_binding (#4334) 2022-10-14 21:47:37 +00:00
JP Simard 5ae1d98596 Create new GeneratedTests and IntegrationTests test targets (#4304)
* Move generated rule tests to a dedicated GeneratedTests target
* Move integration tests to a dedicated IntegrationTests target

This will improve bazel cacheability by having fewer tests depend on all
lint inputs, which are only needed by the integration tests.
2022-10-06 00:10:04 -04:00