@navikt/aksel-stylelint 3.4.0 → 3.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/deprecations.js +9 -0
- package/dist/index.css +4663 -0
- package/dist/index.js +8 -0
- package/dist/internal-tokens.json +48 -0
- package/dist/recommended.js +11 -0
- package/dist/rules/aksel-design-token-exists/index.js +72 -0
- package/dist/rules/aksel-design-token-exists/index.test.js +115 -0
- package/dist/rules/aksel-design-token-no-component-reference/index.js +49 -0
- package/dist/rules/aksel-design-token-no-component-reference/index.test.js +53 -0
- package/dist/rules/aksel-design-token-no-global-override/index.js +47 -0
- package/dist/rules/aksel-design-token-no-global-override/index.test.js +66 -0
- package/dist/rules/aksel-no-class-override/index.js +41 -0
- package/dist/rules/aksel-no-class-override/index.test.js +53 -0
- package/dist/rules/aksel-no-deprecated-classes/index.js +40 -0
- package/dist/rules/aksel-no-deprecated-classes/index.test.js +60 -0
- package/dist/rules/aksel-no-internal-tokens/index.js +56 -0
- package/dist/rules/aksel-no-internal-tokens/index.test.js +102 -0
- package/dist/rules/index.js +20 -0
- package/dist/tokens.json +395 -0
- package/dist/utils.js +115 -0
- package/package.json +4 -4
package/dist/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const stylelint_1 = require("stylelint");
|
|
4
|
+
const rules_1 = require("./rules");
|
|
5
|
+
const rulesPlugins = Object.keys(rules_1.rules).map((ruleName) => {
|
|
6
|
+
return (0, stylelint_1.createPlugin)(`${ruleName}`, rules_1.rules[ruleName]);
|
|
7
|
+
});
|
|
8
|
+
exports.default = rulesPlugins;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"copytoclipboard": {
|
|
3
|
+
"--ac-copy-to-clipboard-text": "--a-text-default"
|
|
4
|
+
},
|
|
5
|
+
"dropdown": {
|
|
6
|
+
"--ac-dropdown-text": "--a-text-default",
|
|
7
|
+
"--ac-dropdown-border": "--a-border-default",
|
|
8
|
+
"--ac-dropdown-item-text": "--a-text-action",
|
|
9
|
+
"--ac-dropdown-item-hover-bg": "--a-surface-action-subtle-hover",
|
|
10
|
+
"--ac-dropdown-item-active-bg": "--a-surface-action-active",
|
|
11
|
+
"--ac-dropdown-item-active-text": "--a-text-on-active"
|
|
12
|
+
},
|
|
13
|
+
"header": {
|
|
14
|
+
"--ac-header-bg": "--a-surface-inverted",
|
|
15
|
+
"--ac-header-divider": "--a-gray-600",
|
|
16
|
+
"--ac-header-text": "--a-text-on-inverted",
|
|
17
|
+
"--ac-header-hover-bg": "--a-surface-inverted-hover",
|
|
18
|
+
"--ac-header-active-bg": "--a-surface-inverted-active"
|
|
19
|
+
},
|
|
20
|
+
"timeline": {
|
|
21
|
+
"--ac-timeline-row-bg": "--a-surface-subtle",
|
|
22
|
+
"--ac-timeline-row-active-bg": "--a-surface-selected",
|
|
23
|
+
"--ac-timeline-period-success-bg": "--a-surface-success-subtle",
|
|
24
|
+
"--ac-timeline-period-success-border": "--a-border-success",
|
|
25
|
+
"--ac-timeline-period-success-bg-hover": "--a-surface-success-subtle-hover",
|
|
26
|
+
"--ac-timeline-period-warning-bg": "--a-surface-warning-subtle",
|
|
27
|
+
"--ac-timeline-period-warning-border": "--a-border-warning",
|
|
28
|
+
"--ac-timeline-period-warning-bg-hover": "--a-surface-warning-subtle-hover",
|
|
29
|
+
"--ac-timeline-period-danger-bg": "--a-surface-danger-subtle",
|
|
30
|
+
"--ac-timeline-period-danger-border": "--a-border-danger",
|
|
31
|
+
"--ac-timeline-period-danger-bg-hover": "--a-surface-danger-subtle-hover",
|
|
32
|
+
"--ac-timeline-period-info-bg": "--a-surface-info-subtle",
|
|
33
|
+
"--ac-timeline-period-info-border": "--a-border-info",
|
|
34
|
+
"--ac-timeline-period-info-bg-hover": "--a-surface-info-subtle-hover",
|
|
35
|
+
"--ac-timeline-period-neutral-bg": "--a-bg-subtle",
|
|
36
|
+
"--ac-timeline-period-neutral-border": "--a-border-default",
|
|
37
|
+
"--ac-timeline-period-neutral-bg-hover": "--a-gray-200",
|
|
38
|
+
"--ac-timeline-period-selected-border": "--a-border-action-selected",
|
|
39
|
+
"--ac-timeline-pin-bg": "--a-surface-danger",
|
|
40
|
+
"--ac-timeline-pin-bg-hover": "--a-surface-danger-hover",
|
|
41
|
+
"--ac-timeline-zoom-border": "--a-border-default",
|
|
42
|
+
"--ac-timeline-zoom-bg": "--a-surface-default",
|
|
43
|
+
"--ac-timeline-zoom-bg-hover": "--a-surface-action-subtle-hover",
|
|
44
|
+
"--ac-timeline-zoom-selected-bg": "--a-surface-inverted",
|
|
45
|
+
"--ac-timeline-zoom-selected-text": "--a-text-on-inverted",
|
|
46
|
+
"--ac-timeline-axislabel-text": "--a-text-subtle"
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
plugins: ["."],
|
|
3
|
+
rules: {
|
|
4
|
+
"aksel/design-token-exists": true,
|
|
5
|
+
"aksel/no-internal-tokens": true,
|
|
6
|
+
"aksel/no-class-override": [true, { severity: "warning" }],
|
|
7
|
+
"aksel/no-deprecated-classes": true,
|
|
8
|
+
"aksel/design-token-no-global-override": true,
|
|
9
|
+
"aksel/design-token-no-component-reference": true,
|
|
10
|
+
},
|
|
11
|
+
};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.messages = exports.controlledPrefixes = void 0;
|
|
7
|
+
const stylelint_1 = __importDefault(require("stylelint"));
|
|
8
|
+
const postcss_value_parser_1 = __importDefault(require("postcss-value-parser"));
|
|
9
|
+
const node_fs_1 = require("node:fs");
|
|
10
|
+
const utils_1 = require("../../utils");
|
|
11
|
+
const packageJson = JSON.parse((0, node_fs_1.readFileSync)(`${__dirname}/../../../package.json`).toString());
|
|
12
|
+
const ruleName = "aksel/design-token-exists";
|
|
13
|
+
const prefix_a = "--a-";
|
|
14
|
+
const prefix_ac = "--ac-";
|
|
15
|
+
exports.controlledPrefixes = [prefix_a, prefix_ac];
|
|
16
|
+
const packageVersion = packageJson.version;
|
|
17
|
+
exports.messages = stylelint_1.default.utils.ruleMessages(ruleName, {
|
|
18
|
+
propNotExist: (node) => `("${node.prop}") does not exist in the design system.\n\n` +
|
|
19
|
+
`Property "${node.prop}" has a name that seems like it intends to override a design token by ` +
|
|
20
|
+
`using one of the following prefixes [${exports.controlledPrefixes}]. ` +
|
|
21
|
+
`However, that token doesn"t seem to exist in the design system. ` +
|
|
22
|
+
`\n\nVersion: ${packageVersion}`,
|
|
23
|
+
valueNotExist: (node, invalidValues) => `("${invalidValues}") does not exist in the design system.\n\n` +
|
|
24
|
+
`Property "${node.prop}" has offending value "${invalidValues}", ` +
|
|
25
|
+
`and the value seems like it intends to reference a design token by ` +
|
|
26
|
+
`using one of the following prefixes [${exports.controlledPrefixes}]. ` +
|
|
27
|
+
`However, that token doesn't seem to exist in the design system. ` +
|
|
28
|
+
`\n\nVersion: ${packageVersion}`,
|
|
29
|
+
});
|
|
30
|
+
const checkDeclValue = (controlledPrefixes, value, postcssResult, rootNode) => {
|
|
31
|
+
(0, postcss_value_parser_1.default)(value).walk((node) => {
|
|
32
|
+
if (node.type === "word" &&
|
|
33
|
+
(0, utils_1.isCustomProperty)(node.value) &&
|
|
34
|
+
controlledPrefixes.some((prefix) => node.value.startsWith(prefix)) &&
|
|
35
|
+
!(0, utils_1.tokenExists)(controlledPrefixes, node.value)) {
|
|
36
|
+
stylelint_1.default.utils.report({
|
|
37
|
+
message: exports.messages.valueNotExist(rootNode, node.value),
|
|
38
|
+
node: rootNode,
|
|
39
|
+
result: postcssResult,
|
|
40
|
+
ruleName,
|
|
41
|
+
word: node.value,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
const checkDeclProp = (controlledPrefixes, prop, postcssResult, rootNode) => {
|
|
47
|
+
if ((0, utils_1.isCustomProperty)(prop) &&
|
|
48
|
+
controlledPrefixes.some((prefix) => prop.startsWith(prefix)) &&
|
|
49
|
+
!(0, utils_1.tokenExists)(controlledPrefixes, prop)) {
|
|
50
|
+
stylelint_1.default.utils.report({
|
|
51
|
+
message: exports.messages.propNotExist(rootNode),
|
|
52
|
+
node: rootNode,
|
|
53
|
+
result: postcssResult,
|
|
54
|
+
ruleName,
|
|
55
|
+
word: prop,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
const ruleFunction = () => {
|
|
60
|
+
return (postcssRoot, postcssResult) => {
|
|
61
|
+
postcssRoot.walkDecls((node) => {
|
|
62
|
+
checkDeclValue(exports.controlledPrefixes, node.value, postcssResult, node);
|
|
63
|
+
checkDeclProp(exports.controlledPrefixes, node.prop, postcssResult, node);
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
ruleFunction.ruleName = ruleName;
|
|
68
|
+
ruleFunction.messages = {};
|
|
69
|
+
ruleFunction.meta = {
|
|
70
|
+
url: `https://github.com/navikt/aksel/blob/main/%40navikt/aksel-stylelint/README.md#${ruleName}`,
|
|
71
|
+
};
|
|
72
|
+
exports.default = ruleFunction;
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
const jest_preset_stylelint_1 = require("jest-preset-stylelint");
|
|
27
|
+
const _1 = __importStar(require("."));
|
|
28
|
+
(0, jest_preset_stylelint_1.getTestRule)()({
|
|
29
|
+
plugins: ["./dist/index.js"],
|
|
30
|
+
ruleName: _1.default.ruleName,
|
|
31
|
+
config: true,
|
|
32
|
+
accept: [
|
|
33
|
+
{
|
|
34
|
+
code: ".foo { --ac-accordion-header-bg-hover: 1px; --ac-header-bg: red; }",
|
|
35
|
+
description: "existing '--ac-' tokens overridden",
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
code: ".foo { --my-custom-color: var(--a-orange-800); }",
|
|
39
|
+
description: "existing '--a-' token referenced",
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
reject: [
|
|
43
|
+
{
|
|
44
|
+
code: ".foo { --a-does-not-exist: 1px }",
|
|
45
|
+
description: "attempt to override nonexistent '--a-' token",
|
|
46
|
+
warnings: [
|
|
47
|
+
{
|
|
48
|
+
message: _1.messages.propNotExist({ prop: "--a-does-not-exist" }),
|
|
49
|
+
line: 1,
|
|
50
|
+
endLine: 1,
|
|
51
|
+
column: 8,
|
|
52
|
+
endColumn: 26,
|
|
53
|
+
},
|
|
54
|
+
],
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
code: ".foo \n { \n --ac-does-not-exist: 1px; \n }",
|
|
58
|
+
description: "attempt to override nonexistent '--ac-' token",
|
|
59
|
+
message: _1.messages.propNotExist({ prop: "--ac-does-not-exist" }),
|
|
60
|
+
line: 3,
|
|
61
|
+
endLine: 3,
|
|
62
|
+
column: 2,
|
|
63
|
+
endColumn: 21,
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
code: ".foo { color: var(--a-bar) }",
|
|
67
|
+
description: "attempt to use nonexistent token",
|
|
68
|
+
message: _1.messages.valueNotExist({ prop: "color" }, "--a-bar"),
|
|
69
|
+
line: 1,
|
|
70
|
+
endLine: 1,
|
|
71
|
+
column: 19,
|
|
72
|
+
endColumn: 26,
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
code: ".foo { width: var(--ac-bar, --a-baz) }",
|
|
76
|
+
description: "attempt to use two nonexistent tokens in one var()",
|
|
77
|
+
warnings: [
|
|
78
|
+
{
|
|
79
|
+
message: _1.messages.valueNotExist({ prop: "width" }, "--ac-bar"),
|
|
80
|
+
line: 1,
|
|
81
|
+
endLine: 1,
|
|
82
|
+
column: 19,
|
|
83
|
+
endColumn: 27,
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
message: _1.messages.valueNotExist({ prop: "width" }, "--a-baz"),
|
|
87
|
+
line: 1,
|
|
88
|
+
endLine: 1,
|
|
89
|
+
column: 29,
|
|
90
|
+
endColumn: 36,
|
|
91
|
+
},
|
|
92
|
+
],
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
code: ".foo { padding: var(--a-bar) var(--a-baz); }",
|
|
96
|
+
description: "attempt to use two nonexistent tokens as separate vars",
|
|
97
|
+
warnings: [
|
|
98
|
+
{
|
|
99
|
+
message: _1.messages.valueNotExist({ prop: "padding" }, "--a-bar"),
|
|
100
|
+
line: 1,
|
|
101
|
+
endLine: 1,
|
|
102
|
+
column: 21,
|
|
103
|
+
endColumn: 28,
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
message: _1.messages.valueNotExist({ prop: "padding" }, "--a-baz"),
|
|
107
|
+
line: 1,
|
|
108
|
+
endLine: 1,
|
|
109
|
+
column: 34,
|
|
110
|
+
endColumn: 41,
|
|
111
|
+
},
|
|
112
|
+
],
|
|
113
|
+
},
|
|
114
|
+
],
|
|
115
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.messages = void 0;
|
|
7
|
+
const stylelint_1 = __importDefault(require("stylelint"));
|
|
8
|
+
const postcss_value_parser_1 = __importDefault(require("postcss-value-parser"));
|
|
9
|
+
const utils_1 = require("../../utils");
|
|
10
|
+
const ruleName = "aksel/design-token-no-component-reference";
|
|
11
|
+
const packageVersion = (0, utils_1.getPackageVersion)();
|
|
12
|
+
const prefix_ac = "--ac-";
|
|
13
|
+
exports.messages = stylelint_1.default.utils.ruleMessages(ruleName, {
|
|
14
|
+
valueRefComponent: (node, invalidValue) => `Referencing ("${prefix_ac}*") not allowed.\n\n` +
|
|
15
|
+
`Property "${node.prop}" has offending value "${invalidValue}". ` +
|
|
16
|
+
`The value references a component level token ("${prefix_ac}"). ` +
|
|
17
|
+
`It is better to either reference a global level token ("--a-") or ` +
|
|
18
|
+
`create a custom token instead. ` +
|
|
19
|
+
`\n\nVersion: ${packageVersion}`,
|
|
20
|
+
});
|
|
21
|
+
const checkDeclValue = (controlledPrefixes, value, postcssResult, rootNode) => {
|
|
22
|
+
(0, postcss_value_parser_1.default)(value).walk((node) => {
|
|
23
|
+
if (node.type === "word" &&
|
|
24
|
+
(0, utils_1.isCustomProperty)(node.value) &&
|
|
25
|
+
node.value.startsWith(prefix_ac) &&
|
|
26
|
+
(0, utils_1.tokenExists)(controlledPrefixes, node.value)) {
|
|
27
|
+
stylelint_1.default.utils.report({
|
|
28
|
+
message: exports.messages.valueRefComponent(rootNode, node.value),
|
|
29
|
+
node: rootNode,
|
|
30
|
+
result: postcssResult,
|
|
31
|
+
ruleName,
|
|
32
|
+
word: node.value,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
const ruleFunction = () => {
|
|
38
|
+
return (postcssRoot, postcssResult) => {
|
|
39
|
+
postcssRoot.walkDecls((node) => {
|
|
40
|
+
checkDeclValue([prefix_ac], node.value, postcssResult, node);
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
ruleFunction.ruleName = ruleName;
|
|
45
|
+
ruleFunction.messages = {};
|
|
46
|
+
ruleFunction.meta = {
|
|
47
|
+
url: `https://github.com/navikt/aksel/blob/main/%40navikt/aksel-stylelint/README.md#${ruleName}`,
|
|
48
|
+
};
|
|
49
|
+
exports.default = ruleFunction;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
const jest_preset_stylelint_1 = require("jest-preset-stylelint");
|
|
27
|
+
const _1 = __importStar(require("."));
|
|
28
|
+
(0, jest_preset_stylelint_1.getTestRule)()({
|
|
29
|
+
plugins: ["./dist/index.js"],
|
|
30
|
+
ruleName: _1.default.ruleName,
|
|
31
|
+
config: true,
|
|
32
|
+
accept: [
|
|
33
|
+
{
|
|
34
|
+
code: ".foo { --ac-accordion-header-bg-hover: 1px; --ac-header-bg: red; }",
|
|
35
|
+
description: "existing '--ac-' tokens overridden",
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
code: ".foo { --my-custom-color: var(--a-orange-800); }",
|
|
39
|
+
description: "existing '--a-' token referenced",
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
reject: [
|
|
43
|
+
{
|
|
44
|
+
code: ".foo { width: var(--ac-button-padding) }",
|
|
45
|
+
description: "attempt to use '--ac-' token",
|
|
46
|
+
message: _1.messages.valueRefComponent({ prop: "width" }, "--ac-button-padding"),
|
|
47
|
+
line: 1,
|
|
48
|
+
endLine: 1,
|
|
49
|
+
column: 19,
|
|
50
|
+
endColumn: 38,
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.messages = void 0;
|
|
7
|
+
const stylelint_1 = __importDefault(require("stylelint"));
|
|
8
|
+
const node_fs_1 = require("node:fs");
|
|
9
|
+
const utils_1 = require("../../utils");
|
|
10
|
+
const packageJson = JSON.parse((0, node_fs_1.readFileSync)(`${__dirname}/../../../package.json`).toString());
|
|
11
|
+
const ruleName = "aksel/design-token-no-global-override";
|
|
12
|
+
const prefix_a = "--a-";
|
|
13
|
+
const packageVersion = packageJson.version;
|
|
14
|
+
exports.messages = stylelint_1.default.utils.ruleMessages(ruleName, {
|
|
15
|
+
propOverrideGlobal: (node) => `Overriding ("${node.prop}*") not allowed.\n\n` +
|
|
16
|
+
`Property "${node.prop}" tries to override a global level token ("${prefix_a}"), this is highly discouraged. ` +
|
|
17
|
+
`It is better to override a component level token ("--ac-") or create a custom token instead. ` +
|
|
18
|
+
`Overriding global tokens should only be done when creating custom global themes.` +
|
|
19
|
+
`\n\nVersion: ${packageVersion}`,
|
|
20
|
+
});
|
|
21
|
+
const checkDeclProp = (controlledPrefixes, prop, postcssResult, rootNode) => {
|
|
22
|
+
if ((0, utils_1.isCustomProperty)(prop) &&
|
|
23
|
+
controlledPrefixes.some((prefix) => prop.startsWith(prefix))) {
|
|
24
|
+
if (prop.startsWith(prefix_a)) {
|
|
25
|
+
stylelint_1.default.utils.report({
|
|
26
|
+
message: exports.messages.propOverrideGlobal(rootNode),
|
|
27
|
+
node: rootNode,
|
|
28
|
+
result: postcssResult,
|
|
29
|
+
ruleName,
|
|
30
|
+
word: prop,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
const ruleFunction = () => {
|
|
36
|
+
return (postcssRoot, postcssResult) => {
|
|
37
|
+
postcssRoot.walkDecls((node) => {
|
|
38
|
+
checkDeclProp([prefix_a], node.prop, postcssResult, node);
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
ruleFunction.ruleName = ruleName;
|
|
43
|
+
ruleFunction.messages = {};
|
|
44
|
+
ruleFunction.meta = {
|
|
45
|
+
url: `https://github.com/navikt/aksel/blob/main/%40navikt/aksel-stylelint/README.md#${ruleName}`,
|
|
46
|
+
};
|
|
47
|
+
exports.default = ruleFunction;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
const jest_preset_stylelint_1 = require("jest-preset-stylelint");
|
|
27
|
+
const _1 = __importStar(require("."));
|
|
28
|
+
(0, jest_preset_stylelint_1.getTestRule)()({
|
|
29
|
+
plugins: ["./dist/index.js"],
|
|
30
|
+
ruleName: _1.default.ruleName,
|
|
31
|
+
config: true,
|
|
32
|
+
accept: [
|
|
33
|
+
{
|
|
34
|
+
code: ".foo { --ac-accordion-header-bg-hover: 1px; --ac-header-bg: red; }",
|
|
35
|
+
description: "existing '--ac-' tokens overridden",
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
code: ".foo { --my-custom-color: var(--a-orange-800); }",
|
|
39
|
+
description: "existing '--a-' token referenced",
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
reject: [
|
|
43
|
+
{
|
|
44
|
+
code: ".foo { --a-surface-action: 1px }",
|
|
45
|
+
description: "existing '--a-' token overridden",
|
|
46
|
+
message: _1.messages.propOverrideGlobal({ prop: "--a-surface-action" }),
|
|
47
|
+
line: 1,
|
|
48
|
+
endLine: 1,
|
|
49
|
+
column: 8,
|
|
50
|
+
endColumn: 26,
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
code: ".foo { --a-does-not-exist: 1px }",
|
|
54
|
+
description: "attempt to override nonexistent '--a-' token",
|
|
55
|
+
warnings: [
|
|
56
|
+
{
|
|
57
|
+
message: _1.messages.propOverrideGlobal({ prop: "--a-does-not-exist" }),
|
|
58
|
+
line: 1,
|
|
59
|
+
endLine: 1,
|
|
60
|
+
column: 8,
|
|
61
|
+
endColumn: 26,
|
|
62
|
+
},
|
|
63
|
+
],
|
|
64
|
+
},
|
|
65
|
+
],
|
|
66
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.messages = void 0;
|
|
7
|
+
const stylelint_1 = __importDefault(require("stylelint"));
|
|
8
|
+
const postcss_selector_parser_1 = __importDefault(require("postcss-selector-parser"));
|
|
9
|
+
const ruleName = "aksel/no-class-override";
|
|
10
|
+
const url = "https://github.com/navikt/aksel/blob/main/%40navikt/aksel-stylelint/README.md#aksel/no-class-override";
|
|
11
|
+
const prefixes = ["navds-", "navdsi-"];
|
|
12
|
+
exports.messages = stylelint_1.default.utils.ruleMessages(ruleName, {
|
|
13
|
+
unexpected: (value) => `("${value}") not allowed.\n\n` +
|
|
14
|
+
`"${value}" looks like a class name used in the design system, ` +
|
|
15
|
+
`because it starts with "${prefixes.join('" or "')}". ` +
|
|
16
|
+
"It is not recommended to override the styling in the design system.",
|
|
17
|
+
});
|
|
18
|
+
const ruleFunction = () => {
|
|
19
|
+
return (postcssRoot, postcssResult) => {
|
|
20
|
+
postcssRoot.walkRules((node) => {
|
|
21
|
+
(0, postcss_selector_parser_1.default)((selectors) => {
|
|
22
|
+
selectors.walkClasses((className) => {
|
|
23
|
+
if (!prefixes.some((prefix) => className.value.startsWith(prefix))) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
stylelint_1.default.utils.report({
|
|
27
|
+
message: exports.messages.unexpected(className.value),
|
|
28
|
+
node,
|
|
29
|
+
result: postcssResult,
|
|
30
|
+
ruleName,
|
|
31
|
+
word: className.value,
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
}).processSync(node.selector);
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
ruleFunction.ruleName = ruleName;
|
|
39
|
+
ruleFunction.messages = exports.messages;
|
|
40
|
+
ruleFunction.meta = { url };
|
|
41
|
+
exports.default = ruleFunction;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
const jest_preset_stylelint_1 = require("jest-preset-stylelint");
|
|
27
|
+
const _1 = __importStar(require("."));
|
|
28
|
+
(0, jest_preset_stylelint_1.getTestRule)()({
|
|
29
|
+
plugins: ["./dist/index.js"],
|
|
30
|
+
ruleName: _1.default.ruleName,
|
|
31
|
+
config: true,
|
|
32
|
+
accept: [{ code: ".foo-navds-bar {}", description: "allowed class name" }],
|
|
33
|
+
reject: [
|
|
34
|
+
{
|
|
35
|
+
code: ".foo, \n .navds-button \n .bar {}",
|
|
36
|
+
description: "selector with disallowed class name .navds-*",
|
|
37
|
+
message: _1.messages.unexpected("navds-button"),
|
|
38
|
+
line: 2,
|
|
39
|
+
endLine: 2,
|
|
40
|
+
column: 3,
|
|
41
|
+
endColumn: 15,
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
code: ".foo .navdsi-button \n .bar {}",
|
|
45
|
+
description: "selector with disallowed class name .navdsi-*",
|
|
46
|
+
message: _1.messages.unexpected("navdsi-button"),
|
|
47
|
+
line: 1,
|
|
48
|
+
endLine: 1,
|
|
49
|
+
column: 7,
|
|
50
|
+
endColumn: 20,
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.messages = void 0;
|
|
7
|
+
const stylelint_1 = __importDefault(require("stylelint"));
|
|
8
|
+
const postcss_selector_parser_1 = __importDefault(require("postcss-selector-parser"));
|
|
9
|
+
const deprecations_1 = require("../../deprecations");
|
|
10
|
+
const ruleName = "aksel/no-deprecated-classes";
|
|
11
|
+
const url = "https://github.com/navikt/aksel/blob/main/%40navikt/aksel-stylelint/README.md#aksel/no-deprecated-classes";
|
|
12
|
+
exports.messages = stylelint_1.default.utils.ruleMessages(ruleName, {
|
|
13
|
+
unexpected: (value, secondaryOption) => `Class "${value}" is deprecated. ` + secondaryOption,
|
|
14
|
+
});
|
|
15
|
+
const ruleFunction = () => {
|
|
16
|
+
return (postcssRoot, postcssResult) => {
|
|
17
|
+
postcssRoot.walkRules((node) => {
|
|
18
|
+
(0, postcss_selector_parser_1.default)((selectors) => {
|
|
19
|
+
selectors.walkClasses((className) => {
|
|
20
|
+
for (const deprecation of deprecations_1.deprecations) {
|
|
21
|
+
if (!deprecation.classes.includes(className.value)) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
stylelint_1.default.utils.report({
|
|
25
|
+
message: exports.messages.unexpected(className.value, deprecation.message),
|
|
26
|
+
node,
|
|
27
|
+
result: postcssResult,
|
|
28
|
+
ruleName,
|
|
29
|
+
word: className.value,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}).processSync(node.selector);
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
ruleFunction.ruleName = ruleName;
|
|
38
|
+
ruleFunction.messages = exports.messages;
|
|
39
|
+
ruleFunction.meta = { url };
|
|
40
|
+
exports.default = ruleFunction;
|