question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Feature request] eslint setting for custom class-string regex

See original GitHub issue

Is your feature request related to a problem? Please describe. I’m using the package Twrnc for React-Native, and I’d love to be able to use your plugin. The tailwind classes for Twrnc are in the format style={tw`classes here like-this`} but can also be in other slightly different formats depending on how you configure it (eg. style={tws(`classes-like this`, someBoolean && `more class-es`)}

Describe the solution you’d like I would love it if you could provide an ESlint tailwind setting for providing custom regexes to identify the start and end of tailwind strings. I’m thinking it could be set up so that the regex capture group(s) contain the identified tailwind class strings.

That would make the regex for the simpler case need something like: tw`([^`])`

And perhaps the more complex case would be a set of regexes expanding as far as the number of sequential strings you wanted to support: tws\([^`]*`([^`]*)`[^\)]*\) tws\([^`]*`[^`]*`[^`]*`([^`]*)`[^\)]*\) tws\([^`]*`[^`]*`[^`]*`[^`]*`[^`]*`([^`]*)`[^\)]*\) tws\([^`]*`[^`]*`[^`]*`[^`]*`[^`]*`[^`]*`[^`]*([^`]*)`[^\)]*\)

If you provided the option to switch to a regex-based version it would also support class name strings that aren’t in-situ in a React node.

FYI the VSCode Tailwind plugin does a great job of utilising complex regex group location, using the multi-regexp2 package: see this function.

Describe alternatives you’ve considered No alternative that I can see if I want to use this plugin with React-Native and Twrnc

Additional context N/A

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

0reactions
lukesmurraycommented, Aug 28, 2022

Wondering if the regex syntax could be supported as well.

For instance using vite-plugin-inline-css-module we can write

const styles = css`
  .h2 {
    @apply font-neue text-4xl leading-relaxed underline h-5;
  }
`;

The tailwind library supports parsing this using

  "tailwindCSS.experimental.classRegex": [
    "@apply\\s([^;]*)", // @apply ...,
  ]
Read more comments on GitHub >

github_iconTop Results From Across the Web

prefer-regex-literals - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >
ESLint rules using Regular Expressions - GitHub
The idea is to allow the creation of different eslint rules based on Regular Expressions in order to have some "freedom" to create...
Read more >
eslint-plugin-regex - npm
Start using eslint-plugin-regex in your project by running `npm i ... There are 7 other projects in the npm registry using eslint-plugin-regex.
Read more >
Can I create an ESLint rule that will allow all globals matching ...
If you use a JavaScript config file, does the /[A-Z][a-z]*Model/ regex syntax work? – ssube. Sep 27, 2016 at 20:01. So rename my ......
Read more >
PhpStorm 2022.1 (221.5080.224 build) Release Notes
Feature, WI-63616, Calling static method on class-string ... Bug, WI-65533, Regex: /e modifier: should be highlighted since PHP 5.5 as deprecated. Feature ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found