Skip to content

Commit b4f2895

Browse files
committed
feat(stylelint): ignore rules when nested
1 parent cdccdba commit b4f2895

2 files changed

Lines changed: 38 additions & 3 deletions

File tree

packages/stylelint/__tests__/index.spec.ts

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import stylelint from 'stylelint';
22
import configPromise, { configure } from '@deot/dev-stylelint';
33

44
// @vitest-environment node
5-
const lint = async (text: string, codeFilename?: string) => {
5+
const lint = async (text: string, options?: stylelint.LinterOptions) => {
66
const resultObject = await stylelint.lint({
77
config: await configPromise,
88
code: text,
9-
codeFilename
9+
...options
1010
});
1111
return resultObject;
1212
};
@@ -65,7 +65,7 @@ describe('index.js', () => {
6565
code += `a { color: color(1); }\n`;
6666
code += '</style>';
6767

68-
const data = await lint(code, './any.vue');
68+
const data = await lint(code, { codeFilename: './any.vue' });
6969
expect(data.errored).toBe(false);
7070
});
7171

@@ -97,6 +97,39 @@ describe('index.js', () => {
9797
const data = await lint(code);
9898
expect(data.report).toMatch('Expected \\"top\\" to come before \\"bottom\\" (order/properties-order)');
9999
});
100+
101+
it('nesting-selector-no-missing-scoping-root/ignore', async () => {
102+
expect.hasAssertions();
103+
104+
let code = '';
105+
code += `@include b(any) {\n`;
106+
code += ` @include when(any) {\n`;
107+
code += ` &:hover {\n`;
108+
code += ` color: red;\n`;
109+
code += ` }\n`;
110+
code += ` }\n`;
111+
code += `}\n`;
112+
113+
const data = await lint(code);
114+
expect(data.errored).toBe(false);
115+
});
116+
it('block-no-redundant-nested-style-rule/ignore', async () => {
117+
expect.hasAssertions();
118+
119+
let code = '';
120+
code += `@include b(any) {\n`;
121+
code += ` @include when(any) {\n`;
122+
code += ` & {\n`;
123+
code += ` ::after {\n`;
124+
code += ` color: red;\n`;
125+
code += ` }\n`;
126+
code += ` }\n`;
127+
code += ` }\n`;
128+
code += `}\n`;
129+
130+
const data = await lint(code, { fix: true });
131+
expect(data.errored).toBe(false);
132+
});
100133
});
101134

102135
/**

packages/stylelint/src/configure.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ export const configure = async (): Promise<Config> => {
3434
],
3535
'no-empty-source': null,
3636
'no-descending-specificity': null,
37+
'nesting-selector-no-missing-scoping-root': null,
38+
'block-no-redundant-nested-style-rules': null,
3739

3840
'block-no-empty': null,
3941
'selector-class-pattern': '[a-zA-Z0-9_-]+',

0 commit comments

Comments
 (0)