Skip to content

Commit

Permalink
Expose shorthand properties reference as public API
Browse files Browse the repository at this point in the history
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('};')
```
  • Loading branch information
ybiquitous committed Jun 23, 2022
1 parent bd8c7fd commit 37fa87e
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ const createStylelint = require('./createStylelint');
const formatters = require('./formatters');
const postcssPlugin = require('./postcssPlugin');
const report = require('./utils/report');
const resolveConfig = require('./resolveConfig');
const ruleMessages = require('./utils/ruleMessages');
const rules = require('./rules');
const shorthandData = require('./reference/shorthandData');
const standalone = require('./standalone');
const validateOptions = require('./utils/validateOptions');
const resolveConfig = require('./resolveConfig');

/** @type {import('stylelint').PublicApi} */
const stylelint = Object.assign(postcssPlugin, {
Expand All @@ -26,6 +27,9 @@ const stylelint = Object.assign(postcssPlugin, {
validateOptions,
checkAgainstRule,
},
reference: {
shorthandData,
},
});

module.exports = stylelint;
44 changes: 44 additions & 0 deletions types/stylelint/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,44 @@ declare module 'stylelint' {
line?: number;
};

export type ShorthandData = {
margin: Set<string>;
padding: Set<string>;
background: Set<string>;
font: Set<string>;
border: Set<string>;
'border-top': Set<string>;
'border-bottom': Set<string>;
'border-left': Set<string>;
'border-right': Set<string>;
'border-width': Set<string>;
'border-style': Set<string>;
'border-color': Set<string>;
'list-style': Set<string>;
'border-radius': Set<string>;
transition: Set<string>;
animation: Set<string>;
'border-block-end': Set<string>;
'border-block-start': Set<string>;
'border-image': Set<string>;
'border-inline-end': Set<string>;
'border-inline-start': Set<string>;
'column-rule': Set<string>;
columns: Set<string>;
flex: Set<string>;
'flex-flow': Set<string>;
grid: Set<string>;
'grid-area': Set<string>;
'grid-column': Set<string>;
'grid-gap': Set<string>;
'grid-row': Set<string>;
'grid-template': Set<string>;
outline: Set<string>;
'text-decoration': Set<string>;
'text-emphasis': Set<string>;
mask: Set<string>;
};

export type PublicApi = PostCSS.PluginCreator<PostcssPluginOptions> & {
/**
* Runs stylelint with the given options and returns a Promise that
Expand Down Expand Up @@ -455,6 +493,12 @@ declare module 'stylelint' {
callback: (warning: PostCSS.Warning) => void,
) => void;
};
reference: {
/**
* Shorthand properties having longhand sub-properties.
*/
shorthandData: ShorthandData;
};
};

/**
Expand Down
2 changes: 2 additions & 0 deletions types/stylelint/type-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,5 @@ messages.warning('some string');

// @ts-expect-error Null is not allowed in `RuleMessageFunc` parameters.
messages.warning(null);

const shorthandSubProps: Set<string> = stylelint.reference.shorthandData['border-color'];

0 comments on commit 37fa87e

Please sign in to comment.