Skip to content

Commit

Permalink
Set up Rubocop for the template - Enable cop rules (#324)
Browse files Browse the repository at this point in the history
* Enable regex literal style

* Enable global var style

* Enable frozen string literal style

* Enable filename naming

* Fix default addon message
  • Loading branch information
rosle authored Mar 21, 2022
1 parent 43311cb commit 7810d17
Show file tree
Hide file tree
Showing 113 changed files with 270 additions and 52 deletions.
2 changes: 2 additions & 0 deletions .gitignore.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

append_to_file '.gitignore' do
<<~IGNORE
Expand Down
17 changes: 5 additions & 12 deletions .template/.rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,15 @@ Metrics/PerceivedComplexity:
- '**/template.rb'

Naming/FileName:
Enabled: false
Exclude:
- '**/.tool-versions.rb'
- '**/Dangerfile.rb'
- '**/Gemfile.rb'
- '**/Procfile.dev.rb'

Style/Documentation:
Enabled: false

Style/FrozenStringLiteralComment:
Enabled: false

# TODO: Enable this rule later
Style/GlobalVars:
Enabled: false

# TODO: Enable this rule later
Style/RegexpLiteral:
Enabled: false

Style/TrivialAccessors:
Exclude:
- '../template.rb'
Expand Down
2 changes: 2 additions & 0 deletions .template/Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

source 'https://rubygems.org'

gem 'docker-api' # A lightweight Ruby client for the Docker Remote API
Expand Down
2 changes: 1 addition & 1 deletion .template/addons/bootstrap/application.scss.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

insert_into_file 'app/assets/stylesheets/application.scss', after: /\/\/ Dependencies\n/ do
insert_into_file 'app/assets/stylesheets/application.scss', after: %r{// Dependencies\n} do
<<~SCSS
@import './vendor';
SCSS
Expand Down
2 changes: 2 additions & 0 deletions .template/addons/devise/Gemfile.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

insert_into_file 'Gemfile', after: /# Authentications & Authorizations.*\n/ do
<<~RUBY
gem 'devise' # Authentication solution for Rails with Warden
Expand Down
2 changes: 2 additions & 0 deletions .template/addons/devise/spec_support.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

file 'spec/support/devise.rb', <<~RUBY
RSpec.configure do |config|
config.include Devise::Test::ControllerHelpers, type: :controller
Expand Down
2 changes: 2 additions & 0 deletions .template/addons/devise/template.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

apply '.template/addons/devise/Gemfile.rb'
apply '.template/addons/devise/spec_support.rb'

Expand Down
2 changes: 2 additions & 0 deletions .template/addons/docker/template.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

use_source_path __dir__

template 'Dockerfile.tt'
Expand Down
2 changes: 2 additions & 0 deletions .template/addons/github/template.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

use_source_path __dir__

directory '.github'
Expand Down
2 changes: 2 additions & 0 deletions .template/addons/heroku/template.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

use_source_path __dir__

template 'Dockerfile.web.tt'
Expand Down
2 changes: 2 additions & 0 deletions .template/addons/nginx/bin/start.sh.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

insert_into_file 'bin/start.sh', after: "fi\n" do
<<~SHELL
Expand Down
2 changes: 2 additions & 0 deletions .template/addons/nginx/bin/template.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

use_source_path __dir__

apply 'start.sh.rb'
Expand Down
2 changes: 2 additions & 0 deletions .template/addons/nginx/config/environments/production.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

gsub_file(
'config/environments/production.rb',
/config.public_file_server.enabled.*/,
Expand Down
2 changes: 2 additions & 0 deletions .template/addons/nginx/config/template.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

use_source_path __dir__

apply 'config/environments/production.rb'
Expand Down
4 changes: 3 additions & 1 deletion .template/addons/nginx/docker.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# frozen_string_literal: true

insert_into_file 'Dockerfile', after: 'unzip ' do
'nginx '
end

insert_into_file 'Dockerfile', after: %r{WORKDIR.+\n} do
insert_into_file 'Dockerfile', after: /WORKDIR.+\n/ do
<<~DOCKERFILE
# Nginx config
Expand Down
2 changes: 2 additions & 0 deletions .template/addons/nginx/template.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

use_source_path __dir__

apply 'bin/template.rb'
Expand Down
4 changes: 3 additions & 1 deletion .template/addons/phrase_app/spec/codebase/codebase_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
insert_into_file 'spec/codebase/codebase_spec.rb', before: %r{end\Z} do
# frozen_string_literal: true

insert_into_file 'spec/codebase/codebase_spec.rb', before: /end\Z/ do
<<~RUBY.indent(2)
# rubocop:disable RSpec/ExampleLength
Expand Down
2 changes: 2 additions & 0 deletions .template/addons/phrase_app/spec/template.rb
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# frozen_string_literal: true

apply 'spec/codebase/codebase_spec.rb'
2 changes: 2 additions & 0 deletions .template/addons/phrase_app/template.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

after_bundle do
use_source_path __dir__

Expand Down
2 changes: 2 additions & 0 deletions .template/addons/semaphore/template.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

use_source_path __dir__

directory '.semaphore'
2 changes: 2 additions & 0 deletions .template/addons/slim/template.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# frozen_string_literal: true

apply '.template/addons/slim/Gemfile.rb'
apply '.template/addons/slim/Dangerfile.rb'
2 changes: 2 additions & 0 deletions .template/hooks/before_complete/fix_rubocop.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

def fixing_rubocop
after_bundle do
use_source_path __dir__
Expand Down
2 changes: 2 additions & 0 deletions .template/hooks/before_complete/report.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

def report
after_bundle do
say "\n🚀 The project has been successfully created 🚀\n", :green
Expand Down
2 changes: 2 additions & 0 deletions .template/lib/template.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Template
require_relative 'template/messages'
require_relative 'template/errors'
Expand Down
2 changes: 2 additions & 0 deletions .template/lib/template/errors.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# rubocop:todo Style/ClassAndModuleChildren
class Template::Errors < Template::Messages; end
# rubocop:enable Style/ClassAndModuleChildren
2 changes: 2 additions & 0 deletions .template/lib/template/messages.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# rubocop:todo Style/ClassAndModuleChildren
class Template::Messages
delegate :empty?, to: :messages
Expand Down
2 changes: 2 additions & 0 deletions .template/spec/addons/base/devise/gemfile_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

describe 'Devise Addon - Gemfile' do
subject { file('Gemfile') }

Expand Down
2 changes: 2 additions & 0 deletions .template/spec/addons/base/devise/template_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

describe 'Devise addon - template' do
it 'creates the Devise spec support file' do
expect(file('spec/support/devise.rb')).to exist
Expand Down
2 changes: 2 additions & 0 deletions .template/spec/addons/base/docker/template_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

describe 'Docker addon - template' do
it 'creates the Dockerfile' do
expect(file('Dockerfile')).to exist
Expand Down
2 changes: 2 additions & 0 deletions .template/spec/addons/base/github/template_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

describe 'Github addon - template' do
it 'creates the PULL_REQUEST_TEMPLATE file' do
expect(file('.github/PULL_REQUEST_TEMPLATE.md')).to exist
Expand Down
2 changes: 2 additions & 0 deletions .template/spec/addons/base/nginx/template_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

describe 'Nginx addon - template' do
it 'creates the inject_port_into_nginx script' do
expect(file('bin/inject_port_into_nginx.sh')).to exist
Expand Down
2 changes: 2 additions & 0 deletions .template/spec/addons/base/phrase_app/template.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

describe 'PhraseApp addon - template' do
it 'creates .phraseapp.yml file' do
expect(file('.phraseapp.yml')).to exist
Expand Down
2 changes: 2 additions & 0 deletions .template/spec/addons/base/semaphore/template_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

describe 'Semaphore addon - template' do
it 'creates the Dockerfile.web' do
expect(file('Dockerfile.web')).to exist
Expand Down
2 changes: 2 additions & 0 deletions .template/spec/addons/variants/api/nginx/template_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

describe 'Nginx addon - template' do
it 'creates config/nginx/app.conf.template file' do
expect(file('config/nginx/app.conf.template')).not_to contain('gzip on;')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

describe 'Bootstrap Addon - application.js' do
subject { file('app/javascript/application.js') }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

describe 'Bootstrap Addon - application.scss' do
subject { file('app/assets/stylesheets/application.scss') }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

describe 'Bootstrap addon - package.json' do
subject do
JSON.parse(file('package.json').content)
Expand Down
2 changes: 2 additions & 0 deletions .template/spec/addons/variants/web/bootstrap/template_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

describe 'Bootstrap addon - template' do
it 'creates app/assets/stylesheets/vendor/index.scss' do
expect(file('app/assets/stylesheets/vendor/index.scss')).to exist
Expand Down
2 changes: 2 additions & 0 deletions .template/spec/addons/variants/web/nginx/template_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

describe 'Nginx addon - template' do
it 'creates config/nginx/app.conf.template file' do
expect(file('config/nginx/app.conf.template')).to contain('gzip on;')
Expand Down
2 changes: 2 additions & 0 deletions .template/spec/addons/variants/web/slim/dangerfile_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

describe 'Slim Addon - Dangerfile' do
subject { file('Dangerfile') }

Expand Down
2 changes: 2 additions & 0 deletions .template/spec/addons/variants/web/slim/gemfile_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

describe 'Slim Addon - Gemfile' do
subject { file('Gemfile') }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

describe 'localization concern' do
subject { file('app/controllers/concerns/localization.rb') }

Expand Down
2 changes: 2 additions & 0 deletions .template/spec/base/application_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

describe 'Application' do
it 'is listening on port 80' do
# Config the wait time to 1 minute in case if the container has not fully started.
Expand Down
2 changes: 2 additions & 0 deletions .template/spec/base/bin/template_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

describe '/bin template' do
it 'creates the envsetup script' do
expect(file('bin/envsetup.sh')).to exist
Expand Down
2 changes: 2 additions & 0 deletions .template/spec/base/config/application_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

describe 'config/application.rb' do
subject { file('config/application.rb') }

Expand Down
2 changes: 2 additions & 0 deletions .template/spec/base/config/environments/development_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

describe 'config/environments/development.rb' do
subject { file('config/environments/development.rb') }

Expand Down
2 changes: 2 additions & 0 deletions .template/spec/base/config/environments/production_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

describe 'config/environments/production.rb' do
subject { file('config/environments/production.rb') }

Expand Down
2 changes: 2 additions & 0 deletions .template/spec/base/config/environments/test_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

describe 'config/environments/test.rb' do
subject { file('config/environments/test.rb') }

Expand Down
2 changes: 2 additions & 0 deletions .template/spec/base/config/template_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

describe '/config template' do
it 'creates the Figaro configuration for application variables' do
expect(file('config/application.yml')).to exist
Expand Down
2 changes: 2 additions & 0 deletions .template/spec/base/spec/template_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

describe '/spec template' do
it 'creates the base spec directory' do
expect(file('spec/codebase')).to be_directory
Expand Down
2 changes: 2 additions & 0 deletions .template/spec/base/template_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

describe 'Base template' do
it 'creates Rubocop configuration files' do
expect(file('.rubocop.yml')).to exist
Expand Down
2 changes: 2 additions & 0 deletions .template/spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'rspec/wait'

Dir[[__dir__, 'support', '**', '*.rb'].join('/')].each { |f| require f }
Expand Down
25 changes: 18 additions & 7 deletions .template/spec/support/serverspec.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,31 @@
# frozen_string_literal: true

require 'serverspec'
require 'docker-api'

module ServerSpecHelpers
# Prebuild and run docker image before running the test
# Because the docker api does not support docker compose
def self.test_container
container_id = `docker ps -qf "name=#{ENV.fetch('APP_NAME')}_test"`

Docker::Container.get(container_id.strip)
end
end

RSpec.configure do |config|
config.before(:suite) do
# Prebuild and run docker image before running the test
# Because the docker api does not support docker compose
container_id = `docker ps -qf "name=#{ENV.fetch('APP_NAME')}_test"`
$container = Docker::Container.get(container_id.strip)
container = ServerSpecHelpers.test_container

set :os, family: :debian
set :backend, :docker
set :docker_container, $container.id
set :docker_container, container.id
end

config.after(:suite) do
$container.stop
$container.remove(force: true)
container = ServerSpecHelpers.test_container

container.stop
container.remove(force: true)
end
end
2 changes: 2 additions & 0 deletions .template/spec/variants/api/template_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

describe 'Api variant - template' do
context 'Controllers' do
it 'creates the localization concern' do
Expand Down
2 changes: 2 additions & 0 deletions .template/spec/variants/web/app/template_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

describe 'Web variant - /app template' do
context 'Javascript' do
it 'creates base javascript directory' do
Expand Down
2 changes: 2 additions & 0 deletions .template/spec/variants/web/config/application_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

describe 'Web variant - config/application.rb' do
subject { file('config/application.rb') }

Expand Down
Loading

0 comments on commit 7810d17

Please sign in to comment.