correct rubocop offenses

This commit is contained in:
Ben Balter 2019-05-24 11:02:15 +02:00
parent 2db291b3c5
commit aa9bec6256
No known key found for this signature in database
GPG Key ID: DBB67C246AD356C4
79 changed files with 180 additions and 26 deletions

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
source 'https://rubygems.org'
gemspec

View File

@ -1,4 +1,5 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
require 'dotenv/load'
require 'thor'

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require_relative 'licensee/version'
require 'forwardable'
require 'pathname'
@ -19,7 +21,7 @@ module Licensee
CONFIDENCE_THRESHOLD = 98
# Base domain from which to build license URLs
DOMAIN = 'http://choosealicense.com'.freeze
DOMAIN = 'http://choosealicense.com'
class << self
attr_writer :confidence_threshold

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
class LicenseeCLI < Thor
# Methods to call when displaying information about ProjectFiles
MATCHED_FILE_METHODS = %i[

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'tmpdir'
class LicenseeCLI < Thor

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
class LicenseeCLI < Thor
desc 'license-path [PATH]', "Returns the path to the given project's license file"
def license_path(_path)

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
class LicenseeCLI < Thor
desc 'version', 'Return the Licensee version'
def version

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'set'
require 'digest'
@ -89,9 +91,7 @@ module Licensee
# A set of each word in the license, without duplicates
def wordset
@wordset ||= if content_normalized
content_normalized.scan(/(?:\w(?:'s|(?<=s)')?)+/).to_set
end
@wordset ||= content_normalized&.scan(/(?:\w(?:'s|(?<=s)')?)+/)&.to_set
end
# Number of characteres in the normalized content

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Licensee
module HashHelper
def to_h

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'uri'
module Licensee

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Licensee
class LicenseField < Struct.new(:name, :description)
class << self

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Licensee
class LicenseMeta < Struct.new(
:title, :spdx_id, :source, :description, :how, :conditions, :permissions,

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Licensee
# Exposes #conditions, #permissions, and #limitation arrays of LicenseRules
class LicenseRules < Struct.new(:conditions, :permissions, :limitations)

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Licensee
module Matchers
autoload :Matcher, 'licensee/matchers/matcher'

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Licensee
module Matchers
class Cabal < Licensee::Matchers::Package

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Licensee
module Matchers
class Cargo < Licensee::Matchers::Package

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Licensee
module Matchers
class Copyright < Licensee::Matchers::Matcher

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Licensee
module Matchers
class Cran < Licensee::Matchers::Package

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Licensee
module Matchers
class Dice < Licensee::Matchers::Matcher

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Licensee
module Matchers
class DistZilla < Licensee::Matchers::Package

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Licensee
module Matchers
class Exact < Licensee::Matchers::Matcher

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Licensee
module Matchers
class Gemspec < Licensee::Matchers::Package

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Licensee
module Matchers
class Matcher

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Licensee
module Matchers
class NpmBower < Licensee::Matchers::Package

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Licensee
module Matchers
class Package < Licensee::Matchers::Matcher

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Licensee
module Matchers
# Matches README files that include a license by reference

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Licensee
module Matchers
class Spdx < Licensee::Matchers::Package

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Licensee
module ProjectFiles
autoload :ProjectFile, 'licensee/project_files/project_file'

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Licensee
module ProjectFiles
class LicenseFile < Licensee::ProjectFiles::ProjectFile
@ -72,11 +74,11 @@ module Licensee
end
def gpl?
license && license.gpl?
license&.gpl?
end
def license
if matcher && matcher.match
if matcher&.match
matcher.match
else
License.find('other')

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Licensee
module ProjectFiles
class PackageManagerFile < Licensee::ProjectFiles::ProjectFile

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
# A project file is a file within a project that contains license information
# Currently extended by LicenseFile, PackageManagerFile, and ReadmeFile
#
@ -32,7 +34,7 @@ module Licensee
#
# Returns a new Licensee::ProjectFile
def initialize(content, metadata = {})
@content = content
@content = content.dup
@content.force_encoding(ENCODING)
unless @content.valid_encoding?
@content.encode!(ENCODING, ENCODING_OPTIONS)
@ -70,17 +72,17 @@ module Licensee
# Returns the percent confident with the match
def confidence
matcher && matcher.confidence
matcher&.confidence
end
def license
matcher && matcher.match
matcher&.match
end
alias match license
def matched_license
license.spdx_id if license
license&.spdx_id
end
# Is this file a COPYRIGHT file with only a copyright statement?

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Licensee
module ProjectFiles
class ReadmeFile < Licensee::ProjectFiles::LicenseFile

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Licensee
module Projects
autoload :Project, 'licensee/projects/project'

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
# Filesystem-based project
#
# Analyze a folder on the filesystem for license information

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
# Git-based project
#
# Analyze a given (bare) Git repository for license information

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
# GitHub project
#
# Analyses a remote GitHub repository for license information

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
# Licensee::Project represents an open source project on disk
# It is not used directly, but rather is extended by FSProject and GitProject
# depending on the type of file system access available
@ -113,7 +115,7 @@ module Licensee
return [] if files.empty? || files.nil?
found = files.map { |file| file.merge(score: yield(file[:name])) }
found.select! { |file| file[:score] > 0 }
found.select! { |file| file[:score].positive? }
found.sort { |a, b| b[:score] <=> a[:score] }
end
@ -137,7 +139,7 @@ module Licensee
# Returns an array of LicenseFiles with LPGL first
def prioritize_lgpl(files)
return files if files.empty?
return files unless files.first.license && files.first.license.gpl?
return files unless files.first.license&.gpl?
lesser = files.find_index(&:lgpl?)
files.unshift(files.delete_at(lesser)) if lesser

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Licensee
class Rule
attr_reader :tag, :label, :description, :group

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Licensee
VERSION = '9.11.0'.freeze
VERSION = '9.11.0'
end

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require File.expand_path('lib/licensee/version', __dir__)
Gem::Specification.new do |gem|
@ -32,7 +34,7 @@ Gem::Specification.new do |gem|
gem.add_development_dependency('simplecov', '~> 0.16')
gem.add_development_dependency('webmock', '~> 3.1')
gem.required_ruby_version = '> 2.2'
gem.required_ruby_version = '> 2.3'
# ensure the gem is built out of versioned files
gem.files = Dir[

View File

@ -1,4 +1,5 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
require 'json'
require 'licensee'

View File

@ -1,4 +1,5 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
require_relative '../spec/spec_helper.rb'
@ -14,7 +15,7 @@ fixtures.each do |fixture|
if project.license_file
expectations['hash'] = project.license_file.content_hash
if project.license_file.matcher && project.license_file.matcher.name
if project.license_file.matcher&.name
expectations['matcher'] = project.license_file.matcher.name.to_s
end
end

View File

@ -1,4 +1,6 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
# Write current license hashes to spec/fixtures/license-hashes.json
require 'json'

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
RSpec.describe 'command line invocation' do
let(:command) { ['bundle', 'exec', 'bin/licensee', 'help'] }
let(:arguments) { [] }

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
RSpec.describe 'fixture test' do
fixtures.each do |fixture|
let(:options) { { detect_packages: true, detect_readme: true } }
@ -8,13 +10,14 @@ RSpec.describe 'fixture test' do
let(:none) { Licensee::License.find('none') }
let(:expectations) { fixture_licenses[fixture] || {} }
let(:license_file) { subject.license_file }
let(:matcher) { license_file.matcher if license_file }
let(:matcher) { license_file&.matcher }
subject { Licensee.project(path, options) }
it 'has an expected license in fixtures-licenses.yml' do
msg = "Expected an entry in `#{fixture_path('fixtures-licenses.yml')}` "
msg << "for the `#{fixture}` fixture. Please run "
msg = 'Expected an entry in `'.dup
msg << fixture_path('fixtures-licenses.yml')
msg << "` for the `#{fixture}` fixture. Please run "
msg << 'script/dump-fixture-licenses and confirm the output.'
expect(fixture_licenses).to have_key(fixture), msg
end

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
RSpec.describe 'integration test' do
[
Licensee::Projects::FSProject,

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
RSpec.describe 'detect command' do
let(:command) { ['bundle', 'exec', 'bin/licensee', 'detect'] }
let(:arguments) { [] }
@ -68,7 +70,7 @@ RSpec.describe 'detect command' do
end
it 'returns the expected output' do
msg = '`licensee detect --json` output did not match expectations. '
msg = '`licensee detect --json` output did not match expectations. '.dup
msg << 'Run `script/dump-detect-json-fixture` and verify the output.'
expect(JSON.parse(stdout)).to eql(expected), msg
end

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
RSpec.describe 'license-path command' do
let(:command) { ['bundle', 'exec', 'bin/licensee', 'license-path'] }
let(:arguments) { [project_root] }

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
RSpec.describe 'version command' do
let(:command) { ['bundle', 'exec', 'bin/licensee', 'version'] }
let(:arguments) { [] }

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
class ContentHelperTestHelper
include Licensee::ContentHelper
attr_accessor :content, :data
@ -14,7 +16,7 @@ end
RSpec.describe Licensee::ContentHelper do
let(:content) do
<<-LICENSE.freeze.gsub(/^\s*/, '')
<<-LICENSE.gsub(/^\s*/, '')
# The MIT License
=================
@ -186,7 +188,7 @@ RSpec.describe Licensee::ContentHelper do
end
it 'normalize the content' do
expected = 'the made up license. this license provided "as is". '
expected = 'the made up license. this license provided "as is". '.dup
expected << "please respect the contributors' wishes when implementing "
expected << "the license's \"software\"."
expect(normalized_content).to eql(expected)

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
RSpec.describe Licensee::HashHelper do
class HashHelperSpecFixture
include Licensee::HashHelper

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
RSpec.describe Licensee::LicenseField do
let(:expected_count) { 7 }

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
RSpec.describe Licensee::LicenseMeta do
subject { Licensee::License.find('mit').meta }

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
RSpec.describe Licensee::LicenseRules do
let(:mit) { Licensee::License.find('mit') }
subject { mit.rules }

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
RSpec.describe Licensee::License do
let(:license_count) { 37 }
let(:hidden_license_count) { 25 }

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
RSpec.describe Licensee::Matchers::Cabal do
let(:content) { 'license: mit' }
let(:file) { Licensee::ProjectFiles::LicenseFile.new(content, 'LICENSE.txt') }

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
RSpec.describe Licensee::Matchers::Cargo do
let(:mit) { Licensee::License.find('mit') }
let(:content) { 'license = "MIT"' }

View File

@ -1,5 +1,7 @@
# frozen_string_literal: true
RSpec.describe Licensee::Matchers::Copyright do
let(:content) { 'Copyright 2015 Ben Balter' }
let(:content) { 'Copyright 2015 Ben Balter'.dup }
let(:file) { Licensee::ProjectFiles::LicenseFile.new(content, 'LICENSE.txt') }
let(:mit) { Licensee::License.find('mit') }
let(:no_license) { Licensee::License.find('no-license') }
@ -28,7 +30,7 @@ RSpec.describe Licensee::Matchers::Copyright do
'ASCII-8BIT encoded' => "Copyright \xC2\xA92015 Ben Balter`",
'No year' => 'Copyright Ben Balter',
'Multiline' => "Copyright Ben Balter\nCopyright Another Entity"
.force_encoding('ASCII-8BIT')
.dup.force_encoding('ASCII-8BIT')
}.each do |description, notice|
context "with a #{description} notice" do
let(:content) { notice }

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
RSpec.describe Licensee::Matchers::Cran do
let(:mit) { Licensee::License.find('mit') }
let(:gpl2) { Licensee::License.find('gpl-2.0') }

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
RSpec.describe Licensee::Matchers::Dice do
let(:mit) { Licensee::License.find('mit') }
let(:gpl) { Licensee::License.find('gpl-3.0') }

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
RSpec.describe Licensee::Matchers::DistZilla do
let(:mit) { Licensee::License.find('mit') }
let(:content) { 'license = MIT' }

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
RSpec.describe Licensee::Matchers::Exact do
let(:mit) { Licensee::License.find('mit') }
let(:content) { sub_copyright_info(mit) }

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
RSpec.describe Licensee::Matchers::Gemspec do
let(:mit) { Licensee::License.find('mit') }
let(:content) { "s.license = 'mit'" }

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
RSpec.describe Licensee::Matchers::Matcher do
let(:mit) { Licensee::License.find('mit') }
let(:content) { sub_copyright_info(mit) }

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
RSpec.describe Licensee::Matchers::NpmBower do
let(:content) { '"license": "mit"' }
let(:file) { Licensee::ProjectFiles::LicenseFile.new(content, 'LICENSE.txt') }

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
RSpec.describe Licensee::Matchers::Package do
let(:mit) { Licensee::License.find('mit') }
let(:content) { '' }

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
RSpec.describe Licensee::Matchers::Reference do
let(:content) { 'Copyright 2015 Ben Balter' }
let(:file) { Licensee::ProjectFiles::LicenseFile.new(content, 'LICENSE.txt') }

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
RSpec.describe Licensee::Matchers::Spdx do
let(:content) { 'PackageLicenseDeclared: MIT' }
let(:file) do

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
RSpec.describe Licensee::ProjectFiles::LicenseFile do
let(:filename) { 'LICENSE.txt' }
let(:gpl) { Licensee::License.find('gpl-3.0') }
@ -20,7 +22,7 @@ RSpec.describe Licensee::ProjectFiles::LicenseFile do
end
context 'with an non-UTF-8-encoded license' do
let(:content) { "\x91License\x93".force_encoding('windows-1251') }
let(:content) { "\x91License\x93".dup.force_encoding('windows-1251') }
it "doesn't blow up " do
expect(subject.attribution).to be_nil

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
RSpec.describe Licensee::ProjectFiles::PackageManagerFile do
let(:content) { '' }
let(:filename) { '' }

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
RSpec.describe Licensee::ProjectFiles::ProjectFile do
let(:filename) { 'LICENSE.txt' }
let(:mit) { Licensee::License.find('mit') }

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
RSpec.describe Licensee::ProjectFiles::ReadmeFile do
let(:filename) { 'README.md' }
let(:content) { '' }

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
[
Licensee::Projects::FSProject,
Licensee::Projects::GitProject,

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
RSpec.describe Licensee::Projects::GitProject do
let(:fixture) { 'mit' }

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
RSpec.describe Licensee::Projects::GitHubProject do
let(:repo) { 'benbalter/licensee' }
let(:github_url) { "https://github.com/#{repo}" }

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
RSpec.describe Licensee::Rule do
let(:groups) { %w[permissions conditions limitations] }
subject do

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
RSpec.describe Licensee do
let(:project_path) { fixture_path('mit') }
let(:license_path) { fixture_path('mit/LICENSE.txt') }

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'simplecov'
SimpleCov.start

View File

@ -1,9 +1,11 @@
# frozen_string_literal: true
RSpec.describe 'vendored licenses' do
let(:filename) { 'LICENSE.txt' }
let(:license_file) do
Licensee::ProjectFiles::LicenseFile.new(content, filename)
end
let(:detected_license) { license_file.license if license_file }
let(:detected_license) { license_file&.license }
let(:wtfpl) { Licensee::License.find('wtfpl') }
Licensee.licenses(hidden: true).each do |license|
@ -15,7 +17,7 @@ RSpec.describe 'vendored licenses' do
let(:content) { content_with_copyright }
let(:expected_hash) { license_hashes[license.key] }
let(:hash_change_msg) do
msg = 'Did you update a vendored license? Run'
msg = 'Did you update a vendored license? Run'.dup
msg << ' bundle exec script/hash-licenses'
msg << 'Changes in license hashes must be a MINOR (or MAJOR) bump.'
msg