Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions npm_and_yarn/lib/dependabot/npm_and_yarn/package_name.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
module Dependabot
module NpmAndYarn
class PackageName
DEFINITELY_TYPED_SCOPE = /types/i.freeze
PACKAGE_NAME_REGEX = %r{
PACKAGE_NAME_REGEX = %r{
\A # beginning of string
(?=.{1,214}\z) # enforce length (1 - 214)
(@(?<scope>[a-z0-9\-~][a-z0-9\-\._~]*)\/)? # capture 'scope' if present
(?<name>[a-z0-9\-~][a-z0-9\-._~]*) # capture package name
\z # end of string
}xi.freeze # multi-line/case-insensitive

TYPES_PACKAGE_NAME_REGEX = %r{
\A # beginning of string
@#{DEFINITELY_TYPED_SCOPE}\/ # starts with @types/
@types\/ # starts with @types/
((?<scope>.+)__)? # capture scope
(?<name>.+) # capture name
\z # end of string
Expand Down Expand Up @@ -81,7 +81,7 @@ def scoped?
end

def types_package?
DEFINITELY_TYPED_SCOPE.match?(@scope)
"types".casecmp?(@scope)
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,9 @@

describe "#library_name" do
it "returns nil if it is not a types package" do
jquery = "jquery"

library_name = described_class.new(jquery).library_name

expect(library_name).to be_nil
expect(described_class.new("jquery").library_name).to be_nil
expect(described_class.new("@babel/core").library_name).to be_nil
expect(described_class.new("@typescript-eslint/parser").library_name).to be_nil
end

it "returns the corresponding library for a types package" do
Expand Down