-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path.stylelintrc.js
53 lines (50 loc) · 2.31 KB
/
.stylelintrc.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// @ts-check
const HopperCSSVarRegex = /^hop-([A-Z][A-z0-9]+)(-[a-z0-9]+)*$/;
const NormalKebabCaseRegex = /^[a-z0-9]+(-[a-z0-9]+)*$/;
// we can't enforce that someone doesn't do --hop-button instead of --hop-Button, because it's too hard to know what is
// a component and what is a token, such as --hop-primary-color. So we'll just allow any kebab-case variable name.
const AllowedCSSVarsRegex = new RegExp(`^(${HopperCSSVarRegex.source}|${NormalKebabCaseRegex.source})$`);
/** @type {import('stylelint').Config} */
const config = {
extends: "@workleap/stylelint-configs",
overrides: [
{
files: ["./packages/**/*.css"],
plugins: ["stylelint-use-logical"],
extends: [
"stylelint-config-clean-order" // This is a plugin that enforces a consistent order of CSS properties
],
rules: {
// We want to enforce the use of logical properties
"csstools/use-logical": true,
"selector-class-pattern": [
/** Selector that ensures our classNames have the pattern hop-ComponentName__element-name--modifier-name */
"^hop-([A-Z][A-z0-9]+)([-]?[a-z0-9]+)*(__[a-z0-9]([-]?[a-z0-9]+)*)?(--[a-z0-9]([-]?[a-z0-9]+)*)?$",
{
resolveNestedSelectors: true,
message: selectorValue => `Expected class selector "${selectorValue}" to match our CSS pattern https://github.com/gsoft-inc/wl-hopper/blob/main/CONTRIBUTING.md#css-selector-naming-conventions. Selector validation tool: https://regexr.com/7tftf`
}
],
"custom-property-pattern": [
AllowedCSSVarsRegex.source,
{
"message": "Expected css variables to be kebab-case or hop-ComponentName-kebab-case"
}
],
"property-no-unknown": [
true,
{
ignoreProperties: ["/composes/"]
}
],
"value-keyword-case": [
"lower",
{
ignoreKeywords: ["/^hop-.*$/"]
}
]
}
}
]
};
export default config;