Skip to content

Commit

Permalink
point Primer namespace to root
Browse files Browse the repository at this point in the history
This resolves an Uninitialized Constant error coming from ruby, because
`ERBLint::Linter::Primer::` is a namespace that exists. This error was
not invoked before because the only liner in that namespace -
`ERBLint::Linter::Primer::Accessibility::TooltippedMigration` in the
`tooltipped_migration.rb` file - would load _after_
`argument_mappers/label.rb` and `label_component_migration_counter.rb`.

The introduction of
`ERBLint::Linter::Primer::Accessibility::DetailsMenuMigration` in the
`details_menu_migration.rb` file would load _before_
`label_component_migration_counter.rb`, populating the
`ERBLint::Linter::Primer` namespace, which then causes the failed scope
lookup.

Prepending `::` to these values tells ruby to always look in the root
scope, not any local constants.
  • Loading branch information
keithamus committed Jul 18, 2023
1 parent c695bc3 commit 32b281c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions lib/primer/view_components/linters/argument_mappers/label.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,24 @@ module Linters
module ArgumentMappers
# Maps classes in a label element to arguments for the Label component.
class Label < Base
SCHEME_MAPPINGS = Primer::ViewComponents::Constants.get(
SCHEME_MAPPINGS = ::Primer::ViewComponents::Constants.get(
component: "Primer::Beta::Label",
constant: "SCHEME_MAPPINGS",
symbolize: true
).freeze

SIZE_MAPPINGS = Primer::ViewComponents::Constants.get(
SIZE_MAPPINGS = ::Primer::ViewComponents::Constants.get(
component: "Primer::Beta::Label",
constant: "SIZE_MAPPINGS",
symbolize: true
).freeze

DEFAULT_TAG = Primer::ViewComponents::Constants.get(
DEFAULT_TAG = ::Primer::ViewComponents::Constants.get(
component: "Primer::Beta::Label",
constant: "DEFAULT_TAG"
).freeze

INLINE_CLASS = Primer::ViewComponents::Constants.get(
INLINE_CLASS = ::Primer::ViewComponents::Constants.get(
component: "Primer::Beta::Label",
constant: "INLINE_CLASS"
).freeze
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module Linters
class LabelComponentMigrationCounter < BaseLinter
include Autocorrectable

TAGS = Primer::ViewComponents::Constants.get(
TAGS = ::Primer::ViewComponents::Constants.get(
component: "Primer::Beta::Label",
constant: "TAG_OPTIONS"
).freeze
Expand Down

0 comments on commit 32b281c

Please sign in to comment.