Apply Rubocop config from Rails

This commit is contained in:
Benjamin Fleischer
2017-05-15 10:12:34 -05:00
parent 2771e3225b
commit 2d116f6455
14 changed files with 106 additions and 106 deletions

View File

@@ -1,3 +1,3 @@
# frozen_string_literal: true
require 'ams/version'
require 'ams/serializer'
require "ams/version"
require "ams/serializer"

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
require 'json'
require "json"
module AMS
# Lightweight mapping of a model to a JSON API resource object
# with attributes and relationships
@@ -38,7 +38,7 @@ module AMS
class << self
attr_accessor :_attributes, :_relations, :_id_field, :_type
def add_instance_method(body, receiver=self)
def add_instance_method(body, receiver = self)
cl = caller_locations[0]
silence_warnings { receiver.module_eval body, cl.absolute_path, cl.lineno }
end
@@ -60,7 +60,7 @@ module AMS
super
base._attributes = _attributes.dup
base._relations = _relations.dup
base._type = base.name.split('::')[-1].sub('Serializer', '').downcase
base._type = base.name.split("::")[-1].sub("Serializer", "").downcase
add_class_method "def class; #{base}; end", base
add_instance_method "def id; object.id; end", base
end
@@ -79,7 +79,7 @@ module AMS
end
def attribute(attribute_name, key: attribute_name)
fail 'ForbiddenKey' if attribute_name == :id
fail "ForbiddenKey" if attribute_name == :id
_attributes[attribute_name] = { key: key }
add_instance_method <<-METHOD
def #{attribute_name}

View File

@@ -1,4 +1,4 @@
# frozen_string_literal: true
module AMS
VERSION = '0.99.0'
VERSION = "0.99.0"
end

View File

@@ -1,26 +1,26 @@
# frozen_string_literal: true
require 'yard'
require "yard"
namespace :doc do
desc 'start a gem server'
desc "start a gem server"
task :server do
sh 'bundle exec yard server --gems'
sh "bundle exec yard server --gems"
end
desc 'use Graphviz to generate dot graph'
desc "use Graphviz to generate dot graph"
task :graph do
output_file = 'doc/erd.dot'
output_file = "doc/erd.dot"
sh "bundle exec yard graph --protected --full --dependencies > #{output_file}"
puts 'open doc/erd.dot if you have graphviz installed'
puts "open doc/erd.dot if you have graphviz installed"
end
YARD::Rake::YardocTask.new(:stats) do |t|
t.stats_options = ['--list-undoc']
t.stats_options = ["--list-undoc"]
end
DOC_PATH = File.join('doc')
DOC_PATH = File.join("doc")
YARD::Rake::YardocTask.new(:pages) do |t|
t.options = ['-o', DOC_PATH]
t.options = ["-o", DOC_PATH]
end
end
task doc: ['doc:pages']
task doc: ["doc:pages"]

View File

@@ -1,53 +1,53 @@
# frozen_string_literal: true
begin
require 'rubocop'
require 'rubocop/rake_task'
require "rubocop"
require "rubocop/rake_task"
rescue LoadError # rubocop:disable Lint/HandleExceptions
else
require 'rbconfig'
require "rbconfig"
# https://github.com/bundler/bundler/blob/1b3eb2465a/lib/bundler/constants.rb#L2
windows_platforms = /(msdos|mswin|djgpp|mingw)/
if RbConfig::CONFIG['host_os'] =~ windows_platforms
desc 'No-op rubocop on Windows-- unsupported platform'
if RbConfig::CONFIG["host_os"] =~ windows_platforms
desc "No-op rubocop on Windows-- unsupported platform"
task :rubocop do
puts 'Skipping rubocop on Windows'
puts "Skipping rubocop on Windows"
end
elsif defined?(::Rubinius)
desc 'No-op rubocop to avoid rbx segfault'
desc "No-op rubocop to avoid rbx segfault"
task :rubocop do
puts 'Skipping rubocop on rbx due to segfault'
puts 'https://github.com/rubinius/rubinius/issues/3499'
puts "Skipping rubocop on rbx due to segfault"
puts "https://github.com/rubinius/rubinius/issues/3499"
end
else
Rake::Task[:rubocop].clear if Rake::Task.task_defined?(:rubocop)
patterns = [
'Gemfile',
'Rakefile',
'lib/**/*.{rb,rake}',
'config/**/*.rb',
'app/**/*.rb',
'test/**/*.rb'
"Gemfile",
"Rakefile",
"lib/**/*.{rb,rake}",
"config/**/*.rb",
"app/**/*.rb",
"test/**/*.rb"
]
desc 'Execute rubocop'
desc "Execute rubocop"
RuboCop::RakeTask.new(:rubocop) do |task|
task.options = ['--rails', '--display-cop-names', '--display-style-guide']
task.formatters = ['progress']
task.options = ["--rails", "--display-cop-names", "--display-style-guide"]
task.formatters = ["progress"]
task.patterns = patterns
task.fail_on_error = true
end
namespace :rubocop do
desc 'Auto-gen rubocop config'
desc "Auto-gen rubocop config"
task :auto_gen_config do
options = ['--auto-gen-config'].concat patterns
require 'benchmark'
options = ["--auto-gen-config"].concat patterns
require "benchmark"
result = 0
cli = RuboCop::CLI.new
time = Benchmark.realtime do
result = cli.run(options)
end
puts "Finished in #{time} seconds" if cli.options[:debug]
abort('RuboCop failed!') if result.nonzero?
abort("RuboCop failed!") if result.nonzero?
end
end
end

View File

@@ -1,11 +1,11 @@
# frozen_string_literal: true
require 'rake/testtask'
require "rake/testtask"
Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
t.libs << 'test'
t.pattern = 'test/**/*_test.rb'
t.ruby_opts = ['-r./test/test_helper.rb']
t.ruby_opts << ' -w' unless ENV['NO_WARN'] == 'true'
t.libs << "lib"
t.libs << "test"
t.pattern = "test/**/*_test.rb"
t.ruby_opts = ["-r./test/test_helper.rb"]
t.ruby_opts << " -w" unless ENV["NO_WARN"] == "true"
t.verbose = true
end