licensee 9.10.0 → 9.13.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (128) hide show
  1. checksums.yaml +4 -4
  2. data/bin/licensee +5 -4
  3. data/lib/licensee.rb +4 -2
  4. data/lib/licensee/commands/detect.rb +10 -5
  5. data/lib/licensee/commands/diff.rb +7 -8
  6. data/lib/licensee/commands/license_path.rb +2 -0
  7. data/lib/licensee/commands/version.rb +2 -0
  8. data/lib/licensee/content_helper.rb +234 -85
  9. data/lib/licensee/hash_helper.rb +7 -5
  10. data/lib/licensee/license.rb +32 -25
  11. data/lib/licensee/license_field.rb +4 -1
  12. data/lib/licensee/license_meta.rb +3 -0
  13. data/lib/licensee/license_rules.rb +2 -0
  14. data/lib/licensee/matchers.rb +2 -0
  15. data/lib/licensee/matchers/cabal.rb +16 -2
  16. data/lib/licensee/matchers/cargo.rb +3 -1
  17. data/lib/licensee/matchers/copyright.rb +6 -4
  18. data/lib/licensee/matchers/cran.rb +7 -3
  19. data/lib/licensee/matchers/dice.rb +6 -4
  20. data/lib/licensee/matchers/dist_zilla.rb +3 -1
  21. data/lib/licensee/matchers/exact.rb +3 -0
  22. data/lib/licensee/matchers/gemspec.rb +8 -5
  23. data/lib/licensee/matchers/matcher.rb +3 -1
  24. data/lib/licensee/matchers/npm_bower.rb +3 -1
  25. data/lib/licensee/matchers/package.rb +3 -0
  26. data/lib/licensee/matchers/reference.rb +3 -1
  27. data/lib/licensee/matchers/spdx.rb +3 -1
  28. data/lib/licensee/project_files.rb +2 -0
  29. data/lib/licensee/project_files/license_file.rb +13 -10
  30. data/lib/licensee/project_files/package_manager_file.rb +3 -0
  31. data/lib/licensee/project_files/project_file.rb +12 -4
  32. data/lib/licensee/project_files/readme_file.rb +5 -3
  33. data/lib/licensee/projects.rb +2 -0
  34. data/lib/licensee/projects/fs_project.rb +3 -0
  35. data/lib/licensee/projects/git_project.rb +19 -11
  36. data/lib/licensee/projects/github_project.rb +6 -1
  37. data/lib/licensee/projects/project.rb +16 -5
  38. data/lib/licensee/rule.rb +2 -0
  39. data/lib/licensee/version.rb +3 -1
  40. data/licensee.gemspec +47 -0
  41. data/spec/bin_spec.rb +3 -1
  42. data/spec/fixture_spec.rb +46 -0
  43. data/spec/fixtures/bsd-3-noendorseslash/LICENSE +30 -0
  44. data/spec/fixtures/cc0-cal2013/LICENSE +116 -0
  45. data/spec/fixtures/cc0-cc/LICENSE +121 -0
  46. data/spec/fixtures/detect.json +9 -7
  47. data/spec/fixtures/fixtures.yml +130 -0
  48. data/spec/fixtures/html/license.html +262 -0
  49. data/spec/fixtures/license-hashes.json +41 -0
  50. data/spec/fixtures/mit-optional/LICENSE.txt +21 -0
  51. data/spec/fixtures/multiple-arrs/LICENSE +30 -0
  52. data/spec/fixtures/unlicense-noinfo/LICENSE +22 -0
  53. data/spec/integration_spec.rb +68 -2
  54. data/spec/licensee/commands/detect_spec.rb +10 -6
  55. data/spec/licensee/commands/license_path_spec.rb +3 -1
  56. data/spec/licensee/commands/version_spec.rb +3 -1
  57. data/spec/licensee/content_helper_spec.rb +184 -67
  58. data/spec/licensee/hash_helper_spec.rb +3 -1
  59. data/spec/licensee/license_field_spec.rb +5 -3
  60. data/spec/licensee/license_meta_spec.rb +16 -12
  61. data/spec/licensee/license_rules_spec.rb +6 -2
  62. data/spec/licensee/license_spec.rb +62 -37
  63. data/spec/licensee/matchers/cabal_matcher_spec.rb +97 -2
  64. data/spec/licensee/matchers/cargo_matcher_spec.rb +5 -2
  65. data/spec/licensee/matchers/copyright_matcher_spec.rb +7 -5
  66. data/spec/licensee/matchers/cran_matcher_spec.rb +5 -2
  67. data/spec/licensee/matchers/dice_matcher_spec.rb +15 -12
  68. data/spec/licensee/matchers/dist_zilla_matcher_spec.rb +5 -2
  69. data/spec/licensee/matchers/exact_matcher_spec.rb +5 -2
  70. data/spec/licensee/matchers/gemspec_matcher_spec.rb +5 -2
  71. data/spec/licensee/matchers/matcher_spec.rb +6 -2
  72. data/spec/licensee/matchers/npm_bower_matcher_spec.rb +5 -3
  73. data/spec/licensee/matchers/package_matcher_spec.rb +6 -2
  74. data/spec/licensee/matchers/reference_matcher_spec.rb +4 -2
  75. data/spec/licensee/matchers/spdx_matcher_spec.rb +5 -2
  76. data/spec/licensee/project_files/license_file_spec.rb +20 -18
  77. data/spec/licensee/project_files/package_info_spec.rb +5 -1
  78. data/spec/licensee/project_files/project_file_spec.rb +8 -2
  79. data/spec/licensee/project_files/readme_file_spec.rb +4 -1
  80. data/spec/licensee/project_spec.rb +24 -17
  81. data/spec/licensee/projects/git_project_spec.rb +23 -0
  82. data/spec/licensee/projects/github_project_spec.rb +8 -5
  83. data/spec/licensee/rule_spec.rb +6 -3
  84. data/spec/licensee_spec.rb +12 -9
  85. data/spec/spec_helper.rb +28 -9
  86. data/spec/vendored_license_spec.rb +29 -10
  87. data/vendor/choosealicense.com/_data/meta.yml +0 -4
  88. data/vendor/choosealicense.com/_data/rules.yml +3 -0
  89. data/vendor/choosealicense.com/_licenses/0bsd.txt +39 -0
  90. data/vendor/choosealicense.com/_licenses/afl-3.0.txt +7 -6
  91. data/vendor/choosealicense.com/_licenses/agpl-3.0.txt +0 -1
  92. data/vendor/choosealicense.com/_licenses/apache-2.0.txt +1 -2
  93. data/vendor/choosealicense.com/_licenses/artistic-2.0.txt +1 -2
  94. data/vendor/choosealicense.com/_licenses/bsd-2-clause.txt +8 -6
  95. data/vendor/choosealicense.com/_licenses/bsd-3-clause-clear.txt +2 -2
  96. data/vendor/choosealicense.com/_licenses/bsd-3-clause.txt +12 -10
  97. data/vendor/choosealicense.com/_licenses/bsd-4-clause.txt +61 -0
  98. data/vendor/choosealicense.com/_licenses/bsl-1.0.txt +5 -2
  99. data/vendor/choosealicense.com/_licenses/cc-by-4.0.txt +3 -1
  100. data/vendor/choosealicense.com/_licenses/cc-by-sa-4.0.txt +3 -1
  101. data/vendor/choosealicense.com/_licenses/cc0-1.0.txt +113 -105
  102. data/vendor/choosealicense.com/_licenses/cecill-2.1.txt +579 -0
  103. data/vendor/choosealicense.com/_licenses/ecl-2.0.txt +1 -2
  104. data/vendor/choosealicense.com/_licenses/epl-1.0.txt +1 -2
  105. data/vendor/choosealicense.com/_licenses/epl-2.0.txt +3 -4
  106. data/vendor/choosealicense.com/_licenses/eupl-1.1.txt +0 -1
  107. data/vendor/choosealicense.com/_licenses/eupl-1.2.txt +0 -1
  108. data/vendor/choosealicense.com/_licenses/gpl-2.0.txt +0 -1
  109. data/vendor/choosealicense.com/_licenses/gpl-3.0.txt +1 -2
  110. data/vendor/choosealicense.com/_licenses/isc.txt +0 -1
  111. data/vendor/choosealicense.com/_licenses/lgpl-2.1.txt +0 -1
  112. data/vendor/choosealicense.com/_licenses/lgpl-3.0.txt +1 -3
  113. data/vendor/choosealicense.com/_licenses/lppl-1.3c.txt +1 -2
  114. data/vendor/choosealicense.com/_licenses/mit.txt +1 -2
  115. data/vendor/choosealicense.com/_licenses/mpl-2.0.txt +0 -1
  116. data/vendor/choosealicense.com/_licenses/ms-pl.txt +0 -1
  117. data/vendor/choosealicense.com/_licenses/ms-rl.txt +0 -1
  118. data/vendor/choosealicense.com/_licenses/ncsa.txt +21 -22
  119. data/vendor/choosealicense.com/_licenses/odbl-1.0.txt +573 -0
  120. data/vendor/choosealicense.com/_licenses/ofl-1.1.txt +4 -2
  121. data/vendor/choosealicense.com/_licenses/osl-3.0.txt +1 -2
  122. data/vendor/choosealicense.com/_licenses/postgresql.txt +4 -5
  123. data/vendor/choosealicense.com/_licenses/unlicense.txt +1 -2
  124. data/vendor/choosealicense.com/_licenses/upl-1.0.txt +4 -5
  125. data/vendor/choosealicense.com/_licenses/vim.txt +111 -0
  126. data/vendor/choosealicense.com/_licenses/wtfpl.txt +0 -1
  127. data/vendor/choosealicense.com/_licenses/zlib.txt +4 -2
  128. metadata +77 -19
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Licensee
2
4
  module HashHelper
3
5
  def to_h
@@ -6,11 +8,11 @@ module Licensee
6
8
  key = method.to_s.delete('?').to_sym
7
9
  value = public_send(method)
8
10
  hash[key] = if value.is_a?(Array)
9
- value.map { |v| v.respond_to?(:to_h) ? v.to_h : v }
10
- elsif value.respond_to?(:to_h) && !value.nil?
11
- value.to_h
12
- else
13
- value
11
+ value.map { |v| v.respond_to?(:to_h) ? v.to_h : v }
12
+ elsif value.respond_to?(:to_h) && !value.nil?
13
+ value.to_h
14
+ else
15
+ value
14
16
  end
15
17
  end
16
18
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'uri'
2
4
 
3
5
  module Licensee
@@ -16,11 +18,16 @@ module Licensee
16
18
  # Returns an Array of License objects.
17
19
  def all(options = {})
18
20
  @all[options] ||= begin
21
+ # TODO: Remove in next major version to avoid breaking change
22
+ options[:pseudo] ||= options[:psuedo] unless options[:psuedo].nil?
23
+
19
24
  options = DEFAULT_OPTIONS.merge(options)
20
25
  output = licenses.dup
21
26
  output.reject!(&:hidden?) unless options[:hidden]
22
- output.reject!(&:pseudo_license?) unless options[:psuedo]
27
+ output.reject!(&:pseudo_license?) unless options[:pseudo]
28
+ output.sort_by!(&:key)
23
29
  return output if options[:featured].nil?
30
+
24
31
  output.select { |l| l.featured? == options[:featured] }
25
32
  end
26
33
  end
@@ -40,7 +47,7 @@ module Licensee
40
47
 
41
48
  # Given a license title or nickname, fuzzy match the license
42
49
  def find_by_title(title)
43
- License.all(hidden: true, psuedo: false).find do |license|
50
+ License.all(hidden: true, pseudo: false).find do |license|
44
51
  title =~ /\A(the )?#{license.title_regex}( license)?\z/i
45
52
  end
46
53
  end
@@ -82,17 +89,11 @@ module Licensee
82
89
  DEFAULT_OPTIONS = {
83
90
  hidden: false,
84
91
  featured: nil,
85
- psuedo: true
86
- }.freeze
87
-
88
- ALT_TITLE_REGEX = {
89
- 'bsd-2-clause' => /bsd 2-clause(?: \"simplified\")?/i,
90
- 'bsd-3-clause' => /bsd 3-clause(?: \"new\" or \"revised\")?/i,
91
- 'bsd-3-clause-clear' => /(?:clear bsd|bsd 3-clause(?: clear)?)/i
92
+ pseudo: true
92
93
  }.freeze
93
94
 
94
- SOURCE_PREFIX = %r{https?://(?:www\.)?}i
95
- SOURCE_SUFFIX = %r{(?:\.html?|\.txt|\/)(?:\?[^\s]*)?}i
95
+ SOURCE_PREFIX = %r{https?://(?:www\.)?}i.freeze
96
+ SOURCE_SUFFIX = %r{(?:\.html?|\.txt|\/)(?:\?[^\s]*)?}i.freeze
96
97
 
97
98
  HASH_METHODS = %i[
98
99
  key spdx_id meta url rules fields other? gpl? lgpl? cc?
@@ -125,6 +126,8 @@ module Licensee
125
126
 
126
127
  # Returns the human-readable license name
127
128
  def name
129
+ return key.tr('-', ' ').capitalize if pseudo_license?
130
+
128
131
  title || spdx_id
129
132
  end
130
133
 
@@ -135,20 +138,22 @@ module Licensee
135
138
  def title_regex
136
139
  return @title_regex if defined? @title_regex
137
140
 
138
- title_regex = ALT_TITLE_REGEX[key]
139
- title_regex ||= begin
140
- string = name.downcase.sub('*', 'u')
141
- string.sub!(/\Athe /i, '')
142
- string.sub!(/ license\z/i, '')
143
- string.sub!(/,? version /, ' ')
144
- string.sub!(/v(\d+\.\d+)/, '\1')
145
- string = Regexp.escape(string)
146
- string = string.sub(/ (\d+\\.\d+)/, ',?\ (?:version\ |v)?\1')
147
- string = string.sub(/\bgnu\\ /, '(?:GNU )?')
148
- Regexp.new string, 'i'
149
- end
150
-
151
- parts = [title_regex, key]
141
+ string = name.downcase.sub('*', 'u')
142
+ string.sub!(/\Athe /i, '')
143
+ string.sub!(/,? version /, ' ')
144
+ string.sub!(/v(\d+\.\d+)/, '\1')
145
+ string = Regexp.escape(string)
146
+ string = string.sub(/\\ licen[sc]e/i, '(?:\ licen[sc]e)?')
147
+ string = string.sub(/\\ (\d+\\.\d+)/, ',?\s+(?:version\ |v(?:\. )?)?\1')
148
+ string = string.sub(/\bgnu\\ /, '(?:GNU )?')
149
+ title_regex = Regexp.new string, 'i'
150
+
151
+ string = key.sub('-', '[- ]')
152
+ string.sub!('.', '\.')
153
+ string << '(?:\ licen[sc]e)?'
154
+ key_regex = Regexp.new string, 'i'
155
+
156
+ parts = [title_regex, key_regex]
152
157
  if meta.nickname
153
158
  parts.push Regexp.new meta.nickname.sub(/\bGNU /i, '(?:GNU )?')
154
159
  end
@@ -242,11 +247,13 @@ module Licensee
242
247
  unless File.exist?(path)
243
248
  raise Licensee::InvalidLicense, "'#{key}' is not a valid license key"
244
249
  end
250
+
245
251
  @raw_content ||= File.read(path, encoding: 'utf-8')
246
252
  end
247
253
 
248
254
  def parts
249
255
  return unless raw_content
256
+
250
257
  @parts ||= raw_content.match(/\A(---\n.*\n---\n+)?(.*)/m).to_a
251
258
  end
252
259
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Licensee
2
4
  class LicenseField < Struct.new(:name, :description)
3
5
  class << self
@@ -39,12 +41,13 @@ module Licensee
39
41
  # Given a license body, returns an array of included LicneseFields
40
42
  def from_content(content)
41
43
  return [] unless content
44
+
42
45
  LicenseField.from_array content.scan(FIELD_REGEX).flatten
43
46
  end
44
47
  end
45
48
 
46
49
  alias key name
47
- FIELD_REGEX = /\[(#{Regexp.union(LicenseField.keys)})\]/
50
+ FIELD_REGEX = /\[(#{Regexp.union(LicenseField.keys)})\]/.freeze
48
51
 
49
52
  # The human-readable field name
50
53
  def label
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Licensee
2
4
  class LicenseMeta < Struct.new(
3
5
  :title, :spdx_id, :source, :description, :how, :conditions, :permissions,
@@ -23,6 +25,7 @@ module Licensee
23
25
  # returns a LicenseMeta with defaults set
24
26
  def from_yaml(yaml)
25
27
  return from_hash({}) if yaml.nil? || yaml.to_s.empty?
28
+
26
29
  from_hash YAML.safe_load(yaml)
27
30
  end
28
31
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Licensee
2
4
  # Exposes #conditions, #permissions, and #limitation arrays of LicenseRules
3
5
  class LicenseRules < Struct.new(:conditions, :permissions, :limitations)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Licensee
2
4
  module Matchers
3
5
  autoload :Matcher, 'licensee/matchers/matcher'
@@ -1,15 +1,29 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Licensee
2
4
  module Matchers
3
5
  class Cabal < Licensee::Matchers::Package
4
6
  # While we could parse the cabal file, prefer
5
7
  # a lenient regex for speed and security. Moar parsing moar problems.
6
- LICENSE_REGEX = /^\s*license\s*\:\s*([a-z\-0-9\.]+)\s*$/ix
8
+ LICENSE_REGEX = /^\s*license\s*\:\s*([a-z\-0-9\.]+)\s*$/ix.freeze
9
+ LICENSE_CONVERSIONS = {
10
+ 'GPL-2' => 'GPL-2.0',
11
+ 'GPL-3' => 'GPL-3.0',
12
+ 'LGPL-3' => 'LGPL-3.0',
13
+ 'AGPL-3' => 'AGPL-3.0',
14
+ 'BSD2' => 'BSD-2-Clause',
15
+ 'BSD3' => 'BSD-3-Clause'
16
+ }.freeze
7
17
 
8
18
  private
9
19
 
10
20
  def license_property
11
21
  match = @file.content.match LICENSE_REGEX
12
- match[1].downcase if match && match[1]
22
+ spdx_name(match[1]).downcase if match && match[1]
23
+ end
24
+
25
+ def spdx_name(cabal_name)
26
+ LICENSE_CONVERSIONS[cabal_name] || cabal_name
13
27
  end
14
28
  end
15
29
  end
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Licensee
2
4
  module Matchers
3
5
  class Cargo < Licensee::Matchers::Package
4
6
  LICENSE_REGEX = %r{
5
7
  ^\s*[\'\"]?license[\'\"]?\s*=\s*[\'\"]([a-z\-0-9\. +()\/]+)[\'\"]\s*
6
- }ix
8
+ }ix.freeze
7
9
 
8
10
  private
9
11
 
@@ -1,16 +1,18 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Licensee
2
4
  module Matchers
3
5
  class Copyright < Licensee::Matchers::Matcher
4
6
  attr_reader :file
5
7
 
6
- # rubocop:disable Metrics/LineLength
8
+ # rubocop:disable Layout/LineLength
7
9
  COPYRIGHT_SYMBOLS = Regexp.union([/copyright/i, /\(c\)/i, "\u00A9", "\xC2\xA9"])
8
- REGEX = /\A(\s*#{COPYRIGHT_SYMBOLS}.*$)+/i
9
- # rubocop:enable Metrics/LineLength
10
+ REGEX = /#{ContentHelper::START_REGEX}(?:portions )?(\s*#{COPYRIGHT_SYMBOLS}.*$)+$/i.freeze
11
+ # rubocop:enable Layout/LineLength
10
12
 
11
13
  def match
12
14
  # Note: must use content, and not content_normalized here
13
- if @file.content.strip =~ /\A#{REGEX}\z/i
15
+ if file.content.strip =~ /#{REGEX}+\z/i
14
16
  Licensee::License.find('no-license')
15
17
  end
16
18
  rescue Encoding::CompatibilityError
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Licensee
2
4
  module Matchers
3
5
  class Cran < Licensee::Matchers::Package
@@ -5,9 +7,9 @@ module Licensee
5
7
 
6
8
  # While we could parse the DESCRIPTION file, prefer
7
9
  # a lenient regex for speed and security. Moar parsing moar problems.
8
- LICENSE_FIELD_REGEX = /^license:\s*(.+)/i
9
- PLUS_FILE_LICENSE_REGEX = /\s*\+\s*file\s+LICENSE$/i
10
- GPL_VERSION_REGEX = /^GPL(?:-([23])|\s*\(\s*>=\s*([23])\s*\))$/i
10
+ LICENSE_FIELD_REGEX = /^license:\s*(.+)/i.freeze
11
+ PLUS_FILE_LICENSE_REGEX = /\s*\+\s*file\s+LICENSE$/i.freeze
12
+ GPL_VERSION_REGEX = /^GPL(?:-([23])|\s*\(\s*>=\s*([23])\s*\))$/i.freeze
11
13
 
12
14
  private
13
15
 
@@ -15,6 +17,7 @@ module Licensee
15
17
  # or `nil` if no license field is found
16
18
  def license_field
17
19
  return @license_field if defined? @license_field
20
+
18
21
  match = @file.content.match LICENSE_FIELD_REGEX
19
22
  @license_field = match ? match[1].downcase : nil
20
23
  end
@@ -30,6 +33,7 @@ module Licensee
30
33
  # Rerurns `nil` if no license is found
31
34
  def license_property
32
35
  return unless license_field
36
+
33
37
  # Remove The common + file LICENSE text
34
38
  license_key = license_field.sub(PLUS_FILE_LICENSE_REGEX, '')
35
39
  gpl_version(license_key) || license_key
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Licensee
2
4
  module Matchers
3
5
  class Dice < Licensee::Matchers::Matcher
@@ -5,9 +7,9 @@ module Licensee
5
7
  # than the confidence threshold
6
8
  def match
7
9
  @match ||= if matches.empty?
8
- nil
9
- else
10
- matches.first[0]
10
+ nil
11
+ else
12
+ matches.first[0]
11
13
  end
12
14
  end
13
15
 
@@ -49,7 +51,7 @@ module Licensee
49
51
 
50
52
  # Confidence that the matched license is a match
51
53
  def confidence
52
- @confidence ||= match ? file.similarity(match) : 0
54
+ @confidence ||= match ? match.similarity(file) : 0
53
55
  end
54
56
 
55
57
  private
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Licensee
2
4
  module Matchers
3
5
  class DistZilla < Licensee::Matchers::Package
4
6
  attr_reader :file
5
7
 
6
- LICENSE_REGEX = /^license\s*=\s*([a-z\-0-9\._]+)/i
8
+ LICENSE_REGEX = /^license\s*=\s*([a-z\-0-9\._]+)/i.freeze
7
9
 
8
10
  private
9
11
 
@@ -1,8 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Licensee
2
4
  module Matchers
3
5
  class Exact < Licensee::Matchers::Matcher
4
6
  def match
5
7
  return @match if defined? @match
8
+
6
9
  @match = potential_matches.find do |potential_match|
7
10
  potential_match.wordset == file.wordset
8
11
  end
@@ -1,26 +1,28 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Licensee
2
4
  module Matchers
3
5
  class Gemspec < Licensee::Matchers::Package
4
6
  # a value is a string surrounded by any amount of whitespace
5
7
  # optionally ended with (non-captured) ".freeze"
6
- VALUE_REGEX = /\s*[\'\"]([a-z\-0-9\.]+)[\'\"](?:\.freeze)?\s*/i
8
+ VALUE_REGEX = /\s*[\'\"]([a-z\-0-9\.]+)[\'\"](?:\.freeze)?\s*/i.freeze
7
9
 
8
10
  # an array contains one or more values. all values, or array itself,
9
11
  # can be surrounded by any amount of whitespace. do not capture
10
12
  # non-value groups
11
- ARRAY_REGEX = /\s*\[#{VALUE_REGEX}(?:,#{VALUE_REGEX})*\]\s*/i
13
+ ARRAY_REGEX = /\s*\[#{VALUE_REGEX}(?:,#{VALUE_REGEX})*\]\s*/i.freeze
12
14
 
13
15
  DECLARATION_REGEX = /
14
16
  ^\s*[a-z0-9_]+\.([a-z0-9_]+)\s*\=#{VALUE_REGEX}$
15
- /ix
17
+ /ix.freeze
16
18
 
17
19
  LICENSE_REGEX = /
18
20
  ^\s*[a-z0-9_]+\.license\s*\=#{VALUE_REGEX}$
19
- /ix
21
+ /ix.freeze
20
22
 
21
23
  LICENSE_ARRAY_REGEX = /
22
24
  ^\s*[a-z0-9_]+\.licenses\s*\=#{ARRAY_REGEX}$
23
- /ix
25
+ /ix.freeze
24
26
 
25
27
  private
26
28
 
@@ -34,6 +36,7 @@ module Licensee
34
36
 
35
37
  # use 'other' if array contains multiple licenses
36
38
  return 'other' unless licenses.size == 1
39
+
37
40
  licenses[0]
38
41
  end
39
42
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Licensee
2
4
  module Matchers
3
5
  class Matcher
@@ -25,7 +27,7 @@ module Licensee
25
27
  private
26
28
 
27
29
  def potential_matches
28
- @potential_matches ||= Licensee.licenses(hidden: true)
30
+ @potential_matches ||= Licensee.licenses(hidden: true, psuedo: false)
29
31
  end
30
32
  end
31
33
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Licensee
2
4
  module Matchers
3
5
  class NpmBower < Licensee::Matchers::Package
@@ -5,7 +7,7 @@ module Licensee
5
7
  # a lenient regex for speed and security. Moar parsing moar problems.
6
8
  LICENSE_REGEX = /
7
9
  \s*[\"\']license[\"\']\s*\:\s*[\'\"]([a-z\-0-9\.+ ()]+)[\'\"],?\s*
8
- /ix
10
+ /ix.freeze
9
11
 
10
12
  private
11
13
 
@@ -1,9 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Licensee
2
4
  module Matchers
3
5
  class Package < Licensee::Matchers::Matcher
4
6
  def match
5
7
  return @match if defined? @match
6
8
  return if license_property.nil? || license_property.to_s.empty?
9
+
7
10
  @match = Licensee.licenses(hidden: true).find do |license|
8
11
  license.key == license_property
9
12
  end
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Licensee
2
4
  module Matchers
3
5
  # Matches README files that include a license by reference
4
6
  class Reference < Licensee::Matchers::Matcher
5
7
  def match
6
- License.all(hidden: true, psuedo: false).find do |license|
8
+ potential_matches.find do |license|
7
9
  title_or_source = [license.title_regex, license.source_regex].compact
8
10
  /\b#{Regexp.union(title_or_source)}\b/ =~ file.content
9
11
  end
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Licensee
2
4
  module Matchers
3
5
  class Spdx < Licensee::Matchers::Package
4
6
  # While we could parse the LICENSE.spdx file, prefer
5
7
  # a lenient regex for speed and security. Moar parsing moar problems.
6
- LICENSE_REGEX = /PackageLicenseDeclared:\s*([a-z\-0-9\. +()]+)\s*/i
8
+ LICENSE_REGEX = /PackageLicenseDeclared:\s*([a-z\-0-9\. +()]+)\s*/i.freeze
7
9
 
8
10
  private
9
11