primer_view_components 0.0.71 → 0.0.74

Sign up to get free protection for your applications and to get access to all the features.
@@ -32,7 +32,7 @@ function showCheck(button: HTMLElement) {
32
32
 
33
33
  const clipboardCopyElementTimers = new WeakMap<HTMLElement, number>()
34
34
 
35
- document.addEventListener('clipboard-copy', function ({target}) {
35
+ document.addEventListener('clipboard-copy', function({target}) {
36
36
  if (!(target instanceof HTMLElement)) return
37
37
  if (!target.hasAttribute('data-view-component')) return
38
38
 
@@ -1,4 +1 @@
1
- <%= render Primer::BaseComponent.new(**@system_arguments) do %>
2
- <%= content %>
3
- <%= tooltip %>
4
- <% end %>
1
+ <%= render Primer::BaseComponent.new(**@system_arguments) do -%><%= content -%><%= tooltip -%><% end %>
@@ -5,4 +5,4 @@ import './time_ago_component';
5
5
  import './local_time';
6
6
  import './image_crop';
7
7
  import './dropdown';
8
- import './alpha/tooltip';
8
+ import './alpha/tool-tip-element';
@@ -5,4 +5,4 @@ import './time_ago_component';
5
5
  import './local_time';
6
6
  import './image_crop';
7
7
  import './dropdown';
8
- import './alpha/tooltip';
8
+ import './alpha/tool-tip-element';
@@ -5,4 +5,4 @@ import './time_ago_component'
5
5
  import './local_time'
6
6
  import './image_crop'
7
7
  import './dropdown'
8
- import './alpha/tooltip'
8
+ import './alpha/tool-tip-element'
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "helpers/rubocop_helpers"
4
+
5
+ module ERBLint
6
+ module Linters
7
+ # Replaces calls to `super` with calls to `render_parent`.
8
+ class SuperInComponentTemplates < Linter
9
+ include ERBLint::LinterRegistry
10
+ include Helpers::RubocopHelpers
11
+
12
+ def run(processed_source)
13
+ processed_source.ast.descendants(:erb).each do |erb_node|
14
+ indicator_node, _, code_node = *erb_node
15
+ code = code_node.children.first
16
+ ast = erb_ast(code)
17
+ next unless ast
18
+
19
+ super_call_nodes = find_super_call_nodes(ast)
20
+ next if super_call_nodes.empty?
21
+
22
+ indicator, = *indicator_node
23
+ indicator ||= ""
24
+
25
+ # +2 to account for the leading "<%" characters
26
+ code_start_pos = erb_node.location.begin_pos + indicator.size + 2
27
+
28
+ super_call_nodes.each do |super_call_node|
29
+ orig_loc = code_node.location
30
+ super_call_loc = super_call_node.location.expression
31
+
32
+ new_loc = orig_loc.with(
33
+ begin_pos: super_call_loc.begin_pos + code_start_pos,
34
+ end_pos: super_call_loc.end_pos + code_start_pos
35
+ )
36
+
37
+ add_offense(
38
+ new_loc,
39
+ "Avoid calling `super` in component templates. Call `render_parent` instead",
40
+ "render_parent"
41
+ )
42
+ end
43
+ end
44
+ end
45
+
46
+ def autocorrect(_, offense)
47
+ return unless offense.context
48
+
49
+ lambda do |corrector|
50
+ corrector.replace(offense.source_range, offense.context)
51
+ end
52
+ end
53
+
54
+ private
55
+
56
+ def find_super_call_nodes(ast)
57
+ return [ast] if ast.type == :zsuper
58
+
59
+ ast.each_child_node.flat_map do |child_ast|
60
+ find_super_call_nodes(child_ast)
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
@@ -5,7 +5,7 @@ module Primer
5
5
  module VERSION
6
6
  MAJOR = 0
7
7
  MINOR = 0
8
- PATCH = 71
8
+ PATCH = 74
9
9
 
10
10
  STRING = [MAJOR, MINOR, PATCH].join(".")
11
11
  end
@@ -15,3 +15,6 @@ Primer/PrimerOcticon:
15
15
 
16
16
  Primer/DeprecatedArguments:
17
17
  Enabled: true
18
+
19
+ Primer/DeprecatedComponents:
20
+ Enabled: true
@@ -0,0 +1,80 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rubocop"
4
+ require "json"
5
+ require "parser/current"
6
+
7
+ module RuboCop
8
+ module Cop
9
+ module Primer
10
+ # This cop ensures that components marked as "deprecated" in `static/statuses.json` are discouraged from use.
11
+ #
12
+ # bad
13
+ # Primer::BlankslateComponent.new(:foo)
14
+ #
15
+ # good
16
+ # Primer::Beta::Blankslate.new(:foo)
17
+ #
18
+ # bad
19
+ # Primer::Tooltip.new(:foo)
20
+ #
21
+ # good
22
+ # Primer::Alpha::Tooltip.new(:foo)
23
+ 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
32
+
33
+ def on_send(node)
34
+ return unless node.source.include?("Primer::")
35
+
36
+ deprecated_components.each do |component|
37
+ pattern = NodePattern.new("(send #{pattern(component)} :new ...)")
38
+ add_offense(node, message: message(component)) if pattern.match(node)
39
+ end
40
+ end
41
+
42
+ private
43
+
44
+ # Converts a string to acceptable rubocop-ast pattern syntax
45
+ def pattern(component)
46
+ Parser::CurrentRuby.parse(component)
47
+ .to_s
48
+ .gsub("nil", "nil?")
49
+ .delete("\n")
50
+ .gsub(" ", " ")
51
+ 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
+ end
78
+ end
79
+ end
80
+ 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.71
4
+ version: 0.0.74
5
5
  platform: ruby
6
6
  authors:
7
7
  - GitHub Open Source
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-03-31 00:00:00.000000000 Z
11
+ date: 2022-05-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionview
@@ -383,16 +383,14 @@ files:
383
383
  - app/components/primer/alpha/button_marketing.rb
384
384
  - app/components/primer/alpha/layout.html.erb
385
385
  - app/components/primer/alpha/layout.rb
386
- - app/components/primer/alpha/navigation_list_element.d.ts
387
- - app/components/primer/alpha/navigation_list_element.js
388
386
  - app/components/primer/alpha/tab_nav.html.erb
389
387
  - app/components/primer/alpha/tab_nav.rb
390
388
  - app/components/primer/alpha/tab_panels.html.erb
391
389
  - app/components/primer/alpha/tab_panels.rb
392
- - app/components/primer/alpha/tooltip.d.ts
393
- - app/components/primer/alpha/tooltip.js
390
+ - app/components/primer/alpha/tool-tip-element.d.ts
391
+ - app/components/primer/alpha/tool-tip-element.js
392
+ - app/components/primer/alpha/tool-tip-element.ts
394
393
  - app/components/primer/alpha/tooltip.rb
395
- - app/components/primer/alpha/tooltip.ts
396
394
  - app/components/primer/alpha/underline_nav.html.erb
397
395
  - app/components/primer/alpha/underline_nav.rb
398
396
  - app/components/primer/alpha/underline_panels.html.erb
@@ -543,6 +541,7 @@ files:
543
541
  - lib/primer/view_components/linters/helpers/rubocop_helpers.rb
544
542
  - lib/primer/view_components/linters/label_component_migration_counter.rb
545
543
  - lib/primer/view_components/linters/subhead_component_migration_counter.rb
544
+ - lib/primer/view_components/linters/super_in_component_templates.rb
546
545
  - lib/primer/view_components/linters/tag_tree_helpers.rb
547
546
  - lib/primer/view_components/linters/two_column_layout_migration_counter.rb
548
547
  - lib/primer/view_components/statuses.rb
@@ -553,6 +552,7 @@ files:
553
552
  - lib/rubocop/cop/primer/component_name_migration.rb
554
553
  - lib/rubocop/cop/primer/deprecated_arguments.rb
555
554
  - lib/rubocop/cop/primer/deprecated_button_arguments.rb
555
+ - lib/rubocop/cop/primer/deprecated_components.rb
556
556
  - lib/rubocop/cop/primer/deprecated_label_schemes.rb
557
557
  - lib/rubocop/cop/primer/deprecated_layout_component.rb
558
558
  - lib/rubocop/cop/primer/no_tag_memoize.rb
@@ -1,11 +0,0 @@
1
- declare class NavigationListElement extends HTMLElement {
2
- #private;
3
- connectedCallback(): void;
4
- handleEvent(event: Event): void;
5
- }
6
- export {};
7
- declare global {
8
- interface Window {
9
- NavigationListElement: typeof NavigationListElement;
10
- }
11
- }
@@ -1,42 +0,0 @@
1
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
2
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
3
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
4
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
- };
6
- var _NavigationListElement_instances, _NavigationListElement_handleClick;
7
- class NavigationListElement extends HTMLElement {
8
- constructor() {
9
- super(...arguments);
10
- _NavigationListElement_instances.add(this);
11
- }
12
- connectedCallback() {
13
- this.addEventListener('click', this);
14
- }
15
- handleEvent(event) {
16
- var _a;
17
- if (!(event.target instanceof HTMLElement))
18
- return;
19
- const item = (_a = event.target) === null || _a === void 0 ? void 0 : _a.closest('button');
20
- if ((item === null || item === void 0 ? void 0 : item.closest(this.tagName)) !== this)
21
- return;
22
- if (event.type === 'click') {
23
- __classPrivateFieldGet(this, _NavigationListElement_instances, "m", _NavigationListElement_handleClick).call(this, item, event);
24
- }
25
- }
26
- }
27
- _NavigationListElement_instances = new WeakSet(), _NavigationListElement_handleClick = function _NavigationListElement_handleClick(item, e) {
28
- if (item.getAttribute('aria-expanded') !== null) {
29
- if (item.getAttribute('aria-expanded') === 'true') {
30
- item.setAttribute('aria-expanded', 'false');
31
- }
32
- else {
33
- item.setAttribute('aria-expanded', 'true');
34
- }
35
- }
36
- e.stopPropagation();
37
- };
38
- if (!window.customElements.get('navigation-list')) {
39
- window.NavigationListElement = NavigationListElement;
40
- window.customElements.define('navigation-list', NavigationListElement);
41
- }
42
- export {};