All Projects → heybourn → Headwind

heybourn / Headwind

Licence: mit
An opinionated Tailwind CSS class sorter built for Visual Studio Code

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Headwind

vscode-formatting-toggle
A VS Code extension that allows you to toggle the formatter (Prettier, Beautify, …) ON and OFF with a simple click.
Stars: ✭ 52 (-93.41%)
Mutual labels:  formatter, visual-studio-code
c math viewer
Parses, and hovers math formula of c mathematical library functions
Stars: ✭ 36 (-95.44%)
Mutual labels:  visual-studio-code, visual-studio-extension
Vsc Material Theme
Material Theme, the most epic theme for Visual Studio Code
Stars: ✭ 1,617 (+104.94%)
Mutual labels:  visual-studio-code, visual-studio-extension
Shortcut-Menu-Bar-VSCode-Extension
Add handy buttons like beautify, show opened files, save, toggle terminal, etc to the editor menu bar in VSCode. You can also create your own buttons with custom commands. VSCode Marketplace link: https://marketplace.visualstudio.com/items?itemName=jerrygoyal.shortcut-menu-bar
Stars: ✭ 126 (-84.03%)
Mutual labels:  visual-studio-code, visual-studio-extension
unity-tools
A Visual Studio Code Extension to provide some tools for Unity development
Stars: ✭ 25 (-96.83%)
Mutual labels:  visual-studio-code, visual-studio-extension
vscode-liquid
💧Liquid language support for VS Code
Stars: ✭ 137 (-82.64%)
Mutual labels:  formatter, visual-studio-code
Processing Vscode
A Visual Studio Code extension for the programming language Processing
Stars: ✭ 141 (-82.13%)
Mutual labels:  visual-studio-code, visual-studio-extension
vscode-terminal-manager
VSCode Extension to manage Terminals. Lets you add multiple optional terminals and easily switch through them. 🎉
Stars: ✭ 28 (-96.45%)
Mutual labels:  visual-studio-code, visual-studio-extension
vsc-material-theme-icons
Material Theme Icons, the most epic icons theme for Visual Studio Code and Material Theme.
Stars: ✭ 90 (-88.59%)
Mutual labels:  visual-studio-code, visual-studio-extension
Prettier Vscode
Visual Studio Code extension for Prettier
Stars: ✭ 4,085 (+417.74%)
Mutual labels:  visual-studio-code, formatter
Vscode Icons
Icons for Visual Studio Code
Stars: ✭ 627 (-20.53%)
Mutual labels:  visual-studio-code
Tailwind Config Viewer
A local UI tool for visualizing your Tailwind CSS configuration file.
Stars: ✭ 623 (-21.04%)
Mutual labels:  tailwindcss
Openincode
📂 macOS Finder toolbar app to open current folder in Visual Studio Code
Stars: ✭ 734 (-6.97%)
Mutual labels:  visual-studio-code
Vscode Git Graph
View a Git Graph of your repository in Visual Studio Code, and easily perform Git actions from the graph.
Stars: ✭ 767 (-2.79%)
Mutual labels:  visual-studio-code
Tailwindo
🔌 Convert Bootstrap CSS code to Tailwind CSS code
Stars: ✭ 606 (-23.19%)
Mutual labels:  tailwindcss
Vscode Cmake Tools
CMake integration in Visual Studio Code
Stars: ✭ 702 (-11.03%)
Mutual labels:  visual-studio-code
Dprint
Pluggable and configurable code formatting platform written in Rust.
Stars: ✭ 610 (-22.69%)
Mutual labels:  formatter
Awes Io
Awes.io // boilerplate based on Vue, Nuxt, TailwindCSS plus Laravel as a backend. 🤟
Stars: ✭ 599 (-24.08%)
Mutual labels:  tailwindcss
Ormolu
A formatter for Haskell source code
Stars: ✭ 592 (-24.97%)
Mutual labels:  formatter
Polacode
📸 Polaroid for your code
Stars: ✭ 6,511 (+725.22%)
Mutual labels:  visual-studio-code

Headwind

CircleCI

Headwind is an opinionated Tailwind CSS class sorter for Visual Studio Code. It enforces consistent ordering of classes by parsing your code and reprinting class tags to follow a given order.

Headwind runs on save, will remove duplicate classes and can even sort entire workspaces.


Get it from the VS Code Marketplace →

Use PHPStorm? Get @WalrusSoup's Headwind port →

Explainer

Usage

You can install Headwind via the VS Code Marketplace, or package it yourself using vsce. Headwind works globally once installed and will run on save if a tailwind.config.js file is present within your working directory.

You can also trigger Headwind by:

  • Pressing CMD + Shift + T on Mac
  • Pressing CTRL + ALT + T on Windows
  • Pressing CTRL + ALT + T on Linux

Headwind can sort individual files by running 'Sort Tailwind CSS Classes' via the Command Palette. Workspaces can also be sorted by running 'Sort Tailwind CSS Classes on Entire Workspace'.

Any breakpoints or unknown classes will be moved to the end of the class list, whilst duplicate classes will be removed.

Customisation

Headwind ships with a default class order (located in package.json). You can edit this (and other settings) to your liking on the extension settings page.

headwind.classRegex:

An object with language IDs as keys and their values determining the regex to search for Tailwind CSS classes. The default is located in package.json but this can be customized to suit your needs.

There can be multiple capturing groups, that should only contain a string with Tailwind CSS classes (without any apostrophies etc.). If a new group, which doesn't contain the class string, is created, ensure that it is non-capturing by using (?:).

Example from package.json:

"headwind.classRegex": {
    "html": "\\bclass\\s*=\\s*[\\\"\\']([_a-zA-Z0-9\\s\\-\\:\\/]+)[\\\"\\']",
    "javascriptreact": "(?:\\bclassName\\s*=\\s*[\\\"\\']([_a-zA-Z0-9\\s\\-\\:\\/]+)[\\\"\\'])|(?:\\btw\\s*`([_a-zA-Z0-9\\s\\-\\:\\/]*)`)"
}

Multi-step Regex

A multi-step regex can be specified by using an array of regexes to be executed in order.

Example from package.json:

"headwind.classRegex": {
    "javascript": [
        "(?:\\bclass(?:Name)?\\s*=\\s*(?:{([\\w\\d\\s_\\-:/${}()[\\]\"'`,]+)})|([\"'`][\\w\\d\\s_\\-:/]+[\"'`]))|(?:\\btw\\s*(`[\\w\\d\\s_\\-:/]+`))",
        "(?:[\"'`]([\\w\\d\\s_\\-:/${}()[\\]\"']+)[\"'`])"
    ],
}

The first regex will look for JSX class or className attributes or twin.macro usage.

The second regex will then look for class names to be sorted within these matches.

Configuration Object

Optionally a configuration object can be passed to specify additional options for sorting class names.

  • regex - specifies the regex to be used to find class names
  • separator - regex pattern that is used to separate class names (default: "\\s+")
  • replacement - string used to replace separator matches (default: " ")

Example from package.json:

"headwind.classRegex": {
    "jade": [
        {
            "regex": "\\.([\\._a-zA-Z0-9\\-]+)",
            "separator": "\\.",
            "replacement": "."
        },
        "\\bclass\\s*=\\s*[\\\"\\']([_a-zA-Z0-9\\s\\-\\:\\/]+)[\\\"\\']"
    ],
}

Debugging Custom Regex:

To debug custom classRegex, you can use the code below:

// Your test string here
const editorText = `
  export const Layout = ({ children }) => (
    <div class="h-screen">
      <div className="w-64 h-full bg-blue-400 relative"></div>
      <div>{children}</div>
    </div>
  )
`
// Your Regex here
const regex = /(?:\b(?:class|className)?\s*=\s*{?[\"\']([_a-zA-Z0-9\s\-\:/]+)[\"\']}?)/
const classWrapperRegex = new RegExp(regex, 'gi')

let classWrapper
while ((classWrapper = classWrapperRegex.exec(editorText)) !== null) {
  const wrapperMatch = classWrapper[0]
  const valueMatchIndex = classWrapper.findIndex((match, idx) => idx !== 0 && match)
  const valueMatch = classWrapper[valueMatchIndex]

  console.log('classWrapper', classWrapper)
  console.log('wrapperMatch', wrapperMatch)
  console.log('valueMatchIndex', valueMatchIndex)
  console.log('valueMatch', valueMatch)
}

The result of valueMatch should be the class text exactly, with no other characters.

Good example value: valueMatch w-64 h-full bg-blue-400 relative

Note: Changes made to Headwind's JSON configuration options may not take effect immediately. When experimenting with custom classRegex, after each change you should open the control pallete (Ctrl/Cmd + Shift + P) and run Developer: Reload Window to ensure changes are applied.


headwind.sortTailwindClasses:

An array that determines Headwind's default sort order.

headwind.removeDuplicates:

Headwind will remove duplicate class names by default. This can be toggled on or off.

"headwind.removeDuplicates": false

headwind.prependCustomClasses:

Headwind will append custom class names by default. They can be prepended instead.

"headwind.prependCustomClasses": true

headwind.runOnSave:

Headwind will run on save by default (if a tailwind.config.js file is present within your working directory). This can be toggled on or off.

"headwind.runOnSave": false

Contributing

Headwind is open-source and contributions are always welcome. If you're interested in submitting a pull request, please take a moment to review CONTRIBUTING.md.

Contributors

Code Contributors

This project exists thanks to all the people who contribute. [Contribute].

Financial Contributors

Become a financial contributor and help us sustain our community. [Contribute]

Individuals

Organizations

Support this project with your organization. Your logo will show up here with a link to your website. [Contribute]

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].