Skip to content

Commit

Permalink
Add Typescript and function to customize sort order (#3)
Browse files Browse the repository at this point in the history
* feat: add typescript

* chore(eslint): fix eslint config

* docs: add customization
  • Loading branch information
playhardgopro authored Mar 1, 2021
1 parent 8c7e1de commit 4a977c9
Show file tree
Hide file tree
Showing 13 changed files with 504 additions and 83 deletions.
6 changes: 6 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# don't ever lint node_modules
node_modules
# don't lint build output (make sure it's set to your correct build folder name)
dist
# don't lint nyc coverage output
coverage
24 changes: 24 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": [
"@typescript-eslint"
],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
],
"overrides": [
{
"files": [
"*.js"
],
"env": {
"node": true
},
"rules": {
"@typescript-eslint/no-var-requires": "off",
},
}
]
}
18 changes: 0 additions & 18 deletions .eslintrc.js

This file was deleted.

40 changes: 0 additions & 40 deletions MDNGroups.js

This file was deleted.

98 changes: 96 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@

- [MDN data grouping](#mdn-data-grouping)
- [Usage](#usage)
- [Default order](#default-order)
- [Customization](#customization)
- [Contributing](#contributing)

A [Stylelint][] config that sorts CSS properties based on [MDN-data][]. Also adds a `composes` property to the top of the list.
A [Stylelint][] config that sorts CSS properties based on [MDN-data][].

## Usage

Expand All @@ -26,11 +28,101 @@ npm install --save-dev stylelint stylelint-config-mdn-group-order
{
"extends": "stylelint-config-mdn-group-order",
"rules": {
// You can override rules here
// You can override rules here
}
}
```

## Default order
```js
[
'Composes',
'Compositing and Blending',
'CSS Animations',
'CSS Backgrounds and Borders',
'CSS Basic User Interface',
'CSS Box Alignment',
'CSS Box Model',
'CSS Color',
'CSS Columns',
'CSS Containment',
'CSS Counter Styles',
'CSS Display',
'CSS Flexible Box Layout',
'CSS Fonts',
'CSS Fragmentation',
'CSS Generated Content',
'CSS Grid Layout',
'CSS Images',
'CSS Inline',
'CSS Lists and Counters',
'CSS Logical Properties',
'CSS Masking',
'CSS Miscellaneous',
'CSS Motion Path',
'CSS Overflow',
'CSS Pages',
'CSS Positioning',
'CSS Ruby',
'CSS Scroll Anchoring',
'CSS Scroll Snap',
'CSS Scrollbars',
'CSS Shapes',
'CSS Speech',
'CSS Table',
'CSS Text Decoration',
'CSS Text',
'CSS Transforms',
'CSS Transitions',
'CSS Variables',
'CSS Will Change',
'CSS Writing Modes',
'CSSOM View',
'Filter Effects',
'MathML',
'Microsoft Extensions',
'Mozilla Extensions',
'Pointer Events',
'WebKit Extensions'
]
```

## Customization

If you want to customize order of groups, you can use function
```ts
getOrder(forCSSModules: boolean, sortOrder?: string[])
```

1. First of all install [stylelint-order][] plugin
```bash
npm install stylelint-order --save-dev
```
2. Import `getOrder()` from package
```js
const { getOrder } = require('stylelint-config-mdn-group-order/dist/mdn-groups')
```
3. Now you can use this function.
For example:

```js
"rules": {
'order/properties-order': [
getOrder(true, [
'CSS Display',
'CSS Columns',
'CSS Containment',
'CSS Color',
'CSS Counter Styles',
'CSS Flexible Box Layout'
]),
{
'unspecified': 'bottom',
'emptyLineBeforeUnspecified': 'always',
},
]
}
```
## Contributing

Please, create a [PR][] and describe what you want to add and why :)
Expand All @@ -51,6 +143,8 @@ Please, create a [PR][] and describe what you want to add and why :)

[stylelint]: https://github.com/stylelint/stylelint

[stylelint-order]: https://github.com/hudochenkov/stylelint-order

[mdn-data]: https://github.com/mdn/data

[pr]: https://github.com/playhardgopro/stylelint-config-mdn-group-order/pulls
7 changes: 3 additions & 4 deletions __tests__/test.css
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
.className {
composes: test from 'test';

font-size: 14;

height: 50px;
width: 100%;

font-size: 14;
composes: test from 'test';
}
9 changes: 2 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
const MDNGroups = require('./MDNGroups')
const { getOrder } = require('./dist/mdn-groups')

module.exports = {
plugins: ['stylelint-order'],
rules: {
'order/properties-order': [
{
groupName: 'Composes',
properties: ['composes'],
emptyLineBefore: 'always'
},
...MDNGroups
...getOrder(true)
]
}
}
Loading

0 comments on commit 4a977c9

Please sign in to comment.