@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/utils.js
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
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.getPackageVersion = exports.tokenExists = exports.addTokens = exports.flattenObject = exports.vendorUnprefixed = exports.testAgainstStringOrRegExp = exports.testAgainstStringOrRegExpOrArray = exports.matchesStringOrRegExp = exports.isCustomProperty = void 0;
|
|
7
|
+
const node_fs_1 = require("node:fs");
|
|
8
|
+
const postcss_value_parser_1 = __importDefault(require("postcss-value-parser"));
|
|
9
|
+
const isCustomProperty = (property) => {
|
|
10
|
+
return property.startsWith("--");
|
|
11
|
+
};
|
|
12
|
+
exports.isCustomProperty = isCustomProperty;
|
|
13
|
+
const matchesStringOrRegExp = (input, comparison) => {
|
|
14
|
+
if (!Array.isArray(input)) {
|
|
15
|
+
return (0, exports.testAgainstStringOrRegExpOrArray)(input, comparison);
|
|
16
|
+
}
|
|
17
|
+
for (const inputItem of input) {
|
|
18
|
+
const testResult = (0, exports.testAgainstStringOrRegExpOrArray)(inputItem, comparison);
|
|
19
|
+
if (testResult) {
|
|
20
|
+
return testResult;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return false;
|
|
24
|
+
};
|
|
25
|
+
exports.matchesStringOrRegExp = matchesStringOrRegExp;
|
|
26
|
+
const testAgainstStringOrRegExpOrArray = (value, comparison) => {
|
|
27
|
+
if (!Array.isArray(comparison)) {
|
|
28
|
+
return (0, exports.testAgainstStringOrRegExp)(value, comparison);
|
|
29
|
+
}
|
|
30
|
+
for (const comparisonItem of comparison) {
|
|
31
|
+
const testResult = (0, exports.testAgainstStringOrRegExp)(value, comparisonItem);
|
|
32
|
+
if (testResult) {
|
|
33
|
+
return testResult;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return false;
|
|
37
|
+
};
|
|
38
|
+
exports.testAgainstStringOrRegExpOrArray = testAgainstStringOrRegExpOrArray;
|
|
39
|
+
const testAgainstStringOrRegExp = (value, comparison) => {
|
|
40
|
+
// If it's a RegExp, test directly
|
|
41
|
+
if (comparison instanceof RegExp) {
|
|
42
|
+
return comparison.test(value)
|
|
43
|
+
? { match: value, pattern: comparison }
|
|
44
|
+
: false;
|
|
45
|
+
}
|
|
46
|
+
// Check if it's RegExp in a string
|
|
47
|
+
const firstComparisonChar = comparison[0];
|
|
48
|
+
const lastComparisonChar = comparison[comparison.length - 1];
|
|
49
|
+
const secondToLastComparisonChar = comparison[comparison.length - 2];
|
|
50
|
+
const comparisonIsRegex = firstComparisonChar === "/" &&
|
|
51
|
+
(lastComparisonChar === "/" ||
|
|
52
|
+
(secondToLastComparisonChar === "/" && lastComparisonChar === "i"));
|
|
53
|
+
const hasCaseInsensitiveFlag = comparisonIsRegex && lastComparisonChar === "i";
|
|
54
|
+
// If so, create a new RegExp from it
|
|
55
|
+
if (comparisonIsRegex) {
|
|
56
|
+
const valueMatches = hasCaseInsensitiveFlag
|
|
57
|
+
? new RegExp(comparison.slice(1, -2), "i").test(value)
|
|
58
|
+
: new RegExp(comparison.slice(1, -1)).test(value);
|
|
59
|
+
return valueMatches ? { match: value, pattern: comparison } : false;
|
|
60
|
+
}
|
|
61
|
+
// Otherwise, it's a string. Do a strict comparison
|
|
62
|
+
return value === comparison ? { match: value, pattern: comparison } : false;
|
|
63
|
+
};
|
|
64
|
+
exports.testAgainstStringOrRegExp = testAgainstStringOrRegExp;
|
|
65
|
+
const vendorUnprefixed = (prop) => {
|
|
66
|
+
return prop.replace(/^-\w+-/, "");
|
|
67
|
+
};
|
|
68
|
+
exports.vendorUnprefixed = vendorUnprefixed;
|
|
69
|
+
const flattenObject = (obj) => {
|
|
70
|
+
const flattened = Object.keys(obj).reduce((acc, key) => {
|
|
71
|
+
if (typeof obj[key] === "string") {
|
|
72
|
+
acc.push(key);
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
acc.push((0, exports.flattenObject)(obj[key]));
|
|
76
|
+
}
|
|
77
|
+
return acc;
|
|
78
|
+
}, []);
|
|
79
|
+
return flattened.flat();
|
|
80
|
+
};
|
|
81
|
+
exports.flattenObject = flattenObject;
|
|
82
|
+
const tokenCSSFile = "./index.css";
|
|
83
|
+
const tokenJsonFile = "./tokens.json";
|
|
84
|
+
const internalTokensJSONFile = "./internal-tokens.json";
|
|
85
|
+
let allowedTokenNames = [];
|
|
86
|
+
const addTokens = (tokenJSONFile, allowedTokenNames) => {
|
|
87
|
+
const jsonFileBuffer = (0, node_fs_1.readFileSync)(`${__dirname}/${tokenJSONFile}`);
|
|
88
|
+
const fileString = jsonFileBuffer.toString();
|
|
89
|
+
const flattened = (0, exports.flattenObject)(JSON.parse(fileString));
|
|
90
|
+
flattened.forEach((token) => allowedTokenNames.push(token));
|
|
91
|
+
};
|
|
92
|
+
exports.addTokens = addTokens;
|
|
93
|
+
const tokenExists = (controlledPrefixes, inputToken) => {
|
|
94
|
+
// "singleton" if statement (attempt at caching file parsing)
|
|
95
|
+
if (!allowedTokenNames.length) {
|
|
96
|
+
const cssFileBuffer = (0, node_fs_1.readFileSync)(`${__dirname}/${tokenCSSFile}`);
|
|
97
|
+
const cssFileString = cssFileBuffer.toString();
|
|
98
|
+
(0, postcss_value_parser_1.default)(cssFileString).walk((node) => {
|
|
99
|
+
if (node.type === "word" &&
|
|
100
|
+
(0, exports.isCustomProperty)(node.value) &&
|
|
101
|
+
controlledPrefixes.some((prefix) => node.value.startsWith(prefix))) {
|
|
102
|
+
allowedTokenNames.push(node.value);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
(0, exports.addTokens)(tokenJsonFile, allowedTokenNames);
|
|
106
|
+
(0, exports.addTokens)(internalTokensJSONFile, allowedTokenNames);
|
|
107
|
+
}
|
|
108
|
+
return allowedTokenNames.includes(inputToken);
|
|
109
|
+
};
|
|
110
|
+
exports.tokenExists = tokenExists;
|
|
111
|
+
const packageJson = JSON.parse((0, node_fs_1.readFileSync)(`${__dirname}/../package.json`).toString());
|
|
112
|
+
const getPackageVersion = () => {
|
|
113
|
+
return packageJson.version;
|
|
114
|
+
};
|
|
115
|
+
exports.getPackageVersion = getPackageVersion;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@navikt/aksel-stylelint",
|
|
3
|
-
"version": "3.4.
|
|
3
|
+
"version": "3.4.1",
|
|
4
4
|
"author": "Aksel | NAV",
|
|
5
5
|
"homepage": "https://aksel.nav.no/grunnleggende/kode/stylelint",
|
|
6
6
|
"repository": {
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"./recommended": "./dist/recommended.js"
|
|
24
24
|
},
|
|
25
25
|
"files": [
|
|
26
|
-
"
|
|
26
|
+
"/dist"
|
|
27
27
|
],
|
|
28
28
|
"scripts": {
|
|
29
29
|
"test": "jest",
|
|
@@ -36,8 +36,8 @@
|
|
|
36
36
|
"dev": "yarn watch:lint"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@navikt/ds-css": "^3.4.
|
|
40
|
-
"@navikt/ds-tokens": "^3.4.
|
|
39
|
+
"@navikt/ds-css": "^3.4.1",
|
|
40
|
+
"@navikt/ds-tokens": "^3.4.1",
|
|
41
41
|
"@types/jest": "^29.0.0",
|
|
42
42
|
"concurrently": "7.2.1",
|
|
43
43
|
"copyfiles": "2.4.1",
|