-
-
Notifications
You must be signed in to change notification settings - Fork 51
feat(no-unused-class-name): Support Regex for allowedClassNames
option
#1257
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(no-unused-class-name): Support Regex for allowedClassNames
option
#1257
Conversation
🦋 Changeset detectedLatest commit: 893b19f The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
allowedClassNames
allowedClassNames
option
Try the Instant Preview in Online PlaygroundInstall the Instant Preview to Your Local
Published Instant Preview Packages:
|
allowedClassNames
optionallowedClassNames
option
if ( | ||
!allowedClassNames.includes(className) && | ||
!allowedClassNames.some((allowedClassName: string) => { | ||
const regex = /^\/(.*)\/$/.exec(allowedClassName); | ||
if (regex == null || regex[1] == null) { | ||
return false; | ||
} | ||
|
||
return new RegExp(regex[1]).test(className); | ||
}) && | ||
!classesUsedInStyle.includes(className) | ||
) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use isRegExp
from utils/regexp.js
to check the className
is regexp or not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks!
fixed. e4c983b
!allowedClassNames.includes(className) && | ||
!allowedClassNames.some((allowedClassName: string) => { | ||
if (!isRegExp(allowedClassName)) { | ||
return false; | ||
} | ||
|
||
return toRegExp(allowedClassName).test(className); | ||
}) && | ||
!classesUsedInStyle.includes(className) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is simpler?
!allowedClassNames.includes(className) && | |
!allowedClassNames.some((allowedClassName: string) => { | |
if (!isRegExp(allowedClassName)) { | |
return false; | |
} | |
return toRegExp(allowedClassName).test(className); | |
}) && | |
!classesUsedInStyle.includes(className) | |
allowedClassNames.none((allowedClassName) => { | |
if (isRegExp(allowedClassName)) { | |
return toRegExp(allowedClassName).test(className); | |
} | |
return allowedClassName === className; | |
}) && | |
!classesUsedInStyle.includes(className) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think this code is enough. (All Test cases passed)
.changeset/forty-signs-smoke.md
Outdated
'eslint-plugin-svelte': minor | ||
--- | ||
|
||
feat(no-unused-class-name): Support Regex for allowedClassNames option |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
feat(no-unused-class-name): Support Regex for allowedClassNames option | |
feat(no-unused-class-name): support regex for `allowedClassNames` option |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I got it!
CI is failed. |
@@ -4,6 +4,7 @@ import type { AnyNode } from 'postcss'; | |||
import type { Node as SelectorNode } from 'postcss-selector-parser'; | |||
import { findClassesInAttribute } from '../utils/ast-utils.js'; | |||
import type { SourceCode } from '../types.js'; | |||
import { toRegExp } from 'src/utils/regexp.js'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use relative path to specify the file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
Motivation
When I use this rule for project which is using
unocss
, I want to add unocss's dynamic-rules toallowedClassNames
ex)
/^m-(\d+)$/