primer_view_components 0.0.82 → 0.0.83

Sign up to get free protection for your applications and to get access to all the features.
@@ -180,6 +180,7 @@ class ToolTipElement extends HTMLElement {
180
180
  var _a;
181
181
  if (!this.shadowRoot) {
182
182
  const shadow = this.attachShadow({ mode: 'open' });
183
+ // eslint-disable-next-line github/no-inner-html
183
184
  shadow.innerHTML = `
184
185
  <style>
185
186
  ${this.styles()}
@@ -179,6 +179,7 @@ class ToolTipElement extends HTMLElement {
179
179
  connectedCallback() {
180
180
  if (!this.shadowRoot) {
181
181
  const shadow = this.attachShadow({mode: 'open'})
182
+ // eslint-disable-next-line github/no-inner-html
182
183
  shadow.innerHTML = `
183
184
  <style>
184
185
  ${this.styles()}
@@ -1,3 +1,4 @@
1
+ <%# erblint:counter DeprecatedComponentsCounter 1 %>
1
2
  <%= render(Primer::FlexComponent.new(**@system_arguments)) do %>
2
3
  <% if @side == :left %>
3
4
  <%= sidebar %>
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "helpers/deprecated_components_helpers"
4
+ require "erblint-github/linters/custom_helpers"
5
+
6
+ module ERBLint
7
+ module Linters
8
+ # Lints against deprecated components
9
+ class DeprecatedComponentsCounter < Linter
10
+ include CustomHelpers
11
+ include ERBLint::LinterRegistry
12
+ include Helpers::DeprecatedComponentsHelpers
13
+
14
+ def run(processed_source)
15
+ processed_source.ast.descendants(:erb).each do |erb_node|
16
+ _, _, code_node = *erb_node
17
+ code = code_node.children.first.strip
18
+
19
+ next unless code.include?("Primer::")
20
+
21
+ deprecated_components.each do |component|
22
+ next unless code.include?(component)
23
+
24
+ add_offense(
25
+ erb_node.loc,
26
+ message(component)
27
+ )
28
+ end
29
+ end
30
+
31
+ counter_correct?(processed_source)
32
+ end
33
+
34
+ def autocorrect(processed_source, offense)
35
+ return unless offense.context
36
+
37
+ lambda do |corrector|
38
+ if processed_source.file_content.include?("erblint:counter #{self.class.name.gsub('ERBLint::Linters::', '')}")
39
+ # update the counter if exists
40
+ corrector.replace(offense.source_range, offense.context)
41
+ else
42
+ # add comment with counter if none
43
+ corrector.insert_before(processed_source.source_buffer.source_range, "#{offense.context}\n")
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ERBLint
4
+ module Linters
5
+ module Helpers
6
+ # Helpers to share between DeprecatedComponents ERB lint and Rubocop cop
7
+ module DeprecatedComponentsHelpers
8
+ # If there is no alternative to suggest, set the value to nil
9
+ COMPONENT_TO_USE_INSTEAD = {
10
+ "Primer::BlankslateComponent" => "Primer::Beta::Blankslate",
11
+ "Primer::DropdownMenuComponent" => nil,
12
+ "Primer::Tooltip" => "Primer::Alpha::Tooltip",
13
+ "Primer::FlexComponent" => nil,
14
+ "Primer::FlexItemComponent" => nil
15
+ }.freeze
16
+
17
+ def message(component)
18
+ message = "#{component} has been deprecated and should not be used."
19
+ message += " Try #{COMPONENT_TO_USE_INSTEAD[component]} instead." if COMPONENT_TO_USE_INSTEAD.fetch(component).present?
20
+ message
21
+ end
22
+
23
+ def statuses_json
24
+ JSON.parse(
25
+ File.read(
26
+ File.join(File.dirname(__FILE__), "../../../../../static/statuses.json")
27
+ )
28
+ ).freeze
29
+ end
30
+
31
+ def deprecated_components
32
+ @deprecated_components ||= statuses_json.select { |_, value| value == "deprecated" }.keys.tap do |deprecated_components|
33
+ deprecated_components.each do |deprecated|
34
+ unless COMPONENT_TO_USE_INSTEAD.key?(deprecated)
35
+ raise "Please provide a component that should be used in place of #{deprecated} in COMPONENT_TO_USE_INSTEAD. "\
36
+ "If there is no alternative, set the value to nil."
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -5,7 +5,7 @@ module Primer
5
5
  module VERSION
6
6
  MAJOR = 0
7
7
  MINOR = 0
8
- PATCH = 82
8
+ PATCH = 83
9
9
 
10
10
  STRING = [MAJOR, MINOR, PATCH].join(".")
11
11
  end
@@ -3,6 +3,7 @@
3
3
  require "rubocop"
4
4
  require "json"
5
5
  require "parser/current"
6
+ require_relative "./../../../primer/view_components/linters/helpers/deprecated_components_helpers"
6
7
 
7
8
  module RuboCop
8
9
  module Cop
@@ -21,14 +22,7 @@ module RuboCop
21
22
  # good
22
23
  # Primer::Alpha::Tooltip.new(:foo)
23
24
  class DeprecatedComponents < BaseCop
24
- # If there is no alternative to suggest, set the value to nil.
25
- COMPONENT_TO_USE_INSTEAD = {
26
- "Primer::BlankslateComponent" => "Primer::Beta::Blankslate",
27
- "Primer::DropdownMenuComponent" => nil,
28
- "Primer::Tooltip" => "Primer::Alpha::Tooltip",
29
- "Primer::FlexComponent" => nil,
30
- "Primer::FlexItemComponent" => nil
31
- }.freeze
25
+ include ERBLint::Linters::Helpers::DeprecatedComponentsHelpers
32
26
 
33
27
  def on_send(node)
34
28
  return unless node.source.include?("Primer::")
@@ -49,31 +43,6 @@ module RuboCop
49
43
  .delete("\n")
50
44
  .gsub(" ", " ")
51
45
  end
52
-
53
- def message(component)
54
- message = "#{component} has been deprecated and should not be used."
55
- message += " Try #{COMPONENT_TO_USE_INSTEAD[component]} instead." if COMPONENT_TO_USE_INSTEAD.fetch(component).present?
56
- message
57
- end
58
-
59
- def statuses_json
60
- JSON.parse(
61
- File.read(
62
- File.join(File.dirname(__FILE__), "../../../../static/statuses.json")
63
- )
64
- ).freeze
65
- end
66
-
67
- def deprecated_components
68
- @deprecated_components ||= statuses_json.select { |_, value| value == "deprecated" }.keys.tap do |deprecated_components|
69
- deprecated_components.each do |deprecated|
70
- unless COMPONENT_TO_USE_INSTEAD.key?(deprecated)
71
- raise "Please provide a component that should be used in place of #{deprecated} in COMPONENT_TO_USE_INSTEAD. "\
72
- "If there is no alternative, set the value to nil."
73
- end
74
- end
75
- end
76
- end
77
46
  end
78
47
  end
79
48
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: primer_view_components
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.82
4
+ version: 0.0.83
5
5
  platform: ruby
6
6
  authors:
7
7
  - GitHub Open Source
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-07-21 00:00:00.000000000 Z
11
+ date: 2022-07-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionview
@@ -170,6 +170,20 @@ dependencies:
170
170
  - - ">="
171
171
  - !ruby/object:Gem::Version
172
172
  version: '0'
173
+ - !ruby/object:Gem::Dependency
174
+ name: erblint-github
175
+ requirement: !ruby/object:Gem::Requirement
176
+ requirements:
177
+ - - '='
178
+ - !ruby/object:Gem::Version
179
+ version: 0.1.0
180
+ type: :development
181
+ prerelease: false
182
+ version_requirements: !ruby/object:Gem::Requirement
183
+ requirements:
184
+ - - '='
185
+ - !ruby/object:Gem::Version
186
+ version: 0.1.0
173
187
  - !ruby/object:Gem::Dependency
174
188
  name: listen
175
189
  requirement: !ruby/object:Gem::Requirement
@@ -184,6 +198,20 @@ dependencies:
184
198
  - - "~>"
185
199
  - !ruby/object:Gem::Version
186
200
  version: '3.0'
201
+ - !ruby/object:Gem::Dependency
202
+ name: matrix
203
+ requirement: !ruby/object:Gem::Requirement
204
+ requirements:
205
+ - - "~>"
206
+ - !ruby/object:Gem::Version
207
+ version: 0.4.2
208
+ type: :development
209
+ prerelease: false
210
+ version_requirements: !ruby/object:Gem::Requirement
211
+ requirements:
212
+ - - "~>"
213
+ - !ruby/object:Gem::Version
214
+ version: 0.4.2
187
215
  - !ruby/object:Gem::Dependency
188
216
  name: minitest
189
217
  requirement: !ruby/object:Gem::Requirement
@@ -366,7 +394,7 @@ dependencies:
366
394
  - - "~>"
367
395
  - !ruby/object:Gem::Version
368
396
  version: 0.9.25
369
- description:
397
+ description:
370
398
  email:
371
399
  - opensource+primer_view_components@github.com
372
400
  executables: []
@@ -536,8 +564,10 @@ files:
536
564
  - lib/primer/view_components/linters/button_component_migration_counter.rb
537
565
  - lib/primer/view_components/linters/clipboard_copy_component_migration_counter.rb
538
566
  - lib/primer/view_components/linters/close_button_component_migration_counter.rb
567
+ - lib/primer/view_components/linters/deprecated_components_counter.rb
539
568
  - lib/primer/view_components/linters/disallow_action_list.rb
540
569
  - lib/primer/view_components/linters/flash_migration_counter.rb
570
+ - lib/primer/view_components/linters/helpers/deprecated_components_helpers.rb
541
571
  - lib/primer/view_components/linters/helpers/rubocop_helpers.rb
542
572
  - lib/primer/view_components/linters/label_component_migration_counter.rb
543
573
  - lib/primer/view_components/linters/subhead_component_migration_counter.rb
@@ -580,7 +610,7 @@ licenses:
580
610
  - MIT
581
611
  metadata:
582
612
  allowed_push_host: https://rubygems.org
583
- post_install_message:
613
+ post_install_message:
584
614
  rdoc_options: []
585
615
  require_paths:
586
616
  - lib
@@ -588,15 +618,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
588
618
  requirements:
589
619
  - - ">="
590
620
  - !ruby/object:Gem::Version
591
- version: 2.5.0
621
+ version: 2.6.0
592
622
  required_rubygems_version: !ruby/object:Gem::Requirement
593
623
  requirements:
594
624
  - - ">="
595
625
  - !ruby/object:Gem::Version
596
626
  version: '0'
597
627
  requirements: []
598
- rubygems_version: 3.2.22
599
- signing_key:
628
+ rubygems_version: 3.1.6
629
+ signing_key:
600
630
  specification_version: 4
601
631
  summary: ViewComponents for the Primer Design System
602
632
  test_files: []