@culur/config-stylelint 1.0.0 → 1.0.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/CHANGELOG.md +35 -12
- package/README.md +122 -122
- package/dist/index.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/package.json +10 -10
- package/src/__tests__/dedent.ts +5 -5
- package/src/__tests__/describe-lint-and-fix.ts +61 -0
- package/src/__tests__/describe-rule-or-config.ts +73 -0
- package/src/__tests__/index.ts +8 -5
- package/src/__tests__/mock.ts +36 -36
- package/src/__tests__/spy-on-utils-packages.ts +14 -0
- package/src/__tests__/syntax.ts +11 -11
- package/src/configs/css.test.ts +9 -10
- package/src/configs/css.ts +16 -16
- package/src/configs/scss.test.ts +8 -9
- package/src/configs/scss.ts +11 -11
- package/src/configs/shared.test.ts +8 -9
- package/src/configs/shared.ts +5 -5
- package/src/configs/vue.test.ts +19 -18
- package/src/configs/vue.ts +10 -10
- package/src/factory.test.ts +16 -15
- package/src/factory.ts +23 -23
- package/src/index.test.ts +9 -9
- package/src/index.ts +3 -3
- package/src/rules/at-rule-no-unknown.test.ts +46 -43
- package/src/rules/at-rule-no-unknown.ts +33 -33
- package/src/rules/declaration-block-no-redundant-longhand-properties.test.ts +41 -38
- package/src/rules/declaration-block-no-redundant-longhand-properties.ts +11 -11
- package/src/rules/dollar-variable-pattern.test.ts +26 -27
- package/src/rules/dollar-variable-pattern.ts +18 -18
- package/src/rules/function-no-unknown.test.ts +43 -39
- package/src/rules/function-no-unknown.ts +35 -35
- package/src/rules/order.test.ts +47 -46
- package/src/rules/order.ts +108 -108
- package/src/utils/index.ts +1 -1
- package/src/utils/utils.test.ts +46 -46
- package/src/utils/utils.ts +44 -44
- package/src/__tests__/test-lint-and-fix.ts +0 -55
- package/src/__tests__/test-rule-or-config-value.ts +0 -68
|
@@ -1,38 +1,41 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
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
|
-
margin-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
1
|
+
import * as utilsPackages from '@culur/utils-packages';
|
|
2
|
+
import { assert, expect } from 'vitest';
|
|
3
|
+
import {
|
|
4
|
+
declarationBlockNoRedundantLonghandProperties,
|
|
5
|
+
declarationBlockNoRedundantLonghandPropertiesRule,
|
|
6
|
+
} from './declaration-block-no-redundant-longhand-properties';
|
|
7
|
+
import { css, describeLintAndFix, describeRule } from '~/__tests__';
|
|
8
|
+
|
|
9
|
+
describeRule(
|
|
10
|
+
utilsPackages,
|
|
11
|
+
declarationBlockNoRedundantLonghandPropertiesRule,
|
|
12
|
+
rule => {
|
|
13
|
+
assert(Array.isArray(rule));
|
|
14
|
+
assert(typeof rule[1] === 'object');
|
|
15
|
+
expect(rule[1].ignoreShorthands).toHaveLength(1);
|
|
16
|
+
},
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
describeLintAndFix(
|
|
20
|
+
utilsPackages,
|
|
21
|
+
{
|
|
22
|
+
rules: declarationBlockNoRedundantLonghandProperties,
|
|
23
|
+
},
|
|
24
|
+
[
|
|
25
|
+
{
|
|
26
|
+
code: css`
|
|
27
|
+
a {
|
|
28
|
+
margin-top: 1px;
|
|
29
|
+
margin-right: 2px;
|
|
30
|
+
margin-bottom: 3px;
|
|
31
|
+
margin-left: 4px;
|
|
32
|
+
}
|
|
33
|
+
`,
|
|
34
|
+
fixedCode: css`
|
|
35
|
+
a {
|
|
36
|
+
margin: 1px 2px 3px 4px;
|
|
37
|
+
}
|
|
38
|
+
`,
|
|
39
|
+
},
|
|
40
|
+
],
|
|
41
|
+
);
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { defineRule, defineRules } from '~/utils';
|
|
2
|
-
|
|
3
|
-
export const declarationBlockNoRedundantLonghandPropertiesRule = defineRule<
|
|
4
|
-
true,
|
|
5
|
-
{ ignoreShorthands?: (string | RegExp)[] }
|
|
6
|
-
>([true, { ignoreShorthands: ['grid-template'] }]);
|
|
7
|
-
|
|
8
|
-
export const declarationBlockNoRedundantLonghandProperties = defineRules({
|
|
9
|
-
'declaration-block-no-redundant-longhand-properties':
|
|
10
|
-
declarationBlockNoRedundantLonghandPropertiesRule,
|
|
11
|
-
});
|
|
1
|
+
import { defineRule, defineRules } from '~/utils';
|
|
2
|
+
|
|
3
|
+
export const declarationBlockNoRedundantLonghandPropertiesRule = defineRule<
|
|
4
|
+
true,
|
|
5
|
+
{ ignoreShorthands?: (string | RegExp)[] }
|
|
6
|
+
>([true, { ignoreShorthands: ['grid-template'] }]);
|
|
7
|
+
|
|
8
|
+
export const declarationBlockNoRedundantLonghandProperties = defineRules({
|
|
9
|
+
'declaration-block-no-redundant-longhand-properties':
|
|
10
|
+
declarationBlockNoRedundantLonghandPropertiesRule,
|
|
11
|
+
});
|
|
@@ -1,27 +1,26 @@
|
|
|
1
|
-
import { assert, expectTypeOf } from 'vitest';
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
rule
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
{ isError:
|
|
24
|
-
{ isError: true, code: scss`a { $
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
);
|
|
1
|
+
import { assert, expectTypeOf } from 'vitest';
|
|
2
|
+
import * as utilsPackages from '@culur/utils-packages';
|
|
3
|
+
import {
|
|
4
|
+
dollarVariablePatternRule,
|
|
5
|
+
dollarVariablePatternSCSS,
|
|
6
|
+
} from './dollar-variable-pattern';
|
|
7
|
+
import { describeLintAndFix, describeRule, scss } from '~/__tests__';
|
|
8
|
+
|
|
9
|
+
describeRule(utilsPackages, dollarVariablePatternRule, rule => {
|
|
10
|
+
assert(Array.isArray(rule));
|
|
11
|
+
assert(typeof rule[1] === 'object');
|
|
12
|
+
expectTypeOf(rule[1].message).toBeString();
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
describeLintAndFix(
|
|
16
|
+
utilsPackages,
|
|
17
|
+
{
|
|
18
|
+
extends: ['stylelint-config-standard-scss'],
|
|
19
|
+
rules: dollarVariablePatternSCSS,
|
|
20
|
+
},
|
|
21
|
+
[
|
|
22
|
+
{ isError: false, code: scss`a { $kebab-case: 123; }` },
|
|
23
|
+
{ isError: true, code: scss`a { $snake_case: 123; }` },
|
|
24
|
+
{ isError: true, code: scss`a { $camelCase: 123; }` },
|
|
25
|
+
],
|
|
26
|
+
);
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { defineRule, defineRules } from '~/utils';
|
|
2
|
-
|
|
3
|
-
type PrimaryOption = string;
|
|
4
|
-
interface SecondaryOptions {
|
|
5
|
-
message: string;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export const dollarVariablePatternRule = defineRule<
|
|
9
|
-
PrimaryOption,
|
|
10
|
-
SecondaryOptions
|
|
11
|
-
>([
|
|
12
|
-
'^(-{0,2}?[a-z][a-z0-9]*)(-[a-z0-9]+)*$',
|
|
13
|
-
{ message: 'Expected variable to be kebab-case' },
|
|
14
|
-
]);
|
|
15
|
-
|
|
16
|
-
export const dollarVariablePatternSCSS = defineRules({
|
|
17
|
-
'scss/dollar-variable-pattern': dollarVariablePatternRule,
|
|
18
|
-
});
|
|
1
|
+
import { defineRule, defineRules } from '~/utils';
|
|
2
|
+
|
|
3
|
+
type PrimaryOption = string;
|
|
4
|
+
interface SecondaryOptions {
|
|
5
|
+
message: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export const dollarVariablePatternRule = defineRule<
|
|
9
|
+
PrimaryOption,
|
|
10
|
+
SecondaryOptions
|
|
11
|
+
>([
|
|
12
|
+
'^(-{0,2}?[a-z][a-z0-9]*)(-[a-z0-9]+)*$',
|
|
13
|
+
{ message: 'Expected variable to be kebab-case' },
|
|
14
|
+
]);
|
|
15
|
+
|
|
16
|
+
export const dollarVariablePatternSCSS = defineRules({
|
|
17
|
+
'scss/dollar-variable-pattern': dollarVariablePatternRule,
|
|
18
|
+
});
|
|
@@ -1,39 +1,43 @@
|
|
|
1
|
-
import { assert, expect } from 'vitest';
|
|
2
|
-
import
|
|
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
|
-
|
|
1
|
+
import { assert, expect } from 'vitest';
|
|
2
|
+
import * as utilsPackages from '@culur/utils-packages';
|
|
3
|
+
import {
|
|
4
|
+
functionNoUnknown,
|
|
5
|
+
functionNoUnknownRule,
|
|
6
|
+
} from './function-no-unknown';
|
|
7
|
+
import { describeLintAndFix, describeRule } from '~/__tests__';
|
|
8
|
+
|
|
9
|
+
describeRule(
|
|
10
|
+
utilsPackages,
|
|
11
|
+
functionNoUnknownRule,
|
|
12
|
+
[
|
|
13
|
+
{ hasTailwind: true, hasSass: false, hasVue: false, length: 2 },
|
|
14
|
+
{ hasTailwind: false, hasSass: true, hasVue: false, length: 1 },
|
|
15
|
+
{ hasTailwind: false, hasSass: false, hasVue: true, length: 1 },
|
|
16
|
+
],
|
|
17
|
+
(rule, options) => {
|
|
18
|
+
assert(Array.isArray(rule));
|
|
19
|
+
assert(typeof rule[1] === 'object');
|
|
20
|
+
expect(rule[1].ignoreFunctions).toHaveLength(options.length);
|
|
21
|
+
},
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
describeLintAndFix(
|
|
25
|
+
utilsPackages, //
|
|
26
|
+
() => ({ rules: functionNoUnknown() }),
|
|
27
|
+
[
|
|
28
|
+
{
|
|
29
|
+
isError: true,
|
|
30
|
+
code: 'a { color: unknown(1); }',
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
hasTailwind: true,
|
|
34
|
+
isError: false,
|
|
35
|
+
code: 'a { color: theme(colors.blue.500); }',
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
hasVue: true,
|
|
39
|
+
isError: false,
|
|
40
|
+
code: 'a { color: v-bind(colors); }',
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
);
|
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
import { hasSass, hasTailwind, hasVue } from '@culur/utils-packages';
|
|
2
|
-
import { defineRule, defineRules } from '~/utils';
|
|
3
|
-
|
|
4
|
-
export
|
|
5
|
-
const ignoreFunctions = [
|
|
6
|
-
// https://tailwindcss.com/docs/functions-and-directives#functions
|
|
7
|
-
...(hasTailwind() //
|
|
8
|
-
? ['theme', 'screen']
|
|
9
|
-
: []),
|
|
10
|
-
|
|
11
|
-
// https://sass-lang.com/documentation/modules/list
|
|
12
|
-
// https://sass-lang.com/documentation/modules/math
|
|
13
|
-
// https://sass-lang.com/documentation/modules/color
|
|
14
|
-
...(hasSass() //
|
|
15
|
-
? [/^(list|math|color)\..+/]
|
|
16
|
-
: []),
|
|
17
|
-
|
|
18
|
-
// https://vuejs.org/api/sfc-css-features.html#v-bind-in-css
|
|
19
|
-
...(hasVue() //
|
|
20
|
-
? ['v-bind']
|
|
21
|
-
: []),
|
|
22
|
-
];
|
|
23
|
-
|
|
24
|
-
return defineRule<boolean, { ignoreFunctions?: (string | RegExp)[] }>([
|
|
25
|
-
true,
|
|
26
|
-
ignoreFunctions.length > 0
|
|
27
|
-
? { ignoreFunctions }
|
|
28
|
-
: { ignoreFunctions: undefined },
|
|
29
|
-
]);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export const functionNoUnknown = () =>
|
|
33
|
-
defineRules({
|
|
34
|
-
'function-no-unknown': functionNoUnknownRule(),
|
|
35
|
-
});
|
|
1
|
+
import { hasSass, hasTailwind, hasVue } from '@culur/utils-packages';
|
|
2
|
+
import { defineRule, defineRules } from '~/utils';
|
|
3
|
+
|
|
4
|
+
export function functionNoUnknownRule() {
|
|
5
|
+
const ignoreFunctions = [
|
|
6
|
+
// https://tailwindcss.com/docs/functions-and-directives#functions
|
|
7
|
+
...(hasTailwind() //
|
|
8
|
+
? ['theme', 'screen']
|
|
9
|
+
: []),
|
|
10
|
+
|
|
11
|
+
// https://sass-lang.com/documentation/modules/list
|
|
12
|
+
// https://sass-lang.com/documentation/modules/math
|
|
13
|
+
// https://sass-lang.com/documentation/modules/color
|
|
14
|
+
...(hasSass() //
|
|
15
|
+
? [/^(list|math|color)\..+/]
|
|
16
|
+
: []),
|
|
17
|
+
|
|
18
|
+
// https://vuejs.org/api/sfc-css-features.html#v-bind-in-css
|
|
19
|
+
...(hasVue() //
|
|
20
|
+
? ['v-bind']
|
|
21
|
+
: []),
|
|
22
|
+
];
|
|
23
|
+
|
|
24
|
+
return defineRule<boolean, { ignoreFunctions?: (string | RegExp)[] }>([
|
|
25
|
+
true,
|
|
26
|
+
ignoreFunctions.length > 0
|
|
27
|
+
? { ignoreFunctions }
|
|
28
|
+
: { ignoreFunctions: undefined },
|
|
29
|
+
]);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const functionNoUnknown = () =>
|
|
33
|
+
defineRules({
|
|
34
|
+
'function-no-unknown': functionNoUnknownRule(),
|
|
35
|
+
});
|
package/src/rules/order.test.ts
CHANGED
|
@@ -1,46 +1,47 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
(rule,
|
|
16
|
-
assert(Array.isArray(rule));
|
|
17
|
-
|
|
18
|
-
assert(Array.isArray(rule[0]));
|
|
19
|
-
expect(rule[0]).toHaveLength(
|
|
20
|
-
|
|
21
|
-
assert(typeof rule[1] === 'object');
|
|
22
|
-
expect(rule[1]).toStrictEqual({ unspecified: 'bottom' });
|
|
23
|
-
},
|
|
24
|
-
);
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
plugins: ['stylelint-order'],
|
|
30
|
-
rules:
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
]
|
|
1
|
+
import * as utilsPackages from '@culur/utils-packages';
|
|
2
|
+
import { assert, expect } from 'vitest';
|
|
3
|
+
import { order, orderRule } from './order';
|
|
4
|
+
import { describeLintAndFix, describeRule, scss } from '~/__tests__';
|
|
5
|
+
|
|
6
|
+
describeRule(
|
|
7
|
+
utilsPackages,
|
|
8
|
+
orderRule,
|
|
9
|
+
[
|
|
10
|
+
{ hasTailwind: false, hasSass: false, length: 8 },
|
|
11
|
+
{ hasTailwind: true, hasSass: false, length: 15 },
|
|
12
|
+
{ hasTailwind: false, hasSass: true, length: 16 },
|
|
13
|
+
{ hasTailwind: true, hasSass: true, length: 23 },
|
|
14
|
+
],
|
|
15
|
+
(rule, testCase) => {
|
|
16
|
+
assert(Array.isArray(rule));
|
|
17
|
+
|
|
18
|
+
assert(Array.isArray(rule[0]));
|
|
19
|
+
expect(rule[0]).toHaveLength(testCase.length);
|
|
20
|
+
|
|
21
|
+
assert(typeof rule[1] === 'object');
|
|
22
|
+
expect(rule[1]).toStrictEqual({ unspecified: 'bottom' });
|
|
23
|
+
},
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
describeLintAndFix(
|
|
27
|
+
utilsPackages,
|
|
28
|
+
async () => ({
|
|
29
|
+
plugins: ['stylelint-order'],
|
|
30
|
+
rules: order(),
|
|
31
|
+
}),
|
|
32
|
+
[
|
|
33
|
+
{
|
|
34
|
+
hasTailwind: false,
|
|
35
|
+
hasSass: false,
|
|
36
|
+
code: scss`
|
|
37
|
+
a {
|
|
38
|
+
$variable: 1px;
|
|
39
|
+
--property: 3px;
|
|
40
|
+
@variable: 2px;
|
|
41
|
+
width: 4px;
|
|
42
|
+
}
|
|
43
|
+
`,
|
|
44
|
+
isError: false,
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
);
|
package/src/rules/order.ts
CHANGED
|
@@ -1,108 +1,108 @@
|
|
|
1
|
-
import { hasSass, hasTailwind } from '@culur/utils-packages';
|
|
2
|
-
import { defineRule, defineRules } from '~/utils';
|
|
3
|
-
|
|
4
|
-
// https://github.com/hudochenkov/stylelint-order/blob/master/rules/order/README.md#options
|
|
5
|
-
|
|
6
|
-
type Keyword =
|
|
7
|
-
| 'custom-properties' /**/ // Custom properties (e.g. --property: 10px;)
|
|
8
|
-
| 'dollar-variables' /***/ // Dollar variables (e.g. $variable)
|
|
9
|
-
| 'at-variables' /*******/ // At-variables (e.g. @variable available in Less syntax)
|
|
10
|
-
| 'declarations' /*******/ // CSS declarations (e.g. display: block)
|
|
11
|
-
| 'rules' /**************/ // Nested rules (e.g. a { span {} })
|
|
12
|
-
| 'at-rules' /***********/ // Nested at-rules (e.g. div { @media () {} })
|
|
13
|
-
| 'less-mixins'; /*******/ // Mixins in Less syntax (e.g. .mixin();)
|
|
14
|
-
|
|
15
|
-
interface AtRule {
|
|
16
|
-
type: 'at-rule';
|
|
17
|
-
name?: string;
|
|
18
|
-
parameter?: string | RegExp;
|
|
19
|
-
hasBlock?: boolean;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
interface Rule {
|
|
23
|
-
type: 'rule';
|
|
24
|
-
selector?: string | RegExp;
|
|
25
|
-
name?: string;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
type PrimaryOption = Array<Keyword | AtRule | Rule>;
|
|
29
|
-
interface SecondaryOptions {
|
|
30
|
-
unspecified?: 'top' | 'bottom' | 'ignore';
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* https://sass-lang.com/documentation/at-rules
|
|
35
|
-
*/
|
|
36
|
-
const atRuleScssImport: PrimaryOption = [
|
|
37
|
-
{ type: 'at-rule', name: 'use' },
|
|
38
|
-
{ type: 'at-rule', name: 'forward' },
|
|
39
|
-
{ type: 'at-rule', name: 'import' },
|
|
40
|
-
];
|
|
41
|
-
const atRuleScss: PrimaryOption = [
|
|
42
|
-
{ type: 'at-rule', name: 'function' },
|
|
43
|
-
{ type: 'at-rule', name: 'mixin' },
|
|
44
|
-
{ type: 'at-rule', name: 'extend' },
|
|
45
|
-
{ type: 'at-rule', name: 'include' },
|
|
46
|
-
{ type: 'at-rule', name: 'at-root' },
|
|
47
|
-
];
|
|
48
|
-
|
|
49
|
-
const variables: PrimaryOption = [
|
|
50
|
-
'dollar-variables', // $variable
|
|
51
|
-
'at-variables', // @variable
|
|
52
|
-
'custom-properties', // --property: 10px
|
|
53
|
-
];
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* https://tailwindcss.com/docs/functions-and-directives
|
|
57
|
-
*/
|
|
58
|
-
const atRuleTailwind: PrimaryOption = [
|
|
59
|
-
{ type: 'at-rule', name: 'tailwind' },
|
|
60
|
-
{ type: 'at-rule', name: 'layer' },
|
|
61
|
-
{ type: 'at-rule', name: 'apply' },
|
|
62
|
-
{ type: 'at-rule', name: 'config' },
|
|
63
|
-
];
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* https://v2.tailwindcss.com/docs/functions-and-directives
|
|
67
|
-
*
|
|
68
|
-
* backwards compatible for v2
|
|
69
|
-
*/
|
|
70
|
-
const atRuleTailwindV2: PrimaryOption = [
|
|
71
|
-
{ type: 'at-rule', name: 'variants' },
|
|
72
|
-
{ type: 'at-rule', name: 'responsive' },
|
|
73
|
-
{ type: 'at-rule', name: 'screen' },
|
|
74
|
-
];
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Nested rules (e.g. a { span {} })
|
|
78
|
-
*/
|
|
79
|
-
const rules: PrimaryOption = [
|
|
80
|
-
{
|
|
81
|
-
type: 'rule',
|
|
82
|
-
selector: /^&::[\w-]+/,
|
|
83
|
-
},
|
|
84
|
-
'rules',
|
|
85
|
-
];
|
|
86
|
-
|
|
87
|
-
export const orderRule = () =>
|
|
88
|
-
defineRule<PrimaryOption, SecondaryOptions>([
|
|
89
|
-
[
|
|
90
|
-
...(hasSass() ? atRuleScssImport : []),
|
|
91
|
-
...(hasTailwind() ? atRuleTailwind : []),
|
|
92
|
-
...variables,
|
|
93
|
-
...(hasSass() ? atRuleScss : []),
|
|
94
|
-
...(hasTailwind() ? atRuleTailwindV2 : []),
|
|
95
|
-
'at-rules',
|
|
96
|
-
'less-mixins',
|
|
97
|
-
'declarations',
|
|
98
|
-
...rules,
|
|
99
|
-
],
|
|
100
|
-
{
|
|
101
|
-
unspecified: 'bottom',
|
|
102
|
-
},
|
|
103
|
-
]);
|
|
104
|
-
|
|
105
|
-
export const order = () =>
|
|
106
|
-
defineRules({
|
|
107
|
-
'order/order': orderRule(),
|
|
108
|
-
});
|
|
1
|
+
import { hasSass, hasTailwind } from '@culur/utils-packages';
|
|
2
|
+
import { defineRule, defineRules } from '~/utils';
|
|
3
|
+
|
|
4
|
+
// https://github.com/hudochenkov/stylelint-order/blob/master/rules/order/README.md#options
|
|
5
|
+
|
|
6
|
+
type Keyword =
|
|
7
|
+
| 'custom-properties' /**/ // Custom properties (e.g. --property: 10px;)
|
|
8
|
+
| 'dollar-variables' /***/ // Dollar variables (e.g. $variable)
|
|
9
|
+
| 'at-variables' /*******/ // At-variables (e.g. @variable available in Less syntax)
|
|
10
|
+
| 'declarations' /*******/ // CSS declarations (e.g. display: block)
|
|
11
|
+
| 'rules' /**************/ // Nested rules (e.g. a { span {} })
|
|
12
|
+
| 'at-rules' /***********/ // Nested at-rules (e.g. div { @media () {} })
|
|
13
|
+
| 'less-mixins'; /*******/ // Mixins in Less syntax (e.g. .mixin();)
|
|
14
|
+
|
|
15
|
+
interface AtRule {
|
|
16
|
+
type: 'at-rule';
|
|
17
|
+
name?: string;
|
|
18
|
+
parameter?: string | RegExp;
|
|
19
|
+
hasBlock?: boolean;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
interface Rule {
|
|
23
|
+
type: 'rule';
|
|
24
|
+
selector?: string | RegExp;
|
|
25
|
+
name?: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
type PrimaryOption = Array<Keyword | AtRule | Rule>;
|
|
29
|
+
interface SecondaryOptions {
|
|
30
|
+
unspecified?: 'top' | 'bottom' | 'ignore';
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* https://sass-lang.com/documentation/at-rules
|
|
35
|
+
*/
|
|
36
|
+
const atRuleScssImport: PrimaryOption = [
|
|
37
|
+
{ type: 'at-rule', name: 'use' },
|
|
38
|
+
{ type: 'at-rule', name: 'forward' },
|
|
39
|
+
{ type: 'at-rule', name: 'import' },
|
|
40
|
+
];
|
|
41
|
+
const atRuleScss: PrimaryOption = [
|
|
42
|
+
{ type: 'at-rule', name: 'function' },
|
|
43
|
+
{ type: 'at-rule', name: 'mixin' },
|
|
44
|
+
{ type: 'at-rule', name: 'extend' },
|
|
45
|
+
{ type: 'at-rule', name: 'include' },
|
|
46
|
+
{ type: 'at-rule', name: 'at-root' },
|
|
47
|
+
];
|
|
48
|
+
|
|
49
|
+
const variables: PrimaryOption = [
|
|
50
|
+
'dollar-variables', // $variable
|
|
51
|
+
'at-variables', // @variable
|
|
52
|
+
'custom-properties', // --property: 10px
|
|
53
|
+
];
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* https://tailwindcss.com/docs/functions-and-directives
|
|
57
|
+
*/
|
|
58
|
+
const atRuleTailwind: PrimaryOption = [
|
|
59
|
+
{ type: 'at-rule', name: 'tailwind' },
|
|
60
|
+
{ type: 'at-rule', name: 'layer' },
|
|
61
|
+
{ type: 'at-rule', name: 'apply' },
|
|
62
|
+
{ type: 'at-rule', name: 'config' },
|
|
63
|
+
];
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* https://v2.tailwindcss.com/docs/functions-and-directives
|
|
67
|
+
*
|
|
68
|
+
* backwards compatible for v2
|
|
69
|
+
*/
|
|
70
|
+
const atRuleTailwindV2: PrimaryOption = [
|
|
71
|
+
{ type: 'at-rule', name: 'variants' },
|
|
72
|
+
{ type: 'at-rule', name: 'responsive' },
|
|
73
|
+
{ type: 'at-rule', name: 'screen' },
|
|
74
|
+
];
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Nested rules (e.g. a { span {} })
|
|
78
|
+
*/
|
|
79
|
+
const rules: PrimaryOption = [
|
|
80
|
+
{
|
|
81
|
+
type: 'rule',
|
|
82
|
+
selector: /^&::[\w-]+/,
|
|
83
|
+
},
|
|
84
|
+
'rules',
|
|
85
|
+
];
|
|
86
|
+
|
|
87
|
+
export const orderRule = () =>
|
|
88
|
+
defineRule<PrimaryOption, SecondaryOptions>([
|
|
89
|
+
[
|
|
90
|
+
...(hasSass() ? atRuleScssImport : []),
|
|
91
|
+
...(hasTailwind() ? atRuleTailwind : []),
|
|
92
|
+
...variables,
|
|
93
|
+
...(hasSass() ? atRuleScss : []),
|
|
94
|
+
...(hasTailwind() ? atRuleTailwindV2 : []),
|
|
95
|
+
'at-rules',
|
|
96
|
+
'less-mixins',
|
|
97
|
+
'declarations',
|
|
98
|
+
...rules,
|
|
99
|
+
],
|
|
100
|
+
{
|
|
101
|
+
unspecified: 'bottom',
|
|
102
|
+
},
|
|
103
|
+
]);
|
|
104
|
+
|
|
105
|
+
export const order = () =>
|
|
106
|
+
defineRules({
|
|
107
|
+
'order/order': orderRule(),
|
|
108
|
+
});
|