Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/linters/contentQuotesLinter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const linter: Linter = (key, value, info) => {
typeof value !== 'string' ||
(contentValues.indexOf(value) === -1 &&
!contentValuePattern.test(value) &&
!value.startsWith('var(') &&
(value.charAt(0) !== value.charAt(value.length - 1) ||
(value.charAt(0) !== '"' && value.charAt(0) !== "'")))
) {
Expand Down
74 changes: 46 additions & 28 deletions tests/linter.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
logicalPropertiesLinter,
parentSelectorLinter,
} from '../src/linters';
import { resetWarned } from 'rc-util/lib/warning';

interface DesignToken {
primaryColor: string;
Expand All @@ -31,7 +32,7 @@ const derivative = (designToken: DesignToken): DerivativeToken => ({
const theme = new Theme(derivative);

describe('style warning', () => {
const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => { });

afterEach(() => {
errorSpy.mockReset();
Expand Down Expand Up @@ -67,7 +68,7 @@ describe('style warning', () => {
[prop]: 1,
});
const Demo = () => {
const [token] = useCacheToken<DerivativeToken>(theme, [], { cssVar: {key: 'css-var-test'}});
const [token] = useCacheToken<DerivativeToken>(theme, [], { cssVar: { key: 'css-var-test' } });
useStyleRegister({ theme, token, path: [`${prop}`] }, () => [
genStyle(),
]);
Expand All @@ -87,21 +88,38 @@ describe('style warning', () => {
});
});

it('content value should contain quotes', () => {
const genStyle = (): CSSObject => ({
content: 'test',
describe('contentQuotesLinter', () => {
beforeAll(() => {
resetWarned()
});
it('should not warn for content with var() function', () => {
const genStyle = (): CSSObject => ({
content: 'var(--content-value)',
});
const Demo = () => {
const [token] = useCacheToken<DerivativeToken>(theme, [], { cssVar: { key: 'css-var-test' } });
useStyleRegister({ theme, token, path: ['content-var'] }, () => [genStyle()]);
return <div />;
};
render(<Demo />);
expect(errorSpy).not.toHaveBeenCalled();
});
it('should warn when content value is without quotes', () => {
const genStyle = (): CSSObject => ({
content: 'test',
});
const Demo = () => {
const [token] = useCacheToken<DerivativeToken>(theme, [], { cssVar: { key: 'css-var-test' } });
useStyleRegister({ theme, token, path: ['content'] }, () => [genStyle()]);
return <div />;
};
render(<Demo />);
expect(errorSpy).toHaveBeenCalledWith(
expect.stringContaining(
`You seem to be using a value for 'content' without quotes`,
),
);
});
const Demo = () => {
const [token] = useCacheToken<DerivativeToken>(theme, [], { cssVar: {key: 'css-var-test'}});
useStyleRegister({ theme, token, path: ['content'] }, () => [genStyle()]);
return <div />;
};
render(<Demo />);
expect(errorSpy).toHaveBeenCalledWith(
expect.stringContaining(
`You seem to be using a value for 'content' without quotes`,
),
);
});

['margin', 'padding', 'borderWidth', 'borderStyle'].forEach((prop) =>
Expand All @@ -110,7 +128,7 @@ describe('style warning', () => {
[prop]: '0 1px 0 3px',
});
const Demo = () => {
const [token] = useCacheToken<DerivativeToken>(theme, [], { cssVar: {key: 'css-var-test'}});
const [token] = useCacheToken<DerivativeToken>(theme, [], { cssVar: { key: 'css-var-test' } });
useStyleRegister({ theme, token, path: [prop] }, () => [genStyle()]);
return <div />;
};
Expand All @@ -133,7 +151,7 @@ describe('style warning', () => {
[prop]: 'left',
});
const Demo = () => {
const [token] = useCacheToken<DerivativeToken>(theme, [], { cssVar: {key: 'css-var-test'}});
const [token] = useCacheToken<DerivativeToken>(theme, [], { cssVar: { key: 'css-var-test' } });
useStyleRegister({ theme, token, path: [prop] }, () => [genStyle()]);
return <div />;
};
Expand Down Expand Up @@ -162,7 +180,7 @@ describe('style warning', () => {
borderRadius: value,
});
const Demo = () => {
const [token] = useCacheToken<DerivativeToken>(theme, [], { cssVar: {key: 'css-var-test'}});
const [token] = useCacheToken<DerivativeToken>(theme, [], { cssVar: { key: 'css-var-test' } });
useStyleRegister(
{ theme, token, path: [`borderRadius: ${value}`] },
() => [genStyle()],
Expand All @@ -187,7 +205,7 @@ describe('style warning', () => {
content: { _skip_check_: true, value: 'content' },
});
const Demo = () => {
const [token] = useCacheToken<DerivativeToken>(theme, [], { cssVar: {key: 'css-var-test'}});
const [token] = useCacheToken<DerivativeToken>(theme, [], { cssVar: { key: 'css-var-test' } });
useStyleRegister({ theme, token, path: ['content_skip'] }, () => [
genStyle(),
]);
Expand All @@ -202,7 +220,7 @@ describe('style warning', () => {
content: '',
});
const Demo = () => {
const [token] = useCacheToken<DerivativeToken>(theme, [], { cssVar: {key: 'css-var-test'}});
const [token] = useCacheToken<DerivativeToken>(theme, [], { cssVar: { key: 'css-var-test' } });
useStyleRegister({ theme, token, path: ['component-msg'] }, () => [
genStyle(),
]);
Expand All @@ -221,7 +239,7 @@ describe('style warning', () => {
},
});
const Demo = () => {
const [token] = useCacheToken<DerivativeToken>(theme, [], { cssVar: {key: 'css-var-test'}});
const [token] = useCacheToken<DerivativeToken>(theme, [], { cssVar: { key: 'css-var-test' } });
useStyleRegister({ theme, token, path: ['selector-in-warning'] }, () => [
genStyle(),
]);
Expand Down Expand Up @@ -252,7 +270,7 @@ describe('style warning', () => {
animation: anim.getName(),
});
const Demo = () => {
const [token, hashId] = useCacheToken<DerivativeToken>(theme, [], { cssVar: {key: 'css-var-test'}});
const [token, hashId] = useCacheToken<DerivativeToken>(theme, [], { cssVar: { key: 'css-var-test' } });
useStyleRegister(
{ theme, token, path: ['anim-hashed-animation'], hashId },
() => [genStyle(), anim],
Expand All @@ -278,7 +296,7 @@ describe('style warning', () => {
},
});
const Demo = () => {
const [token] = useCacheToken<DerivativeToken>(theme, [], { cssVar: {key: 'css-var-test'}});
const [token] = useCacheToken<DerivativeToken>(theme, [], { cssVar: { key: 'css-var-test' } });
useStyleRegister({ theme, token, path: ['content'] }, () => [
genStyle(),
]);
Expand Down Expand Up @@ -308,7 +326,7 @@ describe('style warning', () => {
},
});
const Demo = () => {
const [token] = useCacheToken<DerivativeToken>(theme, [], { cssVar: {key: 'css-var-test'}});
const [token] = useCacheToken<DerivativeToken>(theme, [], { cssVar: { key: 'css-var-test' } });
useStyleRegister(
{ theme, token, path: ['attribute selector in :not'] },
() => [genStyle()],
Expand Down Expand Up @@ -342,7 +360,7 @@ describe('style warning', () => {
},
});
const Demo = () => {
const [token] = useCacheToken<DerivativeToken>(theme, [], { cssVar: {key: 'css-var-test'}});
const [token] = useCacheToken<DerivativeToken>(theme, [], { cssVar: { key: 'css-var-test' } });
useStyleRegister({ theme, token, path: ['parent selector'] }, () => [
genStyle(),
]);
Expand Down Expand Up @@ -370,7 +388,7 @@ describe('style warning', () => {
},
});
const Demo = () => {
const [token] = useCacheToken<DerivativeToken>(theme, [], { cssVar: {key: 'css-var-test'}});
const [token] = useCacheToken<DerivativeToken>(theme, [], { cssVar: { key: 'css-var-test' } });
useStyleRegister({ theme, token, path: ['parent selector2'] }, () => [
genStyle(),
]);
Expand Down Expand Up @@ -400,7 +418,7 @@ describe('style warning', () => {
},
});
const Demo = () => {
const [token] = useCacheToken<DerivativeToken>(theme, [], { cssVar: {key: 'css-var-test'}});
const [token] = useCacheToken<DerivativeToken>(theme, [], { cssVar: { key: 'css-var-test' } });
useStyleRegister({ theme, token, path: ['parent selector3'] }, () => [
genStyle(),
]);
Expand Down