Skip to content

Commit

Permalink
Single rubocop config, also better lint task naming (#1372)
Browse files Browse the repository at this point in the history
* Single rubocop config, also better lint task naming
Fixes #1370

* Setup lint namespace, use rake_helper

* Run all lint, still just rubocop but makes future proof
  • Loading branch information
treydock authored Aug 27, 2021
1 parent 9295add commit 97fe6af
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 64 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
run: bundle exec rake test:unit

- name: Run lint tests
run: bundle exec rake test:lint || true
run: bundle exec rake lint || true

- name: Run System Dashboard tests
run: cd apps/dashboard; bin/rake test:system
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,7 @@ tags

# Ignore distribution files
/dist

# Ignore copies of .rubocop.yml
.rubocop.yml
!/.rubocop.yml
File renamed without changes.
49 changes: 3 additions & 46 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,57 +9,14 @@ INSTALL_ROOT = Pathname.new(ENV["PREFIX"] || "/opt/ood")
VENDOR_BUNDLE = (ENV['VENDOR_BUNDLE'] == "yes" || ENV['VENDOR_BUNDLE'] == "true")
PASSENGER_APP_ENV = ENV["PASSENGER_APP_ENV"] || "production"

require "#{TASK_DIR}/rake_helper"
require "#{TASK_DIR}/packaging"
require "#{TASK_DIR}/test"
require "#{TASK_DIR}/lint"
require "#{TASK_DIR}/docker"
require "#{TASK_DIR}/development"

def infrastructure
[
'mod_ood_proxy',
'nginx_stage',
'ood_auth_map',
'ood-portal-generator',
].map { |d| Component.new(d) }
end

def apps
Dir["#{APPS_DIR}/*"].map { |d| Component.new(d) }
end

def ruby_apps
apps.select(&:ruby_app?)
end

def yarn_apps
apps.select(&:package_json?)
end

class Component
attr_reader :name
attr_reader :path

def initialize(app)
@name = File.basename(app)
@path = Pathname.new(app)
end

def ruby_app?
@path.join('config.ru').exist?
end

def node_app?
@path.join('app.js').exist?
end

def package_json?
@path.join('package.json').exist?
end

def gemfile?
@path.join('Gemfile.lock').exist?
end
end
include RakeHelper

namespace :build do
desc "Build gems"
Expand Down
1 change: 0 additions & 1 deletion lib/.rubocop.yml

This file was deleted.

35 changes: 35 additions & 0 deletions lib/tasks/lint.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
require 'rubocop/rake_task'
require 'fileutils'

desc "Lint OnDemand"
task :lint => 'lint:all'

namespace :lint do
require_relative 'rake_helper'
include RakeHelper

begin
RuboCop::RakeTask.new(:rubocop, [:path]) do |t, args|
t.options = ["--config=#{PROJ_DIR.join(".rubocop.yml")}"]
default_patterns = [
"apps/**/*.rb",
"lib/**/*.rb",
"nginx_stage/**/*.rb",
"ood-portal-generator/**/*.rb",
"spec/**/*.rb",
]
t.patterns = args[:path].nil? ? default_patterns : [args[:path]]
end
rescue LoadError
end

desc "Setup .rubocop.yml files"
task :setup do
source = PROJ_DIR.join('.rubocop.yml')
(ruby_apps + infrastructure).each do |app|
FileUtils.cp(source, app.path.join('.rubocop.yml'), verbose: true)
end
end

task :all => [:rubocop]
end
51 changes: 51 additions & 0 deletions lib/tasks/rake_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# frozen_string_literal: true
require "pathname"

module RakeHelper
def infrastructure
[
'mod_ood_proxy',
'nginx_stage',
'ood_auth_map',
'ood-portal-generator',
].map { |d| Component.new(d) }
end

def apps
Dir["#{APPS_DIR}/*"].map { |d| Component.new(d) }
end

def ruby_apps
apps.select(&:ruby_app?)
end

def yarn_apps
apps.select(&:package_json?)
end

class Component
attr_reader :name
attr_reader :path

def initialize(app)
@name = File.basename(app)
@path = Pathname.new(app)
end

def ruby_app?
@path.join('config.ru').exist?
end

def node_app?
@path.join('app.js').exist?
end

def package_json?
@path.join('package.json').exist?
end

def gemfile?
@path.join('Gemfile.lock').exist?
end
end
end
16 changes: 0 additions & 16 deletions lib/tasks/test.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require 'rubocop/rake_task'

desc "Test OnDemand"
task :test => 'test:all'

Expand Down Expand Up @@ -45,20 +43,6 @@ def yarn_app?(path)
end
end

begin
RuboCop::RakeTask.new(:lint) do |t|
t.options = ["--config=#{File.join(proj_root, "apps/dashboard/.rubocop.yml")}"]
t.patterns = [
"apps/**/*.rb",
"lib/**/*.rb",
"nginx_stage/**/*.rb",
"ood-portal-generator/**/*.rb",
"spec/**/*.rb",
]
end
rescue LoadError
end

desc "Run shellcheck"
task :shellcheck do
sh "shellcheck -x ood-portal-generator/sbin/update_ood_portal"
Expand Down

0 comments on commit 97fe6af

Please sign in to comment.