Skip to content

Commit

Permalink
Merge pull request #4 from mikz/luacheck-0.22.0-1
Browse files Browse the repository at this point in the history
update luacheck to 0.22.0
  • Loading branch information
mikz authored Jun 13, 2018
2 parents 59d3eb2 + 0cfdd4d commit a56e160
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 7 deletions.
1 change: 1 addition & 0 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ engines:
- new
only:
- new
max_cyclomatic_complexity: 3
checks:
global:
enabled: false
Expand Down
9 changes: 5 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM alpine:3.7

LABEL maintainer "Michal Cichra <[email protected]>"
ENV LUA_VERSION=5.3 LUACHECK_VERSION=0.21.2
LABEL maintainer="Michal Cichra <[email protected]>"
ENV LUA_VERSION=5.3 LUACHECK_VERSION=0.22.0

WORKDIR /tmp
COPY Gemfile* /tmp/
Expand All @@ -10,10 +10,11 @@ RUN adduser -D -H -h /code -u 9000 -s /bin/false app \
&& apk add --no-cache --virtual build-dependencies \
lua${LUA_VERSION}-dev build-base curl ruby-dev icu-dev zlib-dev openssl-dev cmake \
&& luarocks-${LUA_VERSION} install luacheck ${LUACHECK_VERSION} \
&& luarocks-${LUA_VERSION} install lua-cjson \
&& luarocks-${LUA_VERSION} install lua-cjson 2.1.0-1 \
&& BUNDLE_SILENCE_ROOT_WARNING=1 bundle install --system \
&& apk del build-dependencies \
&& ln -s $(which lua${LUA_VERSION}) /usr/local/bin/lua
&& ln -s $(which lua${LUA_VERSION}) /usr/local/bin/lua \
&& lua -e 'require("cjson").encode({})'

USER app
VOLUME /code
Expand Down
24 changes: 23 additions & 1 deletion bin/engine-luacheck
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,20 @@ checks.each do |name, value|
end
end

LENGTH_OPTIONS = %w(max_line_length max_code_line_length max_string_line_length max_comment_line_length max_cyclomatic_complexity)

length_options = LENGTH_OPTIONS.map do |name|
value = options.fetch(name, nil)
opt = name.tr('_', '-')

case value
when nil then next
when false then "--no-#{opt}"
when Numeric then [ "--#{opt}", value.to_s ]
else warn "Unknown value #{value} (#{value.class}) for option #{name}"
end
end

ARRAY_OPTIONS = %w(globals read_globals new_globals new_read_globals not_globals ignore enable only)

array_options = ARRAY_OPTIONS.map do |name|
Expand Down Expand Up @@ -107,7 +121,15 @@ Find.find(*existing_paths) do |path|
end
end

cmd = ['luacheck', *check_options.compact, *boolean_options.compact, *array_options.compact.flatten, '--formatter', 'codeclimate', *files ]
cmd = [
'luacheck',
*check_options.compact,
*boolean_options.compact,
*length_options.compact.flatten,
*array_options.compact.flatten,
'--formatter', 'codeclimate',
*files
]
warn Shellwords.join(cmd)

IO.popen(cmd) do |io|
Expand Down
12 changes: 10 additions & 2 deletions lib/codeclimate.lua
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ local event_codes = {
minutes = 3,
description = [[https://luacheck.readthedocs.io/en/stable/warnings.html#control-flow-and-data-flow-issues]]
},
['561'] = { -- complexity
severity = 'major',
categories = { 'Complexity' },
minutes = function(event) return (event.complexity - event.max_complexity) * 10 end,
description = [[https://docs.codeclimate.com/docs/cyclomatic-complexity]]
},
['6'] = { -- whitespace
severity = 'info',
categories = { 'Style' },
Expand All @@ -78,7 +84,7 @@ local event_codes = {
}

local function event_info(event)
return event_codes[event.code:sub(1,1)]
return event_codes[event.code] or event_codes[event.code:sub(1,1)]
end

local function event_severity(event)
Expand All @@ -98,7 +104,9 @@ local function event_categories(event)
end

local function event_remediation_points(event)
return event_info(event).minutes * 10000
local minutes = event_info(event).minutes
if type(minutes) == 'function' then minutes = minutes(event) end
return minutes * 10000
end

local function hash(str)
Expand Down

0 comments on commit a56e160

Please sign in to comment.