From 724a11c5354d0dc2228f25526cbde933fbca0aba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20A=CC=8Ahman?= Date: Sun, 7 Apr 2019 17:25:47 +0200 Subject: [PATCH] Add rubocop --- .rubocop.yml | 24 ++++++++++++++++++++ Gemfile | 6 +++-- Rakefile | 14 +++++++----- bin/console | 7 +++--- lib/nssql.rb | 16 ++++++++------ lib/nssql/settings.rb | 8 +++---- lib/nssql/version.rb | 2 ++ nssql.gemspec | 44 +++++++++++++++++++------------------ test/nssql_settings_test.rb | 4 +++- test/nssql_table_test.rb | 4 +++- test/nssql_test.rb | 4 +++- test/test_helper.rb | 8 ++++--- 12 files changed, 92 insertions(+), 49 deletions(-) create mode 100644 .rubocop.yml diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..3a650ed --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,24 @@ +# This is the modified configuration used to check the source code. + +# === OVERRIDE === +# +# - https://rubocop.readthedocs.io/en/latest/cops_metrics/#metricslinelength +# +Metrics/LineLength: + Max: 120 + +# === OVERRIDE === +# +# - https://rubocop.readthedocs.io/en/latest/cops_metrics/#metricsmethodlength +# +Metrics/MethodLength: + Max: 15 + +# === DISABLE +# +# - https://rubocop.readthedocs.io/en/latest/cops_style/#styletrivialaccessors +# +# Why? Faulty corrections. +# +Style/TrivialAccessors: + Enabled: false diff --git a/Gemfile b/Gemfile index da83192..58c238a 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,8 @@ -source "https://rubygems.org" +# frozen_string_literal: true -git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } +source 'https://rubygems.org' + +git_source(:github) { |repo_name| "https://github.com/#{repo_name}" } # Specify your gem's dependencies in nssql.gemspec gemspec diff --git a/Rakefile b/Rakefile index d433a1e..4caa98e 100644 --- a/Rakefile +++ b/Rakefile @@ -1,10 +1,12 @@ -require "bundler/gem_tasks" -require "rake/testtask" +# frozen_string_literal: true + +require 'bundler/gem_tasks' +require 'rake/testtask' Rake::TestTask.new(:test) do |t| - t.libs << "test" - t.libs << "lib" - t.test_files = FileList["test/**/*_test.rb"] + t.libs << 'test' + t.libs << 'lib' + t.test_files = FileList['test/**/*_test.rb'] end -task :default => :test +task default: :test diff --git a/bin/console b/bin/console index a759d21..2d4fb2d 100755 --- a/bin/console +++ b/bin/console @@ -1,7 +1,8 @@ #!/usr/bin/env ruby +# frozen_string_literal: true -require "bundler/setup" -require "nssql" +require 'bundler/setup' +require 'nssql' # You can add fixtures and/or initialization code here to make experimenting # with your gem easier. You can also use a different console, if you like. @@ -10,5 +11,5 @@ require "nssql" # require "pry" # Pry.start -require "irb" +require 'irb' IRB.start(__FILE__) diff --git a/lib/nssql.rb b/lib/nssql.rb index 4cbd000..8d815b3 100644 --- a/lib/nssql.rb +++ b/lib/nssql.rb @@ -1,18 +1,20 @@ -require "nssql/version" -require "nssql/settings" -require "nssql/table" +# frozen_string_literal: true + +require 'nssql/version' +require 'nssql/settings' +require 'nssql/table' require 'odbc_utf8' require 'tempfile' +# NSSQL module. +# module NSSQL class Error < StandardError; end class << self def select_array(query) - execute(query) do |result| - result.fetch_all - end + execute(query, &:fetch_all) end def select_to_file(query) @@ -45,7 +47,7 @@ def system_call(command) end def one_line_query(query) - query.gsub("\n", ' ').gsub(/\s+/, ' ').strip + query.tr("\n", ' ').gsub(/\s+/, ' ').strip end def netsuite_connection diff --git a/lib/nssql/settings.rb b/lib/nssql/settings.rb index 1f485c3..4d2cde0 100644 --- a/lib/nssql/settings.rb +++ b/lib/nssql/settings.rb @@ -5,12 +5,12 @@ module NSSQL class Settings include Singleton - SETTINGS = [ - :user, - :password, + SETTINGS = %i[ + user + password ].freeze - attr_accessor *SETTINGS + attr_accessor(*SETTINGS) class << self SETTINGS.each do |setting| diff --git a/lib/nssql/version.rb b/lib/nssql/version.rb index 35959c5..1a60778 100644 --- a/lib/nssql/version.rb +++ b/lib/nssql/version.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module NSSQL VERSION = '0.1.0' end diff --git a/nssql.gemspec b/nssql.gemspec index f290e18..6ad35a5 100644 --- a/nssql.gemspec +++ b/nssql.gemspec @@ -1,44 +1,46 @@ +# frozen_string_literal: true -lib = File.expand_path("../lib", __FILE__) +lib = File.expand_path('lib', __dir__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) -require "nssql/version" +require 'nssql/version' Gem::Specification.new do |spec| - spec.name = "nssql" + spec.name = 'nssql' spec.version = NSSQL::VERSION - spec.authors = ["Love Ottosson"] - spec.email = ["love.ottosson@apoex.se"] + spec.authors = ['Love Ottosson'] + spec.email = ['love.ottosson@apoex.se'] - spec.summary = "Lightweight gem for fetching data from NetSuite with SQL." - spec.description = "Represent NetSuite tables as you want and fetch only the needed data." - spec.homepage = "https://github.com/apoex/nssql" - spec.license = "MIT" + spec.summary = 'Lightweight gem for fetching data from NetSuite with SQL.' + spec.description = 'Represent NetSuite tables as you want and fetch only the needed data.' + spec.homepage = 'https://github.com/apoex/nssql' + spec.license = 'MIT' # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host' # to allow pushing to a single host or delete this section to allow pushing to any host. if spec.respond_to?(:metadata) - spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'" + spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'" - spec.metadata["homepage_uri"] = spec.homepage - spec.metadata["source_code_uri"] = "https://github.com/apoex/nssql" - spec.metadata["changelog_uri"] = "https://github.com/apoex/nssql/blob/master/CHANGELOG.md" + spec.metadata['homepage_uri'] = spec.homepage + spec.metadata['source_code_uri'] = 'https://github.com/apoex/nssql' + spec.metadata['changelog_uri'] = 'https://github.com/apoex/nssql/blob/master/CHANGELOG.md' else - raise "RubyGems 2.0 or newer is required to protect against " \ - "public gem pushes." + raise 'RubyGems 2.0 or newer is required to protect against ' \ + 'public gem pushes.' end # Specify which files should be added to the gem when it is released. # The `git ls-files -z` loads the files in the RubyGem that have been added into git. - spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do + spec.files = Dir.chdir(File.expand_path(__dir__)) do `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } end - spec.bindir = "exe" + spec.bindir = 'exe' spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } - spec.require_paths = ["lib"] + spec.require_paths = ['lib'] spec.add_runtime_dependency 'ruby-odbc', '~> 0.99997' - spec.add_development_dependency "bundler", "~> 1.17" - spec.add_development_dependency "rake", "~> 10.0" - spec.add_development_dependency "minitest", "~> 5.0" + spec.add_development_dependency 'bundler', '~> 1.17' + spec.add_development_dependency 'minitest', '~> 5.0' + spec.add_development_dependency 'rake', '~> 10.0' + spec.add_development_dependency 'rubocop', '>= 0.60.0' end diff --git a/test/nssql_settings_test.rb b/test/nssql_settings_test.rb index 2c337a8..a78b821 100644 --- a/test/nssql_settings_test.rb +++ b/test/nssql_settings_test.rb @@ -1,4 +1,6 @@ -require "test_helper" +# frozen_string_literal: true + +require 'test_helper' class NssqlSettingsTest < Minitest::Test def test_that_it_is_configurable diff --git a/test/nssql_table_test.rb b/test/nssql_table_test.rb index c706b4b..654263d 100644 --- a/test/nssql_table_test.rb +++ b/test/nssql_table_test.rb @@ -1,4 +1,6 @@ -require "test_helper" +# frozen_string_literal: true + +require 'test_helper' class NssqlTableTest < Minitest::Test class TestTable < NSSQL::Table diff --git a/test/nssql_test.rb b/test/nssql_test.rb index f2a3e4f..1abb2e6 100644 --- a/test/nssql_test.rb +++ b/test/nssql_test.rb @@ -1,4 +1,6 @@ -require "test_helper" +# frozen_string_literal: true + +require 'test_helper' class NssqlTest < Minitest::Test def setup diff --git a/test/test_helper.rb b/test/test_helper.rb index c6d25d6..d77a5c4 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,4 +1,6 @@ -$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__) -require "nssql" +# frozen_string_literal: true -require "minitest/autorun" +$LOAD_PATH.unshift File.expand_path('../lib', __dir__) +require 'nssql' + +require 'minitest/autorun'