Skip to content

Commit

Permalink
Merge pull request #1 from ryuichis/swift-3.1
Browse files Browse the repository at this point in the history
Catch up with Swift 3.1 and swift-ast 0.1.4 changes
  • Loading branch information
Ryuichi Saito committed Apr 26, 2017
2 parents 722d531 + 4de5edd commit 061bc49
Show file tree
Hide file tree
Showing 55 changed files with 1,365 additions and 1,177 deletions.
1 change: 1 addition & 0 deletions .ruby-version
@@ -0,0 +1 @@
2.3.1
2 changes: 1 addition & 1 deletion .swift-version
@@ -1 +1 @@
swift-2.2-SNAPSHOT-2016-01-11-a
3.1
11 changes: 5 additions & 6 deletions .travis.yml
Expand Up @@ -4,12 +4,11 @@ os:
language: generic
sudo: required
dist: trusty
osx_image: xcode7.2
osx_image: xcode8.3
install:
- curl -sL https://gist.github.com/kylef/5c0475ff02b7c7671d2a/raw/621ef9b29bbb852fdfd2e10ed147b321d792c1e4/swiftenv-install.sh | bash
- eval "$(curl -sL https://gist.githubusercontent.com/kylef/5c0475ff02b7c7671d2a/raw/9f442512a46d7a2af7b850d65a7e9bd31edfb09b/swiftenv-install.sh)"
script:
- . ~/.swiftenv/init
- make test
matrix:
allow_failures:
- os: linux
- ./dogFooding.sh
after_success:
- eval "$(curl -sL https://swift.vapor.sh/codecov)"
5 changes: 5 additions & 0 deletions Gemfile
@@ -0,0 +1,5 @@
source 'https://rubygems.org'

gem 'rb-readline'
gem 'colored'
gem 'guard-shell'
53 changes: 53 additions & 0 deletions Gemfile.lock
@@ -0,0 +1,53 @@
GEM
remote: https://rubygems.org/
specs:
coderay (1.1.1)
colored (1.2)
ffi (1.9.18)
formatador (0.2.5)
guard (2.14.1)
formatador (>= 0.2.4)
listen (>= 2.7, < 4.0)
lumberjack (~> 1.0)
nenv (~> 0.1)
notiffany (~> 0.0)
pry (>= 0.9.12)
shellany (~> 0.0)
thor (>= 0.18.1)
guard-compat (1.2.1)
guard-shell (0.7.1)
guard (>= 2.0.0)
guard-compat (~> 1.0)
listen (3.1.5)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
ruby_dep (~> 1.2)
lumberjack (1.0.11)
method_source (0.8.2)
nenv (0.3.0)
notiffany (0.1.1)
nenv (~> 0.1)
shellany (~> 0.0)
pry (0.10.4)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
slop (~> 3.4)
rb-fsevent (0.9.8)
rb-inotify (0.9.8)
ffi (>= 0.5.0)
rb-readline (0.5.4)
ruby_dep (1.5.0)
shellany (0.0.1)
slop (3.6.0)
thor (0.19.4)

PLATFORMS
ruby

DEPENDENCIES
colored
guard-shell
rb-readline

BUNDLED WITH
1.13.6
29 changes: 29 additions & 0 deletions Guardfile
@@ -0,0 +1,29 @@
require 'colored'
require 'open3'

clearing :on

guard :shell do
watch(/(.*).swift$/) {|m|

puts "Running tests..."

output = ""
errors = ""
exit_status = Open3.popen3("make test") do |stdin, stdout, stderr, wait_thr|
stdin.close
output << stdout.read
errors << stderr.read
wait_thr.value
end

puts output.yellow

if exit_status.success?
puts "Passed".green
else
puts errors
puts "Failed".red
end
}
end
38 changes: 6 additions & 32 deletions Makefile
@@ -1,43 +1,17 @@
SWIFT_BIN=$(shell which swift)
SWIFT_LINT=$(SWIFT_BIN)-lint

SWIFTC=swiftc
COPY=cp
REMOVE=rm

UNAME=$(shell uname)

ifeq ($(UNAME), Darwin)
XCODE=$(shell xcode-select -p)
SDK=$(XCODE)/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk
TARGET=x86_64-apple-macosx10.10
SWIFTC=swiftc -target $(TARGET) -sdk $(SDK) -Xlinker -all_load
COPY=sudo cp
REMOVE=sudo rm
endif

BUILD_DIR=.build/debug
LIBS=$(wildcard $(BUILD_DIR)/*.a)
LDFLAGS=$(foreach lib,$(LIBS),-Xlinker $(lib))

.PHONY: all clean build test install uninstall
.PHONY: all clean build test xcodegen

all: build

clean:
swift build --clean
swift package clean

build:
swift build

test: build $(BUILD_DIR)/test_runner
./$(BUILD_DIR)/test_runner

$(BUILD_DIR)/test_runner: Tests/*.swift Tests/rule/*.swift Tests/reporter/*.swift $(BUILD_DIR)/lint.a
$(SWIFTC) -o $@ Tests/*.swift Tests/rule/*.swift Tests/reporter/*.swift -I$(BUILD_DIR) -Xlinker $(BUILD_DIR)/Spectre.a $(LDFLAGS)

install:
$(COPY) $(BUILD_DIR)/swift-lint $(SWIFT_LINT)
test: build
swift test

uninstall:
$(REMOVE) $(SWIFT_LINT)
xcodegen:
swift package generate-xcodeproj --enable-code-coverage
12 changes: 12 additions & 0 deletions Package.pins
@@ -0,0 +1,12 @@
{
"autoPin": true,
"pins": [
{
"package": "swift-ast",
"reason": null,
"repositoryURL": "https://github.com/yanagiba/swift-ast",
"version": "0.1.4"
}
],
"version": 1
}
57 changes: 40 additions & 17 deletions Package.swift
@@ -1,5 +1,5 @@
/*
Copyright 2015 Ryuichi Saito, LLC
Copyright 2015-2017 Ryuichi Saito, LLC and the Yanagiba project contributors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -17,20 +17,43 @@
import PackageDescription

let package = Package(
name: "swift-lint",
targets: [
Target(
name: "swift-lint",
dependencies: [
"lint",
]
),
],
dependencies: [
.Package(url: "https://github.com/yanagiba/swift-ast", Version(0, 1, 3)),
.Package(url: "https://github.com/kylef/Commander", majorVersion: 0)
],
testDependencies: [
.Package(url: "https://github.com/kylef/Spectre.git", majorVersion: 0),
]
name: "swift-lint",
targets: [
Target(
name: "Lint"
),
Target(
name: "swift-lint",
dependencies: [
"Lint",
]
),

// MARK: Tests

Target(
name: "CanaryTests"
),
Target(
name: "LintTests",
dependencies: [
"Lint",
]
),
Target(
name: "RuleTests",
dependencies: [
"Lint",
]
),
Target(
name: "ReporterTests",
dependencies: [
"Lint",
]
),
],
dependencies: [
.Package(url: "https://github.com/yanagiba/swift-ast", Version(0, 1, 4)),
]
)
30 changes: 14 additions & 16 deletions README.md
@@ -1,6 +1,12 @@
# Swift Lint

[![Travis CI Status](https://api.travis-ci.org/yanagiba/swift-lint.svg?branch=master)](https://travis-ci.org/yanagiba/swift-lint)
[![codecov](https://codecov.io/gh/yanagiba/swift-lint/branch/master/graph/badge.svg)](https://codecov.io/gh/yanagiba/swift-lint)
![Swift 3.1](https://img.shields.io/badge/swift-3.1-brightgreen.svg)
[![swift-ast 0.1.4](https://img.shields.io/badge/swift‐ast-0.1.4-C70025.svg)](https://github.com/yanagiba/swift-ast)
![Swift Package Manager](https://img.shields.io/badge/SPM-ready-orange.svg)
![Platforms](https://img.shields.io/badge/platform-%20Linux%20|%20macOS%20-red.svg)
![License](https://img.shields.io/github/license/yanagiba/swift-lint.svg)

The Swift Lint is a static code analysis tool for improving quality and reducing
defects by inspecting [Swift](https://swift.org/about/) code and looking for
Expand All @@ -18,11 +24,11 @@ Both the [Swift Abstract Syntax Tree](https://github.com/yanagiba/swift-ast)
and the Swift Lint are still in early design and development. Many features are
incomplete or partially implemented. Some with technical limitations.

Please also check out the [status](https://github.com/yanagiba/swift-ast#a-work-in-progress) and [technical limitations](https://github.com/yanagiba/swift-ast#known-limitations) from [swift-ast](https://github.com/yanagiba/swift-ast).
Please also check out the [status](https://github.com/yanagiba/swift-ast#a-work-in-progress) from [swift-ast](https://github.com/yanagiba/swift-ast).

## Requirements

- [Swift 2.2 Snapshot](https://swift.org/download/)
- [Swift 3.1](https://swift.org/download/)

## Installing

Expand All @@ -37,13 +43,9 @@ git clone https://github.com/yanagiba/swift-lint
Go to the repository folder, run the following command:

```bash
make && make install
swift build
```

For Mac users, it will prompt for `sudo` passcode. This will automatically finds
the path for the current swift you are using, and install the executable to
the correct location.

### Embed Into Your Project

Add the swift-lint dependency to your SPM dependencies in Package.swift:
Expand All @@ -65,15 +67,11 @@ An example project will be added soon.

### Command Line

```bash
$ swift lint --help
Usage:
Simply append the path(s) of the file(s) to `swift-lint`:

$ /usr/bin/swift-lint <file paths>

Options:
--report-type - Change output report type
--streaming - Enable streaming outputs immediately when issues are emitted
```bash
swift-lint path/to/Awesome.swift
swift-lint path1/to1/foo.swift path2/to2/bar.swift ... path3/to3/main.swift
```

## Development
Expand All @@ -94,7 +92,7 @@ swift build

The dev version of the tool will be generated to `.build/debug/swift-lint`.

### Running [Spectre](https://github.com/kylef/Spectre) Tests
### Running Tests

Compile and run the entire tests by:

Expand Down
20 changes: 7 additions & 13 deletions Tests/main.swift → Sources/Lint/ASTContext.swift
@@ -1,5 +1,5 @@
/*
Copyright 2015 Ryuichi Saito, LLC
Copyright 2017 Ryuichi Saito, LLC and the Yanagiba project contributors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -14,16 +14,10 @@
limitations under the License.
*/

specCanary()
import Source
import AST

specCorrection()
specDriver()
specRuleProtocol()
specASTVisitorRuleBase()
specSourceCodeRuleBase()

// spec reporters
specTextReporter()

// spec rules
specNoForceCastRule()
struct ASTContext {
let sourceFile: SourceFile
let topLevelDeclaration: TopLevelDeclaration
}
29 changes: 29 additions & 0 deletions Sources/Lint/ASTVisitorRule.swift
@@ -0,0 +1,29 @@
/*
Copyright 2015-2017 Ryuichi Saito, LLC and the Yanagiba project contributors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import AST

protocol ASTVisitorRule : Rule, ASTVisitor {
}

extension ASTVisitorRule where Self: RuleBase {
func inspect(_ astContext: ASTContext, configurations: [String: Any]? = nil) {
self.astContext = astContext
self.configurations = configurations

_ = try? traverse(astContext.topLevelDeclaration)
}
}
6 changes: 3 additions & 3 deletions Sources/lint/Constant.swift → Sources/Lint/Constant.swift
@@ -1,5 +1,5 @@
/*
Copyright 2015 Ryuichi Saito, LLC
Copyright 2015 Ryuichi Saito, LLC and the Yanagiba project contributors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -14,6 +14,6 @@
limitations under the License.
*/

public let SWIFT_LINT_VERSION = "0.1.1"
import Foundation

let EMIT_ISSUE_NOTIFICATION_NAME = "org.swiftlint.emit_issue_notification"
public let SWIFT_LINT_VERSION = "0.1.2"

0 comments on commit 061bc49

Please sign in to comment.