@culur/config-stylelint 1.0.0 → 1.0.2

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.
Files changed (41) hide show
  1. package/CHANGELOG.md +56 -12
  2. package/README.md +122 -122
  3. package/dist/index.cjs +2 -2
  4. package/dist/index.cjs.map +1 -1
  5. package/dist/index.js +2 -2
  6. package/dist/index.js.map +1 -1
  7. package/package.json +14 -14
  8. package/src/__tests__/dedent.ts +5 -5
  9. package/src/__tests__/describe-lint-and-fix.ts +61 -0
  10. package/src/__tests__/describe-rule-or-config.ts +73 -0
  11. package/src/__tests__/index.ts +8 -5
  12. package/src/__tests__/mock.ts +36 -36
  13. package/src/__tests__/spy-on-utils-packages.ts +14 -0
  14. package/src/__tests__/syntax.ts +11 -11
  15. package/src/configs/css.test.ts +9 -10
  16. package/src/configs/css.ts +16 -16
  17. package/src/configs/scss.test.ts +8 -9
  18. package/src/configs/scss.ts +11 -11
  19. package/src/configs/shared.test.ts +8 -9
  20. package/src/configs/shared.ts +5 -5
  21. package/src/configs/vue.test.ts +19 -18
  22. package/src/configs/vue.ts +10 -10
  23. package/src/factory.test.ts +16 -15
  24. package/src/factory.ts +23 -23
  25. package/src/index.test.ts +9 -9
  26. package/src/index.ts +3 -3
  27. package/src/rules/at-rule-no-unknown.test.ts +46 -43
  28. package/src/rules/at-rule-no-unknown.ts +33 -33
  29. package/src/rules/declaration-block-no-redundant-longhand-properties.test.ts +41 -38
  30. package/src/rules/declaration-block-no-redundant-longhand-properties.ts +11 -11
  31. package/src/rules/dollar-variable-pattern.test.ts +26 -27
  32. package/src/rules/dollar-variable-pattern.ts +18 -18
  33. package/src/rules/function-no-unknown.test.ts +43 -39
  34. package/src/rules/function-no-unknown.ts +35 -35
  35. package/src/rules/order.test.ts +47 -46
  36. package/src/rules/order.ts +108 -108
  37. package/src/utils/index.ts +1 -1
  38. package/src/utils/utils.test.ts +46 -46
  39. package/src/utils/utils.ts +44 -44
  40. package/src/__tests__/test-lint-and-fix.ts +0 -55
  41. package/src/__tests__/test-rule-or-config-value.ts +0 -68
@@ -1,33 +1,33 @@
1
- import { hasTailwind } from '@culur/utils-packages';
2
- import { defineRule, defineRules } from '~/utils';
3
-
4
- // https://tailwindcss.com/docs/functions-and-directives
5
- const directives = [
6
- 'tailwind',
7
- 'layer',
8
- 'apply',
9
- 'config',
10
-
11
- // https://v2.tailwindcss.com/docs/functions-and-directives
12
- // backwards compatible for v2
13
- 'variants',
14
- 'responsive',
15
- 'screen',
16
- ];
17
-
18
- export const atRuleNoUnknownRule = () =>
19
- defineRule<boolean, { ignoreAtRules: (string | RegExp)[] }>([
20
- true,
21
- { ignoreAtRules: hasTailwind() ? directives : [] },
22
- ]);
23
-
24
- export const atRuleNoUnknownCSS = () =>
25
- defineRules({
26
- 'at-rule-no-unknown': atRuleNoUnknownRule(),
27
- });
28
-
29
- export const atRuleNoUnknownSCSS = () =>
30
- defineRules({
31
- 'at-rule-no-unknown': null,
32
- 'scss/at-rule-no-unknown': atRuleNoUnknownRule(),
33
- });
1
+ import { hasTailwind } from '@culur/utils-packages';
2
+ import { defineRule, defineRules } from '~/utils';
3
+
4
+ // https://tailwindcss.com/docs/functions-and-directives
5
+ const directives = [
6
+ 'tailwind',
7
+ 'layer',
8
+ 'apply',
9
+ 'config',
10
+
11
+ // https://v2.tailwindcss.com/docs/functions-and-directives
12
+ // backwards compatible for v2
13
+ 'variants',
14
+ 'responsive',
15
+ 'screen',
16
+ ];
17
+
18
+ export const atRuleNoUnknownRule = () =>
19
+ defineRule<boolean, { ignoreAtRules: (string | RegExp)[] }>([
20
+ true,
21
+ { ignoreAtRules: hasTailwind() ? directives : [] },
22
+ ]);
23
+
24
+ export const atRuleNoUnknownCSS = () =>
25
+ defineRules({
26
+ 'at-rule-no-unknown': atRuleNoUnknownRule(),
27
+ });
28
+
29
+ export const atRuleNoUnknownSCSS = () =>
30
+ defineRules({
31
+ 'at-rule-no-unknown': null,
32
+ 'scss/at-rule-no-unknown': atRuleNoUnknownRule(),
33
+ });
@@ -1,38 +1,41 @@
1
- import { assert, expect } from 'vitest';
2
- import {
3
- declarationBlockNoRedundantLonghandProperties,
4
- declarationBlockNoRedundantLonghandPropertiesRule,
5
- } from './declaration-block-no-redundant-longhand-properties';
6
- import { css, testLintAndFix, testRuleValue } from '~/__tests__';
7
-
8
- testRuleValue(
9
- declarationBlockNoRedundantLonghandPropertiesRule, //
10
- rule => {
11
- assert(Array.isArray(rule));
12
- assert(typeof rule[1] === 'object');
13
- expect(rule[1].ignoreShorthands).toHaveLength(1);
14
- },
15
- );
16
-
17
- testLintAndFix(
18
- {
19
- rules: declarationBlockNoRedundantLonghandProperties,
20
- },
21
- [
22
- {
23
- code: css`
24
- a {
25
- margin-top: 1px;
26
- margin-right: 2px;
27
- margin-bottom: 3px;
28
- margin-left: 4px;
29
- }
30
- `,
31
- fixedCode: css`
32
- a {
33
- margin: 1px 2px 3px 4px;
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
- dollarVariablePatternRule,
4
- dollarVariablePatternSCSS,
5
- } from './dollar-variable-pattern';
6
- import { scss, testLintAndFix, testRuleValue } from '~/__tests__';
7
-
8
- testRuleValue(
9
- () => dollarVariablePatternRule,
10
- rule => {
11
- assert(Array.isArray(rule));
12
- assert(typeof rule[1] === 'object');
13
- expectTypeOf(rule[1].message).toBeString();
14
- },
15
- );
16
-
17
- testLintAndFix(
18
- {
19
- extends: ['stylelint-config-standard-scss'],
20
- rules: dollarVariablePatternSCSS,
21
- }, //
22
- [
23
- { isError: false, code: scss`a { $kebab-case: 123; }` },
24
- { isError: true, code: scss`a { $snake_case: 123; }` },
25
- { isError: true, code: scss`a { $camelCase: 123; }` },
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 { testLintAndFix, testRuleValue } from '~/__tests__';
3
-
4
- testRuleValue(
5
- [
6
- { hasTailwind: true, hasSass: false, hasVue: false, length: 2 },
7
- { hasTailwind: false, hasSass: true, hasVue: false, length: 1 },
8
- { hasTailwind: false, hasSass: false, hasVue: true, length: 1 },
9
- ],
10
- async () => {
11
- const module = await import('./function-no-unknown');
12
- return module.functionNoUnknownRule();
13
- },
14
- (rule, options) => {
15
- assert(Array.isArray(rule));
16
- assert(typeof rule[1] === 'object');
17
- expect(rule[1].ignoreFunctions).toHaveLength(options.length);
18
- },
19
- );
20
-
21
- testLintAndFix(async () => {
22
- const module = await import('./function-no-unknown');
23
- return { rules: module.functionNoUnknown() };
24
- }, [
25
- {
26
- isError: true,
27
- code: 'a { color: unknown(1); }',
28
- },
29
- {
30
- hasTailwind: true,
31
- isError: false,
32
- code: 'a { color: theme(colors.blue.500); }',
33
- },
34
- {
35
- hasVue: true,
36
- isError: false,
37
- code: 'a { color: v-bind(colors); }',
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 const 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
- });
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
+ });
@@ -1,46 +1,47 @@
1
- import { assert, expect } from 'vitest';
2
- import { scss, testLintAndFix, testRuleValue } from '~/__tests__';
3
-
4
- testRuleValue(
5
- [
6
- { hasTailwind: false, hasSass: false, length: 8 },
7
- { hasTailwind: true, hasSass: false, length: 15 },
8
- { hasTailwind: false, hasSass: true, length: 16 },
9
- { hasTailwind: true, hasSass: true, length: 23 },
10
- ],
11
- async () => {
12
- const module = await import('./order');
13
- return module.orderRule();
14
- },
15
- (rule, options) => {
16
- assert(Array.isArray(rule));
17
-
18
- assert(Array.isArray(rule[0]));
19
- expect(rule[0]).toHaveLength(options.length);
20
-
21
- assert(typeof rule[1] === 'object');
22
- expect(rule[1]).toStrictEqual({ unspecified: 'bottom' });
23
- },
24
- );
25
-
26
- testLintAndFix(async () => {
27
- const module = await import('./order');
28
- return {
29
- plugins: ['stylelint-order'],
30
- rules: module.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
- ]);
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
+ );