@servicetitan/stylelint-config 40.2.1 → 40.3.0
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@servicetitan/stylelint-config",
|
|
3
|
-
"version": "40.
|
|
3
|
+
"version": "40.3.0",
|
|
4
4
|
"description": "Core Stylelint rule sets for ServiceTitan web projects",
|
|
5
5
|
"homepage": "https://docs.st.dev/docs/frontend/uikit/eslint-config",
|
|
6
6
|
"repository": {
|
|
@@ -13,7 +13,11 @@
|
|
|
13
13
|
"typings": "./dist/index.d.ts",
|
|
14
14
|
"files": [
|
|
15
15
|
"dist",
|
|
16
|
-
"src"
|
|
16
|
+
"src",
|
|
17
|
+
"!**/__tests__",
|
|
18
|
+
"!**/__mocks__",
|
|
19
|
+
"!**/__snapshots__",
|
|
20
|
+
"!**/*.test.*"
|
|
17
21
|
],
|
|
18
22
|
"dependencies": {
|
|
19
23
|
"color": "~5.0.3",
|
|
@@ -23,7 +27,7 @@
|
|
|
23
27
|
"stylelint-prettier": "~5.0.3"
|
|
24
28
|
},
|
|
25
29
|
"devDependencies": {
|
|
26
|
-
"@servicetitan/anvil2": "^3.
|
|
30
|
+
"@servicetitan/anvil2": "^3.19.1",
|
|
27
31
|
"@servicetitan/tokens": "~12.9.0",
|
|
28
32
|
"stylelint": "~17.16.0"
|
|
29
33
|
},
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import postcss from 'postcss';
|
|
2
|
-
|
|
3
|
-
/*
|
|
4
|
-
* Stylelint is ESM-only, and Jest can only load ESM-only packages on Node 24.9+ with
|
|
5
|
-
* --experimental-vm-modules, so the rule runs directly against a postcss tree with stylelint's
|
|
6
|
-
* plugin utilities replaced.
|
|
7
|
-
*/
|
|
8
|
-
jest.mock('stylelint', () => ({
|
|
9
|
-
createPlugin: (ruleName: string, rule: unknown) => ({ ruleName, rule }),
|
|
10
|
-
utils: {
|
|
11
|
-
ruleMessages: (_ruleName: string, messages: unknown) => messages,
|
|
12
|
-
validateOptions: () => mockValidOptions,
|
|
13
|
-
report: mockReport,
|
|
14
|
-
},
|
|
15
|
-
}));
|
|
16
|
-
|
|
17
|
-
const mockReport = jest.fn();
|
|
18
|
-
let mockValidOptions: boolean;
|
|
19
|
-
|
|
20
|
-
/*
|
|
21
|
-
* The rule reads stylelint's utilities when it loads, so it's required after the mocks they
|
|
22
|
-
* reference are initialized. A static import would be hoisted above them.
|
|
23
|
-
*/
|
|
24
|
-
const { rule } = require('../function-url-no-absolute');
|
|
25
|
-
|
|
26
|
-
describe(`[stylelint-config] ${rule.ruleName} rule`, () => {
|
|
27
|
-
let declaration: string;
|
|
28
|
-
|
|
29
|
-
beforeEach(() => {
|
|
30
|
-
jest.clearAllMocks();
|
|
31
|
-
mockValidOptions = true;
|
|
32
|
-
declaration = 'background: url(/assets/image.png)';
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
const subject = () => {
|
|
36
|
-
rule(true, {}, {})(postcss.parse(`a { ${declaration} }`), {});
|
|
37
|
-
return mockReport.mock.calls.map(([report]) => report);
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
test('reports the absolute url', () => {
|
|
41
|
-
expect(subject()).toEqual([
|
|
42
|
-
expect.objectContaining({
|
|
43
|
-
message: 'Unexpected absolute url',
|
|
44
|
-
index: declaration.indexOf('/assets'),
|
|
45
|
-
endIndex: declaration.indexOf(')'),
|
|
46
|
-
}),
|
|
47
|
-
]);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
describe.each([
|
|
51
|
-
['double quotes', 'background: url("/assets/image.png")'],
|
|
52
|
-
['single quotes', "background: url('/assets/image.png')"],
|
|
53
|
-
['spaces and quotes', 'background: url( "/assets/image.png" )'],
|
|
54
|
-
['an uppercase function name', 'background: URL(/assets/image.png)'],
|
|
55
|
-
])('with %s', (_description, value) => {
|
|
56
|
-
beforeEach(() => (declaration = value));
|
|
57
|
-
|
|
58
|
-
test('reports the absolute url', () => {
|
|
59
|
-
expect(subject()).toHaveLength(1);
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
describe.each([
|
|
64
|
-
['a relative url', 'background: url(./assets/image.png)'],
|
|
65
|
-
['a protocol-relative url', 'background: url(//cdn.example.com/image.png)'],
|
|
66
|
-
['a full url', 'background: url(https://cdn.example.com/image.png)'],
|
|
67
|
-
['a data url', 'background: url(data:image/png;base64,AAAA)'],
|
|
68
|
-
['no url', 'color: red'],
|
|
69
|
-
])('with %s', (_description, value) => {
|
|
70
|
-
beforeEach(() => (declaration = value));
|
|
71
|
-
|
|
72
|
-
test('reports nothing', () => {
|
|
73
|
-
expect(subject()).toEqual([]);
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
describe('with invalid options', () => {
|
|
78
|
-
beforeEach(() => (mockValidOptions = false));
|
|
79
|
-
|
|
80
|
-
test('reports nothing', () => {
|
|
81
|
-
expect(subject()).toEqual([]);
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
});
|
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
import { fs, vol } from 'memfs';
|
|
2
|
-
import type { Token } from '../load-tokens';
|
|
3
|
-
|
|
4
|
-
jest.mock('fs', () => fs);
|
|
5
|
-
jest.mock('@servicetitan/tokens/core', () => ({
|
|
6
|
-
tokens: mockInstalled(mockDesignSystemTokens),
|
|
7
|
-
}));
|
|
8
|
-
jest.mock('@servicetitan/anvil2/token', () => {
|
|
9
|
-
if (mockAnvil2Error) {
|
|
10
|
-
throw mockAnvil2Error;
|
|
11
|
-
}
|
|
12
|
-
return { core: { primitive: mockInstalled(mockAnvil2Primitives) } };
|
|
13
|
-
});
|
|
14
|
-
jest.mock('@servicetitan/anvil2/package.json', () => {
|
|
15
|
-
if (mockAnvil2Version === undefined) {
|
|
16
|
-
throw Object.assign(new Error('Package subpath not exported'), {
|
|
17
|
-
code: 'ERR_PACKAGE_PATH_NOT_EXPORTED',
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
return { version: mockAnvil2Version };
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
let mockDesignSystemTokens: Record<string, string> | undefined;
|
|
24
|
-
let mockAnvil2Primitives: Record<string, { value: string }> | undefined;
|
|
25
|
-
let mockAnvil2Error: Error | undefined;
|
|
26
|
-
let mockAnvil2Version: string | undefined;
|
|
27
|
-
|
|
28
|
-
function mockInstalled<T>(exports: T | undefined) {
|
|
29
|
-
if (!exports) {
|
|
30
|
-
throw Object.assign(new Error('Cannot find module'), { code: 'MODULE_NOT_FOUND' });
|
|
31
|
-
}
|
|
32
|
-
return exports;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
describe('[stylelint-config] loadTokens', () => {
|
|
36
|
-
const designSystemLessPath = require.resolve('@servicetitan/tokens/core/tokens.less');
|
|
37
|
-
const value = '#0265dc';
|
|
38
|
-
|
|
39
|
-
beforeEach(() => {
|
|
40
|
-
jest.resetModules();
|
|
41
|
-
mockDesignSystemTokens = undefined;
|
|
42
|
-
mockAnvil2Primitives = undefined;
|
|
43
|
-
mockAnvil2Error = undefined;
|
|
44
|
-
mockAnvil2Version = '3.15.0';
|
|
45
|
-
vol.reset();
|
|
46
|
-
vol.fromJSON({ [designSystemLessPath]: '' });
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
const subject = (): Token[] => require('../load-tokens').loadTokens();
|
|
50
|
-
|
|
51
|
-
function itReturnsNoTokens() {
|
|
52
|
-
test('returns no tokens', () => {
|
|
53
|
-
expect(subject()).toEqual([]);
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
itReturnsNoTokens();
|
|
58
|
-
|
|
59
|
-
describe('with @servicetitan/tokens', () => {
|
|
60
|
-
beforeEach(() => (mockDesignSystemTokens = { colorBlue500: value }));
|
|
61
|
-
|
|
62
|
-
test('returns its tokens', () => {
|
|
63
|
-
expect(subject()).toEqual([
|
|
64
|
-
{
|
|
65
|
-
name: 'color-blue-500',
|
|
66
|
-
customProperty: '--color-blue-500',
|
|
67
|
-
source: '@servicetitan/tokens',
|
|
68
|
-
value,
|
|
69
|
-
},
|
|
70
|
-
]);
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
describe('with an alias', () => {
|
|
74
|
-
beforeEach(() => {
|
|
75
|
-
mockDesignSystemTokens!.colorPrimary = value;
|
|
76
|
-
vol.fromJSON({
|
|
77
|
-
[designSystemLessPath]: '@color-primary: @color-blue-500; // (alias)',
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
test('excludes the alias', () => {
|
|
82
|
-
expect(subject().map(({ name }) => name)).toEqual(['color-blue-500']);
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
describe('with @servicetitan/anvil2', () => {
|
|
88
|
-
beforeEach(() => (mockAnvil2Primitives = { ColorBlue600: { value } }));
|
|
89
|
-
|
|
90
|
-
test('returns its primitive tokens', () => {
|
|
91
|
-
expect(subject()).toEqual([
|
|
92
|
-
{
|
|
93
|
-
name: 'color-blue-600',
|
|
94
|
-
customProperty: '--a2-color-blue-600',
|
|
95
|
-
source: '@servicetitan/anvil2',
|
|
96
|
-
value,
|
|
97
|
-
},
|
|
98
|
-
]);
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
describe('when version is earlier than 3', () => {
|
|
102
|
-
beforeEach(() => (mockAnvil2Version = '2.9.6'));
|
|
103
|
-
|
|
104
|
-
test('omits the "a2" prefix', () => {
|
|
105
|
-
expect(subject()[0].customProperty).toBe('--color-blue-600');
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
describe('when version cannot be determined', () => {
|
|
110
|
-
beforeEach(() => (mockAnvil2Version = undefined));
|
|
111
|
-
|
|
112
|
-
test('adds the "a2" prefix', () => {
|
|
113
|
-
expect(subject()[0].customProperty).toBe('--a2-color-blue-600');
|
|
114
|
-
});
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
describe('without the token export', () => {
|
|
118
|
-
beforeEach(() => {
|
|
119
|
-
mockAnvil2Error = Object.assign(new Error('Package subpath not exported'), {
|
|
120
|
-
code: 'ERR_PACKAGE_PATH_NOT_EXPORTED',
|
|
121
|
-
});
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
itReturnsNoTokens();
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
describe('when the package fails to load', () => {
|
|
128
|
-
beforeEach(() => (mockAnvil2Error = new Error('Unexpected token')));
|
|
129
|
-
|
|
130
|
-
test('throws the error', () => {
|
|
131
|
-
expect(subject).toThrow(mockAnvil2Error);
|
|
132
|
-
});
|
|
133
|
-
});
|
|
134
|
-
});
|
|
135
|
-
});
|
|
@@ -1,414 +0,0 @@
|
|
|
1
|
-
import postcss from 'postcss';
|
|
2
|
-
import type { Token } from '../load-tokens';
|
|
3
|
-
|
|
4
|
-
/*
|
|
5
|
-
* Stylelint is ESM-only, and Jest can only load ESM-only packages on Node 24.9+ with
|
|
6
|
-
* --experimental-vm-modules, so the rule runs directly against a postcss tree with stylelint's
|
|
7
|
-
* plugin utilities replaced.
|
|
8
|
-
*/
|
|
9
|
-
jest.mock('stylelint', () => ({
|
|
10
|
-
createPlugin: (ruleName: string, rule: unknown) => ({ ruleName, rule }),
|
|
11
|
-
utils: {
|
|
12
|
-
ruleMessages: (_ruleName: string, messages: unknown) => messages,
|
|
13
|
-
report: mockReport,
|
|
14
|
-
},
|
|
15
|
-
}));
|
|
16
|
-
jest.mock('../load-tokens', () => ({
|
|
17
|
-
...jest.requireActual('../load-tokens'),
|
|
18
|
-
loadTokens: () => mockTokens,
|
|
19
|
-
}));
|
|
20
|
-
|
|
21
|
-
const mockReport = jest.fn();
|
|
22
|
-
const mockTokens: Token[] = [];
|
|
23
|
-
|
|
24
|
-
describe('[stylelint-config] @servicetitan/use-tokens rule', () => {
|
|
25
|
-
const value = '#0265dc';
|
|
26
|
-
const designSystemToken: Token = {
|
|
27
|
-
name: 'color-blue-500',
|
|
28
|
-
customProperty: '--color-blue-500',
|
|
29
|
-
source: '@servicetitan/tokens',
|
|
30
|
-
value,
|
|
31
|
-
};
|
|
32
|
-
const anvil2Token: Token = {
|
|
33
|
-
name: 'color-blue-600',
|
|
34
|
-
customProperty: '--a2-color-blue-600',
|
|
35
|
-
source: '@servicetitan/anvil2',
|
|
36
|
-
value,
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
let declaration: string;
|
|
40
|
-
let codeFilename: string | undefined;
|
|
41
|
-
let fix: boolean;
|
|
42
|
-
|
|
43
|
-
beforeEach(() => {
|
|
44
|
-
jest.clearAllMocks();
|
|
45
|
-
mockTokens.splice(0);
|
|
46
|
-
declaration = `color: ${value};`;
|
|
47
|
-
codeFilename = 'styles.css';
|
|
48
|
-
fix = false;
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
const subject = () => {
|
|
52
|
-
let rule: any;
|
|
53
|
-
// Rule initializes state when it loads, so load it after tests have set up tokens.
|
|
54
|
-
jest.isolateModules(() => (rule = require('../use-tokens').rule));
|
|
55
|
-
const root = postcss.parse(`a { ${declaration} }`);
|
|
56
|
-
rule(true, {}, { fix })(root, { opts: { from: codeFilename } });
|
|
57
|
-
return {
|
|
58
|
-
messages: mockReport.mock.calls.map(([{ message }]) => message),
|
|
59
|
-
words: mockReport.mock.calls.map(([{ word }]) => word),
|
|
60
|
-
code: root.toString(),
|
|
61
|
-
};
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
function itReportsNothing() {
|
|
65
|
-
test('reports nothing', () => {
|
|
66
|
-
expect(subject().messages).toEqual([]);
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function itNegatesCustomPropertyWithCalc(customProperty: string) {
|
|
71
|
-
test('negates its custom property with calc()', () => {
|
|
72
|
-
expect(subject().messages[0]).toContain(`"calc(-1 * var(${customProperty}))"`);
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
itReportsNothing();
|
|
77
|
-
|
|
78
|
-
describe('when the value matches a design-system token', () => {
|
|
79
|
-
beforeEach(() => mockTokens.push({ ...designSystemToken }));
|
|
80
|
-
|
|
81
|
-
test('reports its custom property', () => {
|
|
82
|
-
expect(subject().messages).toEqual([
|
|
83
|
-
`You should use "var(${designSystemToken.customProperty})" from \`${designSystemToken.source}\` instead of "${value}".`,
|
|
84
|
-
]);
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
describe('with a Less file', () => {
|
|
88
|
-
beforeEach(() => (codeFilename = 'styles.less'));
|
|
89
|
-
|
|
90
|
-
test('reports its Less variable', () => {
|
|
91
|
-
expect(subject().messages[0]).toContain(`"@${designSystemToken.name}"`);
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
describe.each(['styles.scss', 'styles.sass'])('with %s', filename => {
|
|
96
|
-
beforeEach(() => (codeFilename = filename));
|
|
97
|
-
|
|
98
|
-
test('reports its Sass variable', () => {
|
|
99
|
-
expect(subject().messages[0]).toContain(`"$${designSystemToken.name}"`);
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
describe('without a file name', () => {
|
|
104
|
-
beforeEach(() => (codeFilename = undefined));
|
|
105
|
-
|
|
106
|
-
test('reports its custom property', () => {
|
|
107
|
-
expect(subject().messages[0]).toContain(
|
|
108
|
-
`"var(${designSystemToken.customProperty})"`
|
|
109
|
-
);
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
describe('when fixing', () => {
|
|
114
|
-
beforeEach(() => (fix = true));
|
|
115
|
-
|
|
116
|
-
test('replaces the value', () => {
|
|
117
|
-
expect(subject().code).toBe(
|
|
118
|
-
`a { color: var(${designSystemToken.customProperty}); }`
|
|
119
|
-
);
|
|
120
|
-
});
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
describe.each([
|
|
124
|
-
['an uppercase hex color', '#0265DC'],
|
|
125
|
-
['an rgb() color', 'rgb(2, 101, 220)'],
|
|
126
|
-
['a space-separated rgb() color', 'rgb(2 101 220)'],
|
|
127
|
-
['an rgb() color among other values', '1px solid rgb(2, 101, 220)'],
|
|
128
|
-
['a hex color in a gradient', 'linear-gradient(90deg, #0265dc 0%, #fff 100%)'],
|
|
129
|
-
[
|
|
130
|
-
'an rgb() color in a gradient',
|
|
131
|
-
'linear-gradient(90deg, rgb(2, 101, 220) 0%, #fff 100%)',
|
|
132
|
-
],
|
|
133
|
-
])('with %s', (_description, color) => {
|
|
134
|
-
beforeEach(() => (declaration = `color: ${color};`));
|
|
135
|
-
|
|
136
|
-
test('reports its custom property', () => {
|
|
137
|
-
expect(subject().messages[0]).toContain(
|
|
138
|
-
`"var(${designSystemToken.customProperty})"`
|
|
139
|
-
);
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
describe.each([
|
|
144
|
-
['a translucent rgba() color', 'rgba(2, 101, 220, 0.5)'],
|
|
145
|
-
['a translucent hex color', '#0265dc80'],
|
|
146
|
-
])('with %s', (_description, color) => {
|
|
147
|
-
beforeEach(() => (declaration = `color: ${color};`));
|
|
148
|
-
|
|
149
|
-
itReportsNothing();
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
describe('with a color among other values', () => {
|
|
153
|
-
beforeEach(() => (declaration = `border: 1px solid ${value};`));
|
|
154
|
-
|
|
155
|
-
test('reports only the color', () => {
|
|
156
|
-
expect(subject().messages).toEqual([
|
|
157
|
-
expect.stringContaining(`"var(${designSystemToken.customProperty})"`),
|
|
158
|
-
]);
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
test('reports the color as written', () => {
|
|
162
|
-
expect(subject().words).toEqual([value]);
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
describe('when fixing', () => {
|
|
166
|
-
beforeEach(() => (fix = true));
|
|
167
|
-
|
|
168
|
-
function itReplacesOnlyTheColor() {
|
|
169
|
-
test('replaces only the color', () => {
|
|
170
|
-
expect(subject().code).toBe(
|
|
171
|
-
`a { border: 1px solid var(${designSystemToken.customProperty}); }`
|
|
172
|
-
);
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
itReplacesOnlyTheColor();
|
|
177
|
-
|
|
178
|
-
describe('with an rgb() color', () => {
|
|
179
|
-
beforeEach(() => (declaration = 'border: 1px solid rgb(2, 101, 220);'));
|
|
180
|
-
|
|
181
|
-
itReplacesOnlyTheColor();
|
|
182
|
-
});
|
|
183
|
-
});
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
describe('with several matching values', () => {
|
|
187
|
-
const spacing1: Token = {
|
|
188
|
-
...designSystemToken,
|
|
189
|
-
name: 'spacing-1',
|
|
190
|
-
customProperty: '--spacing-1',
|
|
191
|
-
value: '8px',
|
|
192
|
-
};
|
|
193
|
-
const spacing2: Token = {
|
|
194
|
-
...designSystemToken,
|
|
195
|
-
name: 'spacing-2',
|
|
196
|
-
customProperty: '--spacing-2',
|
|
197
|
-
value: '16px',
|
|
198
|
-
};
|
|
199
|
-
|
|
200
|
-
beforeEach(() => {
|
|
201
|
-
mockTokens.push(spacing1, spacing2);
|
|
202
|
-
declaration = `margin: ${spacing1.value} ${spacing2.value};`;
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
test('reports each value', () => {
|
|
206
|
-
expect(subject().messages).toEqual([
|
|
207
|
-
expect.stringContaining(`"var(${spacing1.customProperty})"`),
|
|
208
|
-
expect.stringContaining(`"var(${spacing2.customProperty})"`),
|
|
209
|
-
]);
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
describe('when fixing', () => {
|
|
213
|
-
beforeEach(() => (fix = true));
|
|
214
|
-
|
|
215
|
-
test('replaces each value', () => {
|
|
216
|
-
expect(subject().code).toBe(
|
|
217
|
-
`a { margin: var(${spacing1.customProperty}) var(${spacing2.customProperty}); }`
|
|
218
|
-
);
|
|
219
|
-
});
|
|
220
|
-
});
|
|
221
|
-
|
|
222
|
-
describe('with a negative value', () => {
|
|
223
|
-
beforeEach(() => (declaration = `margin: -${spacing2.value};`));
|
|
224
|
-
|
|
225
|
-
itNegatesCustomPropertyWithCalc(spacing2.customProperty);
|
|
226
|
-
|
|
227
|
-
test('reports the value with its minus sign', () => {
|
|
228
|
-
expect(subject().words).toEqual([`-${spacing2.value}`]);
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
describe('with a Sass file', () => {
|
|
232
|
-
beforeEach(() => (codeFilename = 'styles.scss'));
|
|
233
|
-
|
|
234
|
-
test('negates its Sass variable', () => {
|
|
235
|
-
expect(subject().messages[0]).toContain(`"-$${spacing2.name}"`);
|
|
236
|
-
});
|
|
237
|
-
});
|
|
238
|
-
|
|
239
|
-
describe('with a Less file', () => {
|
|
240
|
-
beforeEach(() => (codeFilename = 'styles.less'));
|
|
241
|
-
|
|
242
|
-
test('negates its Less variable', () => {
|
|
243
|
-
expect(subject().messages[0]).toContain(`"-@${spacing2.name}"`);
|
|
244
|
-
});
|
|
245
|
-
});
|
|
246
|
-
|
|
247
|
-
describe('when fixing', () => {
|
|
248
|
-
beforeEach(() => (fix = true));
|
|
249
|
-
|
|
250
|
-
test('replaces the value', () => {
|
|
251
|
-
expect(subject().code).toBe(
|
|
252
|
-
`a { margin: calc(-1 * var(${spacing2.customProperty})); }`
|
|
253
|
-
);
|
|
254
|
-
});
|
|
255
|
-
});
|
|
256
|
-
});
|
|
257
|
-
});
|
|
258
|
-
|
|
259
|
-
describe.each([
|
|
260
|
-
['typescale-2', 'font-size', '14px', '14px'],
|
|
261
|
-
['border-radius-1', 'border-radius', '3px', '3px'],
|
|
262
|
-
['border-radius-0', 'border-radius', '0px', '0'],
|
|
263
|
-
['border-radius-1', 'border-top-left-radius', '3px', '3px'],
|
|
264
|
-
['spacing-1', 'margin', '8px', '8px'],
|
|
265
|
-
['spacing-0', 'margin', '0px', '0'],
|
|
266
|
-
['font-weight-semibold', 'font-weight', '600', '600'],
|
|
267
|
-
['opacity-disabled', 'opacity', '0.6', '.6'],
|
|
268
|
-
['opacity-disabled', 'opacity', '.6', '.6'],
|
|
269
|
-
['z-index-drawer', 'z-index', '1100', '1100'],
|
|
270
|
-
['base-line-height', 'line-height', '1.5', '1.5'],
|
|
271
|
-
[
|
|
272
|
-
'base-font-family',
|
|
273
|
-
'font-family',
|
|
274
|
-
"'Nunito Sans', sans-serif",
|
|
275
|
-
"'Nunito Sans', sans-serif",
|
|
276
|
-
],
|
|
277
|
-
])('when %s replaces %s: %s', (name, property, literal, tokenValue) => {
|
|
278
|
-
beforeEach(() => {
|
|
279
|
-
Object.assign(mockTokens[0], {
|
|
280
|
-
name,
|
|
281
|
-
customProperty: `--${name}`,
|
|
282
|
-
value: tokenValue,
|
|
283
|
-
});
|
|
284
|
-
declaration = `${property}: ${literal};`;
|
|
285
|
-
});
|
|
286
|
-
|
|
287
|
-
test(`reports var(--${name})`, () => {
|
|
288
|
-
expect(subject().messages[0]).toContain(`"var(--${name})"`);
|
|
289
|
-
});
|
|
290
|
-
});
|
|
291
|
-
});
|
|
292
|
-
|
|
293
|
-
describe('when the value matches an anvil2 token', () => {
|
|
294
|
-
beforeEach(() => mockTokens.push({ ...anvil2Token }));
|
|
295
|
-
|
|
296
|
-
test('reports its custom property', () => {
|
|
297
|
-
expect(subject().messages).toEqual([
|
|
298
|
-
`You should use "var(${anvil2Token.customProperty})" from \`${anvil2Token.source}\` instead of "${value}".`,
|
|
299
|
-
]);
|
|
300
|
-
});
|
|
301
|
-
|
|
302
|
-
describe('with a Less file', () => {
|
|
303
|
-
beforeEach(() => (codeFilename = 'styles.less'));
|
|
304
|
-
|
|
305
|
-
test('reports its custom property', () => {
|
|
306
|
-
expect(subject().messages[0]).toContain(`"var(${anvil2Token.customProperty})"`);
|
|
307
|
-
});
|
|
308
|
-
});
|
|
309
|
-
|
|
310
|
-
describe('with a Sass file', () => {
|
|
311
|
-
beforeEach(() => (codeFilename = 'styles.scss'));
|
|
312
|
-
|
|
313
|
-
test('reports its Sass variable', () => {
|
|
314
|
-
expect(subject().messages[0]).toContain(`"$${anvil2Token.name}"`);
|
|
315
|
-
});
|
|
316
|
-
});
|
|
317
|
-
|
|
318
|
-
describe('with an unsupported color format', () => {
|
|
319
|
-
beforeEach(() => (mockTokens[0].value = 'oklch(70% 0.1 200)'));
|
|
320
|
-
|
|
321
|
-
itReportsNothing();
|
|
322
|
-
});
|
|
323
|
-
|
|
324
|
-
describe('with a negative spacing value', () => {
|
|
325
|
-
const spacing: Pick<Token, 'name' | 'customProperty' | 'value'> = {
|
|
326
|
-
name: 'size-1',
|
|
327
|
-
customProperty: '--a2-size-1',
|
|
328
|
-
value: '0.25rem',
|
|
329
|
-
};
|
|
330
|
-
|
|
331
|
-
beforeEach(() => {
|
|
332
|
-
Object.assign(mockTokens[0], spacing);
|
|
333
|
-
declaration = `margin: -${spacing.value};`;
|
|
334
|
-
});
|
|
335
|
-
|
|
336
|
-
itNegatesCustomPropertyWithCalc(spacing.customProperty);
|
|
337
|
-
|
|
338
|
-
describe('with a Sass file', () => {
|
|
339
|
-
beforeEach(() => (codeFilename = 'styles.scss'));
|
|
340
|
-
|
|
341
|
-
test('negates its Sass variable with calc()', () => {
|
|
342
|
-
expect(subject().messages[0]).toContain(`"calc(-1 * $${spacing.name})"`);
|
|
343
|
-
});
|
|
344
|
-
});
|
|
345
|
-
|
|
346
|
-
describe('with a Less file', () => {
|
|
347
|
-
beforeEach(() => (codeFilename = 'styles.less'));
|
|
348
|
-
|
|
349
|
-
itNegatesCustomPropertyWithCalc(spacing.customProperty);
|
|
350
|
-
});
|
|
351
|
-
});
|
|
352
|
-
|
|
353
|
-
describe.each([
|
|
354
|
-
['font-size-300', 'font-size', '0.875rem'],
|
|
355
|
-
['radius-1', 'border-radius', '0.1875rem'],
|
|
356
|
-
['size-1', 'padding', '0.25rem'],
|
|
357
|
-
['font-weight-bold', 'font-weight', '700'],
|
|
358
|
-
['font-line-height-base', 'line-height', '1.5'],
|
|
359
|
-
['font-family-base', 'font-family', "'Nunito Sans', sans-serif"],
|
|
360
|
-
])('when %s replaces %s: %s', (name, property, value) => {
|
|
361
|
-
beforeEach(() => {
|
|
362
|
-
Object.assign(mockTokens[0], { name, customProperty: `--a2-${name}`, value });
|
|
363
|
-
declaration = `${property}: ${value};`;
|
|
364
|
-
});
|
|
365
|
-
|
|
366
|
-
test(`reports var(--a2-${name})`, () => {
|
|
367
|
-
expect(subject().messages[0]).toContain(`"var(--a2-${name})"`);
|
|
368
|
-
});
|
|
369
|
-
});
|
|
370
|
-
});
|
|
371
|
-
|
|
372
|
-
describe('when the value matches tokens from both packages', () => {
|
|
373
|
-
beforeEach(() => mockTokens.push({ ...designSystemToken }, { ...anvil2Token }));
|
|
374
|
-
|
|
375
|
-
test('reports every match', () => {
|
|
376
|
-
expect(subject().messages).toEqual([
|
|
377
|
-
`You should use "var(${designSystemToken.customProperty})" from \`${designSystemToken.source}\`` +
|
|
378
|
-
` or "var(${anvil2Token.customProperty})" from \`${anvil2Token.source}\` instead of "${value}".`,
|
|
379
|
-
]);
|
|
380
|
-
});
|
|
381
|
-
|
|
382
|
-
describe('when fixing', () => {
|
|
383
|
-
beforeEach(() => (fix = true));
|
|
384
|
-
|
|
385
|
-
test('leaves the value', () => {
|
|
386
|
-
expect(subject().code).toBe(`a { ${declaration} }`);
|
|
387
|
-
});
|
|
388
|
-
});
|
|
389
|
-
|
|
390
|
-
describe('when the tokens share a name', () => {
|
|
391
|
-
const name = 'color-shared';
|
|
392
|
-
|
|
393
|
-
beforeEach(() => mockTokens.forEach(token => (token.name = name)));
|
|
394
|
-
|
|
395
|
-
describe('with a Sass file', () => {
|
|
396
|
-
beforeEach(() => (codeFilename = 'styles.scss'));
|
|
397
|
-
|
|
398
|
-
test('reports the shared variable once', () => {
|
|
399
|
-
expect(subject().messages).toEqual([
|
|
400
|
-
`You should use "$${name}" from \`${mockTokens[0].source}\` instead of "${value}".`,
|
|
401
|
-
]);
|
|
402
|
-
});
|
|
403
|
-
|
|
404
|
-
describe('when fixing', () => {
|
|
405
|
-
beforeEach(() => (fix = true));
|
|
406
|
-
|
|
407
|
-
test('replaces the value', () => {
|
|
408
|
-
expect(subject().code).toBe(`a { color: $${name}; }`);
|
|
409
|
-
});
|
|
410
|
-
});
|
|
411
|
-
});
|
|
412
|
-
});
|
|
413
|
-
});
|
|
414
|
-
});
|