dense-analysis / dense-analysis/ale

Add support for Swift's own swiftc

Open
#3,131 0 comments 1 reaction 0 assignees View on GitHub
new tool
Dominant language
Vim Script
Stars
14k
Forks
1.5k
Avg merge
17h 49m
Merged PRs (30d)
1

Description

**Name:** swiftc
**URL:** https://swift.org

There is current support for two third-party swift tools, but `swiftc` by itself provides the following flags for linting:

```
-parse Parse input file(s)
-print-ast Parse and type-check input file(s) and pretty print AST(s)
-resolve-imports Parse and resolve imports in input file(s)
-typecheck Parse and type-check input file(s)
```

I also found those extra flags, which may prove useful:

```
-suppress-warnings Suppress all warnings
-warnings-as-errors Treat warnings as errors
```

Sample output of various cases:

```
$ cat main.swift
}foo
$ swiftc -parse main.swift; echo "RC=$?"
main.swift:1:1: error: extraneous '}' at top level
}foo
^
RC=1
```

```
$ cat main.swift
import FoundationTypo
$ swiftc -parse main.swift; echo "RC=$?"
RC=0
$ swiftc -resolve-imports main.swift; echo "RC=$?"
main.swift:1:8: error: no such module 'FoundationTypo'
import FoundationTypo
^
RC=1
```

```
$ cat main.swift
println("Hello, world!");
$ swiftc -parse main.swift; echo "RC=$?"
RC=0
$ swiftc -resolve-imports main.swift; echo "RC=$?"
RC=0
$ swiftc -typecheck main.swift; echo "RC=$?"
main.swift:1:1: error: use of unresolved identifier 'println'
println("Hello, world!");
^~~~~~~
RC=1
```

```
$ cat main.swift
var foo = "foo";
var bar = 42;
print(foo + bar);
$ swiftc -parse main.swift; echo "RC=$?"
RC=0
$ swiftc -typecheck main.swift; echo "RC=$?"
main.swift:3:11: error: binary operator '+' cannot be applied to operands of type 'String' and 'Int'
print(foo + bar);
~~~ ^ ~~~
main.swift:3:11: note: overloads for '+' exist with these partially matching parameter lists: (Int, Int), (String, String)
print(foo + bar);
^
Swift.String:2:35: note: candidate expects value of type 'String' for parameter #2
@inlinable public static func + (lhs: String, rhs: String) -> String
^
Swift.Int:9:24: note: candidate expects value of type 'Int' for parameter #1
public static func + (lhs: Int, rhs: Int) -> Int
^
Swift.AdditiveArithmetic:3:17: note: candidate expects value of type 'Int' for parameter #1
static func + (lhs: Self, rhs: Self) -> Self
^
Swift.BinaryInteger:18:26: note: candidate expects value of type 'Int' for parameter #1
override static func + (lhs: Self, rhs: Self) -> Self
^
RC=1
```

```
$ cat main.swift
func foo() -> Int {
return 42
}
foo()
swiftc -typecheck main.swift; echo "RC=$?"
main.swift:5:1: warning: result of call to 'foo()' is unused
foo()
^ ~~
RC=0
$ swiftc -typecheck -suppress-warnings main.swift; echo "RC=$?"
RC=0
swiftc -typecheck -warnings-as-errors main.swift; echo "RC=$?"
main.swift:5:1: error: result of call to 'foo()' is unused
foo()
^ ~~
RC=1
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.