38 Commits

Author SHA1 Message Date
Danny Mösch 599e51a5a2 Format code (#6151) 2025-07-02 17:50:53 -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 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
Danny Mösch 5eed8fe91b Enable if_let_shadowing rule and fix all violations (#4247) 2023-01-31 22:31:38 +01:00
Danny Mösch 32152646f3 Use Self in constructor calls (#4505) 2022-11-02 22:50:22 +00:00
Danny Mösch 050473a0e1 Add optional prefer_self_in_static_references rule (#3732) 2021-11-29 18:42:53 +00:00
Paul Taykalo 693ee2cae9 Add Isnot Empty extension in the Swift Framework (#3387) 2020-11-07 18:42:55 -05:00
JP Simard 889dc49bb6 Remove support for compiling with 5.0.x (#3180)
* Remove support for compiling with 5.0.x

* fixup! Remove support for compiling with 5.0.x
2020-04-14 08:46:23 -07:00
JP Simard 399f5b7df6 Fix docstring formatting issues using DrString (#3032)
Using command:
$ drstring check -i 'Source/**/*.swift' --first-letter lowercase --vertical-align
2020-01-12 11:19:33 -08:00
JP Simard 37167a8a35 Add documentation comments to all public declarations (#3027) 2020-01-08 09:47:10 -08:00
JP Simard 3a0c2b0c05 Migrate LinterCache to use Codable models (#2799)
* Migrate LinterCache to use Codable models

improving performance and type safety

* Fix Linux

* Avoid creating a Decoder if it won't be used

For example if the file doesn't exist or can't be read.

* Use corelibs plist coder if available

It's available in the Swift 5.1 branch: https://github.com/apple/swift-corelibs-foundation/pull/1849

* Remove unused error case
2019-07-07 00:35:10 -07:00
Colton Schlosser 18e90be780 Split cache into one file per configuration (#2796)
* Split cache into one file per configuration

* Only write cache files with changes

* Avoid converting from Data -> String -> Data when saving cache files

* Move empty check to for where

* Split cache changelog entry

* Reword changelog entry to better reflect impact
2019-07-06 11:50:20 -07:00
JP Simard b83e0991b9 Remove all file headers
The MIT license doesn't require that all files be prepended with this
licensing or copyright information. Realm confirmed that they're ok with this
change. This will enable some companies to contribute to SwiftLint and the
date & authorship information will remain accessible via git source control.
2018-05-04 13:42:02 -07:00
Norio Nomura 2a0ac455bc 'flatMap' is deprecated: renamed to 'compactMap(_:)' 2018-04-08 13:28:09 +09:00
Marcelo Fabri ae0e21f0f8 Fix crash when saving cache
Fixes #2032
2018-03-24 21:23:14 -07:00
JP Simard 34f429b0a3 Fix caching on Linux
This has never worked for two reasons:

1. We've used dictionaries to represent cache descriptions, which
   don't guarantee stable ordering of keys across invocations.
   This is true both on Darwin and Linux, but in practice ordering
   varies significantly more on Linux.
2. Storing a `TimeInterval` value in a `[String: Any]` dictionary
   and retrieving it again will not be dynamically castable to
   `Double` or `TimeInterval` but will be castable to `Int`.
2017-10-26 12:23:13 -07:00
JP Simard b39b369d12 Fix setting Swift version when caching.
See https://github.com/realm/SwiftLint/pull/1790/files#r134323431.
2017-08-21 13:28:43 -07:00
Marcelo Fabri 0a07628d8c Invalidate cache when Swift version changes 2017-08-21 00:19:04 +02:00
Marcelo Fabri c01f4bd19f Enable extension_access_modifier rule 2017-07-21 21:08:52 +02:00
Marcelo Fabri e86763739f Move kind to RuleDescription 2017-07-02 15:50:16 +02:00
Marcelo Fabri 9a5e30e794 Split cache into read cache and write cache 2017-05-24 17:03:51 +02:00
JP Simard ca08d6598a move LinterCache+CommandLine to SwiftLintFramework
and make cacheURL an internal member of Configuration
2017-05-18 14:53:39 -07:00
JP Simard 690b567421 simplify serialized cache structure 2017-05-18 14:40:40 -07:00
JP Simard bd7169e40c cache each file with its own configuration cache description
to make the cache play nicely with nested configurations
2017-05-18 14:31:33 -07:00
JP Simard 258a80b5cc don't overwrite cache results from different versions 2017-05-18 14:31:33 -07:00
JP Simard 70bcb2c4e5 add LinterCache.Key enum
rather than use hardcoded, duplicate string literals
2017-05-18 13:59:24 -07:00
Víctor Pimentel 5ed010c9c0 Change LinterCache to use file modification dates instead of hashing files with a weak algorithm. 2017-05-18 13:39:05 -07:00
Marcelo Fabri 94f48f4ebd PR feedback 2017-01-10 13:09:18 -02:00
Marcelo Fabri 0cf433834e PR feedback 2017-01-05 12:01:47 -02:00
Marcelo Fabri e8ead8827b Make LinterCache thread-safe 2017-01-02 16:44:54 -02:00
Marcelo Fabri b3cd5008c0 Make LinterCache final 2016-12-31 01:42:18 -02:00
Marcelo Fabri 3d376241be Moving cache usage to the linter 2016-12-31 00:26:05 -02:00
Marcelo Fabri 77e4249a3d Improved cache structure 2016-12-31 00:24:54 -02:00
Marcelo Fabri a47385a64f Ignore cache if configuration has changed 2016-12-31 00:24:54 -02:00
Marcelo Fabri b1f62e2b63 Add some tests 2016-12-31 00:24:54 -02:00
Marcelo Fabri f1e33760f0 Fixing compile isse 2016-12-31 00:24:54 -02:00
Marcelo Fabri a92a24c598 Ignore cache when versions are different 2016-12-31 00:24:54 -02:00
Marcelo Fabri c698d021dc Initial cache implementation 2016-12-31 00:24:54 -02:00