Skip to content

Commit

Permalink
style(all): add custom stylelint rule to suggest usage of the `clicka…
Browse files Browse the repository at this point in the history
…ble` mixin over setting `cursor: pointer;` (#3402)
  • Loading branch information
xelaint authored Jan 15, 2025
1 parent 2017cc8 commit cefef18
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 5 deletions.
4 changes: 3 additions & 1 deletion .stylelintrc
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
{
"plugins": [
"stylelint-selector-bem-pattern",
"@stylistic/stylelint-plugin"
"@stylistic/stylelint-plugin",
"./custom-stylelint-plugins/no-direct-cursor-pointer"
],
"extends": "stylelint-config-recommended-scss",
"rules": {
"daffodil/no-direct-cursor-pointer": true,
"color-hex-length": "long",
"color-no-invalid-hex": true,
"color-named": "never",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
grid-template-columns: 1fr 3fr;

&__image {
cursor: pointer;
@include clickable();
display: block;
max-width: 100%;
}
Expand All @@ -19,7 +19,7 @@
}

&__name {
cursor: pointer;
@include clickable();
font-size: 1rem;
font-weight: bold;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
padding: 75px 25px 0;

&__close {
cursor: pointer;
@include clickable();
font-size: $medium-font-size;
position: absolute;
right: 25px;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
@use 'utilities' as *;

.demo-product-card {
@include clickable();
border: none;
cursor: pointer;

&__details {
padding: 15px 15px 0;
Expand Down
24 changes: 24 additions & 0 deletions custom-stylelint-plugins/no-direct-cursor-pointer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const stylelint = require('stylelint');

const ruleName = 'daffodil/no-direct-cursor-pointer';
const messages = stylelint.utils.ruleMessages(ruleName, {
rejected: 'Use the `clickable()` mixin instead of directly setting `cursor: pointer;`.',
});

module.exports = stylelint.createPlugin(ruleName, (primaryOption) => {
return (postcssRoot, postcssResult) => {
postcssRoot.walkDecls((decl) => {
if (decl.prop === 'cursor' && decl.value === 'pointer') {
stylelint.utils.report({
message: messages.rejected,
node: decl,
result: postcssResult,
ruleName,
});
}
});
};
});

module.exports.ruleName = ruleName;
module.exports.messages = messages;
1 change: 1 addition & 0 deletions libs/design/scss/interactions/mouse/_clickable.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
// @include clickable();
// ```
@mixin clickable() {
// stylelint-disable daffodil/no-direct-cursor-pointer
cursor: pointer;
-webkit-user-select: none;
/// Chrome all / Safari all ///
Expand Down

0 comments on commit cefef18

Please sign in to comment.