Skip to content

Commit a56e160

Browse files
authored
Merge pull request #4 from mikz/luacheck-0.22.0-1
update luacheck to 0.22.0
2 parents 59d3eb2 + 0cfdd4d commit a56e160

File tree

4 files changed

+39
-7
lines changed

4 files changed

+39
-7
lines changed

.codeclimate.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ engines:
3131
- new
3232
only:
3333
- new
34+
max_cyclomatic_complexity: 3
3435
checks:
3536
global:
3637
enabled: false

Dockerfile

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
FROM alpine:3.7
22

3-
LABEL maintainer "Michal Cichra <[email protected]>"
4-
ENV LUA_VERSION=5.3 LUACHECK_VERSION=0.21.2
3+
LABEL maintainer="Michal Cichra <[email protected]>"
4+
ENV LUA_VERSION=5.3 LUACHECK_VERSION=0.22.0
55

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

1819
USER app
1920
VOLUME /code

bin/engine-luacheck

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,20 @@ checks.each do |name, value|
6161
end
6262
end
6363

64+
LENGTH_OPTIONS = %w(max_line_length max_code_line_length max_string_line_length max_comment_line_length max_cyclomatic_complexity)
65+
66+
length_options = LENGTH_OPTIONS.map do |name|
67+
value = options.fetch(name, nil)
68+
opt = name.tr('_', '-')
69+
70+
case value
71+
when nil then next
72+
when false then "--no-#{opt}"
73+
when Numeric then [ "--#{opt}", value.to_s ]
74+
else warn "Unknown value #{value} (#{value.class}) for option #{name}"
75+
end
76+
end
77+
6478
ARRAY_OPTIONS = %w(globals read_globals new_globals new_read_globals not_globals ignore enable only)
6579

6680
array_options = ARRAY_OPTIONS.map do |name|
@@ -107,7 +121,15 @@ Find.find(*existing_paths) do |path|
107121
end
108122
end
109123

110-
cmd = ['luacheck', *check_options.compact, *boolean_options.compact, *array_options.compact.flatten, '--formatter', 'codeclimate', *files ]
124+
cmd = [
125+
'luacheck',
126+
*check_options.compact,
127+
*boolean_options.compact,
128+
*length_options.compact.flatten,
129+
*array_options.compact.flatten,
130+
'--formatter', 'codeclimate',
131+
*files
132+
]
111133
warn Shellwords.join(cmd)
112134

113135
IO.popen(cmd) do |io|

lib/codeclimate.lua

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ local event_codes = {
6969
minutes = 3,
7070
description = [[https://luacheck.readthedocs.io/en/stable/warnings.html#control-flow-and-data-flow-issues]]
7171
},
72+
['561'] = { -- complexity
73+
severity = 'major',
74+
categories = { 'Complexity' },
75+
minutes = function(event) return (event.complexity - event.max_complexity) * 10 end,
76+
description = [[https://docs.codeclimate.com/docs/cyclomatic-complexity]]
77+
},
7278
['6'] = { -- whitespace
7379
severity = 'info',
7480
categories = { 'Style' },
@@ -78,7 +84,7 @@ local event_codes = {
7884
}
7985

8086
local function event_info(event)
81-
return event_codes[event.code:sub(1,1)]
87+
return event_codes[event.code] or event_codes[event.code:sub(1,1)]
8288
end
8389

8490
local function event_severity(event)
@@ -98,7 +104,9 @@ local function event_categories(event)
98104
end
99105

100106
local function event_remediation_points(event)
101-
return event_info(event).minutes * 10000
107+
local minutes = event_info(event).minutes
108+
if type(minutes) == 'function' then minutes = minutes(event) end
109+
return minutes * 10000
102110
end
103111

104112
local function hash(str)

0 commit comments

Comments
 (0)