Skip to content

Commit 8930786

Browse files
docs(shoreline-stylelint): add package documentation
1 parent 5990c4b commit 8930786

File tree

9 files changed

+5484
-15539
lines changed

9 files changed

+5484
-15539
lines changed

packages/components/src/text-input/text-input.css

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
[data-sl-text-input-container] {
88
height: 2.75rem;
99
width: 100%;
10+
text: var(--sl-text-body);
1011
font: var(--sl-text-body-font);
1112
letter-spacing: var(--sl-text-body-letter-spacing);
1213
border-radius: var(--sl-border-radius-medium);

packages/stylelint/README.md

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Shoreline Stylelint
2+
3+
A configuration of [Stylelint]() rules to help with the Shoreline adoption.
4+
5+
## How to run?
6+
7+
All files:
8+
9+
```bash
10+
pnpm stylelint **/*.css
11+
```
12+
13+
Specific file:
14+
15+
```bash
16+
pnpm run stylelint src/example.css
17+
```
18+
19+
Fix:
20+
21+
```bash
22+
pnpm stylelint **/*.css --fix
23+
```
24+
25+
### Development
26+
27+
### Add new rules
28+
29+
1. Refer to the [Writing rules](https://stylelint.io/developer-guide/rules) guide of the Stylelint documentation
30+
31+
### Build custom rules
32+
33+
1. Refer to the [Writing plugins](https://stylelint.io/developer-guide/plugins) guide of the Stylelint documentation
34+
2. Create your rule in the `/src/plugins` directory
35+
3. Validate your plugin with tests (reference sibling plugins for examples)
36+
37+
Useful references:
38+
39+
1. [PostCSS API](https://postcss.org/api/): It is useful when writing a new plugin.
40+
2. [jest-preset-stylelint](https://github.com/stylelint/jest-preset-stylelint#usage): Use this documentation when writing tests.
41+
3. [stylelint-prettier](https://github.com/prettier/stylelint-prettier)
42+
43+
### Setup new rule/plugin
44+
45+
You must setup the new rule or plugin on [the Stylelint configuration file](./src/index.js)

packages/stylelint/src/index.js

+2-19
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,12 @@
11
'use strict'
22

33
const textPlugin = require('./plugins/no-text-property')
4-
const spacePlugin = require('./plugins/no-space-in-px')
5-
6-
const colorRules = {
7-
'color-no-invalid-hex': [
8-
true,
9-
{
10-
message: 'Please use a Shoreline color token instead of %s',
11-
},
12-
],
13-
}
14-
15-
const typographyRules = {
16-
'shoreline/no-text-property': true,
17-
}
18-
19-
const spaceRules = {
20-
'shoreline/no-space-in-px': true,
21-
}
4+
const spacePlugin = require('./plugins/no-px-values')
225

236
module.exports = {
247
plugins: [textPlugin, spacePlugin],
258
reportDescriptionlessDisables: true,
269
reportNeedlessDisables: true,
2710
reportInvalidScopeDisables: true,
28-
rules: { ...colorRules, ...typographyRules, ...spaceRules },
11+
rules: { 'shoreline/no-text-property': true, 'shoreline/no-px-values': true },
2912
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# shoreline/no-px-values
2+
3+
Disallows use of `px` values.
4+
5+
```diff
6+
7+
// Do
8+
+ padding: 1rem;
9+
+ margin: 1rem 0.5rem;
10+
// Don't
11+
- padding: 16px;
12+
- margin: 16px 8px;
13+
```
14+
15+
## How to configure?
16+
17+
```js
18+
const stylelintConfig = {
19+
rules: {
20+
'shoreline/no-px-values': true,
21+
},
22+
}
23+
```
24+
25+
## How to run?
26+
27+
All files:
28+
29+
```bash
30+
pnpm stylelint **/*.css
31+
```
32+
33+
Specific file:
34+
35+
```bash
36+
pnpm run stylelint src/example.css
37+
```
38+
39+
## Fix
40+
41+
```bash
42+
pnpm stylelint **/*.css --fix
43+
```
44+
45+
```diff
46+
- margin: 16px 8px;
47+
+ margin: 1rem 0.5rem;
48+
```
49+
50+
## Output
51+
52+
```bash
53+
10:5 ✖ Expected "padding: 16px" to be "padding: 1rem". shoreline/no-px-values
54+
11:5 ✖ Expected "margin: 8px 4px" to be "margin: 0.5rem 0.25rem". shoreline/no-px-values
55+
```

packages/stylelint/src/plugins/no-space-in-px/index.js packages/stylelint/src/plugins/no-px-values/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const { replaceDeclaration } = require('../../utils/replace-declaration.js')
33

44
const { ruleMessages, validateOptions, report } = stylelint.utils
55

6-
const ruleName = 'shoreline/no-space-in-px'
6+
const ruleName = 'shoreline/no-px-values'
77
const messages = ruleMessages(ruleName, {
88
expected: (prop, value, expectedValue) =>
99
`Expected "${prop}: ${value}" to be "${prop}: ${expectedValue}".`,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# shoreline/no-text-property
2+
3+
Disallows use of `px` values.
4+
5+
```diff
6+
7+
// Do
8+
+ font: var(--sl-text-body-font);
9+
+ letter-spacing: var(--sl-text-body-letter-spacing);
10+
// Don't
11+
- text: var(--sl-text-body);
12+
```
13+
14+
## How to configure?
15+
16+
```js
17+
const stylelintConfig = {
18+
rules: {
19+
'shoreline/no-text-property': true,
20+
},
21+
}
22+
```
23+
24+
## How to run?
25+
26+
All files:
27+
28+
```bash
29+
pnpm stylelint **/*.css
30+
```
31+
32+
Specific file:
33+
34+
```bash
35+
pnpm run stylelint src/example.css
36+
```
37+
38+
## Fix
39+
40+
```bash
41+
pnpm stylelint **/*.css --fix
42+
```
43+
44+
```diff
45+
- text: var(--sl-text-body);
46+
+ font: var(--sl-text-body-font);
47+
+ letter-spacing: var(--sl-text-body-letter-spacing);
48+
```
49+
50+
## Output
51+
52+
```bash
53+
10:5 ✖ Expected "text" property to be splited in "font" and "letter-spacing" shoreline/no-text-property
54+
```

packages/stylelint/src/plugins/no-text-property/index.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,19 @@ module.exports = stylelint.createPlugin(
3030
if (isAutoFixing) {
3131
const hasShorelinePrefix = decl.value.includes(textTokenPrefix)
3232

33-
const newFontValue = hasShorelinePrefix
33+
const fontValue = hasShorelinePrefix
3434
? decl.value.replace(')', '-font)')
3535
: decl.value
3636

37-
const newLetterSpacingValue = hasShorelinePrefix
38-
? newFontValue.replace('font', 'letter-spacing')
37+
const letterSpacingValue = hasShorelinePrefix
38+
? fontValue.replace('font', 'letter-spacing')
3939
: decl.value
4040

41-
replaceDeclaration(decl, newFontValue, 'font')
41+
replaceDeclaration(decl, fontValue, 'font')
4242

4343
decl.cloneAfter({
4444
prop: 'letter-spacing',
45-
value: newLetterSpacingValue,
45+
value: letterSpacingValue,
4646
})
4747
} else {
4848
report({

0 commit comments

Comments
 (0)