Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rubocop: Somewhere there is a crime happening #1271

Merged
merged 10 commits into from
Nov 18, 2016
80 changes: 0 additions & 80 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -357,100 +357,20 @@ Style/Semicolon:
- 'samples/simple-polygon-line.rb'
- 'samples/simple-stack-flow-buttons.rb'

# Offense count: 14
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: only_raise, only_fail, semantic
Style/SignalException:
Exclude:
- 'shoes-core/lib/shoes/color.rb'
- 'shoes-core/lib/shoes/color/dsl_helpers.rb'
- 'shoes-core/lib/shoes/color/hex_converter.rb'
- 'shoes-core/lib/shoes/configuration.rb'
- 'shoes-core/lib/shoes/dsl.rb'
- 'shoes-core/lib/shoes/image.rb'
- 'shoes-core/lib/shoes/slot.rb'

# Offense count: 1
# Configuration parameters: Methods.
# Methods: {"reduce"=>["acc", "elem"]}, {"inject"=>["acc", "elem"]}
Style/SingleLineBlockParams:
Exclude:
- 'shoes-swt/lib/shoes/swt/text_block/text_font_factory.rb'

# Offense count: 5
# Cop supports --auto-correct.
# Configuration parameters: AllowIfMethodIsEmpty.
Style/SingleLineMethods:
Exclude:
- 'samples/expert-tankspank.rb'
- 'shoes-package/lib/warbler/traits/shoes.rb'

# Offense count: 13
# Cop supports --auto-correct.
Style/SpaceAfterColon:
Exclude:
- 'samples/simple-guess-game.rb'
- 'samples/simple-loogink-cy.rb'
- 'shoes-swt/spec/shoes/swt/text_block/centered_text_segment_spec.rb'
- 'shoes-swt/spec/shoes/swt/text_block/cursor_painter_spec.rb'
- 'shoes-swt/spec/shoes/swt/text_block/fitter_spec.rb'
- 'shoes-swt/spec/shoes/swt/text_block/text_segment_collection_spec.rb'
- 'shoes-swt/spec/shoes/swt/text_block/text_segment_spec.rb'

# Offense count: 166
# Cop supports --auto-correct.
Style/SpaceAfterComma:
Enabled: false

# Offense count: 1
# Cop supports --auto-correct.
Style/SpaceAfterNot:
Exclude:
- 'samples/simple-tictactoe.rb'

# Offense count: 8
# Cop supports --auto-correct.
Style/SpaceAroundKeyword:
Exclude:
- 'samples/expert-othello-adjusted.rb'
- 'samples/expert-othello.rb'
- 'samples/good-psychidelic-circles.rb'
- 'samples/simple-polygon-line.rb'
- 'shoes-swt/lib/shoes/swt/key_listener.rb'

# Offense count: 360
# Cop supports --auto-correct.
# Configuration parameters: AllowForAlignment.
Style/SpaceAroundOperators:
Enabled: false

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: AllowForAlignment.
Style/SpaceBeforeFirstArg:
Exclude:
- 'samples/class-book-adjusted.rb'

# Offense count: 1236
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters.
# SupportedStyles: space, no_space
Style/SpaceInsideBlockBraces:
Enabled: false

# Offense count: 2
# Cop supports --auto-correct.
Style/SpaceInsideParens:
Exclude:
- 'samples/good-reminder.rb'

# Offense count: 2
# Cop supports --auto-correct.
Style/Tab:
Exclude:
- 'samples/good-reminder.rb'

# Offense count: 4
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, AllowSafeAssignment.
Expand Down
6 changes: 3 additions & 3 deletions benchmark/clear.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ def fill_up_app_with_senseless_stuff
end
stack do
30.times do
rect 400, 596, 75, 30,fill: green
rect 500, 696, 75, 30,fill: red
rect 600, 796, 75, 30,fill: blue
rect 400, 596, 75, 30, fill: green
rect 500, 696, 75, 30, fill: red
rect 600, 796, 75, 30, fill: blue
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions samples/class-book-adjusted.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ def table_of_contents
toc = []
INCIDENTS.each_with_index do |(title, _story), i|
toc.push "(#{i + 1}) ",
link(title) {visit "/incidents/#{i}"},
link(title) { visit "/incidents/#{i}" },
" / "
end
toc[0...-1] << "\n"*5
toc[0...-1] << "\n" * 5
end

def incident(num)
Expand All @@ -33,7 +33,7 @@ def incident(num)
para(*table_of_contents, size: 8)
end

stack width: width-180, margin: [20, 0, 10, 0] do
stack width: width - 180, margin: [20, 0, 10, 0] do
INCIDENTS[num][1].split(/\n\n+/).each do |p|
para p
end
Expand Down
26 changes: 13 additions & 13 deletions samples/expert-game-of-life-adjusted.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,48 +120,48 @@ def clear
end
end

def cell_neighbours(y,x)
def cell_neighbours(y, x)
result = []
top_row = y - 1
left_col = x - 1
right_col = x + 1
bottom_row = y + 1

result << @board[y-1][x-1] if top_row >= 0 && left_col >= 0
result << @board[y - 1][x - 1] if top_row >= 0 && left_col >= 0

result << @board[y-1][x] if top_row >= 0
result << @board[y - 1][x] if top_row >= 0

result << @board[y-1][x+1] if top_row >= 0 && right_col < @width
result << @board[y - 1][x + 1] if top_row >= 0 && right_col < @width

result << @board[y][x-1] if left_col >= 0
result << @board[y][x - 1] if left_col >= 0

result << @board[y][x+1] if right_col < @width
result << @board[y][x + 1] if right_col < @width

result << @board[y+1][x-1] if bottom_row < @height && left_col >= 0
result << @board[y + 1][x - 1] if bottom_row < @height && left_col >= 0

result << @board[y+1][x] if bottom_row < @height
result << @board[y + 1][x] if bottom_row < @height

result << @board[y+1][x+1] if bottom_row < @height && right_col < @width
result << @board[y + 1][x + 1] if bottom_row < @height && right_col < @width

result.compact
end

def add_species(*cells)
cells.each do |y,x|
cells.each do |y, x|
@board[y][x].toggle_state
end
end

def add_glider
add_species [4,2], [4,3], [4,4], [3,4], [2,3]
add_species [4, 2], [4, 3], [4, 4], [3, 4], [2, 3]
end

def add_spaceship
add_species [12,3], [12,6], [13,7], [14,3], [14,7], [15,4], [15,5], [15,6], [15,7]
add_species [12, 3], [12, 6], [13, 7], [14, 3], [14, 7], [15, 4], [15, 5], [15, 6], [15, 7]
end

def add_diehard
add_species [18,12], [12,13], [13,13], [13,14], [17,14], [18,14], [19,14]
add_species [18, 12], [12, 13], [13, 13], [13, 14], [17, 14], [18, 14], [19, 14]
end
end

Expand Down
26 changes: 13 additions & 13 deletions samples/expert-game-of-life.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,48 +117,48 @@ def clear
end
end

def cell_neighbours(y,x)
def cell_neighbours(y, x)
result = []
top_row = y - 1
left_col = x - 1
right_col = x + 1
bottom_row = y + 1

result << @board[y-1][x-1] if top_row >= 0 && left_col >= 0
result << @board[y - 1][x - 1] if top_row >= 0 && left_col >= 0

result << @board[y-1][x] if top_row >= 0
result << @board[y - 1][x] if top_row >= 0

result << @board[y-1][x+1] if top_row >= 0 && right_col < @width
result << @board[y - 1][x + 1] if top_row >= 0 && right_col < @width

result << @board[y][x-1] if left_col >= 0
result << @board[y][x - 1] if left_col >= 0

result << @board[y][x+1] if right_col < @width
result << @board[y][x + 1] if right_col < @width

result << @board[y+1][x-1] if bottom_row < @height && left_col >= 0
result << @board[y + 1][x - 1] if bottom_row < @height && left_col >= 0

result << @board[y+1][x] if bottom_row < @height
result << @board[y + 1][x] if bottom_row < @height

result << @board[y+1][x+1] if bottom_row < @height && right_col < @width
result << @board[y + 1][x + 1] if bottom_row < @height && right_col < @width

result.compact
end

def add_species(*cells)
cells.each do |y,x|
cells.each do |y, x|
@board[y][x].toggle_state
end
end

def add_glider
add_species [4,2], [4,3], [4,4], [3,4], [2,3]
add_species [4, 2], [4, 3], [4, 4], [3, 4], [2, 3]
end

def add_spaceship
add_species [12,3], [12,6], [13,7], [14,3], [14,7], [15,4], [15,5], [15,6], [15,7]
add_species [12, 3], [12, 6], [13, 7], [14, 3], [14, 7], [15, 4], [15, 5], [15, 6], [15, 7]
end

def add_diehard
add_species [18,12], [12,13], [13,13], [13,14], [17,14], [18,14], [19,14]
add_species [18, 12], [12, 13], [13, 13], [13, 14], [17, 14], [18, 14], [19, 14]
end
end

Expand Down
48 changes: 24 additions & 24 deletions samples/expert-minesweeper-adjusted.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,17 @@ def game_over?
def render_cell(x, y, color = "#AAA", stroke = true)
@app.stroke "#666" if stroke
@app.fill color
@app.rect $x+x*cell_size, $y+y*cell_size, cell_size-1, cell_size-1
@app.rect $x + x * cell_size, $y + y * cell_size, cell_size - 1, cell_size - 1
@app.stroke "#BBB" if stroke
@app.line $x+x*cell_size+1, $y+y*cell_size+1, $x+x*cell_size+cell_size-1, $y+y*cell_size
@app.line $x+x*cell_size+1, $y+y*cell_size+1, $x+x*cell_size, $y+y*cell_size+cell_size-1
@app.line $x + x * cell_size + 1, $y + y * cell_size + 1, $x + x * cell_size + cell_size - 1, $y + y * cell_size
@app.line $x + x * cell_size + 1, $y + y * cell_size + 1, $x + x * cell_size, $y + y * cell_size + cell_size - 1
end

def render_flag(x, y)
@app.stroke "#000"
@app.line($x+x*cell_size+cell_size / 4 + 1, $y+y*cell_size + cell_size / 5, $x+x*cell_size+cell_size / 4 + 1, $y+y*cell_size+cell_size / 5 * 4)
@app.line($x + x * cell_size + cell_size / 4 + 1, $y + y * cell_size + cell_size / 5, $x + x * cell_size + cell_size / 4 + 1, $y + y * cell_size + cell_size / 5 * 4)
@app.fill "#A00"
@app.rect($x+x*cell_size+cell_size / 4+2, $y+y*cell_size + cell_size / 5,
@app.rect($x + x * cell_size + cell_size / 4 + 2, $y + y * cell_size + cell_size / 5,
cell_size / 3, cell_size / 4)
end

Expand All @@ -93,16 +93,16 @@ def render_bomb(x, y)
render_cell(x, y, @app.rgb(0xFF, 0, 0, 0.5)) if self[x, y].exploded
@app.nostroke
@app.fill @app.rgb(0, 0, 0, 0.8)
@app.oval($x+x*cell_size+3, $y+y*cell_size+3, 13)
@app.oval($x + x * cell_size + 3, $y + y * cell_size + 3, 13)
@app.fill "#333"
@app.oval($x+x*cell_size+5, $y+y*cell_size+5, 7)
@app.oval($x + x * cell_size + 5, $y + y * cell_size + 5, 7)
@app.fill "#AAA"
@app.oval($x+x*cell_size+6, $y+y*cell_size+6, 3)
@app.oval($x + x * cell_size + 6, $y + y * cell_size + 6, 3)
@app.fill @app.rgb(0, 0, 0, 0.8)
@app.stroke "#222"
@app.strokewidth 2
@app.oval($x+x*cell_size + cell_size / 2 + 2, $y+y*cell_size + cell_size / 4 - 2, 2)
@app.oval($x+x*cell_size + cell_size / 2 + 4, $y+y*cell_size + cell_size / 4 - 2, 1)
@app.oval($x + x * cell_size + cell_size / 2 + 2, $y + y * cell_size + cell_size / 4 - 2, 2)
@app.oval($x + x * cell_size + cell_size / 2 + 4, $y + y * cell_size + cell_size / 4 - 2, 1)
@app.strokewidth 1
end
end
Expand All @@ -112,15 +112,15 @@ def render_number(x, y)
if self[x, y].number != 0
@app.nostroke
@app.nofill
@app.oval($x+x*cell_size + 3, $y+y*cell_size - 2, 10)
@app.para self[x, y].number.to_s, left: $x+x*cell_size + 3, top: $y+y*cell_size - 2,
@app.oval($x + x * cell_size + 3, $y + y * cell_size - 2, 10)
@app.para self[x, y].number.to_s, left: $x + x * cell_size + 3, top: $y + y * cell_size - 2,
size: 13, stroke: COLORS[self[x, y].number - 1]
end
end

def paint
0.upto @h-1 do |y|
0.upto @w-1 do |x|
0.upto @h - 1 do |y|
0.upto @w - 1 do |x|
@app.nostroke
case self[x, y]
when EmptyCell then render_cell(x, y)
Expand All @@ -133,19 +133,19 @@ def paint
end

def bombs_left
@bombs - @field.flatten.compact.reject {|e| !e.flag }.size
@bombs - @field.flatten.compact.reject { |e| !e.flag }.size
end

def all_found?
@field.flatten.compact.reject {|e| !e.is_a?(OpenCell) }.size + @bombs == @w*@h
@field.flatten.compact.reject { |e| !e.is_a?(OpenCell) }.size + @bombs == @w * @h
end

def reveal!(x, y)
return unless cell_exists?(x, y)
return unless self[x, y].is_a?(Field::OpenCell)
if flags_around(x, y) >= self[x, y].number
(-1..1).each do |v|
(-1..1).each { |h| click!(x+h, y+v) unless (v==0 && h==0) || has_flag?(x+h, y+v) }
(-1..1).each { |h| click!(x + h, y + v) unless (v == 0 && h == 0) || has_flag?(x + h, y + v) }
end
end
end
Expand Down Expand Up @@ -177,15 +177,15 @@ def open(x, y)

def neighbors
(-1..1).each do |col|
(-1..1).each { |row| yield row, col unless col==0 && row == 0 }
(-1..1).each { |row| yield row, col unless col == 0 && row == 0 }
end
end

def discover(x, y)
open(x, y)
neighbors do |col, row|
cx = x+row
cy = y+col
cx = x + row
cy = y + col
next unless cell_exists?(cx, cy)
discover(cx, cy) if can_be_discovered?(cx, cy)
open(cx, cy)
Expand All @@ -200,11 +200,11 @@ def count_neighbors
end

def bombs_around(x, y)
count_neighbors { |v, h| bomb?(x+h, y+v) }
count_neighbors { |v, h| bomb?(x + h, y + v) }
end

def flags_around(x, y)
count_neighbors { |v, h| has_flag?(x+h, y+v) }
count_neighbors { |v, h| has_flag?(x + h, y + v) }
end

def die!(x, y)
Expand Down Expand Up @@ -261,8 +261,8 @@ def new_game(level)

click do |button, x, y|
next if @field.game_over? || @field.all_found?
fx = ((x-@field.offset.first) / @field.cell_size).to_i
fy = ((y-@field.offset.last) / @field.cell_size).to_i
fx = ((x - @field.offset.first) / @field.cell_size).to_i
fy = ((y - @field.offset.last) / @field.cell_size).to_i
@field.click!(fx, fy) if button == 1
@field.reveal!(fx, fy) if button == 2
@field.flag!(fx, fy) if button == 3
Expand Down
Loading