@greenharness/greenrack-eslint-plugin 0.0.0-stage → 7.0.1
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/LICENSE +21 -0
- package/README.md +195 -2
- package/dist/index.d.ts +46 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +32 -0
- package/dist/index.js.map +1 -0
- package/dist/rules/index.d.ts +36 -0
- package/dist/rules/index.d.ts.map +1 -0
- package/dist/rules/index.js +23 -0
- package/dist/rules/index.js.map +1 -0
- package/dist/rules/no-deprecated-table-parts.d.ts +17 -0
- package/dist/rules/no-deprecated-table-parts.d.ts.map +1 -0
- package/dist/rules/no-deprecated-table-parts.js +92 -0
- package/dist/rules/no-deprecated-table-parts.js.map +1 -0
- package/dist/rules/no-flex-grow-web.d.ts +22 -0
- package/dist/rules/no-flex-grow-web.d.ts.map +1 -0
- package/dist/rules/no-flex-grow-web.js +38 -0
- package/dist/rules/no-flex-grow-web.js.map +1 -0
- package/dist/rules/no-raw-breakpoint-query.d.ts +16 -0
- package/dist/rules/no-raw-breakpoint-query.d.ts.map +1 -0
- package/dist/rules/no-raw-breakpoint-query.js +78 -0
- package/dist/rules/no-raw-breakpoint-query.js.map +1 -0
- package/dist/rules/no-raw-design-values.d.ts +60 -0
- package/dist/rules/no-raw-design-values.d.ts.map +1 -0
- package/dist/rules/no-raw-design-values.js +657 -0
- package/dist/rules/no-raw-design-values.js.map +1 -0
- package/dist/rules/no-raw-html-element.d.ts +24 -0
- package/dist/rules/no-raw-html-element.d.ts.map +1 -0
- package/dist/rules/no-raw-html-element.js +112 -0
- package/dist/rules/no-raw-html-element.js.map +1 -0
- package/dist/rules/no-raw-layer-values.d.ts +28 -0
- package/dist/rules/no-raw-layer-values.d.ts.map +1 -0
- package/dist/rules/no-raw-layer-values.js +185 -0
- package/dist/rules/no-raw-layer-values.js.map +1 -0
- package/dist/rules/no-tokens-barrel-import.d.ts +17 -0
- package/dist/rules/no-tokens-barrel-import.d.ts.map +1 -0
- package/dist/rules/no-tokens-barrel-import.js +0 -0
- package/dist/rules/no-tokens-barrel-import.js.map +1 -0
- package/dist/rules/prefer-ds-form-components.d.ts +11 -0
- package/dist/rules/prefer-ds-form-components.d.ts.map +1 -0
- package/dist/rules/prefer-ds-form-components.js +92 -0
- package/dist/rules/prefer-ds-form-components.js.map +1 -0
- package/dist/util/glob.d.ts +5 -0
- package/dist/util/glob.d.ts.map +1 -0
- package/dist/util/glob.js +55 -0
- package/dist/util/glob.js.map +1 -0
- package/dist/util/imports.d.ts +20 -0
- package/dist/util/imports.d.ts.map +1 -0
- package/dist/util/imports.js +74 -0
- package/dist/util/imports.js.map +1 -0
- package/dist/util/jsx.d.ts +14 -0
- package/dist/util/jsx.d.ts.map +1 -0
- package/dist/util/jsx.js +121 -0
- package/dist/util/jsx.js.map +1 -0
- package/dist/util/tokens.d.ts +74 -0
- package/dist/util/tokens.d.ts.map +1 -0
- package/dist/util/tokens.js +510 -0
- package/dist/util/tokens.js.map +1 -0
- package/package.json +57 -3
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { BREAKPOINT_TOKENS_BY_PX } from '../util/tokens.js';
|
|
2
|
+
import { ensureNamedImport, isShadowed } from '../util/imports.js';
|
|
3
|
+
const QUERY_RE = /\((?:min|max)-(?:width|height)\s*:\s*(\d+)px\)/;
|
|
4
|
+
const BREAKPOINTS_MODULE = '@greenharness/greenrack-tokens/tokens/breakpoints.css';
|
|
5
|
+
const SCALE = Object.keys(BREAKPOINT_TOKENS_BY_PX)
|
|
6
|
+
.map(Number)
|
|
7
|
+
.sort((a, b) => a - b)
|
|
8
|
+
.join(' / ');
|
|
9
|
+
/**
|
|
10
|
+
* A media-query string anywhere in a file — `useMediaQuery("(min-width:
|
|
11
|
+
* 768px)")`, `matchMedia(...)`, a hook's constant — carries a raw breakpoint.
|
|
12
|
+
* `no-raw-design-values` covers the `@media` keys inside css.create; this
|
|
13
|
+
* covers the strings that never reach a style object and so slipped past it.
|
|
14
|
+
*
|
|
15
|
+
* On the scale the fix rewrites the literal to a template literal reading
|
|
16
|
+
* `breakpoints.<key>` (a css.defineConsts string, so `${breakpoints.md}`
|
|
17
|
+
* interpolates to '768px') and adds the import. Off the scale it reports.
|
|
18
|
+
*/
|
|
19
|
+
export const noRawBreakpointQuery = {
|
|
20
|
+
defaultOptions: [],
|
|
21
|
+
meta: {
|
|
22
|
+
type: 'suggestion',
|
|
23
|
+
docs: {
|
|
24
|
+
description: 'Disallow raw px breakpoints in media-query strings; use breakpoints.<key>',
|
|
25
|
+
},
|
|
26
|
+
fixable: 'code',
|
|
27
|
+
schema: [],
|
|
28
|
+
messages: {
|
|
29
|
+
rawBreakpointQuery: '{{value}}px is a raw breakpoint in a media query. Use `breakpoints.{{token}}` from @greenharness/greenrack-tokens/tokens/breakpoints.css (the scale is {{scale}}px).',
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
create(context) {
|
|
33
|
+
const sourceCode = context.sourceCode;
|
|
34
|
+
function isStyleKey(node) {
|
|
35
|
+
return node.parent?.type === 'Property' && node.parent.key === node;
|
|
36
|
+
}
|
|
37
|
+
function check(node, text) {
|
|
38
|
+
const match = QUERY_RE.exec(text);
|
|
39
|
+
if (!match)
|
|
40
|
+
return;
|
|
41
|
+
// css.create condition keys belong to no-raw-design-values.
|
|
42
|
+
if (isStyleKey(node))
|
|
43
|
+
return;
|
|
44
|
+
const px = Number(match[1]);
|
|
45
|
+
const token = BREAKPOINT_TOKENS_BY_PX[px];
|
|
46
|
+
const data = { value: String(px), token: token ?? '*', scale: SCALE };
|
|
47
|
+
if (!token) {
|
|
48
|
+
context.report({ node, messageId: 'rawBreakpointQuery', data });
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const shadowed = isShadowed(sourceCode.getScope(node), 'breakpoints', BREAKPOINTS_MODULE);
|
|
52
|
+
context.report({
|
|
53
|
+
node,
|
|
54
|
+
messageId: 'rawBreakpointQuery',
|
|
55
|
+
data,
|
|
56
|
+
fix: shadowed
|
|
57
|
+
? null
|
|
58
|
+
: (fixer) => {
|
|
59
|
+
const { local, fixes } = ensureNamedImport(sourceCode, fixer, BREAKPOINTS_MODULE, 'breakpoints');
|
|
60
|
+
const rewritten = text.replace(`${px}px`, `\${${local}.${token}}`);
|
|
61
|
+
return [...fixes, fixer.replaceText(node, '`' + rewritten.replace(/`/g, '\\`') + '`')];
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
Literal(node) {
|
|
67
|
+
if (typeof node.value === 'string')
|
|
68
|
+
check(node, node.value);
|
|
69
|
+
},
|
|
70
|
+
TemplateLiteral(node) {
|
|
71
|
+
if (node.expressions.length > 0)
|
|
72
|
+
return;
|
|
73
|
+
check(node, node.quasis.map((q) => q.value.cooked ?? '').join(''));
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
//# sourceMappingURL=no-raw-breakpoint-query.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"no-raw-breakpoint-query.js","sourceRoot":"","sources":["../../src/rules/no-raw-breakpoint-query.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,uBAAuB,EAAC,MAAM,mBAAmB,CAAA;AACzD,OAAO,EAAC,iBAAiB,EAAE,UAAU,EAAC,MAAM,oBAAoB,CAAA;AAKhE,MAAM,QAAQ,GAAG,gDAAgD,CAAA;AACjE,MAAM,kBAAkB,GAAG,uDAAuD,CAAA;AAElF,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,uBAAuB,CAAC;KAC/C,GAAG,CAAC,MAAM,CAAC;KACX,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC;KACrB,IAAI,CAAC,KAAK,CAAC,CAAA;AAEd;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAA6C;IAC5E,cAAc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,SAAS,EAAE,oBAAoB;gBAC/B,IAAI;gBACJ,GAAG,EAAE,QAAQ;oBACX,CAAC,CAAC,IAAI;oBACN,CAAC,CAAC,CAAC,KAAK,EAAE,EAAE;wBACR,MAAM,EAAC,KAAK,EAAE,KAAK,EAAC,GAAG,iBAAiB,CACtC,UAAU,EACV,KAAK,EACL,kBAAkB,EAClB,aAAa,CACd,CAAA;wBACD,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,IAAI,EAAE,MAAM,KAAK,IAAI,KAAK,GAAG,CAAC,CAAA;wBAClE,OAAO,CAAC,GAAG,KAAK,EAAE,KAAK,CAAC,WAAW,CAAC,IAAI,EAAE,GAAG,GAAG,SAAS,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC,CAAA;oBACxF,CAAC;aACN,CAAC,CAAA;QACJ,CAAC;QAED,OAAO;YACL,OAAO,CAAC,IAAsB;gBAC5B,IAAI,OAAO,IAAI,CAAC,KAAK,KAAK,QAAQ;oBAAE,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,CAAA;YAC7D,CAAC;YACD,eAAe,CAAC,IAA8B;gBAC5C,IAAI,IAAI,CAAC,WAAW,CAAC,MAAM,GAAG,CAAC;oBAAE,OAAM;gBACvC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAA;YACpE,CAAC;SACF,CAAA;IACH,CAAC;CACF,CAAA"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { TSESLint } from '@typescript-eslint/utils';
|
|
2
|
+
type MessageIds = 'rawColorToken' | 'rawColor' | 'rawSpacing' | 'rawMicroSpacing' | 'rawRadius' | 'offScaleSpacing' | 'offScaleRadius' | 'rawBreakpoint' | 'rawFontSize' | 'rawFontWeight' | 'rawShadow' | 'rawDuration' | 'rawEasing' | 'rawMeasure' | 'ambiguousMeasure' | 'missingMeasureToken' | 'nearestMeasureRole' | 'rawShadowLength' | 'rawTrack' | 'replaceWithToken';
|
|
3
|
+
type Options = [
|
|
4
|
+
{
|
|
5
|
+
factories?: string[];
|
|
6
|
+
spacingProperties?: string[];
|
|
7
|
+
radiiProperties?: string[];
|
|
8
|
+
exemptFiles?: string[];
|
|
9
|
+
inlineStyle?: boolean;
|
|
10
|
+
}?
|
|
11
|
+
];
|
|
12
|
+
/**
|
|
13
|
+
* Inside css.create() style objects, flag raw design values — anything with a
|
|
14
|
+
* token equivalent, and anything on a tokenised property that is off the
|
|
15
|
+
* scale:
|
|
16
|
+
*
|
|
17
|
+
* - colors: a hex / rgb() / hsl() literal anywhere. A palette value suggests
|
|
18
|
+
* its token; an off-palette one reports without a fix.
|
|
19
|
+
* - spacing and radius: a px value on the properties where that mapping is
|
|
20
|
+
* unambiguous. On the scale → suggest the token; off the scale (`marginTop:
|
|
21
|
+
* 23`) → report, because "not a token" is the finding.
|
|
22
|
+
* - breakpoints: a px inside a `@media` / `@container` condition key. On the
|
|
23
|
+
* scale → suggest the `breakpoints.<key>` template-literal key.
|
|
24
|
+
* - font size (px or rem), font weight, box-shadow, transition/animation
|
|
25
|
+
* duration and timing function: a literal suggests its token when one
|
|
26
|
+
* matches, else reports.
|
|
27
|
+
*
|
|
28
|
+
* - sizes and border widths: a px length on width/height (and min/max,
|
|
29
|
+
* flexBasis, block/inline size), on border*Width / outlineWidth /
|
|
30
|
+
* outlineOffset and on the width inside a border* / outline shorthand,
|
|
31
|
+
* negatives included. Each property has its own candidate tokens (sizes.*,
|
|
32
|
+
* borders hairline/strong/accent, focusRing, focusOffset/focusOffsetSm),
|
|
33
|
+
* filtered by axis: a `…W` token is only offered on a width property and a
|
|
34
|
+
* `…H` token on a height one. One match suggests it; several give one
|
|
35
|
+
* suggestion each; none names the nearest role (every token at the nearest
|
|
36
|
+
* value within ±10%, both values smaller first on a tie), or says to add a
|
|
37
|
+
* token when nothing is that close. Percent, viewport, em/rem/ch, keywords
|
|
38
|
+
* and calc() without a px are fine.
|
|
39
|
+
* - box-shadow in a template literal: a px length in its static text is a raw
|
|
40
|
+
* shadow (`inset 0 0 0 1px ${colors.border}`); use a `shadows.*` token.
|
|
41
|
+
*
|
|
42
|
+
* - shorthands: on a spacing or radius property a multi-word string
|
|
43
|
+
* ('4px 8px') is split on whitespace and each nonzero px word is checked
|
|
44
|
+
* as a single value, without a suggestion (a swap would rewrite the whole
|
|
45
|
+
* string). 0, auto, %, rem, em, var() and calc() words pass.
|
|
46
|
+
* - inline styles: a `style={{...}}` object literal on any JSX element is
|
|
47
|
+
* walked like a css.create style, without suggestions (plain React has no
|
|
48
|
+
* token imports). References, arrays, spreads, custom-property keys and
|
|
49
|
+
* computed keys are ignored. Option `inlineStyle: false` turns it off.
|
|
50
|
+
*
|
|
51
|
+
* Option `exemptFiles` (globs) silences the rule for whole files.
|
|
52
|
+
*
|
|
53
|
+
* Skipped on purpose: 0, negatives on the spacing properties, transitions
|
|
54
|
+
* ('opacity 150ms'), identifiers, member expressions, template literals and
|
|
55
|
+
* calls — the rule reads literals, not expressions (the size, border-width
|
|
56
|
+
* and box-shadow properties also read static px text in template literals).
|
|
57
|
+
*/
|
|
58
|
+
export declare const noRawDesignValues: TSESLint.RuleModule<MessageIds, Options>;
|
|
59
|
+
export {};
|
|
60
|
+
//# sourceMappingURL=no-raw-design-values.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"no-raw-design-values.d.ts","sourceRoot":"","sources":["../../src/rules/no-raw-design-values.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,QAAQ,EAAW,MAAM,0BAA0B,CAAA;AA6BhE,KAAK,UAAU,GACX,eAAe,GACf,UAAU,GACV,YAAY,GACZ,iBAAiB,GACjB,WAAW,GACX,iBAAiB,GACjB,gBAAgB,GAChB,eAAe,GACf,aAAa,GACb,eAAe,GACf,WAAW,GACX,aAAa,GACb,WAAW,GACX,YAAY,GACZ,kBAAkB,GAClB,qBAAqB,GACrB,oBAAoB,GACpB,iBAAiB,GACjB,UAAU,GACV,kBAAkB,CAAA;AACtB,KAAK,OAAO,GAAG;IACb;QACE,SAAS,CAAC,EAAE,MAAM,EAAE,CAAA;QACpB,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAA;QAC5B,eAAe,CAAC,EAAE,MAAM,EAAE,CAAA;QAC1B,WAAW,CAAC,EAAE,MAAM,EAAE,CAAA;QACtB,WAAW,CAAC,EAAE,OAAO,CAAA;KACtB,CAAC;CACH,CAAA;AA+HD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACH,eAAO,MAAM,iBAAiB,EAAE,QAAQ,CAAC,UAAU,CAAC,UAAU,EAAE,OAAO,CAomBtE,CAAA"}
|