@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.
Files changed (41) hide show
  1. package/CHANGELOG.md +35 -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 +10 -10
  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 +1 @@
1
- export * from './utils';
1
+ export * from './utils';
@@ -1,46 +1,46 @@
1
- import { assert, describe, expect, expectTypeOf, it } from 'vitest';
2
- import { defineRule, defineRules, mergeConfigs } from './utils';
3
-
4
- describe('rules', () => {
5
- it('defineRule & rules', () => {
6
- type PrimaryOption = true;
7
- interface SecondaryOptions {
8
- ignore: ['comments'];
9
- }
10
-
11
- const blockNoEmptyRule = defineRule<PrimaryOption, SecondaryOptions>([
12
- true,
13
- { ignore: ['comments'] },
14
- ]);
15
- const blockNoEmpty = defineRules({ 'block-no-empty': blockNoEmptyRule });
16
-
17
- assert(Array.isArray(blockNoEmptyRule));
18
- expectTypeOf(blockNoEmpty).toBeObject();
19
- });
20
- });
21
-
22
- describe('merge configs', () => {
23
- it('should merge plugins', () => {
24
- const mergedConfigs = mergeConfigs(
25
- { plugins: ['plugin-a'] }, //
26
- { plugins: ['plugin-b'] },
27
- { plugins: [] },
28
- {},
29
- );
30
-
31
- assert(Array.isArray(mergedConfigs.plugins));
32
- expect(mergedConfigs.plugins).toHaveLength(2);
33
- });
34
-
35
- it('should merge overrides', () => {
36
- const mergedConfigs = mergeConfigs(
37
- { overrides: [{ files: 'a.css' }] },
38
- { overrides: [{ files: 'b.css' }] },
39
- { overrides: [] },
40
- {},
41
- );
42
-
43
- assert(Array.isArray(mergedConfigs.overrides));
44
- expect(mergedConfigs.overrides).toHaveLength(2);
45
- });
46
- });
1
+ import { assert, describe, expect, expectTypeOf, it } from 'vitest';
2
+ import { defineRule, defineRules, mergeConfigs } from './utils';
3
+
4
+ describe('rules', () => {
5
+ it('defineRule & rules', () => {
6
+ type PrimaryOption = true;
7
+ interface SecondaryOptions {
8
+ ignore: ['comments'];
9
+ }
10
+
11
+ const blockNoEmptyRule = defineRule<PrimaryOption, SecondaryOptions>([
12
+ true,
13
+ { ignore: ['comments'] },
14
+ ]);
15
+ const blockNoEmpty = defineRules({ 'block-no-empty': blockNoEmptyRule });
16
+
17
+ assert(Array.isArray(blockNoEmptyRule));
18
+ expectTypeOf(blockNoEmpty).toBeObject();
19
+ });
20
+ });
21
+
22
+ describe('merge configs', () => {
23
+ it('should merge plugins', () => {
24
+ const mergedConfigs = mergeConfigs(
25
+ { plugins: ['plugin-a'] }, //
26
+ { plugins: ['plugin-b'] },
27
+ { plugins: [] },
28
+ {},
29
+ );
30
+
31
+ assert(Array.isArray(mergedConfigs.plugins));
32
+ expect(mergedConfigs.plugins).toHaveLength(2);
33
+ });
34
+
35
+ it('should merge overrides', () => {
36
+ const mergedConfigs = mergeConfigs(
37
+ { overrides: [{ files: 'a.css' }] },
38
+ { overrides: [{ files: 'b.css' }] },
39
+ { overrides: [] },
40
+ {},
41
+ );
42
+
43
+ assert(Array.isArray(mergedConfigs.overrides));
44
+ expect(mergedConfigs.overrides).toHaveLength(2);
45
+ });
46
+ });
@@ -1,44 +1,44 @@
1
- import type { Config, ConfigRuleSettings } from 'stylelint';
2
-
3
- export type ConfigRulePrimaryOption =
4
- | boolean
5
- | number
6
- | string
7
- | Array<boolean | number | string | object>;
8
- export type ConfigRuleSecondaryOptions = object;
9
-
10
- export const defineRule = <
11
- PrimaryOption extends ConfigRulePrimaryOption,
12
- SecondaryOptions extends ConfigRuleSecondaryOptions,
13
- >(
14
- rule: ConfigRuleSettings<PrimaryOption, SecondaryOptions>,
15
- ) => rule;
16
-
17
- export const defineRules = <TRules extends Config['rules']>(rule: TRules) =>
18
- rule;
19
-
20
- // clone function mergeConfigs from stylelint repository
21
- export const mergeConfigs = (
22
- ...configsOrNull: (Config | undefined | null | false)[]
23
- ) => {
24
- const configs = configsOrNull.filter((c): c is Config => !!c);
25
-
26
- return {
27
- plugins: [...new Set(configs.flatMap(c => c.plugins ?? []))],
28
- overrides: [...new Set(configs.flatMap(c => c.overrides ?? []))],
29
- extends: configs
30
- .flatMap(c => c.extends ?? [])
31
- .filter((item, index, arr) => arr.lastIndexOf(item) === index),
32
- rules: configs.reduce(
33
- (acc, config) => ({ ...acc, ...config.rules }),
34
- {} as Config['rules'],
35
- ),
36
- ...configs.reduce(
37
- (
38
- acc,
39
- { plugins: _p, overrides: _o, extends: _e, rules: _r, ...config },
40
- ) => ({ ...acc, ...config }),
41
- {} as Config,
42
- ),
43
- };
44
- };
1
+ import type { Config, ConfigRuleSettings } from 'stylelint';
2
+
3
+ export type ConfigRulePrimaryOption =
4
+ | boolean
5
+ | number
6
+ | string
7
+ | Array<boolean | number | string | object>;
8
+ export type ConfigRuleSecondaryOptions = object;
9
+
10
+ export const defineRule = <
11
+ PrimaryOption extends ConfigRulePrimaryOption,
12
+ SecondaryOptions extends ConfigRuleSecondaryOptions,
13
+ >(
14
+ rule: ConfigRuleSettings<PrimaryOption, SecondaryOptions>,
15
+ ) => rule;
16
+
17
+ export const defineRules = <TRules extends Config['rules']>(rule: TRules) =>
18
+ rule;
19
+
20
+ // clone function mergeConfigs from stylelint repository
21
+ export const mergeConfigs = (
22
+ ...configsOrNull: (Config | undefined | null | false)[]
23
+ ) => {
24
+ const configs = configsOrNull.filter((c): c is Config => !!c);
25
+
26
+ return {
27
+ plugins: [...new Set(configs.flatMap(c => c.plugins ?? []))],
28
+ overrides: [...new Set(configs.flatMap(c => c.overrides ?? []))],
29
+ extends: configs
30
+ .flatMap(c => c.extends ?? [])
31
+ .filter((item, index, arr) => arr.lastIndexOf(item) === index),
32
+ rules: configs.reduce(
33
+ (acc, config) => ({ ...acc, ...config.rules }),
34
+ {} as Config['rules'],
35
+ ),
36
+ ...configs.reduce(
37
+ (
38
+ acc,
39
+ { plugins: _p, overrides: _o, extends: _e, rules: _r, ...config },
40
+ ) => ({ ...acc, ...config }),
41
+ {} as Config,
42
+ ),
43
+ };
44
+ };
@@ -1,55 +0,0 @@
1
- import { resolve } from 'node:path';
2
- import type { Config } from 'stylelint';
3
- import stylelint from 'stylelint';
4
- import type { Awaitable } from 'vitest';
5
- import { describe, expect, it } from 'vitest';
6
- import type { UtilsPackages } from './mock';
7
- import { defineMockUtilsPackages } from './mock';
8
-
9
- type LintAndFixCase = {
10
- code: string;
11
- fixedCode?: string;
12
- isError?: boolean;
13
- ext?: 'css' | 'scss' | 'vue';
14
- debug?: boolean;
15
- } & UtilsPackages;
16
-
17
- export const testLintAndFix = (
18
- getConfig: Config | (() => Awaitable<Config>),
19
- testCases: LintAndFixCase[],
20
- ) =>
21
- describe('test lint and fix', () => {
22
- const mockUtilsPackages = defineMockUtilsPackages(testCases);
23
-
24
- const name = [
25
- ...(['hasTailwind', 'hasSass', 'hasVue', 'isError'] as const) //
26
- .filter(field => testCases.some(t => typeof t[field] === 'boolean')),
27
- ...(['code', 'fixedCode'] as const) //
28
- .filter(field => testCases.some(t => typeof t[field] === 'string')),
29
- ]
30
- .map(field => `${field} = $${field}`)
31
- .join(', ');
32
-
33
- it.each(testCases)(name, async options => {
34
- await mockUtilsPackages(options);
35
-
36
- const config =
37
- typeof getConfig === 'function' ? await getConfig() : getConfig;
38
- const result = await stylelint.lint({
39
- code: options.code,
40
- codeFilename: `filename.${options.ext ?? 'css'}`,
41
- config,
42
- fix: 'fixedCode' in options,
43
- configBasedir: resolve(__dirname, '..'),
44
- });
45
-
46
- if (options.debug) {
47
- /* eslint-disable no-console */
48
- console.log(result.results.flatMap(r => r.warnings));
49
- console.log(result.code);
50
- /* eslint-enable no-console */
51
- }
52
- if ('fixedCode' in options) expect(result.code).toBe(options.fixedCode);
53
- if ('isError' in options) expect(result.errored).toBe(options.isError);
54
- });
55
- });
@@ -1,68 +0,0 @@
1
- import type { Awaitable } from 'vitest';
2
- import { describe, it } from 'vitest';
3
- import type { Config, ConfigRuleSettings } from 'stylelint';
4
- import type { UtilsPackages } from './mock';
5
- import { defineMockUtilsPackages } from './mock';
6
-
7
- import type {
8
- ConfigRulePrimaryOption,
9
- ConfigRuleSecondaryOptions,
10
- } from '~/utils';
11
-
12
- type TArgs<TOptions extends object, TRuleOrConfig> = [
13
- getRuleOrConfig: (() => Awaitable<TRuleOrConfig>) | TRuleOrConfig,
14
- fn: (
15
- ruleOrConfig: TRuleOrConfig,
16
- options: UtilsPackages & TOptions,
17
- ) => Promise<void> | void,
18
- ];
19
-
20
- const testRuleOrConfigValue = <
21
- TBaseRuleOrConfig extends
22
- | ConfigRuleSettings<ConfigRulePrimaryOption, ConfigRuleSecondaryOptions>
23
- | Config,
24
- >(
25
- ruleOrConfig: 'rule' | 'config',
26
- ) => {
27
- return <
28
- TCase extends UtilsPackages & object,
29
- TRuleOrConfig extends TBaseRuleOrConfig,
30
- >(
31
- ...args:
32
- | [testCases: TCase[], ...TArgs<TCase, TRuleOrConfig>]
33
- | [...TArgs<TCase, TRuleOrConfig>]
34
- ) => {
35
- describe(ruleOrConfig, () => {
36
- const [testCases, getRuleOrConfig, fn] =
37
- args.length === 3
38
- ? [...args]
39
- : [[{} as UtilsPackages & TCase], ...args];
40
-
41
- const mockUtilsPackages = defineMockUtilsPackages(testCases);
42
-
43
- const name = (['hasTailwind', 'hasSass', 'hasVue'] as const)
44
- .filter(field => testCases.some(t => typeof t[field] === 'boolean'))
45
- .map(field => `${field} = $${field}`)
46
- .join(', ');
47
-
48
- it.each(testCases)(name, async options => {
49
- await mockUtilsPackages(options);
50
-
51
- const ruleOrConfig =
52
- typeof getRuleOrConfig === 'function'
53
- ? await getRuleOrConfig()
54
- : getRuleOrConfig;
55
-
56
- await fn(ruleOrConfig, options);
57
- });
58
- });
59
- };
60
- };
61
-
62
- export const testConfigValue = testRuleOrConfigValue<Config>('config');
63
- export const testRuleValue = testRuleOrConfigValue<
64
- ConfigRuleSettings<
65
- ConfigRulePrimaryOption, //
66
- ConfigRuleSecondaryOptions
67
- >
68
- >('rule');