-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit bcc74fd
Showing
11 changed files
with
215 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- | ||
engines: | ||
luacheck: | ||
enabled: true | ||
exclude_paths: | ||
- Dockerfile | ||
- ".*.yml" | ||
rubocop: | ||
enabled: true | ||
bundler-audit: | ||
enabled: true | ||
reek: | ||
enabled: true | ||
ratings: | ||
paths: | ||
- "**/*.lua" | ||
- bin/* | ||
exclude_paths: | ||
- lib/test.lua | ||
- "**/.*.swp" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
FROM alpine:3.5 | ||
|
||
ARG LUA_VERSION=5.3 | ||
ARG LUACHECK_VERSION=0.19.1 | ||
WORKDIR /tmp | ||
COPY Gemfile* /tmp/ | ||
RUN adduser -D -H -h /code -u 9000 -s /bin/false app \ | ||
&& apk add --no-cache luarocks${LUA_VERSION} ruby-bundler ruby-json icu-libs zlib \ | ||
lua${LUA_VERSION}-dev build-base curl ruby-dev icu-dev zlib-dev cmake \ | ||
&& luarocks-${LUA_VERSION} install luacheck ${LUACHECK_VERSION} \ | ||
&& luarocks-${LUA_VERSION} install lua-cjson \ | ||
&& BUNDLE_SILENCE_ROOT_WARNING=1 bundle install --system \ | ||
&& apk del build-base curl lua${LUA_VERSION}-dev ruby-dev zlib-dev icu-dev cmake \ | ||
&& ln -s $(which lua${LUA_VERSION}) /usr/local/bin/lua | ||
|
||
COPY bin /usr/local/bin/ | ||
COPY lib /usr/local/share/lua/${LUA_VERSION}/ | ||
USER app | ||
VOLUME /code | ||
|
||
WORKDIR /code | ||
|
||
COPY engine.json / | ||
|
||
CMD ["engine-luacheck"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
source 'https://rubygems.org' do | ||
gem 'github-linguist' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
GEM | ||
remote: https://rubygems.org/ | ||
specs: | ||
charlock_holmes (0.7.3) | ||
escape_utils (1.1.1) | ||
github-linguist (5.0.8) | ||
charlock_holmes (~> 0.7.3) | ||
escape_utils (~> 1.1.0) | ||
mime-types (>= 1.19) | ||
rugged (>= 0.25.1) | ||
mime-types (3.1) | ||
mime-types-data (~> 3.2015) | ||
mime-types-data (3.2016.0521) | ||
rugged (0.25.1.1) | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
github-linguist! | ||
|
||
BUNDLED WITH | ||
1.14.5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Copyright 2017 Michal Cichra | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
IMAGE_NAME ?= codeclimate/codeclimate-luacheck | ||
|
||
build: | ||
docker build . -t $(IMAGE_NAME) | ||
test: | ||
codeclimate analyze --dev | ||
|
||
bash: USER = 9000 | ||
bash: | ||
docker run -it --user $(USER) --rm --volume $(PWD):/code:ro $(IMAGE_NAME) sh | ||
|
||
local: export LUA_PATH = lib/?.lua | ||
local: export CONFIG_FILE = config.json | ||
local: | ||
@bin/engine-lua-files | ||
|
||
codeclimate: export CODECLIMATE_DEBUG = 1 | ||
codeclimate: | ||
codeclimate analyze --dev |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Code Climate luacheck Engine | ||
|
||
CodeClimate Engine that runs [luacheck](https://github.com/mpeterv/luacheck/) on Lua files. | ||
Uses [linguist](https://github.com/github/linguist) to detect Lua files. | ||
|
||
## Testing | ||
|
||
```shell | ||
make build test | ||
``` | ||
|
||
## TODO | ||
|
||
- [ ] expose luacheck options via to codeclimate | ||
- [ ] fingerprinting | ||
- [ ] detect categories |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require 'linguist' | ||
require 'find' | ||
require 'json' | ||
|
||
config_file = ENV['CONFIG_FILE'] || '/config.json' | ||
config = JSON.parse(File.read(config_file)) | ||
|
||
include_paths = config.fetch('include_paths', %w(.)) | ||
|
||
Lua = Linguist::Language.find_by_name('Lua') | ||
|
||
files = [] | ||
|
||
Find.find(*include_paths) do |path| | ||
next unless FileTest.file?(path) | ||
|
||
blob = Linguist::FileBlob.new(path) | ||
|
||
case blob.language | ||
when Lua | ||
files << path | ||
end | ||
end | ||
|
||
IO.popen(['luacheck', '--formatter', 'codeclimate', *files ]) do |io| | ||
while (line = io.gets) | ||
STDOUT.print line | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"enabled":true,"exclude_paths":["Dockerfile","bin/engine-lua-files","*.yml"],"include_paths":[".codeclimate.yml","bin/engine-luacheck","config.json","engine.json","Gemfile","Gemfile.lock","lib/codeclimate.lua","Makefile","README.md"]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"name": "luacheck", | ||
"description": "Luacheck is a static analyzer and a linter for Lua. Luacheck detects various issues such as usage of undefined global variables, unused variables and values, accessing uninitialized variables, unreachable code and more.", | ||
"maintainer": { | ||
"name": "Michal Cichra", | ||
"email": "[email protected]" | ||
}, | ||
"languages" : ["Lua"], | ||
"version": "da5a2077", | ||
"spec_version": "0.0.1" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
local format = require 'luacheck.format' | ||
local cjson = require 'cjson' | ||
|
||
local function Positions(line, column, end_column) | ||
return { | ||
begin = { | ||
line = line, | ||
column = column | ||
}, | ||
['end'] = { | ||
line = line, | ||
column = end_column | ||
} | ||
} | ||
end | ||
|
||
local function OtherLocations(file, warning) | ||
if warning.prev_line then | ||
return { | ||
{ | ||
path = file, | ||
positions = Positions(warning.line, warning.prev_column, warning.prev_column + warning.end_column - warning.column) | ||
} | ||
} | ||
end | ||
end | ||
|
||
local function Location(file, warning) | ||
return { | ||
path = file, | ||
positions = Positions(warning.line, warning.column, warning.end_column) | ||
|
||
} | ||
end | ||
|
||
local function Issue(file, warning) | ||
return { | ||
type = 'issue', | ||
check_name = warning.code, | ||
description = format.get_message(warning), | ||
categories = { 'Style' }, | ||
location = Location(file, warning), | ||
other_locations = OtherLocations(file, warning), | ||
} | ||
end | ||
return function(report, file_names) | ||
-- CodeClimate formatter does not support any options for now | ||
local issues = {} | ||
|
||
for i, file_report in ipairs(report) do | ||
for _, warning in ipairs(file_report) do | ||
local issue = Issue(file_names[i], warning) | ||
io.stdout:write(cjson.encode(issue),string.char(0), "\n") | ||
table.insert(issues, issue) | ||
end | ||
end | ||
|
||
return '' | ||
end |