Skip to content

Commit 3bd7c9d

Browse files
committed
Rubocop config tweaks and code fixes
1 parent 0093ce5 commit 3bd7c9d

File tree

7 files changed

+39
-23
lines changed

7 files changed

+39
-23
lines changed

lib/generators/shiny/plugin/plugin_generator.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ def wrap_in_modules( unwrapped_code )
7878
unwrapped_code = unwrapped_code.to_s.strip.gsub( /\s$\n/, '' )
7979
modules.reverse.reduce( unwrapped_code ) do |content, mod|
8080
str = +"module #{mod}\n"
81-
str << content.lines.collect { |line| " #{line}" }.join
81+
str << content.lines.collect { |line| " #{line}" }
82+
.join
8283
str << ( content.present? ? "\nend" : 'end' )
8384
end
8485
end

plugins/ShinyCMS/.rubocop.yml

+23-15
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,31 @@ AllCops:
1717
NewCops: enable
1818
Exclude:
1919
# Not Ruby files (skipping these makes Rubocop run faster)
20-
- ../../app/assets/**/* # main_app
21-
- ../*/app/assets/**/* # plugins
20+
## Main app
2221
- ../../bin/*
2322
- ../../coverage/**/*
2423
- ../../docs/**/*
2524
- ../../log/*
2625
- ../../node_modules/**/*
2726
- ../../public/**/*
28-
- ../../themes/**/*
2927
- ../../tmp/**/*
3028
- ../../tools/*
29+
## Plugins and Themes
30+
- ../*/app/assets/**/*
31+
- ../*/bin/*
32+
- ../*/vendor/**/*
33+
- ../../themes/**/*
3134
# Code autogenerated by ActiveRecord spectacularly fails RuboCop
32-
- ../../db/schema.rb
33-
- ../../db/archived-migrations/*
34-
- ../../db/migrate/* # main_app
35-
- ../*/db/migrate/*.rb # plugins
35+
- ../../db/**/* # main_app
36+
- ../*/db/migrate/* # plugins
3637
# RuboCop also hates this autogenerated data file
3738
- db/demo_site_data.rb
3839

40+
# Turning this off for now; ideally this Gemfile would be mostly empty anyway
41+
Bundler/GemVersion:
42+
Exclude:
43+
- ../../Gemfile
44+
3945
# These are mostly expected to contain long blocks due to their DSLs
4046
Metrics/BlockLength:
4147
Exclude:
@@ -50,14 +56,18 @@ Metrics/BlockLength:
5056
# Spec files with I18n.t calls have long lines. I can live with that.
5157
Layout/LineLength:
5258
Exclude:
53-
- ../../spec/**/*.rb # main_app
54-
- ../*/spec/**/*.rb # plugins
59+
- ../*/spec/**/*.rb
5560

5661
# This config file is easier to understand laid out as it is, not as this cop wants it
5762
Layout/MultilineArrayLineBreaks:
5863
Exclude:
5964
- config/initializers/html_sanitizer.rb
6065

66+
# This looks really inconsistent next to `expect().to`
67+
Layout/SingleLineBlockChain:
68+
Exclude:
69+
- ../*/spec/**/*
70+
6171
# This method is not useless - it allows user registrations to be feature-flagged
6272
Lint/UselessMethodDefinition:
6373
Exclude:
@@ -118,7 +128,7 @@ Rails/ApplicationController:
118128
Exclude:
119129
- app/public/controllers/shinycms/admin/tools/base_controller.rb
120130

121-
# Allow read access to ENV
131+
# Allow read access to ENV, for now (but better config handling is on the TODO list)
122132
Rails/EnvironmentVariableAccess:
123133
AllowReads: true
124134

@@ -145,10 +155,6 @@ RSpec/BeforeAfterAll:
145155
- spec/models/shinycms/theme_spec.rb
146156
- spec/support/faker.rb
147157

148-
# Currently inclined to keep this approach, for readability etc
149-
RSpec/DescribedClassModuleWrapping:
150-
Enabled: false
151-
152158
# This is ignoring config/initializers/inflections.rb (as about half of Rails does)
153159
RSpec/FilePath:
154160
Exclude:
@@ -157,6 +163,8 @@ RSpec/FilePath:
157163
# Disabling these two for now (but open to discussion/persuasion on their merits)
158164
RSpec/ExampleLength:
159165
Enabled: false
166+
167+
# A test should test one thing; it may take more than one expectation to do so (thoroughly)
160168
RSpec/MultipleExpectations:
161169
Enabled: false
162170

@@ -242,6 +250,6 @@ Style/MissingElse:
242250
Style/Copyright:
243251
Enabled: false
244252

245-
# Not every method needs a comment explaining what it does
253+
# Most methods already have names that explain what they do, they don't need a comment as well
246254
Style/DocumentationMethod:
247255
Enabled: false

plugins/ShinyCMS/.rubocop_todo.yml

+6-2
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,16 @@
44
#
55
# ShinyCMS is free software; you can redistribute it and/or modify it under the terms of the GPL (version 2 or later)
66

7-
# File created with `rubocop --auto-gen-config` on 2021-04-08 using RuboCop version 1.12.1
7+
# File created with `rubocop --auto-gen-config` on 2021-05-07 using RuboCop version 1.14.0
88
#
99
# Entries in this file should be removed as the offenses are removed from the code.
1010
#
1111
# This file should be regenerated whenever Rubocop is updated.
1212

13+
# Offense count: 27
14+
RSpec/DescribedClassModuleWrapping:
15+
Enabled: false
16+
1317
# Offense count: 22
1418
RSpec/AnyInstance:
1519
Exclude:
@@ -19,7 +23,7 @@ RSpec/AnyInstance:
1923
- '../ShinyForms/spec/requests/shiny_forms/forms_controller_spec.rb'
2024
- '../ShinyLists/spec/requests/shiny_lists/subscriptions_controller_spec.rb'
2125

22-
# Offense count: 129
26+
# Offense count: 140
2327
# Configuration parameters: AssignmentOnly.
2428
RSpec/InstanceVariable:
2529
Exclude:

plugins/ShinyCMS/app/models/concerns/shinycms/plugins_components.rb

+4-2
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@ def models_with_sitemap_items
3131
end
3232

3333
def models_that_are( method )
34-
💎ify[ with_models.collect { |plugin| plugin.models_that_are method }.flatten.sort_by( &:name ) ]
34+
💎ify[ with_models.collect { |plugin| plugin.models_that_are method }
35+
.flatten.sort_by( &:name ) ]
3536
end
3637

3738
def models_that_include( concern )
38-
💎ify[ with_models.collect { |plugin| plugin.models_that_include concern }.flatten.sort_by( &:name ) ]
39+
💎ify[ with_models.collect { |plugin| plugin.models_that_include concern }
40+
.flatten.sort_by( &:name ) ]
3941
end
4042
end
4143
end

plugins/ShinyCMS/app/models/shinycms/plugin.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ def models_that_are( method )
5454
end
5555

5656
def models_that_include( concern )
57-
base_model.descendants.select { |model| model.include?( concern ) }.sort_by( &:name )
57+
base_model.descendants.select { |model| model.include?( concern ) }
58+
.sort_by( &:name )
5859
end
5960

6061
def view_path

plugins/ShinyCMS/app/public/models/concerns/shinycms/has_template.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ def add_elements
3232

3333
# Returns a hash of all the elements for this item, to feed to render as local params
3434
def elements_hash
35-
elements.collect { |element| [ element.name.to_sym, ( element.image.presence || element.content ) ] }.to_h
35+
elements.collect { |element| [ element.name.to_sym, ( element.image.presence || element.content ) ] }
36+
.to_h
3637
end
3738
end
3839

plugins/ShinySEO/app/assets/config/shiny_seo_manifest.js

-1
This file was deleted.

0 commit comments

Comments
 (0)