Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability for SwiftLint to lint files with full type-checked AST awareness #2379

Merged
merged 20 commits into from
Sep 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,20 @@
configuration files.
[JP Simard](https://github.com/jpsim)

#### Experimental

* Add a new `swiftlint analyze` command which can lint Swift files using the
full type-checked AST. Rules of the `AnalyzerRule` type will be added over
time. The compiler log path containing the clean `swiftc` build command
invocation (incremental builds will fail) must be passed to `analyze` via
the `--compiler-log-path` flag.
e.g. `--compiler-log-path /path/to/xcodebuild.log`
[JP Simard](https://github.com/jpsim)

* Add a new opt-in `explicit_self` analyzer rule to enforce the use of explicit
references to `self.` when accessing instance variables or functions.
[JP Simard](https://github.com/jpsim)

#### Enhancements

* Improve performance of `line_length` and
Expand Down
22 changes: 20 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ swiftlint(
$ swiftlint help
Available commands:

analyze [Experimental] Run analysis rules
autocorrect Automatically correct warnings and errors
generate-docs Generates markdown documentation for all rules
help Display general or command-specific help
Expand All @@ -153,8 +154,8 @@ Available commands:
Run `swiftlint` in the directory containing the Swift files to lint. Directories
will be searched recursively.

To specify a list of files when using `lint` or `autocorrect` (like the list of
files modified by Xcode specified by the
To specify a list of files when using `lint`, `autocorrect` or `analyze`
(like the list of files modified by Xcode specified by the
[`ExtraBuildPhase`](https://github.com/norio-nomura/ExtraBuildPhase) Xcode
plugin, or modified files in the working tree based on `git ls-files -m`), you
can do so by passing the option `--use-script-input-files` and setting the
Expand Down Expand Up @@ -304,6 +305,9 @@ Rule inclusion:
* `whitelist_rules`: Acts as a whitelist, only the rules specified in this list
will be enabled. Can not be specified alongside `disabled_rules` or
`opt_in_rules`.
* `analyzer_rules`: This is an entirely separate list of rules that are only
run by the `analyze` command. All analyzer rules are opt-in, so this is the
only configurable rule list (there is no disabled/whitelist equivalent).

```yaml
disabled_rules: # rule identifiers to exclude from running
Expand All @@ -322,6 +326,8 @@ excluded: # paths to ignore during linting. Takes precedence over `included`.
- Source/ExcludedFolder
- Source/ExcludedFile.swift
- Source/*/ExcludedFile.swift # Exclude files with a wildcard
analyzer_rules: # Rules run by `swiftlint analyze` (experimental)
- explicit_self
jpsim marked this conversation as resolved.
Show resolved Hide resolved

# configurable rules can be customized from this configuration file
# binary rules can set their severity level
Expand Down Expand Up @@ -437,6 +443,18 @@ Standard linting is disabled while correcting because of the high likelihood of
violations (or their offsets) being incorrect after modifying a file while
applying corrections.

### Analyze (experimental)

The _experimental_ `swiftlint analyze` command can lint Swift files using the
full type-checked AST. The compiler log path containing the clean `swiftc` build
command invocation (incremental builds will fail) must be passed to `analyze`
via the `--compiler-log-path` flag.
e.g. `--compiler-log-path /path/to/xcodebuild.log`

This command and related code in SwiftLint is subject to substantial changes at
jpsim marked this conversation as resolved.
Show resolved Hide resolved
any time while this feature is marked as experimental. Analyzer rules also tend
to be considerably slower than lint rules.

## License

[MIT licensed.](LICENSE)
Expand Down
Loading