stylelint-plugin-rhythmguard 2.1.0 → 2.2.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/CHANGELOG.md +21 -0
- package/CONTRIBUTING.md +1 -0
- package/README.md +13 -2
- package/package.json +7 -1
- package/src/audit/args.js +6 -1
- package/src/audit/config.js +15 -5
- package/src/audit/contract.js +5 -0
- package/src/audit/render-markdown.js +11 -0
- package/src/audit/render-text.js +7 -1
- package/src/audit/report.js +82 -8
- package/src/cli/index.js +11 -5
- package/src/cli/init.js +5 -1
- package/src/cli/quickstart.js +203 -0
- package/src/configs/embed.js +24 -0
- package/src/configs/embed.mjs +4 -0
- package/src/index.js +1 -0
- package/src/rules/no-offscale-transform/index.js +22 -0
- package/src/rules/prefer-token/index.js +28 -0
- package/src/rules/use-scale/index.js +34 -4
- package/src/utils/length.js +16 -0
- package/src/utils/options.js +53 -3
- package/src/utils/scale-inference.js +255 -0
- package/src/utils/token-map.js +4 -2
- package/src/utils/token-sources.js +32 -2
- package/types/__checks__/consumer.ts +10 -0
- package/types/audit.d.ts +16 -1
- package/types/index.d.ts +4 -0
- package/types/shared.d.ts +22 -1
|
@@ -14,6 +14,7 @@ import { createAuditReport, toAuditContractReport } from 'stylelint-plugin-rhyth
|
|
|
14
14
|
import eslintPlugin from 'stylelint-plugin-rhythmguard/eslint';
|
|
15
15
|
import { getScalePreset, listScalePresetNames } from 'stylelint-plugin-rhythmguard/presets';
|
|
16
16
|
import recommended from 'stylelint-plugin-rhythmguard/configs/recommended';
|
|
17
|
+
import embed from 'stylelint-plugin-rhythmguard/configs/embed';
|
|
17
18
|
import reactTailwind from 'stylelint-plugin-rhythmguard/configs/react-tailwind';
|
|
18
19
|
import useScale, { ruleName as useScaleName } from 'stylelint-plugin-rhythmguard/rules/use-scale';
|
|
19
20
|
|
|
@@ -27,6 +28,8 @@ const pluginConfigs: readonly RhythmguardStylelintConfig[] = [
|
|
|
27
28
|
plugin.configs.motion,
|
|
28
29
|
plugin.configs['react-tailwind'],
|
|
29
30
|
configs.recommended,
|
|
31
|
+
plugin.configs.embed,
|
|
32
|
+
embed,
|
|
30
33
|
recommended,
|
|
31
34
|
reactTailwind,
|
|
32
35
|
];
|
|
@@ -38,6 +41,12 @@ const ruleOptions: RhythmguardRuleOptions = {
|
|
|
38
41
|
tokenMapFromCssCustomProperties: true,
|
|
39
42
|
};
|
|
40
43
|
|
|
44
|
+
const autoScaleOptions: RhythmguardRuleOptions = {
|
|
45
|
+
scale: 'auto',
|
|
46
|
+
scaleSources: ['./tokens.json', { path: './theme.css', format: 'css' }],
|
|
47
|
+
tailwindConfigPath: './tailwind.config.mjs',
|
|
48
|
+
};
|
|
49
|
+
|
|
41
50
|
const useScaleRule = rules['rhythmguard/use-scale'];
|
|
42
51
|
const fixable: boolean | undefined = useScaleRule.meta.fixable;
|
|
43
52
|
const docUrl: string | undefined = useScale.meta.url;
|
|
@@ -59,6 +68,7 @@ async function runAudit(): Promise<AuditContractReport> {
|
|
|
59
68
|
|
|
60
69
|
void pluginConfigs;
|
|
61
70
|
void ruleOptions;
|
|
71
|
+
void autoScaleOptions;
|
|
62
72
|
void fixable;
|
|
63
73
|
void docUrl;
|
|
64
74
|
void name;
|
package/types/audit.d.ts
CHANGED
|
@@ -37,7 +37,8 @@ export interface AuditOptions {
|
|
|
37
37
|
noConfig?: boolean;
|
|
38
38
|
/** Write rendered output to this file instead of stdout (equivalent to `--output`). */
|
|
39
39
|
outputPath?: string;
|
|
40
|
-
scale
|
|
40
|
+
/** Explicit scale values, or `"auto"` to infer from token sources, then scanned CSS, then the default. */
|
|
41
|
+
scale?: Array<number | string> | "auto";
|
|
41
42
|
since?: string;
|
|
42
43
|
sinceBaseline?: boolean;
|
|
43
44
|
staged?: boolean;
|
|
@@ -87,8 +88,19 @@ export interface AuditBaselineComparison {
|
|
|
87
88
|
[key: string]: unknown;
|
|
88
89
|
}
|
|
89
90
|
|
|
91
|
+
export type AuditScaleSource = "default" | "explicit" | "fallback" | "scanned-css" | "token-sources";
|
|
92
|
+
|
|
93
|
+
export interface AuditScale {
|
|
94
|
+
/** Files the scale was derived from (token sources or scanned stylesheets). Empty for explicit, default and fallback. */
|
|
95
|
+
files: string[];
|
|
96
|
+
source: AuditScaleSource;
|
|
97
|
+
tokenCount: number;
|
|
98
|
+
values: Array<number | string>;
|
|
99
|
+
}
|
|
100
|
+
|
|
90
101
|
export interface AuditReport {
|
|
91
102
|
baseline?: AuditBaselineComparison | null;
|
|
103
|
+
scale?: AuditScale | null;
|
|
92
104
|
config?: string | null;
|
|
93
105
|
directory: string;
|
|
94
106
|
findings: {
|
|
@@ -112,8 +124,11 @@ export interface AuditContractReport {
|
|
|
112
124
|
motion?: unknown;
|
|
113
125
|
scale: {
|
|
114
126
|
cleanliness?: unknown;
|
|
127
|
+
files: string[];
|
|
115
128
|
offScaleValues?: unknown;
|
|
129
|
+
source: AuditScaleSource;
|
|
116
130
|
tokenOpportunities?: unknown;
|
|
131
|
+
values: Array<number | string> | null;
|
|
117
132
|
};
|
|
118
133
|
tokens?: unknown;
|
|
119
134
|
};
|
package/types/index.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export type {
|
|
|
14
14
|
RhythmguardRuleOptions,
|
|
15
15
|
RhythmguardStylelintConfig,
|
|
16
16
|
ScalePresetMetadata,
|
|
17
|
+
ScaleSource,
|
|
17
18
|
ScaleValue,
|
|
18
19
|
} from "./shared";
|
|
19
20
|
export type {
|
|
@@ -22,6 +23,8 @@ export type {
|
|
|
22
23
|
AuditFinding,
|
|
23
24
|
AuditOptions,
|
|
24
25
|
AuditReport,
|
|
26
|
+
AuditScale,
|
|
27
|
+
AuditScaleSource,
|
|
25
28
|
AuditScanned,
|
|
26
29
|
AuditSummary,
|
|
27
30
|
AuditTokenKind,
|
|
@@ -35,6 +38,7 @@ export type { StylelintRuleModule } from "./rule";
|
|
|
35
38
|
export interface RhythmguardPlugin extends Array<StylelintRuleModule> {
|
|
36
39
|
audit: typeof auditApi;
|
|
37
40
|
configs: {
|
|
41
|
+
embed: RhythmguardStylelintConfig;
|
|
38
42
|
expanded: RhythmguardStylelintConfig;
|
|
39
43
|
logical: RhythmguardStylelintConfig;
|
|
40
44
|
migration: RhythmguardStylelintConfig;
|
package/types/shared.d.ts
CHANGED
|
@@ -2,13 +2,34 @@ export type ScaleValue = number | string;
|
|
|
2
2
|
|
|
3
3
|
export type RuleSeverity = boolean | "always" | "never";
|
|
4
4
|
|
|
5
|
+
export interface ScaleSource {
|
|
6
|
+
/** Directory that a relative `path` resolves from. Defaults to the working directory. */
|
|
7
|
+
baseDir?: string;
|
|
8
|
+
/** Alias for `path`. */
|
|
9
|
+
file?: string;
|
|
10
|
+
/** `auto` (default), `css`, `flat-json`, `style-dictionary`, or `dtcg`. */
|
|
11
|
+
format?: string;
|
|
12
|
+
path?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
5
15
|
export interface RhythmguardRuleOptions {
|
|
16
|
+
/** Exempt non-zero lengths of one CSS pixel or less (1px, -1px, 0.5px, 0.0625rem). Default true. */
|
|
17
|
+
allowHairlines?: boolean;
|
|
6
18
|
baseFontSize?: number;
|
|
7
19
|
customScale?: ScaleValue[];
|
|
8
20
|
includeMathFunctions?: boolean;
|
|
9
21
|
preset?: string;
|
|
10
22
|
properties?: Array<string | RegExp>;
|
|
11
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Allowed values, or `"auto"` to infer the scale from spacing tokens: `scaleSources`,
|
|
25
|
+
* then `.rhythmguardrc.json` audit token sources, then the linted stylesheet's custom
|
|
26
|
+
* properties, then `tailwindConfigPath`, falling back to the `rhythmic-4` preset.
|
|
27
|
+
*/
|
|
28
|
+
scale?: ScaleValue[] | "auto";
|
|
29
|
+
/** Token files consulted first when `scale` is `"auto"`. */
|
|
30
|
+
scaleSources?: Array<string | ScaleSource>;
|
|
31
|
+
/** Tailwind v3 config whose `theme.spacing` feeds `scale: "auto"` and `tokenMapFromTailwindSpacing`. */
|
|
32
|
+
tailwindConfigPath?: string;
|
|
12
33
|
tokenMap?: Record<string, string>;
|
|
13
34
|
tokenMapFile?: string;
|
|
14
35
|
tokenMapFromCssCustomProperties?: boolean;
|