@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.
- package/CHANGELOG.md +56 -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 +14 -14
- 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
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { resolve } from 'node:path';
|
|
2
|
+
import type { Awaitable } from 'vitest';
|
|
3
|
+
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
4
|
+
import type { Config } from 'stylelint';
|
|
5
|
+
import stylelint from 'stylelint';
|
|
6
|
+
import type { UtilsPackages } from './mock';
|
|
7
|
+
import { spyOnUtilsPackages } from './spy-on-utils-packages';
|
|
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 function describeLintAndFix(
|
|
18
|
+
utilsPackages: typeof import('@culur/utils-packages'),
|
|
19
|
+
getConfig: Config | (() => Awaitable<Config>),
|
|
20
|
+
testCases: LintAndFixCase[],
|
|
21
|
+
) {
|
|
22
|
+
const itName = [
|
|
23
|
+
...(['hasTailwind', 'hasSass', 'hasVue', 'isError'] as const) //
|
|
24
|
+
.filter(field => testCases.some(t => typeof t[field] === 'boolean')),
|
|
25
|
+
...(['code', 'fixedCode'] as const) //
|
|
26
|
+
.filter(field => testCases.some(t => typeof t[field] === 'string')),
|
|
27
|
+
]
|
|
28
|
+
.map(field => `${field} = $${field}`)
|
|
29
|
+
.join(', ');
|
|
30
|
+
|
|
31
|
+
describe('test lint and fix', () => {
|
|
32
|
+
afterEach(() => {
|
|
33
|
+
vi.restoreAllMocks();
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it.each(testCases)(itName, async testCase => {
|
|
37
|
+
spyOnUtilsPackages(utilsPackages, testCase);
|
|
38
|
+
|
|
39
|
+
const config =
|
|
40
|
+
typeof getConfig === 'function' ? await getConfig() : getConfig;
|
|
41
|
+
|
|
42
|
+
const result = await stylelint.lint({
|
|
43
|
+
code: testCase.code,
|
|
44
|
+
codeFilename: `filename.${testCase.ext ?? 'css'}`,
|
|
45
|
+
config,
|
|
46
|
+
fix: 'fixedCode' in testCase,
|
|
47
|
+
configBasedir: resolve(__dirname, '..'),
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
if (testCase.debug) {
|
|
51
|
+
/* eslint-disable no-console */
|
|
52
|
+
console.log(JSON.stringify(config, undefined, 2));
|
|
53
|
+
console.log(result.results.flatMap(r => r.warnings));
|
|
54
|
+
console.log(result.code);
|
|
55
|
+
/* eslint-enable no-console */
|
|
56
|
+
}
|
|
57
|
+
if ('fixedCode' in testCase) expect(result.code).toBe(testCase.fixedCode);
|
|
58
|
+
if ('isError' in testCase) expect(result.errored).toBe(testCase.isError);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { Awaitable } from 'vitest';
|
|
2
|
+
import { afterEach, describe, it, vi } from 'vitest';
|
|
3
|
+
import type { Config, ConfigRuleSettings } from 'stylelint';
|
|
4
|
+
import type { UtilsPackages } from './mock';
|
|
5
|
+
import { hasValues, spyOnUtilsPackages } from './spy-on-utils-packages';
|
|
6
|
+
import type {
|
|
7
|
+
ConfigRulePrimaryOption,
|
|
8
|
+
ConfigRuleSecondaryOptions,
|
|
9
|
+
} from '~/utils';
|
|
10
|
+
|
|
11
|
+
type Fn<
|
|
12
|
+
TTestCase extends UtilsPackages & object,
|
|
13
|
+
TRuleOrConfig extends
|
|
14
|
+
| ConfigRuleSettings<ConfigRulePrimaryOption, ConfigRuleSecondaryOptions>
|
|
15
|
+
| Config,
|
|
16
|
+
> = (
|
|
17
|
+
ruleOrConfig: TRuleOrConfig,
|
|
18
|
+
options: UtilsPackages & TTestCase,
|
|
19
|
+
) => Promise<void> | void;
|
|
20
|
+
|
|
21
|
+
export function describeRuleOrConfigFactory<
|
|
22
|
+
TBaseRuleOrConfig extends
|
|
23
|
+
| ConfigRuleSettings<ConfigRulePrimaryOption, ConfigRuleSecondaryOptions>
|
|
24
|
+
| Config,
|
|
25
|
+
>(describeName: string) {
|
|
26
|
+
function describeRuleOrConfig<
|
|
27
|
+
TRuleOrConfig extends TBaseRuleOrConfig,
|
|
28
|
+
TTestCase extends UtilsPackages & object,
|
|
29
|
+
>(
|
|
30
|
+
utilsPackages: typeof import('@culur/utils-packages'),
|
|
31
|
+
getRuleOrConfig: (() => Awaitable<TRuleOrConfig>) | TRuleOrConfig,
|
|
32
|
+
...args:
|
|
33
|
+
| [testCases: TTestCase[], fn: Fn<TTestCase, TRuleOrConfig>]
|
|
34
|
+
| [fn: Fn<TTestCase, TRuleOrConfig>]
|
|
35
|
+
) {
|
|
36
|
+
const [testCases, fn] =
|
|
37
|
+
args.length === 2 //
|
|
38
|
+
? [...args]
|
|
39
|
+
: [[{} as UtilsPackages & TTestCase], ...args];
|
|
40
|
+
|
|
41
|
+
const itName =
|
|
42
|
+
hasValues
|
|
43
|
+
.filter(field => testCases.some(t => typeof t[field] === 'boolean'))
|
|
44
|
+
.map(field => `${field} = $${field}`)
|
|
45
|
+
.join(', ') || 'default';
|
|
46
|
+
|
|
47
|
+
describe(describeName, () => {
|
|
48
|
+
afterEach(() => {
|
|
49
|
+
vi.restoreAllMocks();
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it.each(testCases)(itName, async testCase => {
|
|
53
|
+
spyOnUtilsPackages(utilsPackages, testCase);
|
|
54
|
+
|
|
55
|
+
const ruleOrConfig =
|
|
56
|
+
typeof getRuleOrConfig === 'function'
|
|
57
|
+
? await getRuleOrConfig()
|
|
58
|
+
: getRuleOrConfig;
|
|
59
|
+
|
|
60
|
+
fn(ruleOrConfig, testCase);
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return describeRuleOrConfig;
|
|
66
|
+
}
|
|
67
|
+
export const describeConfig = describeRuleOrConfigFactory<Config>('config');
|
|
68
|
+
export const describeRule = describeRuleOrConfigFactory<
|
|
69
|
+
ConfigRuleSettings<
|
|
70
|
+
ConfigRulePrimaryOption, //
|
|
71
|
+
ConfigRuleSecondaryOptions
|
|
72
|
+
>
|
|
73
|
+
>('rule');
|
package/src/__tests__/index.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
export * from './dedent';
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './
|
|
4
|
-
export * from './
|
|
5
|
-
export * from './
|
|
1
|
+
export * from './dedent';
|
|
2
|
+
export * from './describe-lint-and-fix';
|
|
3
|
+
export * from './describe-rule-or-config';
|
|
4
|
+
// export * from './mock';
|
|
5
|
+
export * from './spy-on-utils-packages';
|
|
6
|
+
export * from './syntax';
|
|
7
|
+
// export * from './test-lint-and-fix';
|
|
8
|
+
// export * from './test-rule-or-config-value';
|
package/src/__tests__/mock.ts
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
import { vi } from 'vitest';
|
|
2
|
-
|
|
3
|
-
export type UtilsPackages = Partial<{
|
|
4
|
-
hasTailwind: boolean;
|
|
5
|
-
hasSass: boolean;
|
|
6
|
-
hasVue: boolean;
|
|
7
|
-
}>;
|
|
8
|
-
|
|
9
|
-
export const defineMockUtilsPackages = (testCases: UtilsPackages[]) => {
|
|
10
|
-
const shouldMockUtilsPackages = testCases.some(
|
|
11
|
-
t =>
|
|
12
|
-
typeof t.hasTailwind === 'boolean' ||
|
|
13
|
-
typeof t.hasSass === 'boolean' ||
|
|
14
|
-
typeof t.hasVue === 'boolean',
|
|
15
|
-
);
|
|
16
|
-
|
|
17
|
-
if (shouldMockUtilsPackages) {
|
|
18
|
-
vi.mock('@culur/utils-packages');
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
return async ({ hasTailwind, hasSass, hasVue }: UtilsPackages) => {
|
|
22
|
-
if (shouldMockUtilsPackages) {
|
|
23
|
-
const utilsPackages = await import('@culur/utils-packages');
|
|
24
|
-
|
|
25
|
-
if (typeof hasTailwind === 'boolean') {
|
|
26
|
-
utilsPackages.hasTailwind = vi.fn().mockReturnValue(hasTailwind);
|
|
27
|
-
}
|
|
28
|
-
if (typeof hasSass === 'boolean') {
|
|
29
|
-
utilsPackages.hasSass = vi.fn().mockReturnValue(hasSass);
|
|
30
|
-
}
|
|
31
|
-
if (typeof hasVue === 'boolean') {
|
|
32
|
-
utilsPackages.hasVue = vi.fn().mockReturnValue(hasVue);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
};
|
|
1
|
+
import { vi } from 'vitest';
|
|
2
|
+
|
|
3
|
+
export type UtilsPackages = Partial<{
|
|
4
|
+
hasTailwind: boolean;
|
|
5
|
+
hasSass: boolean;
|
|
6
|
+
hasVue: boolean;
|
|
7
|
+
}>;
|
|
8
|
+
|
|
9
|
+
export const defineMockUtilsPackages = (testCases: UtilsPackages[]) => {
|
|
10
|
+
const shouldMockUtilsPackages = testCases.some(
|
|
11
|
+
t =>
|
|
12
|
+
typeof t.hasTailwind === 'boolean' ||
|
|
13
|
+
typeof t.hasSass === 'boolean' ||
|
|
14
|
+
typeof t.hasVue === 'boolean',
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
if (shouldMockUtilsPackages) {
|
|
18
|
+
vi.mock('@culur/utils-packages');
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return async ({ hasTailwind, hasSass, hasVue }: UtilsPackages) => {
|
|
22
|
+
if (shouldMockUtilsPackages) {
|
|
23
|
+
const utilsPackages = await import('@culur/utils-packages');
|
|
24
|
+
|
|
25
|
+
if (typeof hasTailwind === 'boolean') {
|
|
26
|
+
utilsPackages.hasTailwind = vi.fn().mockReturnValue(hasTailwind);
|
|
27
|
+
}
|
|
28
|
+
if (typeof hasSass === 'boolean') {
|
|
29
|
+
utilsPackages.hasSass = vi.fn().mockReturnValue(hasSass);
|
|
30
|
+
}
|
|
31
|
+
if (typeof hasVue === 'boolean') {
|
|
32
|
+
utilsPackages.hasVue = vi.fn().mockReturnValue(hasVue);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { vi } from 'vitest';
|
|
2
|
+
import type { UtilsPackages } from './mock';
|
|
3
|
+
|
|
4
|
+
export const hasValues = ['hasTailwind', 'hasSass', 'hasVue'] as const;
|
|
5
|
+
|
|
6
|
+
export function spyOnUtilsPackages(
|
|
7
|
+
utilsPackages: typeof import('@culur/utils-packages'),
|
|
8
|
+
options: UtilsPackages,
|
|
9
|
+
) {
|
|
10
|
+
for (const hasValue of hasValues) {
|
|
11
|
+
const value = options[hasValue] ?? false;
|
|
12
|
+
vi.spyOn(utilsPackages, hasValue).mockReturnValue(value);
|
|
13
|
+
}
|
|
14
|
+
}
|
package/src/__tests__/syntax.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type { Config } from 'stylelint';
|
|
2
|
-
import postcssScss from 'postcss-scss';
|
|
3
|
-
|
|
4
|
-
type OverrideSyntax = Config['overrides'] extends (infer T)[] | undefined
|
|
5
|
-
? T
|
|
6
|
-
: never;
|
|
7
|
-
|
|
8
|
-
export const syntaxScss: OverrideSyntax = {
|
|
9
|
-
files: ['*.scss', '**/*.scss'],
|
|
10
|
-
customSyntax: postcssScss,
|
|
11
|
-
};
|
|
1
|
+
import type { Config } from 'stylelint';
|
|
2
|
+
import postcssScss from 'postcss-scss';
|
|
3
|
+
|
|
4
|
+
type OverrideSyntax = Config['overrides'] extends (infer T)[] | undefined
|
|
5
|
+
? T
|
|
6
|
+
: never;
|
|
7
|
+
|
|
8
|
+
export const syntaxScss: OverrideSyntax = {
|
|
9
|
+
files: ['*.scss', '**/*.scss'],
|
|
10
|
+
customSyntax: postcssScss,
|
|
11
|
+
};
|
package/src/configs/css.test.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { assert
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
});
|
|
1
|
+
import { assert } from 'vitest';
|
|
2
|
+
import * as utilsPackages from '@culur/utils-packages';
|
|
3
|
+
import { configCss } from './css';
|
|
4
|
+
import { describeConfig } from '~/__tests__';
|
|
5
|
+
|
|
6
|
+
describeConfig(utilsPackages, configCss, config => {
|
|
7
|
+
assert(Array.isArray(config.extends));
|
|
8
|
+
assert(Array.isArray(config.plugins));
|
|
9
|
+
});
|
package/src/configs/css.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import type { Config } from 'stylelint';
|
|
2
|
-
import { atRuleNoUnknownCSS } from '~/rules/at-rule-no-unknown';
|
|
3
|
-
import { declarationBlockNoRedundantLonghandProperties } from '~/rules/declaration-block-no-redundant-longhand-properties';
|
|
4
|
-
import { functionNoUnknown } from '~/rules/function-no-unknown';
|
|
5
|
-
import { order } from '~/rules/order';
|
|
6
|
-
|
|
7
|
-
export const configCss = (): Config => ({
|
|
8
|
-
extends: ['stylelint-config-standard', 'stylelint-config-clean-order'],
|
|
9
|
-
plugins: ['stylelint-order', 'stylelint-selector-bem-pattern'],
|
|
10
|
-
rules: {
|
|
11
|
-
...atRuleNoUnknownCSS(),
|
|
12
|
-
...declarationBlockNoRedundantLonghandProperties,
|
|
13
|
-
...functionNoUnknown(),
|
|
14
|
-
...order(),
|
|
15
|
-
},
|
|
16
|
-
});
|
|
1
|
+
import type { Config } from 'stylelint';
|
|
2
|
+
import { atRuleNoUnknownCSS } from '~/rules/at-rule-no-unknown';
|
|
3
|
+
import { declarationBlockNoRedundantLonghandProperties } from '~/rules/declaration-block-no-redundant-longhand-properties';
|
|
4
|
+
import { functionNoUnknown } from '~/rules/function-no-unknown';
|
|
5
|
+
import { order } from '~/rules/order';
|
|
6
|
+
|
|
7
|
+
export const configCss = (): Config => ({
|
|
8
|
+
extends: ['stylelint-config-standard', 'stylelint-config-clean-order'],
|
|
9
|
+
plugins: ['stylelint-order', 'stylelint-selector-bem-pattern'],
|
|
10
|
+
rules: {
|
|
11
|
+
...atRuleNoUnknownCSS(),
|
|
12
|
+
...declarationBlockNoRedundantLonghandProperties,
|
|
13
|
+
...functionNoUnknown(),
|
|
14
|
+
...order(),
|
|
15
|
+
},
|
|
16
|
+
});
|
package/src/configs/scss.test.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
});
|
|
1
|
+
import * as utilsPackages from '@culur/utils-packages';
|
|
2
|
+
import { assert } from 'vitest';
|
|
3
|
+
import { configScss } from './scss';
|
|
4
|
+
import { describeConfig } from '~/__tests__';
|
|
5
|
+
|
|
6
|
+
describeConfig(utilsPackages, configScss, config => {
|
|
7
|
+
assert(Array.isArray(config.extends));
|
|
8
|
+
});
|
package/src/configs/scss.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type { Config } from 'stylelint';
|
|
2
|
-
import { atRuleNoUnknownSCSS } from '~/rules/at-rule-no-unknown';
|
|
3
|
-
import { dollarVariablePatternSCSS } from '~/rules/dollar-variable-pattern';
|
|
4
|
-
|
|
5
|
-
export const configScss = (): Config => ({
|
|
6
|
-
extends: ['stylelint-config-standard-scss'],
|
|
7
|
-
rules: {
|
|
8
|
-
...atRuleNoUnknownSCSS(),
|
|
9
|
-
...dollarVariablePatternSCSS,
|
|
10
|
-
},
|
|
11
|
-
});
|
|
1
|
+
import type { Config } from 'stylelint';
|
|
2
|
+
import { atRuleNoUnknownSCSS } from '~/rules/at-rule-no-unknown';
|
|
3
|
+
import { dollarVariablePatternSCSS } from '~/rules/dollar-variable-pattern';
|
|
4
|
+
|
|
5
|
+
export const configScss = (): Config => ({
|
|
6
|
+
extends: ['stylelint-config-standard-scss'],
|
|
7
|
+
rules: {
|
|
8
|
+
...atRuleNoUnknownSCSS(),
|
|
9
|
+
...dollarVariablePatternSCSS,
|
|
10
|
+
},
|
|
11
|
+
});
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { assert
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
});
|
|
1
|
+
import { assert } from 'vitest';
|
|
2
|
+
import * as utilsPackages from '@culur/utils-packages';
|
|
3
|
+
import { configShared } from './shared';
|
|
4
|
+
import { describeConfig } from '~/__tests__';
|
|
5
|
+
|
|
6
|
+
describeConfig(utilsPackages, configShared, config => {
|
|
7
|
+
assert(Array.isArray(config.extends));
|
|
8
|
+
});
|
package/src/configs/shared.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Config } from 'stylelint';
|
|
2
|
-
|
|
3
|
-
export const configShared = (): Config => ({
|
|
4
|
-
extends: ['stylelint-config-html'],
|
|
5
|
-
});
|
|
1
|
+
import type { Config } from 'stylelint';
|
|
2
|
+
|
|
3
|
+
export const configShared = (): Config => ({
|
|
4
|
+
extends: ['stylelint-config-html'],
|
|
5
|
+
});
|
package/src/configs/vue.test.ts
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
import { assert
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
1
|
+
import { assert } from 'vitest';
|
|
2
|
+
import * as utilsPackages from '@culur/utils-packages';
|
|
3
|
+
import { configVue } from './vue';
|
|
4
|
+
import { describeConfig } from '~/__tests__';
|
|
5
|
+
|
|
6
|
+
describeConfig(
|
|
7
|
+
utilsPackages,
|
|
8
|
+
configVue,
|
|
9
|
+
[{ hasSass: true }, { hasSass: false }],
|
|
10
|
+
(config, testCase) => {
|
|
11
|
+
assert(Array.isArray(config.extends));
|
|
12
|
+
assert(Array.isArray(config.extends));
|
|
13
|
+
config.extends.includes(
|
|
14
|
+
testCase.hasSass
|
|
15
|
+
? 'stylelint-config-standard-vue/scss'
|
|
16
|
+
: 'stylelint-config-standard-vue',
|
|
17
|
+
);
|
|
18
|
+
},
|
|
19
|
+
);
|
package/src/configs/vue.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { hasSass } from '@culur/utils-packages';
|
|
2
|
-
import type { Config } from 'stylelint';
|
|
3
|
-
|
|
4
|
-
export const configVue = (): Config => ({
|
|
5
|
-
extends: [
|
|
6
|
-
hasSass()
|
|
7
|
-
? 'stylelint-config-standard-vue/scss'
|
|
8
|
-
: 'stylelint-config-standard-vue',
|
|
9
|
-
],
|
|
10
|
-
});
|
|
1
|
+
import { hasSass } from '@culur/utils-packages';
|
|
2
|
+
import type { Config } from 'stylelint';
|
|
3
|
+
|
|
4
|
+
export const configVue = (): Config => ({
|
|
5
|
+
extends: [
|
|
6
|
+
hasSass()
|
|
7
|
+
? 'stylelint-config-standard-vue/scss'
|
|
8
|
+
: 'stylelint-config-standard-vue',
|
|
9
|
+
],
|
|
10
|
+
});
|
package/src/factory.test.ts
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
import * as utilsPackages from '@culur/utils-packages';
|
|
2
|
+
import { css, describeLintAndFix } from './__tests__';
|
|
3
|
+
import defineConfig from './factory';
|
|
4
|
+
|
|
5
|
+
describeLintAndFix(utilsPackages, defineConfig, [
|
|
6
|
+
{
|
|
7
|
+
code: css`
|
|
8
|
+
a {
|
|
9
|
+
color: red;
|
|
10
|
+
}
|
|
11
|
+
`,
|
|
12
|
+
hasSass: true,
|
|
13
|
+
hasVue: true,
|
|
14
|
+
isError: false,
|
|
15
|
+
},
|
|
16
|
+
]);
|
package/src/factory.ts
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import type { Packages } from '@culur/utils-packages';
|
|
2
|
-
import { hasSass, hasVue, updateDefaultPackages } from '@culur/utils-packages';
|
|
3
|
-
import type { Config } from 'stylelint';
|
|
4
|
-
import { configCss } from './configs/css';
|
|
5
|
-
import { configScss } from './configs/scss';
|
|
6
|
-
import { configShared } from './configs/shared';
|
|
7
|
-
import { configVue } from './configs/vue';
|
|
8
|
-
import { mergeConfigs } from './utils';
|
|
9
|
-
|
|
10
|
-
export default function defineConfig(
|
|
11
|
-
options?: Partial<Packages>,
|
|
12
|
-
config?: Config,
|
|
13
|
-
): Config {
|
|
14
|
-
updateDefaultPackages(options);
|
|
15
|
-
|
|
16
|
-
return mergeConfigs(
|
|
17
|
-
configShared(),
|
|
18
|
-
configCss(),
|
|
19
|
-
hasSass() && configScss(),
|
|
20
|
-
hasVue() && configVue(),
|
|
21
|
-
config,
|
|
22
|
-
);
|
|
23
|
-
}
|
|
1
|
+
import type { Packages } from '@culur/utils-packages';
|
|
2
|
+
import { hasSass, hasVue, updateDefaultPackages } from '@culur/utils-packages';
|
|
3
|
+
import type { Config } from 'stylelint';
|
|
4
|
+
import { configCss } from './configs/css';
|
|
5
|
+
import { configScss } from './configs/scss';
|
|
6
|
+
import { configShared } from './configs/shared';
|
|
7
|
+
import { configVue } from './configs/vue';
|
|
8
|
+
import { mergeConfigs } from './utils';
|
|
9
|
+
|
|
10
|
+
export default function defineConfig(
|
|
11
|
+
options?: Partial<Packages>,
|
|
12
|
+
config?: Config,
|
|
13
|
+
): Config {
|
|
14
|
+
updateDefaultPackages(options);
|
|
15
|
+
|
|
16
|
+
return mergeConfigs(
|
|
17
|
+
configShared(),
|
|
18
|
+
configCss(),
|
|
19
|
+
hasSass() && configScss(),
|
|
20
|
+
hasVue() && configVue(),
|
|
21
|
+
config,
|
|
22
|
+
);
|
|
23
|
+
}
|
package/src/index.test.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { describe, expectTypeOf, it } from 'vitest';
|
|
2
|
-
import type { Config } from 'stylelint';
|
|
3
|
-
import defineConfig from '.';
|
|
4
|
-
|
|
5
|
-
describe('index', () => {
|
|
6
|
-
it('root config', () => {
|
|
7
|
-
expectTypeOf(defineConfig).toEqualTypeOf<Config>();
|
|
8
|
-
});
|
|
9
|
-
});
|
|
1
|
+
import { describe, expectTypeOf, it } from 'vitest';
|
|
2
|
+
import type { Config } from 'stylelint';
|
|
3
|
+
import defineConfig from '.';
|
|
4
|
+
|
|
5
|
+
describe('index', () => {
|
|
6
|
+
it('root config', () => {
|
|
7
|
+
expectTypeOf(defineConfig).toEqualTypeOf<Config>();
|
|
8
|
+
});
|
|
9
|
+
});
|
package/src/index.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import defineConfig from './factory';
|
|
2
|
-
|
|
3
|
-
export default defineConfig();
|
|
1
|
+
import defineConfig from './factory';
|
|
2
|
+
|
|
3
|
+
export default defineConfig();
|
|
@@ -1,43 +1,46 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
1
|
+
import * as utilsPackages from '@culur/utils-packages';
|
|
2
|
+
import { assert, expect } from 'vitest';
|
|
3
|
+
import {
|
|
4
|
+
atRuleNoUnknownCSS,
|
|
5
|
+
atRuleNoUnknownRule,
|
|
6
|
+
atRuleNoUnknownSCSS,
|
|
7
|
+
} from './at-rule-no-unknown';
|
|
8
|
+
import { describeLintAndFix, describeRule, syntaxScss } from '~/__tests__';
|
|
9
|
+
|
|
10
|
+
describeRule(
|
|
11
|
+
utilsPackages,
|
|
12
|
+
atRuleNoUnknownRule,
|
|
13
|
+
[
|
|
14
|
+
{ hasTailwind: false, length: 0 },
|
|
15
|
+
{ hasTailwind: true, length: 7 },
|
|
16
|
+
],
|
|
17
|
+
(rule, testCase) => {
|
|
18
|
+
assert(Array.isArray(rule));
|
|
19
|
+
assert(typeof rule[1] === 'object');
|
|
20
|
+
expect(rule[1].ignoreAtRules).toHaveLength(testCase.length);
|
|
21
|
+
},
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
describeLintAndFix(
|
|
25
|
+
utilsPackages, //
|
|
26
|
+
() => ({ rules: atRuleNoUnknownCSS() }),
|
|
27
|
+
[
|
|
28
|
+
{ hasTailwind: false, code: '@unknown {}', isError: true },
|
|
29
|
+
{ hasTailwind: false, code: '@media {}', isError: false },
|
|
30
|
+
{ hasTailwind: true, code: '@tailwind {}', isError: false },
|
|
31
|
+
],
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
describeLintAndFix(
|
|
35
|
+
utilsPackages,
|
|
36
|
+
() => ({
|
|
37
|
+
plugins: ['stylelint-scss'],
|
|
38
|
+
rules: atRuleNoUnknownSCSS(),
|
|
39
|
+
overrides: [syntaxScss],
|
|
40
|
+
}),
|
|
41
|
+
[
|
|
42
|
+
{ ext: 'scss', hasTailwind: false, code: '@unknown {}', isError: true },
|
|
43
|
+
{ ext: 'scss', hasTailwind: false, code: '@media {}', isError: false },
|
|
44
|
+
{ ext: 'scss', hasTailwind: true, code: '@tailwind {}', isError: false },
|
|
45
|
+
],
|
|
46
|
+
);
|