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
Add shorthand properties reference to public API #6168
Conversation
The type definition is generated by the following script: ```js const shorthandData = require("./lib/reference/shorthandData") console.log('export type ShorthandData = {') for (const key of Object.keys(shorthandData)) { console.log(`\t'${key}': Set<string>;`) } console.log('};') ```
37fa87e
to
d12beec
Compare
[ask] The |
@ybiquitous Thank you. It's looking good.
Let's go with Future property sets could include stylelint/lib/reference/keywordSets.js Lines 411 to 423 in bd8c7fd
(Which are in the What file structure shall we use? Choices are:
I feel like either of the last two will be easiest to work with and maintain. For the 1 file per group, offhand I can think of the following groups we have:
|
@jeddy3 Thanks for your helpful feedback! The idea of "1 file per group" seems so nice. 👍🏼 I'll push commits into this pull request, following the ideas of |
Oops, I got it back-to-front. From the spec:
Let's go with |
I have one more suggestion: what if using This MDN doc describes the differences between // Using Object
const longhandSubPropertiesOfShorthandProperties = {
margin: new Set(['margin-top', 'margin-bottom', 'margin-left', 'margin-right']),
// ...
};
longhandSubPropertiesOfShorthandProperties.margin; //=> Set(...)
// Using Map
const longhandSubPropertiesOfShorthandProperties = new Map([
['margin', new Set(['margin-top', 'margin-bottom', 'margin-left', 'margin-right'])],
// ...
]);
longhandSubPropertiesOfShorthandProperties.get('margin'); //=> Set(...) What do you think? |
lib/reference/properties.js
Outdated
padding: new Set(['padding-top', 'padding-bottom', 'padding-left', 'padding-right']), | ||
/** @type {import('stylelint').LonghandSubPropertiesOfShorthandProperties} */ | ||
const longhandSubPropertiesOfShorthandProperties = { | ||
/* eslint sort-keys: 'error' */ |
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.
[note] I've sorted properties alphabetically for findability (the diff increases, though).
lib/reference/properties.js
Outdated
@@ -91,6 +47,18 @@ module.exports = { | |||
'border-block-start-style', | |||
'border-block-start-color', | |||
]), | |||
'border-bottom': new Set([ | |||
// prettier-ignore |
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.
[note] To align always multi-line for readability.
Sounds good to me. All the other changes are looking great, by the way! |
| 'text-decoration' | ||
| 'text-emphasis' | ||
| 'transition', | ||
ReadonlySet<string> |
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.
[note] ReadonlyMap
and ReadonlySet
are built-in types.
|
||
return; | ||
} | ||
|
||
for (const longhandProp of overrideables) { | ||
if (!Object.prototype.hasOwnProperty.call(declarations, prefix + longhandProp)) { | ||
const declaration = declarations.get(prefix + longhandProp); |
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.
[note] Refactor to use Map
instead of Object
; hasOwnProperty
is no longer needed (safe access).
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.
Much nicer.
shorthands.push(shorthand); | ||
longhandToShorthands.set(longhand, shorthands); | ||
} | ||
} |
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.
[note] Refactor to use Map
and for...of
instead of Object
and reduce()
for readability.
@jeddy3 I've switched from |
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.
Fantastic, thank you!
I think we have a good direction here for exposing our reference data.
|
@jeddy3 Thank you for all of your reviews. 😊 👍🏼 |
This pull request is following the suggestion below by @jeddy3 in #6151 (comment):
The type definition is generated by the following script: