Skip to content

[BUG] classnames-order quick fix breaks indentation and sorting on multiline strings #52

@RomanKornev

Description

@RomanKornev

Describe the bug
After applying quick fix, the multiline classnames at still not sorted and now have indentation issues

To Reproduce
Steps to reproduce the behavior:

  1. Invalid Tailwind CSS classnames order:
import ctl from '@netlify/classnames-template-literals'

export const ButtonType = {
    primary: ctl(
        `hover:bg-purple-600 rounded-full py-1 text-sm font-semibold 
        border border-purple-200 text-purple-600 bg-white 
        px-4 hover:text-white`
    ),
}
  1. Apply quick fix
  2. See
export const ButtonType = {
    primary: ctl(
        `        px-4 hover:text-white
hover:bg-purple-600 rounded-full py-1 text-sm font-semibold 
        border border-purple-200 text-purple-600 bg-white `
    ),
}
  1. The first line now has additional indentation while second line doesn't have any
  2. Classnames are still not sorted

Expected behavior
Order classnames as a whole first, then preserve the number of items per line

export const ButtonType = {
    primary: ctl(
        `py-1 px-4 text-sm font-semibold text-purple-600 
        hover:text-white bg-white hover:bg-purple-600 rounded-full
        border border-purple-200`
    ),
}

Screenshots
Before:
image
After:
image

Environment (please complete the following information):

  • OS: WSL Ubuntu 20.04 on Win 10 x64
  • Softwares + version used:
    • VSCode 1.60.1
    • npm v7.24.0
    • node v16.9.1

Additional context
Also, a single space at the end is triggering invalid order as well
Before:
image
After fix:
image

eslint config file or live demo

eslintrc
{
  "parser": "@typescript-eslint/parser",
  "parserOptions": {
      "ecmaVersion": 2021,
      "sourceType": "module"
  },
  "plugins": [
      "import",
      "@typescript-eslint",
      "react-hooks",
      "prettier",
      "classnames",
      "tailwindcss"
  ],
  "extends": [
      "react-app",
      "plugin:import/errors",
      "plugin:import/warnings",
      "plugin:import/typescript",
      "plugin:react/recommended",
      "plugin:@typescript-eslint/recommended",
      "plugin:prettier/recommended",
      "plugin:tailwindcss/recommended"
  ],
  "rules": {
      "react-hooks/rules-of-hooks": "error",
      "react-hooks/exhaustive-deps": "warn",
      "react/prop-types": "off",
      "react/self-closing-comp": ["warn", {
          "component": true,
          "html": true
      }],
      "@typescript-eslint/explicit-module-boundary-types": "off",
      "prettier/prettier": [
          "warn",
          {
              "printWidth": 100
          }
      ]
  },
  "overrides": [{
      "files": ["*.ts"],
      "rules": {
          "@typescript-eslint/explicit-module-boundary-types": ["error"]
      }
  }],
  "settings": {
      "react": {
          "pragma": "React",
          "version": "detect"
      },
      "import/resolver": {
          "node": {
              "extensions": [".js", ".jsx", ".ts", ".tsx"],
              "moduleDirectory": ["node_modules", "src/"]
          }
      },
      "tailwindcss": {
          "groupByResponsive": true
        }
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions