plugins/ShinyCMS/.rubocop.yml
# ShinyCMS ~ https://shinycms.org
#
# Copyright 2009-2024 Denny de la Haye ~ https://denny.me
#
# ShinyCMS is free software; you can redistribute it and/or modify it under the terms of the GPL (version 2 or later)
inherit_from: .rubocop_todo.yml
require:
- rubocop-capybara
- rubocop-factory_bot
- rubocop-performance
- rubocop-rails
- rubocop-rspec
- rubocop-rspec_rails
- rubocop-thread_safety
AllCops:
EnabledByDefault: true
NewCops: enable
Exclude:
# Not Ruby files (skipping these makes Rubocop run faster)
## Main app
- ../../bin/*
- ../../coverage/**/*
- ../../docs/**/*
- ../../log/*
- ../../node_modules/**/*
- ../../public/**/*
- ../../tmp/**/*
- ../../tools/*
## Plugins and Themes
- ../*/app/assets/**/*
- ../*/bin/*
- ../*/vendor/**/*
- ../../themes/**/*
# Code autogenerated by ActiveRecord spectacularly fails RuboCop
- ../../db/**/* # main_app
- ../*/db/migrate/* # plugins
# RuboCop also hates this autogenerated data file
- db/demo_site_data.rb
# Turning this off for now; ideally this Gemfile would be mostly empty anyway
Bundler/GemVersion:
Exclude:
- ../../Gemfile
# These are mostly expected to contain long blocks due to their DSLs
Metrics/BlockLength:
Exclude:
# Main app
- ../../Gemfile
- ../../config/environments/*
# All plugins
- ../*/config/routes.rb
- ../*/shiny*.gemspec
- ../*/spec/**/*.rb
# Core plugin
- app/models/concerns/shinycms/*.rb
- app/public/models/concerns/shinycms/*.rb
- app/public/controllers/concerns/shinycms/*.rb
- config/routes/*.rb
# Spec files with I18n.t calls tend to have long lines. I can live with that.
Layout/LineLength:
Exclude:
- ../*/spec/**/*.rb
# This config file is easier to understand laid out as it is, not as this cop wants it
Layout/MultilineArrayLineBreaks:
Exclude:
- config/initializers/html_sanitizer.rb
# This looks really inconsistent next to `expect().to`
Layout/SingleLineBlockChain:
Exclude:
- ../*/spec/**/*
# Calling super in ViewComponent intializers doesn't do anything currently
Lint/MissingSuper:
Exclude:
- ../*/app/components/shiny*/**/*_component.rb
- app/public/components/shinycms/**/*_component.rb
# This method is not useless - it allows user registrations to be feature-flagged
Lint/UselessMethodDefinition:
Exclude:
- app/controllers/shinycms/users/registrations_controller.rb
# ๐ Persistent๐ method names and include statements (and some related comments) ๐
# ๐ Yes, they are frivolous and impractical; that's my favourite thing about them ๐ ๐
Naming/AsciiIdentifiers:
Exclude:
- app/models/shinycms/plugin.rb
- app/models/shinycms/plugins.rb
- app/models/concerns/shinycms/plugins_components.rb
Style/AsciiComments:
Exclude:
- app/models/shinycms/plugin.rb
- app/models/shinycms/plugins.rb
- app/models/concerns/shinycms/plugins_components.rb
# The plugin code uses the immutable variables from Persistent๐, so I think this is ok?
ThreadSafety/InstanceVariableInClassMethod:
Exclude:
- 'app/models/shinycms/plugin.rb'
- 'app/models/shinycms/plugins.rb'
- 'lib/shinycms.rb' # this is plugins too
# I like chaining methods, it's aesthetically pleasing :-p
Performance/ChainArrayAllocation:
Enabled: false
# Another suggested change that makes the code quite a lot less readable; I'm not keen
Performance/Casecmp:
Enabled: false
# This isn't safe to use if your result array could be completely empty, afaict
Performance/MapCompact:
Enabled: false
# This is the (hopefully helpful) 'how to create an admin account' message displayed after seed data loads
Rails/Output:
Exclude:
- db/seeds.rb
- lib/tasks/support/admin_user_task.rb
# This code is intentionally and helpfully rewriting a bit of HTML
Rails/OutputSafety:
Exclude:
- config/initializers/field_with_errors.rb
# This isn't an ActiveRecord find method
Rails/DynamicFindBy:
Exclude:
- ../ShinySEO/lib/shiny_seo.rb
# And this isn't an ActiveRecord create method
Rails/SaveBang:
Exclude:
- ../ShinySEO/app/models/shiny_seo/sitemap.rb
# This base controller is for 'untrusted' code to inherit from (i.e. controllers from gems), to
# keep them a bit more isolated from the main CMS controllers and whatever ACL privs they have.
Rails/ApplicationController:
Exclude:
- app/public/controllers/shinycms/admin/tools/base_controller.rb
# Allow read access to ENV, for now (but better config handling is on the TODO list)
Rails/EnvironmentVariableAccess:
AllowReads: true
# Unused/demo controller in main_app, and 'no content' fallbacks in ShinyPages
Rails/RenderInline:
Exclude:
- ../../app/controllers/application_controller.rb
- ../ShinyPages/app/controllers/shiny_pages/pages_controller.rb
# Configurable user model
Rails/ReflectionClassName:
Exclude:
- ../../app/models/ahoy/visit.rb
- ../ShinyAccess/app/models/shiny_access/group.rb
- ../ShinyAccess/app/models/shiny_access/membership.rb
- ../ShinyBlog/app/models/shiny_blog/post.rb
- ../ShinyNews/app/models/shiny_news/post.rb
- ../ShinyNewsletters/app/models/shiny_newsletters/send.rb
- ../ShinyProfiles/app/models/shiny_profiles/profile.rb
# There's no database activity in these before all blocks, so this cop doesn't apply
RSpec/BeforeAfterAll:
Exclude:
- spec/models/shinycms/theme_spec.rb
- spec/support/faker.rb
# This is ignoring my custom inflections config (as about half of Rails does)
Rails/FilePath:
Exclude:
- spec/**/shinycms/**/*_spec.rb
# 12-item list used for various pagination tests
FactoryBot/ExcessiveCreateList:
Enabled: false
# Something flaky in how these tests are working?
FactoryBot/FactoryClassName:
Exclude:
- ../ShinyAccess/spec/factories/shiny_access/groups.rb
- ../ShinyAccess/spec/factories/shiny_access/memberships.rb
# I don't want to reorder these two files
Style/RequireOrder:
Exclude:
- ../../config/application.rb
- ../ShinyCMS/config/routes/tools.rb
# Disabling these two for now (but open to discussion/persuasion on their merits)
RSpec/ExampleLength:
Enabled: false
# A test should test one thing; it may take more than one expectation to do so (thoroughly)
RSpec/MultipleExpectations:
Enabled: false
# If I skip a spec temporarily, there's probably a reason!
RSpec/Pending:
Enabled: false
# Disabling this allows 'compact' class names, e.g. Admin::PagesController
Style/ClassAndModuleChildren:
Enabled: false
# I prefer collect to map
Style/CollectionMethods:
PreferredMethods:
map: collect
# Used in some mailers to include an explanatory comment with empty check-dnc methods
Style/CommentedKeyword:
Enabled: false
# I think this makes code significantly harder to read, personally
Style/ConditionalAssignment:
Enabled: false
# Disabling cops for a few lines here and there is handy
Style/DisableCopsWithinSourceCodeDirective:
Enabled: false
# The test is for a feature that parses a list of IP addresses
Style/IpAddresses:
Exclude:
- spec/requests/shinycms/admin_controller_spec.rb
# This style of regex is clearer with URLs: %r{/(path)/parts/} vs /\/(path)\/parts\//
# (and I'd rather use one style everywhere, not switch back and forth)
Style/RegexpLiteral:
Enabled: false
# Whitespace Considered Helpful
Layout/ExtraSpacing:
Enabled: false
Layout/RedundantLineBreak:
Enabled: false
Layout/SpaceAroundBlockParameters:
Enabled: false
Layout/SpaceInsideArrayLiteralBrackets:
EnforcedStyle: space
Layout/SpaceInsideBlockBraces:
EnforcedStyle: space
Layout/SpaceInsideHashLiteralBraces:
EnforcedStyle: space
Layout/SpaceInsideParens:
EnforcedStyle: space
Layout/SpaceInsidePercentLiteralDelimiters:
Enabled: false
Layout/SpaceInsideReferenceBrackets:
Enabled: false
# Alignment also considered helpful. And aesthetically pleasing.
Layout/HashAlignment:
EnforcedColonStyle: table
EnforcedHashRocketStyle: table
# Enabling these leads to less readable code in my opinion
Layout/MultilineMethodArgumentLineBreaks:
Enabled: false
Layout/SpaceBeforeBrackets:
Enabled: false
Lint/ConstantResolution:
Enabled: false
Style/InvertibleUnlessCondition:
Enabled: false
Style/MethodCallWithArgsParentheses:
Enabled: false
# I'm open to debate on this one. Looks cleaner without, to me, but it is less standard.
FactoryBot/ConsistentParenthesesStyle:
Enabled: false
# I don't want to put copyright notices on autogenerated files that I haven't touched
Style/Copyright:
Enabled: false
# Most methods already have names that explain what they do, they don't need a comment as well
Style/DocumentationMethod:
Enabled: false
# Potentially fixable at some point...
Layout/ClassStructure:
Enabled: false
Lint/NumberConversion:
Enabled: false
Rails/RedundantPresenceValidationOnBelongsTo:
Enabled: false
Rails/TableNameAssignment:
Enabled: false
Style/ArgumentsForwarding:
Enabled: false
Style/InlineComment:
Enabled: false
Style/MissingElse:
Enabled: false
Style/RedundantReturn:
Enabled: false
Style/SelectByRegexp:
Enabled: false
# New potentially-fixable copouts
Capybara/NegationMatcher:
Enabled: false
FactoryBot/AssociationStyle:
Enabled: false
Gemspec/DependencyVersion:
Enabled: false
Gemspec/DevelopmentDependencies:
Enabled: false
Gemspec/RequireMFA:
Enabled: false
Rails/ActionControllerFlashBeforeRender:
Enabled: false
Rails/ActionOrder:
Enabled: false
RSpecRails/InferredSpecType:
Enabled: false
RSpec/SpecFilePathFormat:
Enabled: false
Style/FetchEnvVar:
Enabled: false
Style/FileWrite:
Enabled: false
Style/MapToHash:
Enabled: false