@taiga-ui/stylelint-config 0.429.0 → 0.431.0

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/index.js CHANGED
@@ -4,6 +4,7 @@ module.exports = {
4
4
  $schema:
5
5
  'https://raw.githubusercontent.com/SchemaStore/schemastore/master/src/schemas/json/stylelintrc.json',
6
6
  plugins: [
7
+ './relative-less-import-extension.js',
7
8
  'stylelint-order',
8
9
  'stylelint-rem-over-px',
9
10
  'stylelint-use-logical',
@@ -33,6 +34,7 @@ module.exports = {
33
34
  '@stylistic/selector-pseudo-class-parentheses-space-inside': null,
34
35
  '@stylistic/string-quotes': 'single',
35
36
  '@stylistic/value-list-comma-newline-after': null,
37
+ '@taiga-ui/relative-less-import-extension': true,
36
38
  'alpha-value-notation': 'number',
37
39
  'annotation-no-unknown': true,
38
40
  'at-rule-allowed-list': [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@taiga-ui/stylelint-config",
3
- "version": "0.429.0",
3
+ "version": "0.431.0",
4
4
  "description": "Taiga UI stylelint config",
5
5
  "keywords": [
6
6
  "stylelint",
@@ -8,22 +8,40 @@
8
8
  ],
9
9
  "repository": {
10
10
  "type": "git",
11
- "url": "https://github.com/taiga-family/configurations.git"
11
+ "url": "https://github.com/taiga-family/toolkit.git"
12
12
  },
13
13
  "license": "Apache-2.0",
14
+ "contributors": [
15
+ {
16
+ "name": "Alex Inkin",
17
+ "email": "alexander@inkin.ru"
18
+ },
19
+ {
20
+ "name": "Maksim Ivanov",
21
+ "email": "splincodewd@yandex.ru"
22
+ },
23
+ {
24
+ "name": "Vladimir Potekhin",
25
+ "email": "vladimir.potekh@gmail.com"
26
+ },
27
+ {
28
+ "name": "Nikita Barsukov",
29
+ "email": "nikita.s.barsukov@gmail.com"
30
+ }
31
+ ],
14
32
  "main": "index.js",
15
33
  "peerDependencies": {
16
34
  "@stylistic/stylelint-config": "^4.0.0",
17
35
  "@stylistic/stylelint-plugin": "^5.0.1",
18
- "@taiga-ui/browserslist-config": "0.429.0",
19
- "postcss": "^8.5.6",
36
+ "@taiga-ui/browserslist-config": "0.431.0",
37
+ "postcss": "^8.5.8",
20
38
  "postcss-less": "^6.0.0",
21
- "stylelint": "^17.3.0",
39
+ "stylelint": "^17.4.0",
22
40
  "stylelint-config-standard": "^40.0.0",
23
41
  "stylelint-no-unsupported-browser-features": "^8.1.1",
24
- "stylelint-order": "^7.0.1",
25
- "stylelint-plugin-logical-css": "^1.3.0",
26
- "stylelint-plugin-use-baseline": "^1.2.2",
42
+ "stylelint-order": "^8.1.1",
43
+ "stylelint-plugin-logical-css": "^2.0.2",
44
+ "stylelint-plugin-use-baseline": "^1.2.7",
27
45
  "stylelint-rem-over-px": "^1.0.2",
28
46
  "stylelint-use-logical": "^2.1.3"
29
47
  },
@@ -0,0 +1,136 @@
1
+ const path = require('node:path');
2
+ const stylelint = require('stylelint');
3
+
4
+ const {
5
+ createPlugin,
6
+ utils: {report, ruleMessages, validateOptions},
7
+ } = stylelint;
8
+
9
+ const ruleName = '@taiga-ui/relative-less-import-extension';
10
+ const messages = ruleMessages(ruleName, {
11
+ expected: (actual, expected) => `Expected "${actual}" to be "${expected}"`,
12
+ });
13
+
14
+ const meta = {
15
+ fixable: true,
16
+ };
17
+
18
+ function getExpectedExtension(root) {
19
+ const file = root.source && root.source.input && root.source.input.file;
20
+
21
+ if (!file) {
22
+ return '.less';
23
+ }
24
+
25
+ const ext = path.extname(file).toLowerCase();
26
+
27
+ if (ext === '.scss' || ext === '.css' || ext === '.less') {
28
+ return ext;
29
+ }
30
+
31
+ return '.less';
32
+ }
33
+
34
+ function hasKnownStyleExtension(value) {
35
+ return /\.(?:less|scss|css)(?:\?.*)?$/i.test(value);
36
+ }
37
+
38
+ function isExternalImport(value) {
39
+ return (
40
+ value.startsWith('@') ||
41
+ value.startsWith('~') ||
42
+ value.startsWith('/') ||
43
+ value.startsWith('//') ||
44
+ /^https?:/i.test(value) ||
45
+ /^data:/i.test(value)
46
+ );
47
+ }
48
+
49
+ function isUrlImport(params) {
50
+ return /^url\(/i.test(params.trim());
51
+ }
52
+
53
+ function isLocalImportPath(value) {
54
+ if (!value) {
55
+ return false;
56
+ }
57
+
58
+ if (isExternalImport(value)) {
59
+ return false;
60
+ }
61
+
62
+ return true;
63
+ }
64
+
65
+ function splitQueryAndHash(value) {
66
+ const match = value.match(/^([^?#]+)([?#].*)?$/);
67
+
68
+ return {
69
+ pathname: match ? match[1] : value,
70
+ suffix: match ? match[2] || '' : '',
71
+ };
72
+ }
73
+
74
+ /** @type {import('stylelint').Rule} */
75
+ const ruleFunction = (primary) => {
76
+ return (root, result) => {
77
+ const validOptions = validateOptions(result, ruleName, {
78
+ actual: primary,
79
+ possible: [true],
80
+ });
81
+
82
+ if (!validOptions) {
83
+ return;
84
+ }
85
+
86
+ const expectedExtension = getExpectedExtension(root);
87
+
88
+ root.walkAtRules('import', (atRule) => {
89
+ const params = atRule.params.trim();
90
+
91
+ if (isUrlImport(params)) {
92
+ return;
93
+ }
94
+
95
+ const match = params.match(/^(['"])([^'"]+)\1(.*)$/);
96
+
97
+ if (!match) {
98
+ return;
99
+ }
100
+
101
+ const [, quote, rawImportPath, tail] = match;
102
+
103
+ if (!isLocalImportPath(rawImportPath)) {
104
+ return;
105
+ }
106
+
107
+ const {pathname, suffix} = splitQueryAndHash(rawImportPath);
108
+
109
+ if (hasKnownStyleExtension(pathname)) {
110
+ return;
111
+ }
112
+
113
+ const fixedPath = `${pathname}${expectedExtension}${suffix}`;
114
+ const fixedParams = `${quote}${fixedPath}${quote}${tail}`;
115
+
116
+ report({
117
+ fix: () => {
118
+ atRule.params = fixedParams;
119
+ },
120
+ message: messages.expected(rawImportPath, fixedPath),
121
+ node: atRule,
122
+ result,
123
+ ruleName,
124
+ });
125
+ });
126
+ };
127
+ };
128
+
129
+ ruleFunction.ruleName = ruleName;
130
+ ruleFunction.messages = messages;
131
+ ruleFunction.meta = meta;
132
+
133
+ module.exports = createPlugin(ruleName, ruleFunction);
134
+ module.exports.ruleName = ruleName;
135
+ module.exports.messages = messages;
136
+ module.exports.meta = meta;