Add rubocop to CI (closed #2)
This commit is contained in:
parent
742b665f26
commit
39389ae379
27
.github/workflows/style.yml
vendored
Normal file
27
.github/workflows/style.yml
vendored
Normal file
|
@ -0,0 +1,27 @@
|
|||
name: Style
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
pull_request:
|
||||
branches: [ master ]
|
||||
|
||||
jobs:
|
||||
lint:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Set up Ruby 3.1
|
||||
uses: actions/setup-ruby@v1
|
||||
with:
|
||||
ruby-version: 3.1.x
|
||||
- name: Prepare
|
||||
run: |
|
||||
gem install bundler
|
||||
gem install rubocop:1.31.2
|
||||
bundle install --jobs 4 --retry 3
|
||||
- name: Check ruby with rubocop
|
||||
run: |
|
||||
rubocop
|
47
.rubocop.yml
Normal file
47
.rubocop.yml
Normal file
|
@ -0,0 +1,47 @@
|
|||
AllCops:
|
||||
TargetRubyVersion: 3.1.2
|
||||
NewCops: enable
|
||||
|
||||
Metrics/BlockLength:
|
||||
Enabled: false
|
||||
|
||||
Metrics/PerceivedComplexity:
|
||||
Enabled: false
|
||||
|
||||
Metrics/MethodLength:
|
||||
Enabled: false
|
||||
|
||||
Metrics/CyclomaticComplexity:
|
||||
Enabled: false
|
||||
|
||||
Metrics/AbcSize:
|
||||
Enabled: false
|
||||
|
||||
Style/GlobalVars:
|
||||
Enabled: false
|
||||
|
||||
Naming/MethodParameterName:
|
||||
Enabled: false
|
||||
|
||||
Metrics/ClassLength:
|
||||
Enabled: false
|
||||
|
||||
Layout/LineContinuationLeadingSpace:
|
||||
Enabled: false
|
||||
|
||||
# TODO: enable
|
||||
Metrics/ParameterLists:
|
||||
Enabled: false
|
||||
|
||||
Lint/DuplicateBranch:
|
||||
Enabled: false
|
||||
|
||||
Style/Documentation:
|
||||
Enabled: false
|
||||
|
||||
Naming/AccessorMethodName:
|
||||
Enabled: false
|
||||
|
||||
Style/ClassVars:
|
||||
Enabled: false
|
||||
|
|
@ -11,9 +11,9 @@ def str_bytes(str)
|
|||
end
|
||||
|
||||
def bytes_to_str(data)
|
||||
data.unpack('H*').join('')
|
||||
data.unpack('H*').join
|
||||
end
|
||||
|
||||
def get_byte(data, start = 0, num = 1)
|
||||
data[start...(start + num)].unpack('H*').join('').upcase
|
||||
data[start...(start + num)].unpack('H*').join.upcase
|
||||
end
|
||||
|
|
|
@ -75,7 +75,7 @@ class NetChunk
|
|||
size_bits[6..] +
|
||||
seq_bits[2..]
|
||||
header_bits.chars.groups_of(8).map do |eigth_bits|
|
||||
eigth_bits.join('').to_i(2)
|
||||
eigth_bits.join.to_i(2)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -91,8 +91,8 @@ class NetChunk
|
|||
size_bytes = size.chars.groups_of(8)
|
||||
# trim first 2 bits of both bytes
|
||||
# Size: 2 bytes (..00 0000 ..00 0010)
|
||||
size_bytes.map! { |b| b[2..].join('') }
|
||||
@size = size_bytes.join('').to_i(2)
|
||||
size_bytes.map! { |b| b[2..].join }
|
||||
@size = size_bytes.join.to_i(2)
|
||||
|
||||
# sequence number
|
||||
# in da third byte but who needs seq?!
|
||||
|
|
|
@ -13,7 +13,7 @@ class NetBase
|
|||
@port = nil
|
||||
@s = nil
|
||||
@ack = 0
|
||||
@server_token = [0xFF, 0xFF, 0xFF, 0xFF].map { |b| b.to_s(16) }.join('')
|
||||
@server_token = [0xFF, 0xFF, 0xFF, 0xFF].map { |b| b.to_s(16) }.join
|
||||
end
|
||||
|
||||
def connect(socket, ip, port)
|
||||
|
@ -47,7 +47,7 @@ class NetBase
|
|||
header_bits = "00#{flags_bits}#{@ack.to_s(2).rjust(10, '0')}#{num_chunks.to_s(2).rjust(8, '0')}"
|
||||
|
||||
header = header_bits.chars.groups_of(8).map do |eight_bits|
|
||||
eight_bits.join('').to_i(2)
|
||||
eight_bits.join.to_i(2)
|
||||
end
|
||||
|
||||
header += str_bytes(@server_token)
|
||||
|
|
|
@ -53,7 +53,7 @@ class Packer
|
|||
bytes = []
|
||||
num_bits.chars.groups_of(7).each do |seven_bits|
|
||||
# mark all as extended
|
||||
bytes << "1#{seven_bits.join('').rjust(7, '0')}"
|
||||
bytes << "1#{seven_bits.join.rjust(7, '0')}"
|
||||
end
|
||||
# least significant first
|
||||
bytes = bytes.reverse
|
||||
|
@ -105,7 +105,6 @@ class Unpacker
|
|||
# because bigger ints are not sent anyways
|
||||
bytes = @data.map { |byte| byte.to_s(2).rjust(8, '0') }
|
||||
first = bytes[0]
|
||||
other = bytes[1..]
|
||||
|
||||
sign = first[1] == '1' ? -1 : 1
|
||||
bits = []
|
||||
|
@ -127,7 +126,7 @@ class Unpacker
|
|||
bits = [first[2..]]
|
||||
@data = @data[1..]
|
||||
end
|
||||
bits.join('').to_i(2) * sign
|
||||
bits.join.to_i(2) * sign
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -61,10 +61,10 @@ class Packet
|
|||
flags_byte = @data[0].unpack('B*')
|
||||
@flags = PacketFlags.new(flags_byte.first[2..5]).hash
|
||||
@payload = @data[PACKET_HEADER_SIZE..]
|
||||
if flags_compressed
|
||||
@payload = @huffman.decompress(@payload.unpack('C*'))
|
||||
@payload = @payload.pack('C*')
|
||||
end
|
||||
return unless flags_compressed
|
||||
|
||||
@payload = @huffman.decompress(@payload.unpack('C*'))
|
||||
@payload = @payload.pack('C*')
|
||||
end
|
||||
|
||||
def annotate_first_row(bytes)
|
||||
|
@ -81,7 +81,7 @@ class Packet
|
|||
def to_s
|
||||
puts "#{@prefix}Packet"
|
||||
puts @prefix + " flags: #{@flags}"
|
||||
bytes = str_hex(@data).split(' ')
|
||||
bytes = str_hex(@data).split
|
||||
# TODO: check terminal size?
|
||||
max_width = 14
|
||||
rows = bytes.groups_of(max_width)
|
||||
|
|
|
@ -97,7 +97,7 @@ class TeeworldsClient
|
|||
@game_client = GameClient.new(self)
|
||||
# me trying to write cool code
|
||||
@client_token = (1..4).to_a.map { |_| rand(0..255) }
|
||||
@client_token = @client_token.map { |b| b.to_s(16) }.join('')
|
||||
@client_token = @client_token.map { |b| b.to_s(16) }.join
|
||||
puts "client token #{@client_token}"
|
||||
@netbase = NetBase.new
|
||||
@netbase.client_token = @client_token
|
||||
|
|
Loading…
Reference in a new issue