Repository: tailwindlabs/tailwindcss
File: packages/@tailwindcss-upgrade/src/template/codemods/arbitrary-value-to-bare-value.ts (TypeScript)

Code before:

export function arbitraryValueToBareValue(
  designSystem: DesignSystem,
  _userConfig: Config,
  rawCandidate: string,
): string {
  for (let candidate of parseCandidate(rawCandidate, designSystem)) {
    let clone = structuredClone(candidate)
    let changed = false

    // Convert font-stretch-* utilities
    if (
      clone.kind === 'functional' &&
      clone.value?.kind === 'arbitrary' &&
      clone.value.dataType === null &&
      clone.root === 'font-stretch'
    ) {
      if (clone.value.value.endsWith('%')) {
        let percentage = parseFloat(clone.value.value)
        if (percentage >= 50 && percentage <= 200) {
          changed = true
          clone.value = {
            kind: 'named',
            value: clone.value.value,
            fraction: null,
          }
        }
      }
    }

    // Convert arbitrary values with positive integers to bare values
    // Convert arbitrary values with fractions to bare values
    else if (
      clone.kind === 'functional' &&
      clone.value?.kind === 'arbitrary' &&
      clone.value.dataType === null
    ) {
      let parts = segment(clone.value.value, '/')
      if (parts.every((part) => isPositiveInteger(part))) {
        changed = true

        let currentValue = clone.value
        let currentModifier = clone.modifier

        // E.g.: `col-start-[12]`
        //                   ^^
        if (parts.length === 1) {
          clone.value = {
            kind: 'named',
            value: clone.value.value,
            fraction: null,

Review comment (suggestion):
I think only whole numbers are valid for bare values but this might also convert e.g. `font-stretch-[50.5%]` now 

Code after:

export function arbitraryValueToBareValue(
  designSystem: DesignSystem,
  _userConfig: Config,
  rawCandidate: string,
): string {
  for (let candidate of parseCandidate(rawCandidate, designSystem)) {
    let clone = structuredClone(candidate)
    let changed = false

    // Convert font-stretch-* utilities
    if (
      clone.kind === 'functional' &&
      clone.value?.kind === 'arbitrary' &&
      clone.value.dataType === null &&
      clone.root === 'font-stretch'
    ) {
      if (clone.value.value.endsWith('%') && isPositiveInteger(clone.value.value.slice(0, -1))) {
        let percentage = parseInt(clone.value.value)
        if (percentage >= 50 && percentage <= 200) {
          changed = true
          clone.value = {
            kind: 'named',
            value: clone.value.value,
            fraction: null,
          }
        }
      }
    }

    // Convert arbitrary values with positive integers to bare values
    // Convert arbitrary values with fractions to bare values
    else if (
      clone.kind === 'functional' &&
      clone.value?.kind === 'arbitrary' &&
      clone.value.dataType === null
    ) {
      let parts = segment(clone.value.value, '/')
      if (parts.every((part) => isPositiveInteger(part))) {
        changed = true

        let currentValue = clone.value
        let currentModifier = clone.modifier

        // E.g.: `col-start-[12]`
        //                   ^^
        if (parts.length === 1) {
          clone.value = {
            kind: 'named',
            value: clone.value.value,
            fraction: null,