-
Notifications
You must be signed in to change notification settings - Fork 6.5k
feat: introduce stylelint plugin #7644
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
47ccf97
feat: introduce stylelint plugin
canerakdas e6242d1
Update packages/ui-components/stylelint.plugin.mjs
canerakdas 94af7ca
refactor: review suggestions
canerakdas db51994
chore: resolve conflict
canerakdas 981f1ad
chore(docs): align Tailwind usage with official documentation in docs…
canerakdas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,7 +21,7 @@ | |
|
|
||
| & img { | ||
| @apply h-auto | ||
| w-24 | ||
| md:w-48; | ||
| w-24 | ||
| md:w-48; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 18 additions & 4 deletions
22
packages/ui-components/Common/Breadcrumbs/BreadcrumbItem/index.module.css
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,27 +1,41 @@ | ||
| @reference "../../../styles/index.css"; | ||
|
|
||
| .item { | ||
| @apply flex max-w-fit items-center gap-5 truncate text-sm font-medium; | ||
| @apply flex | ||
| max-w-fit | ||
| items-center | ||
| gap-5 | ||
| truncate | ||
| text-sm | ||
| font-medium; | ||
|
|
||
| &:last-child { | ||
| @apply w-full; | ||
| } | ||
|
|
||
| a { | ||
| @apply shrink grow; | ||
| @apply shrink | ||
| grow; | ||
| } | ||
|
|
||
| &, | ||
| > a, | ||
| > a:hover { | ||
| @apply text-neutral-800 motion-safe:transition-colors dark:text-neutral-200; | ||
| @apply text-neutral-800 | ||
| motion-safe:transition-colors | ||
| dark:text-neutral-200; | ||
| } | ||
|
|
||
| &.visuallyHidden { | ||
| @apply hidden; | ||
| } | ||
|
|
||
| .separator { | ||
| @apply size-4 max-w-fit shrink-0 grow text-neutral-600 dark:text-neutral-400; | ||
| @apply size-4 | ||
| max-w-fit | ||
| shrink-0 | ||
| grow | ||
| text-neutral-600 | ||
| dark:text-neutral-400; | ||
| } | ||
| } |
15 changes: 12 additions & 3 deletions
15
packages/ui-components/Common/Breadcrumbs/BreadcrumbLink/index.module.css
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,22 @@ | ||
| @reference "../../../styles/index.css"; | ||
|
|
||
| .link { | ||
| @apply max-w-fit truncate; | ||
| @apply max-w-fit | ||
| truncate; | ||
|
|
||
| &.active { | ||
| @apply rounded bg-green-600 px-2 py-1 font-semibold text-white motion-safe:transition-colors dark:text-white; | ||
| @apply rounded | ||
| bg-green-600 | ||
| px-2 | ||
| py-1 | ||
| font-semibold | ||
| text-white | ||
| motion-safe:transition-colors | ||
| dark:text-white; | ||
|
|
||
| &:hover { | ||
| @apply bg-green-700 text-white; | ||
| @apply bg-green-700 | ||
| text-white; | ||
| } | ||
| } | ||
| } |
6 changes: 5 additions & 1 deletion
6
packages/ui-components/Common/Breadcrumbs/BreadcrumbRoot/index.module.css
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,9 @@ | ||
| @reference "../../../styles/index.css"; | ||
|
|
||
| .list { | ||
| @apply xs:w-full flex w-screen gap-5 px-6; | ||
| @apply xs:w-full | ||
| flex | ||
| w-screen | ||
| gap-5 | ||
| px-6; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,7 +35,7 @@ | |
|
|
||
| .tabSecondaryLabel { | ||
| @apply text-green-800 | ||
| dark:text-green-600; | ||
| dark:text-green-600; | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
canerakdas marked this conversation as resolved.
Outdated
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| import stylelint from 'stylelint'; | ||
|
|
||
| const { | ||
| createPlugin, | ||
| utils: { report, ruleMessages }, | ||
| } = stylelint; | ||
|
|
||
| const name = 'ui-components/one-tailwind-token-per-line'; | ||
|
canerakdas marked this conversation as resolved.
Outdated
|
||
|
|
||
| const messages = ruleMessages(name, { | ||
| className: tokens => | ||
| `Each line should contain only one Tailwind token; "${tokens}"`, | ||
| spacing: tokens => | ||
| `Each class used with @apply should be indented by 2 spaces on a new line; ${tokens}`, | ||
| }); | ||
|
|
||
| const meta = { | ||
| url: 'https://github.com/nodejs/nodejs.org/blob/main/COLLABORATOR_GUIDE.md#styling-a-component', | ||
| fixable: true, | ||
| }; | ||
|
|
||
| /** | ||
| * Adjusts the class names in the rule by cleaning and adding proper indentation. | ||
| * | ||
| * @param {Object} rule - The rule object containing the class names to be processed. | ||
| * @param {string} rule.params - The class names as a string to be formatted. | ||
| * @param {Object} rule.raws - The raw data of the rule. | ||
| * @param {string} rule.raws.before - The raw string before to the @apply rule. | ||
| * @returns {Object|null} The modified rule with properly formatted class names, or null if the rule is invalid. | ||
| */ | ||
| const indentClassNames = rule => { | ||
| // Ensure that the rule contains necessary properties | ||
| if (!rule || !rule.params || !rule.raws || !rule.raws.before) { | ||
| return null; | ||
| } | ||
|
|
||
| const indent = ' '.repeat(rule.raws.before.length + 1); | ||
|
|
||
| // Clean and split the class names | ||
| const cleanedClasses = cleanClassNames(rule.params); | ||
|
|
||
| // Apply the indentation and join the class names back together | ||
| rule.params = applyIndentation(cleanedClasses, indent); | ||
|
|
||
| return rule; | ||
| }; | ||
|
|
||
| /** | ||
| * Cleans the input string by removing unnecessary whitespace and newlines. | ||
| * | ||
| * @param {string} params - The class names string to be cleaned. | ||
| * @returns {string} The cleaned class names string. | ||
| */ | ||
| const cleanClassNames = params => { | ||
| return params | ||
| .replace(/\n+/g, '') // Remove new lines | ||
|
canerakdas marked this conversation as resolved.
Outdated
|
||
| .replace(/\s+/g, ' ') // Replace multiple spaces with a single space | ||
| .trim(); // Trim leading/trailing spaces | ||
| }; | ||
|
|
||
| /** | ||
| * Applies the correct indentation to each class name in the string. | ||
| * | ||
| * @param {string} classes - The cleaned class names as a string. | ||
| * @param {string} indent - The string used for indentation. | ||
| * @returns {string} The class names string with applied indentation. | ||
| */ | ||
| const applyIndentation = (classes, indent) => { | ||
| return classes | ||
| .split(' ') // Split into an array of class names | ||
| .map(className => indent + className) // Add indentation to each class | ||
| .join('\n') // Join with new lines | ||
| .trim(); // Remove extra space at the end | ||
| }; | ||
|
|
||
| /** @type {import('stylelint').Rule} */ | ||
| const rule = () => (root, result) => { | ||
| root.walkAtRules('apply', rule => { | ||
| if (!rule.params.includes(' ')) { | ||
| // If there are no spaces in the params, we don't need to check anything | ||
| return; | ||
| } | ||
|
|
||
| // Since we use 2 spaces for indentation, each line in the apply rule | ||
| // should be indented with two extra whitespaces. | ||
| const classes = rule.params.split(`${rule.raws.before} `); | ||
|
canerakdas marked this conversation as resolved.
Outdated
|
||
| const classNames = classes.join(''); | ||
|
|
||
| // Check if the params contain any spaces | ||
| if (classNames.includes(' ')) { | ||
| if (classNames.includes('\n')) { | ||
| return report({ | ||
| ruleName: name, | ||
| result: result, | ||
| message: messages.spacing(JSON.stringify(rule.params)), | ||
| node: rule, | ||
| fix: indentClassNames(rule), | ||
| }); | ||
|
canerakdas marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| return report({ | ||
| ruleName: name, | ||
| result, | ||
| message: messages.className(rule.params), | ||
| node: rule, | ||
| fix: indentClassNames(rule), | ||
| }); | ||
| } | ||
| }); | ||
| }; | ||
|
|
||
| rule.ruleName = name; | ||
| rule.messages = messages; | ||
| rule.meta = meta; | ||
|
|
||
| export default createPlugin(name, rule); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.