ronantakizawa/codereview-bench huggingface dataset:
Repository: jenkinsci/jenkins
File: src/main/js/components/header/actions-touch.js (JavaScript)

Code before:
export default function updateActionsForTouch() {
  // We want to disable the User action href on touch devices so that they can still activate the overflow menu
  const link = document.querySelector("#root-action-UserAction");

  if (link) {
    const originalHref = link.getAttribute("href");
    const isTouchDevice = window.matchMedia("(hover: none)").matches;

    // HTMLUnit doesn't register itself as supporting hover, thus the href is removed when it shouldn't be
    if (isTouchDevice && !window.isRunAsTest) {
      link.removeAttribute("href");
    } else {
      link.setAttribute("href", originalHref);
    }
  }
}



Review comment (bug):
extracted as the only remaining code from `actions-overflow.js`

Code after:
export default function updateActionsForTouch() {
  // We want to disable the User action href on touch devices so that they can still activate the overflow menu
  const link = document.querySelector("#root-action-UserAction");

  if (link) {
    const originalHref = link.getAttribute("href");
    const isTouchDevice = window.matchMedia("(hover: none)").matches;

    // HTMLUnit doesn't register itself as supporting hover, thus the href is removed when it shouldn't be
    if (isTouchDevice && !window.isRunAsTest) {
      link.removeAttribute("href");
    } else {
      link.setAttribute("href", originalHref);
    }
  }
}
Repository: jenkinsci/jenkins
File: src/main/js/components/header/actions-touch.js (JavaScript)

Code before:
export default function updateActionsForTouch() {
  // We want to disable the User action href on touch devices so that they can still activate the overflow menu
  const link = document.querySelector("#root-action-UserAction");

  if (link) {
    const originalHref = link.getAttribute("href");
    const isTouchDevice = window.matchMedia("(hover: none)").matches;

    // HTMLUnit doesn't register itself as supporting hover, thus the href is removed when it shouldn't be
    if (isTouchDevice && !window.isRunAsTest) {
      link.removeAttribute("href");
    } else {
      link.setAttribute("href", originalHref);
    }
  }
}



Review comment (bug):
I am not sure why we consider it is only important to do this for the `User action` and not any action with a JumpList.

At the same time, this comment seems incorrect.  I can use touch to get the dropdown menu on windows 11 with a touch screen using a long touch and I can navigate directly using a quick touch.  (My laptop is not (generally) detected as a touch device :-) )

Anyway, this was existing code I have just relocated and I am not intending to unpick this in this PR (or even in a follow-up).

Code after:
export default function updateActionsForTouch() {
  // We want to disable the User action href on touch devices so that they can still activate the overflow menu
  const link = document.querySelector("#root-action-UserAction");

  if (link) {
    const originalHref = link.getAttribute("href");
    const isTouchDevice = window.matchMedia("(hover: none)").matches;

    // HTMLUnit doesn't register itself as supporting hover, thus the href is removed when it shouldn't be
    if (isTouchDevice && !window.isRunAsTest) {
      link.removeAttribute("href");
    } else {
      link.setAttribute("href", originalHref);
    }
  }
}
Repository: jenkinsci/jenkins
File: core/src/main/java/hudson/model/RootAction.java (Java)

Code before:

/**
 * Marker interface for actions that are added to {@link jenkins.model.Jenkins}.
 *
 * <p>
 * Extend from this interface and put {@link Extension} on your subtype
 * to have them auto-registered to {@link jenkins.model.Jenkins}.
 *
 * @author Kohsuke Kawaguchi
 * @since 1.311
 */
public interface RootAction extends Action, ExtensionPoint {

    /**
     * A {@link Badge} shown on the button for the action.
     *
     * @return badge or {@code null} if no badge should be shown.
     * @since 2.507
     */
    default @CheckForNull Badge getBadge() {
        return null;
    }

    /**
     * Identifies if the action as a primary action.
     * Primary actions may be handled differently in the UI (for existence by always showing on the header rather than in an actions dropdown).
     * In almost all cases this should return {@code false} which is the default
     * @return {@code true} iff this action should be considered primary.
     */
    default boolean isPrimaryAction() {
        return false;
    }
}


Review comment (suggestion):
```suggestion
     * Identifies if the action is a primary action.
     * Primary actions may be handled differently in the UI (for example, by always showing on the header rather than in an actions dropdown).
```

Code after:

/**
 * Marker interface for actions that are added to {@link jenkins.model.Jenkins}.
 *
 * <p>
 * Extend from this interface and put {@link Extension} on your subtype
 * to have them auto-registered to {@link jenkins.model.Jenkins}.
 *
 * @author Kohsuke Kawaguchi
 * @since 1.311
 */
public interface RootAction extends Action, ExtensionPoint {

    /**
     * A {@link Badge} shown on the button for the action.
     *
     * @return badge or {@code null} if no badge should be shown.
     * @since 2.507
     */
    default @CheckForNull Badge getBadge() {
        return null;
    }

    /**
     * Identifies if the action is a primary action.
     * Primary actions may be handled differently in the UI (for example, by always showing on the header rather than in an actions dropdown).
     * In almost all cases this should return {@code false} which is the default
     * @return {@code true} iff this action should be considered primary.
     * @since TODO
     */
    default boolean isPrimaryAction() {
        return false;
    }
}
Repository: jenkinsci/jenkins
File: core/src/main/java/hudson/model/RootAction.java (Java)

Code before:
 * <p>
 * Extend from this interface and put {@link Extension} on your subtype
 * to have them auto-registered to {@link jenkins.model.Jenkins}.
 *
 * @author Kohsuke Kawaguchi
 * @since 1.311
 */
public interface RootAction extends Action, ExtensionPoint {

    /**
     * A {@link Badge} shown on the button for the action.
     *
     * @return badge or {@code null} if no badge should be shown.
     * @since 2.507
     */
    default @CheckForNull Badge getBadge() {
        return null;
    }

    /**
     * Identifies if the action as a primary action.
     * Primary actions may be handled differently in the UI (for existence by always showing on the header rather than in an actions dropdown).
     * In almost all cases this should return {@code false} which is the default
     * @return {@code true} iff this action should be considered primary.
     */
    default boolean isPrimaryAction() {
        return false;
    }
}


Review comment (suggestion):
New API needs an `@since` entry for Javadoc
```suggestion
     * @since TODO
     */
```

Code after:
 * <p>
 * Extend from this interface and put {@link Extension} on your subtype
 * to have them auto-registered to {@link jenkins.model.Jenkins}.
 *
 * @author Kohsuke Kawaguchi
 * @since 1.311
 */
public interface RootAction extends Action, ExtensionPoint {

    /**
     * A {@link Badge} shown on the button for the action.
     *
     * @return badge or {@code null} if no badge should be shown.
     * @since 2.507
     */
    default @CheckForNull Badge getBadge() {
        return null;
    }

    /**
     * Identifies if the action is a primary action.
     * Primary actions may be handled differently in the UI (for example, by always showing on the header rather than in an actions dropdown).
     * In almost all cases this should return {@code false} which is the default
     * @return {@code true} iff this action should be considered primary.
     * @since TODO
     */
    default boolean isPrimaryAction() {
        return false;
    }
}
Repository: jenkinsci/jenkins
File: core/src/main/resources/lib/form/link/link.js (JavaScript)

Code before:
Behaviour.specify("A.post", "link.post", 0, function (element) {
  var pendingHref = element.getAttribute("data-post-href");
  if (pendingHref) {
    element.setAttribute("href", pendingHref);
    element.removeAttribute("data-post-href");
  }

  element.onclick = function () {
    var form = document.createElement("form");
    form.setAttribute("method", "POST");
    form.setAttribute("action", element.getAttribute("href"));
    crumb.appendToForm(form);
    document.body.appendChild(form);
    form.submit();
    return false;
  };
});


Review comment (suggestion):
```suggestion
  const pendingHref = element.getAttribute("data-post-href");
```

Code after:
Behaviour.specify("A.post", "link.post", 0, function (element) {
  const pendingHref = element.getAttribute("data-post-href");
  if (pendingHref) {
    element.setAttribute("href", pendingHref);
    element.removeAttribute("data-post-href");
  }

  element.onclick = function () {
    var form = document.createElement("form");
    form.setAttribute("method", "POST");
    form.setAttribute("action", element.getAttribute("href"));
    crumb.appendToForm(form);
    document.body.appendChild(form);
    form.submit();
    return false;
  };
});
Repository: jenkinsci/jenkins
File: core/src/test/java/hudson/util/FormValidationTest.java (Java)

Code before:
                    }
                }
            };
            assertThat(urlCheck.check(), is(FormValidation.ok()));

        } finally {
            server.stop(0);
        }
    }


    private static HttpServer createAndStartMockServer() throws IOException {
        HttpServer server = HttpServer.create(new InetSocketAddress("localhost", 0), 0);

        server.createContext("/", exchange -> {
            byte[] response = "<html>Jenkins</html>".getBytes(StandardCharsets.UTF_8);

            exchange.sendResponseHeaders(200, response.length);

            try (OutputStream os = exchange.getResponseBody()) {
                os.write(response);
            }
        });

        server.start();
        return server;
    }
}


Review comment (suggestion):
The `HttpExchange` is never explicitly closed. Closing the response body stream does not reliably close the exchange itself, which can leak resources and cause intermittent hangs in tests on some JDKs. Ensure the handler calls `exchange.close()` in a `finally` block after sending the response (and optionally set a basic `Content-Type` header like `text/html; charset=UTF-8`).

Code after:
                        return handleIOException(uri, e);
                    }
                }
            };
            assertThat(urlCheck.check(), is(FormValidation.ok()));

        } finally {
            server.stop(0);
        }
    }


    private static HttpServer createAndStartMockServer() throws IOException {
        HttpServer server = HttpServer.create(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0), 0);

        server.createContext("/", exchange -> {
            byte[] response = "<html>Jenkins</html>".getBytes(StandardCharsets.UTF_8);

            exchange.sendResponseHeaders(200, response.length);

            try (OutputStream os = exchange.getResponseBody()) {
                os.write(response);
            } finally {
                exchange.close();
            }
        });

        server.start();
        return server;
    }
}
Repository: jenkinsci/jenkins
File: core/src/main/resources/lib/form/confirm.js (JavaScript)

Code before:
      }
    }

    inputs = configForm.getElementsByTagName("select");
    for (let i = 0; i < inputs.length; i++) {
      let input = inputs[i];
      if (!isIgnoringConfirm(input)) {
        input.addEventListener("change", confirm);
      }
    }

    inputs = configForm.getElementsByTagName("textarea");
    for (let i = 0; i < inputs.length; i++) {
      let input = inputs[i];
      if (!isIgnoringConfirm(input)) {
        input.addEventListener("input", confirm);
      }
    }
  }

  window.onbeforeunload = confirmExit;

  function initWhenFormReady() {
    var configForm =
      document.getElementsByName("config")[0] ||
      document.getElementsByName("viewConfig")[0];

    if (configForm) {
      initConfirm();
      return true;
    }
    return false;
  }

  function initWhenReady() {
    if (initWhenFormReady()) {
      return;
    }

    const observer = new MutationObserver(function () {
      if (initWhenFormReady()) {
        observer.disconnect();
      }
    });

    observer.observe(document.body, {
      childList: true,
      subtree: true,
    });
  }


Review comment (suggestion):
you can't rely on the name it could be anything, either `form` elements or elements with the `jenkins-form` class

Code after:
      }
    }

    inputs = configForm.getElementsByTagName("select");
    for (let i = 0; i < inputs.length; i++) {
      let input = inputs[i];
      if (!isIgnoringConfirm(input)) {
        input.addEventListener("change", confirm);
      }
    }

    inputs = configForm.getElementsByTagName("textarea");
    for (let i = 0; i < inputs.length; i++) {
      let input = inputs[i];
      if (!isIgnoringConfirm(input)) {
        input.addEventListener("input", confirm);
      }
    }
  }

  window.onbeforeunload = confirmExit;

  function initWhenFormReady() {
    const configForm =
      document.getElementsByName("config")[0] ||
      document.getElementsByName("viewConfig")[0];

    if (configForm) {
      initConfirm();
      return true;
    }
    return false;
  }

  function initWhenReady() {
    if (initWhenFormReady()) {
      return;
    }

    const observer = new MutationObserver(function () {
      if (initWhenFormReady()) {
        observer.disconnect();
      }
    });

    observer.observe(document.body, {
      childList: true,
      subtree: true,
    });
  }
Repository: juliangarnier/anime
File: src/index.js (JavaScript)

Code before:
    insParams.direction = tl.direction;
    insParams.timelineOffset = is.und(timelineOffset) ? tlDuration : getRelativeValue(timelineOffset, tlDuration);
    passThrough(tl);
    tl.seek(insParams.timelineOffset);
    const ins = anime(insParams);
    passThrough(ins);
    const totalDuration = ins.duration + insParams.timelineOffset;
    children.push(ins);
    const timings = getInstanceTimings(children, params);
    tl.delay = timings.delay;
    tl.endDelay = timings.endDelay;
    tl.duration = timings.duration;
    tl.seek(0);
    tl.reset();
    if (tl.autoplay) tl.play();
    return tl;
  }
  return tl;
}

anime.version = '3.2.0';
anime.speed = 1;
// TODO:#review: naming, documentation
anime.suspendWhenDocumentHidden = true;
anime.running = activeInstances;
anime.remove = removeTargets;
anime.get = getOriginalTargetValue;
anime.set = setTargetsValue;
anime.convertPx = convertPxToUnit;
anime.path = getPath;
anime.setDashoffset = setDashoffset;
anime.stagger = stagger;
anime.timeline = timeline;
anime.easing = parseEasings;
anime.penner = penner;
anime.random = (min, max) => Math.floor(Math.random() * (max - min + 1)) + min;

export default anime;


Review comment (suggestion):
I think due to this being a feature point of the v3 release and so that there is consistency with the minor updates, the default should be set to `false`. A major could introduce this as default behaviour.

Code after:
    const tlDuration = tl.duration;
    insParams.autoplay = false;
    insParams.direction = tl.direction;
    insParams.timelineOffset = is.und(timelineOffset) ? tlDuration : getRelativeValue(timelineOffset, tlDuration);
    passThrough(tl);
    tl.seek(insParams.timelineOffset);
    const ins = anime(insParams);
    passThrough(ins);
    const totalDuration = ins.duration + insParams.timelineOffset;
    children.push(ins);
    const timings = getInstanceTimings(children, params);
    tl.delay = timings.delay;
    tl.endDelay = timings.endDelay;
    tl.duration = timings.duration;
    tl.seek(0);
    tl.reset();
    if (tl.autoplay) tl.play();
    return tl;
  }
  return tl;
}

anime.version = '3.2.0';
anime.speed = 1;
// TODO:#review: naming, documentation
anime.suspendWhenDocumentHidden = true;
anime.running = activeInstances;
anime.remove = removeTargets;
anime.get = getOriginalTargetValue;
anime.set = setTargetsValue;
anime.convertPx = convertPxToUnit;
anime.path = getPath;
anime.setDashoffset = setDashoffset;
anime.stagger = stagger;
anime.timeline = timeline;
anime.easing = parseEasings;
anime.penner = penner;
anime.random = (min, max) => Math.floor(Math.random() * (max - min + 1)) + min;

export default anime;
Repository: leaningtech/webvm
File: src/lib/DiskTab.svelte (Svelte)

Code before:
<script>
	import PanelButton from './PanelButton.svelte';
	import { createEventDispatcher } from 'svelte';
	import { diskLatency } from './activities.js'
	var dispatch = createEventDispatcher();
	let state = "START";
	function handleReset()
	{
		if(state == "START")
			state = "CONFIRM";
		else if (state == "CONFIRM") {
			state = "RESETTING";
			setTimeout(() => {
				dispatch('reset');
				state = "START";
			}, 3000);
		}
	}
	function getButtonText(state)
	{
		if(state == "START")
			return "Reset disk";
		else if (state == "RESETTING")
			return "Resetting...";
		else
			return "Reset disk. Confirm?";
	}
	function getBgColor(state)
	{
		if(state == "START")
		{
			// Use default
			return undefined;
		}
		else
		{
			return "bg-red-900";
		}
	}
	function getHoverColor(state)

Review comment (suggestion):
I don't think we should reset the state after a timeout. After the reset process is complete the page will reload. The purpose here is to make sure the user is aware that reset is in progress and might take a bit.

Code after:
<script>
	import PanelButton from './PanelButton.svelte';
	import { createEventDispatcher } from 'svelte';
	import { diskLatency } from './activities.js'
	var dispatch = createEventDispatcher();
	let state = "START";
	function handleReset()
	{
		if(state == "START")
			state = "CONFIRM";
		else if (state == "CONFIRM") {
			state = "RESETTING";
			dispatch('reset');
		}
	}
	function getButtonText(state)
	{
		if(state == "START")
			return "Reset disk";
		else if (state == "RESETTING")
			return "Resetting...";
		else
			return "Reset disk. Confirm?";
	}
	function getBgColor(state)
	{
		if(state == "START")
		{
			// Use default
			return undefined;
		}
		else
		{
			return "bg-red-900";
		}
	}
	function getHoverColor(state)
	{
		if(state == "START")
		{
Repository: leptos-rs/leptos
File: router/src/components/router.rs (Rust)

Code before:
use crate::{
    create_location, matching::resolve_path, resolve_redirect_url,
    scroll_to_el, use_location, use_navigate, Branch, History, Location,
    LocationChange, RouteContext, RouterIntegrationContext, State,
};
#[cfg(not(feature = "ssr"))]
use crate::{unescape, Url};
use cfg_if::cfg_if;
use leptos::{
    server_fn::{
        error::{ServerFnErrorSerde, ServerFnUrlError},
        redirect::RedirectHook,
    },
    *,
};
#[cfg(feature = "transition")]
use leptos_reactive::use_transition;
use send_wrapper::SendWrapper;
use std::{cell::RefCell, rc::Rc};
use thiserror::Error;
#[cfg(not(feature = "ssr"))]
use wasm_bindgen::JsCast;
use wasm_bindgen::UnwrapThrowExt;

/// Provides for client-side and server-side routing. This should usually be somewhere near
/// the root of the application.
#[component]
pub fn Router(
    /// The base URL for the router. Defaults to `""`.
    #[prop(optional)]
    base: Option<&'static str>,
    /// A fallback that should be shown if no route is matched.
    #[prop(optional)]
    fallback: Option<fn() -> View>,
    /// A signal that will be set while the navigation process is underway.
    #[prop(optional, into)]
    set_is_routing: Option<SignalSetter<bool>>,
    /// How trailing slashes should be handled in [`Route`] paths.
    #[prop(optional)]
    trailing_slash: TrailingSlash,
    /// The `<Router/>` should usually wrap your whole page. It can contain

Review comment (suggestion):
Feature removed in https://github.com/leptos-rs/leptos/commit/c0c42fdf597e52c24f5960a2b1b4d467849959da

Code after:
use crate::{
    create_location, matching::resolve_path, resolve_redirect_url,
    scroll_to_el, use_location, use_navigate, Branch, History, Location,
    LocationChange, RouteContext, RouterIntegrationContext, State,
};
#[cfg(not(feature = "ssr"))]
use crate::{unescape, Url};
use cfg_if::cfg_if;
use leptos::{
    server_fn::{
        error::{ServerFnErrorSerde, ServerFnUrlError},
        redirect::RedirectHook,
    },
    *,
};
use send_wrapper::SendWrapper;
use std::{cell::RefCell, rc::Rc};
use thiserror::Error;
#[cfg(not(feature = "ssr"))]
use wasm_bindgen::JsCast;
use wasm_bindgen::UnwrapThrowExt;

/// Provides for client-side and server-side routing. This should usually be somewhere near
/// the root of the application.
#[component]
pub fn Router(
    /// The base URL for the router. Defaults to `""`.
    #[prop(optional)]
    base: Option<&'static str>,
    /// A fallback that should be shown if no route is matched.
    #[prop(optional)]
    fallback: Option<fn() -> View>,
    /// A signal that will be set while the navigation process is underway.
    #[prop(optional, into)]
    set_is_routing: Option<SignalSetter<bool>>,
    /// How trailing slashes should be handled in [`Route`] paths.
    #[prop(optional)]
    trailing_slash: TrailingSlash,
    /// The `<Router/>` should usually wrap your whole page. It can contain
    /// any elements, and should include a [`Routes`](crate::Routes) component somewhere
    /// to define and display [`Route`](crate::Route)s.