@allxsmith/eslint-plugin-bestax 0.0.0-development
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 +160 -0
- package/dist/configs/recommended.d.ts +21 -0
- package/dist/configs/recommended.d.ts.map +1 -0
- package/dist/configs/recommended.js +11 -0
- package/dist/generated/metadata.d.ts +26 -0
- package/dist/generated/metadata.d.ts.map +1 -0
- package/dist/generated/metadata.js +158 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +67 -0
- package/dist/lib/elements.d.ts +79 -0
- package/dist/lib/elements.d.ts.map +1 -0
- package/dist/lib/elements.js +151 -0
- package/dist/lib/values.d.ts +28 -0
- package/dist/lib/values.d.ts.map +1 -0
- package/dist/lib/values.js +116 -0
- package/dist/rules/no-color-as-surface.d.ts +31 -0
- package/dist/rules/no-color-as-surface.d.ts.map +1 -0
- package/dist/rules/no-color-as-surface.js +67 -0
- package/dist/rules/no-deprecated-props.d.ts +14 -0
- package/dist/rules/no-deprecated-props.d.ts.map +1 -0
- package/dist/rules/no-deprecated-props.js +78 -0
- package/dist/rules/no-inert-flex-props.d.ts +20 -0
- package/dist/rules/no-inert-flex-props.d.ts.map +1 -0
- package/dist/rules/no-inert-flex-props.js +50 -0
- package/dist/rules/valid-helper-value.d.ts +25 -0
- package/dist/rules/valid-helper-value.d.ts.map +1 -0
- package/dist/rules/valid-helper-value.js +78 -0
- package/package.json +77 -0
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
export const PACKAGE = '@allxsmith/bestax-bulma';
|
|
2
|
+
/** Marker for a namespace binding, which contributes no name segment. */
|
|
3
|
+
const NAMESPACE = Symbol('namespace');
|
|
4
|
+
export const emptyImports = () => ({
|
|
5
|
+
named: new Map(),
|
|
6
|
+
namespaces: new Set(),
|
|
7
|
+
});
|
|
8
|
+
/* eslint-disable @typescript-eslint/no-explicit-any --
|
|
9
|
+
ESLint's own Rule types model ESTree, which has no JSX nodes. Reaching for
|
|
10
|
+
a typed JSX AST would mean a runtime dependency on @typescript-eslint/utils
|
|
11
|
+
for what is a handful of well-known shapes, so these walk `any` and check
|
|
12
|
+
`type` explicitly instead. */
|
|
13
|
+
/** Record the library's bindings from one import declaration. */
|
|
14
|
+
export function collectImport(node, into) {
|
|
15
|
+
if (node?.source?.value !== PACKAGE)
|
|
16
|
+
return;
|
|
17
|
+
for (const spec of node.specifiers ?? []) {
|
|
18
|
+
if (spec.type === 'ImportSpecifier') {
|
|
19
|
+
into.named.set(spec.local.name, spec.imported.name);
|
|
20
|
+
}
|
|
21
|
+
else if (spec.type === 'ImportNamespaceSpecifier') {
|
|
22
|
+
into.namespaces.add(spec.local.name);
|
|
23
|
+
}
|
|
24
|
+
// A default import is not a thing this package has; ignore it.
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The canonical library name for a JSX element, or null when the element did
|
|
29
|
+
* not come from the library. Returns null rather than guessing.
|
|
30
|
+
*
|
|
31
|
+
* `bindsToImport` decides whether the root identifier really resolves to the
|
|
32
|
+
* import rather than to a local that shadows it. Both tables here key on
|
|
33
|
+
* identifier TEXT, so without it a file that imports `Box` from the library
|
|
34
|
+
* AND declares its own `const Box` inside a function gets the local's JSX
|
|
35
|
+
* linted against Bulma's rules. Default-true keeps `resolveElement` usable
|
|
36
|
+
* without a scope, which the unit tests rely on.
|
|
37
|
+
*/
|
|
38
|
+
export function resolveElement(nameNode, imports, bindsToImport = () => true) {
|
|
39
|
+
const walk = (node) => {
|
|
40
|
+
if (node?.type === 'JSXIdentifier') {
|
|
41
|
+
const named = imports.named.get(node.name);
|
|
42
|
+
if (named !== undefined)
|
|
43
|
+
return bindsToImport(node.name) ? named : null;
|
|
44
|
+
if (imports.namespaces.has(node.name)) {
|
|
45
|
+
return bindsToImport(node.name) ? NAMESPACE : null;
|
|
46
|
+
}
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
if (node?.type === 'JSXMemberExpression') {
|
|
50
|
+
const base = walk(node.object);
|
|
51
|
+
if (base === null)
|
|
52
|
+
return null;
|
|
53
|
+
const segment = node.property?.name;
|
|
54
|
+
if (typeof segment !== 'string')
|
|
55
|
+
return null;
|
|
56
|
+
return base === NAMESPACE ? segment : `${base}.${segment}`;
|
|
57
|
+
}
|
|
58
|
+
// JSXNamespacedName (`<svg:rect>`) is never one of ours.
|
|
59
|
+
return null;
|
|
60
|
+
};
|
|
61
|
+
const resolved = walk(nameNode);
|
|
62
|
+
return typeof resolved === 'string' ? resolved : null;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* The string value of a JSX attribute, or null when it is not a plain string
|
|
66
|
+
* literal. Anything computed is skipped by every rule here: a value the rule
|
|
67
|
+
* cannot see is not a value it can judge.
|
|
68
|
+
*/
|
|
69
|
+
export function literalValue(attr) {
|
|
70
|
+
const v = attr?.value;
|
|
71
|
+
if (!v)
|
|
72
|
+
return null; // bare `<Box mt>` — boolean shorthand
|
|
73
|
+
if (v.type === 'Literal')
|
|
74
|
+
return typeof v.value === 'string' ? v.value : null;
|
|
75
|
+
if (v.type === 'JSXExpressionContainer') {
|
|
76
|
+
const e = v.expression;
|
|
77
|
+
if (e?.type === 'Literal' && typeof e.value === 'string')
|
|
78
|
+
return e.value;
|
|
79
|
+
if (e?.type === 'TemplateLiteral' && e.quasis?.length === 1) {
|
|
80
|
+
return e.quasis[0].value.cooked ?? null;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
/** Plain-named attributes of an opening element, skipping spreads. */
|
|
86
|
+
export function attributesOf(opening) {
|
|
87
|
+
return (opening?.attributes ?? []).filter((a) => a?.type === 'JSXAttribute' && a.name?.type === 'JSXIdentifier');
|
|
88
|
+
}
|
|
89
|
+
/** Does this element carry a spread, making its full prop set unknowable? */
|
|
90
|
+
export function hasSpread(opening) {
|
|
91
|
+
return (opening?.attributes ?? []).some((a) => a?.type === 'JSXSpreadAttribute');
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* True when `name`, seen at `node`, resolves to an import binding rather than
|
|
95
|
+
* to a local declaration that shadows it.
|
|
96
|
+
*
|
|
97
|
+
* An unresolvable name answers true, keeping the name-table behaviour: a miss
|
|
98
|
+
* here costs a report on library code, which is less bad than going quiet.
|
|
99
|
+
*/
|
|
100
|
+
export function bindsToImportAt(context, node) {
|
|
101
|
+
return name => {
|
|
102
|
+
let scope;
|
|
103
|
+
try {
|
|
104
|
+
scope = context.sourceCode.getScope(node);
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
while (scope) {
|
|
110
|
+
const variable = scope.variables.find((v) => v.name === name);
|
|
111
|
+
if (variable) {
|
|
112
|
+
return (variable.defs ?? []).some((d) => d.type === 'ImportBinding');
|
|
113
|
+
}
|
|
114
|
+
scope = scope.upper;
|
|
115
|
+
}
|
|
116
|
+
return true;
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* The library name for a JSX opening element, scope-checked. This is what the
|
|
121
|
+
* rules call; `resolveElement` is the name-table half of it.
|
|
122
|
+
*/
|
|
123
|
+
export function elementOf(context, opening, imports) {
|
|
124
|
+
return resolveElement(opening?.name, imports, bindsToImportAt(context, opening));
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Wire an import collector into a rule's visitor, returning the shared binding
|
|
128
|
+
* table. Every rule needs exactly this preamble.
|
|
129
|
+
*
|
|
130
|
+
* The collection happens on `Program`, walking its body, rather than in an
|
|
131
|
+
* `ImportDeclaration` visitor. ESLint traverses in document order, so a
|
|
132
|
+
* visitor-based collector has not seen an import that appears BELOW the JSX
|
|
133
|
+
* using it, and every rule here would go silent on that file. Imports hoist,
|
|
134
|
+
* so that file is legal and compiles.
|
|
135
|
+
*/
|
|
136
|
+
export function withImports() {
|
|
137
|
+
const imports = emptyImports();
|
|
138
|
+
return {
|
|
139
|
+
imports,
|
|
140
|
+
visitor: {
|
|
141
|
+
Program(node) {
|
|
142
|
+
for (const stmt of node.body ?? []) {
|
|
143
|
+
if (stmt?.type === 'ImportDeclaration') {
|
|
144
|
+
collectImport(stmt, imports);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
},
|
|
148
|
+
},
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
/* eslint-enable @typescript-eslint/no-explicit-any */
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every helper prop whose accepted values are knowable from a tuple.
|
|
3
|
+
*
|
|
4
|
+
* `color` is deliberately absent: components redeclare it with their own
|
|
5
|
+
* unions (`Button` adds `ghost` and `text`), so checking it against
|
|
6
|
+
* `validColors` would report correct code. The `color` mistake that IS worth
|
|
7
|
+
* reporting — using it as a surface on a component where it means text — is
|
|
8
|
+
* `no-color-as-surface`.
|
|
9
|
+
*
|
|
10
|
+
* KEYED BY PROP, NOT BY ELEMENT, and that is a real limitation rather than a
|
|
11
|
+
* simplification. A few components widen `bgColor` with the scheme colours
|
|
12
|
+
* (`Box`, `Card`, `Container`, `Hero`, `Section`, `Footer`) and the rest do
|
|
13
|
+
* not, so `<Block bgColor="scheme-main-bis" />` renders nothing and this table
|
|
14
|
+
* accepts it. Every such gap points the same way — silence on a wrong value,
|
|
15
|
+
* never a report on a right one — which is the direction to be wrong in, and
|
|
16
|
+
* TypeScript catches this particular one. Closing it properly means a
|
|
17
|
+
* per-element table, which the MCP index already extracts; that is a change
|
|
18
|
+
* with its own dogfooding, not a tweak here. The hand-written `color`
|
|
19
|
+
* exclusion above is the same limitation showing through.
|
|
20
|
+
*/
|
|
21
|
+
export declare const HELPER_VALUES: ReadonlyMap<string, readonly string[]>;
|
|
22
|
+
/** Props that emit a class only when a flex `display` is also set. */
|
|
23
|
+
export declare const FLEX_CONTAINER_PROPS: readonly string[];
|
|
24
|
+
/** Every `display*` prop name, in declaration order. */
|
|
25
|
+
export declare const DISPLAY_PROPS: readonly string[];
|
|
26
|
+
/** `display` values that turn on a flex container. */
|
|
27
|
+
export declare const FLEX_DISPLAYS: readonly string[];
|
|
28
|
+
//# sourceMappingURL=values.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"values.d.ts","sourceRoot":"","sources":["../../src/lib/values.ts"],"names":[],"mappings":"AAgFA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,aAAa,EAAE,WAAW,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CA6B/D,CAAC;AAEH,sEAAsE;AACtE,eAAO,MAAM,oBAAoB,EAAE,SAAS,MAAM,EAMjD,CAAC;AAEF,wDAAwD;AACxD,eAAO,MAAM,aAAa,EAAE,SAAS,MAAM,EAG1C,CAAC;AAEF,sDAAsD;AACtD,eAAO,MAAM,aAAa,EAAE,SAAS,MAAM,EAA4B,CAAC"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The prop → allowed-values table, built from the library's own exported
|
|
3
|
+
* tuples rather than a copy of them.
|
|
4
|
+
*
|
|
5
|
+
* This import is why the package depends on `@allxsmith/bestax-bulma` at
|
|
6
|
+
* runtime: the rule then validates against the tuples belonging to the
|
|
7
|
+
* version the consumer actually installed, so it cannot drift. The
|
|
8
|
+
* `/constants` subpath carries the tuples with no React and no component
|
|
9
|
+
* code, so linting does not load the library proper.
|
|
10
|
+
*/
|
|
11
|
+
import { validAlignContents, validAlignItems, validAlignSelfs, validAlignments, validColorShades, validColors, validDisplays, validFlexDirections, validFlexGrowShrink, validFlexWraps, validFontFamilies, validJustifyContents, validSchemeColors, validSizes, validTextSizes, validTextTransforms, validTextWeights, validViewports, validVisibilities, } from '@allxsmith/bestax-bulma/constants';
|
|
12
|
+
const SPACING_PROPS = [
|
|
13
|
+
'm',
|
|
14
|
+
'mt',
|
|
15
|
+
'mr',
|
|
16
|
+
'mb',
|
|
17
|
+
'ml',
|
|
18
|
+
'mx',
|
|
19
|
+
'my',
|
|
20
|
+
'p',
|
|
21
|
+
'pt',
|
|
22
|
+
'pr',
|
|
23
|
+
'pb',
|
|
24
|
+
'pl',
|
|
25
|
+
'px',
|
|
26
|
+
'py',
|
|
27
|
+
];
|
|
28
|
+
/** The five bands `textSize`/`textAlign` are suffixed with. */
|
|
29
|
+
const TEXT_BANDS = [
|
|
30
|
+
'Mobile',
|
|
31
|
+
'Tablet',
|
|
32
|
+
'Desktop',
|
|
33
|
+
'Widescreen',
|
|
34
|
+
'Fullhd',
|
|
35
|
+
];
|
|
36
|
+
/** The nine bands `display`/`visibility` are suffixed with. */
|
|
37
|
+
const LAYOUT_BANDS = [
|
|
38
|
+
'Mobile',
|
|
39
|
+
'Tablet',
|
|
40
|
+
'TabletOnly',
|
|
41
|
+
'Touch',
|
|
42
|
+
'Desktop',
|
|
43
|
+
'DesktopOnly',
|
|
44
|
+
'Widescreen',
|
|
45
|
+
'WidescreenOnly',
|
|
46
|
+
'Fullhd',
|
|
47
|
+
];
|
|
48
|
+
const family = (base, bands, values) => [
|
|
49
|
+
[base, values],
|
|
50
|
+
...bands.map(b => [`${base}${b}`, values]),
|
|
51
|
+
];
|
|
52
|
+
/**
|
|
53
|
+
* Every helper prop whose accepted values are knowable from a tuple.
|
|
54
|
+
*
|
|
55
|
+
* `color` is deliberately absent: components redeclare it with their own
|
|
56
|
+
* unions (`Button` adds `ghost` and `text`), so checking it against
|
|
57
|
+
* `validColors` would report correct code. The `color` mistake that IS worth
|
|
58
|
+
* reporting — using it as a surface on a component where it means text — is
|
|
59
|
+
* `no-color-as-surface`.
|
|
60
|
+
*
|
|
61
|
+
* KEYED BY PROP, NOT BY ELEMENT, and that is a real limitation rather than a
|
|
62
|
+
* simplification. A few components widen `bgColor` with the scheme colours
|
|
63
|
+
* (`Box`, `Card`, `Container`, `Hero`, `Section`, `Footer`) and the rest do
|
|
64
|
+
* not, so `<Block bgColor="scheme-main-bis" />` renders nothing and this table
|
|
65
|
+
* accepts it. Every such gap points the same way — silence on a wrong value,
|
|
66
|
+
* never a report on a right one — which is the direction to be wrong in, and
|
|
67
|
+
* TypeScript catches this particular one. Closing it properly means a
|
|
68
|
+
* per-element table, which the MCP index already extracts; that is a change
|
|
69
|
+
* with its own dogfooding, not a tweak here. The hand-written `color`
|
|
70
|
+
* exclusion above is the same limitation showing through.
|
|
71
|
+
*/
|
|
72
|
+
export const HELPER_VALUES = new Map([
|
|
73
|
+
...SPACING_PROPS.map(p => [p, validSizes]),
|
|
74
|
+
...family('textSize', TEXT_BANDS, validTextSizes),
|
|
75
|
+
...family('textAlign', TEXT_BANDS, validAlignments),
|
|
76
|
+
// `none` is accepted alongside the display tuple; see BulmaDisplayProps.
|
|
77
|
+
...family('display', LAYOUT_BANDS, [...validDisplays, 'none']),
|
|
78
|
+
...family('visibility', LAYOUT_BANDS, validVisibilities),
|
|
79
|
+
['textTransform', validTextTransforms],
|
|
80
|
+
['textWeight', validTextWeights],
|
|
81
|
+
['fontFamily', validFontFamilies],
|
|
82
|
+
['flexDirection', validFlexDirections],
|
|
83
|
+
['flexWrap', validFlexWraps],
|
|
84
|
+
['justifyContent', validJustifyContents],
|
|
85
|
+
['alignContent', validAlignContents],
|
|
86
|
+
['alignItems', validAlignItems],
|
|
87
|
+
['alignSelf', validAlignSelfs],
|
|
88
|
+
['flexGrow', validFlexGrowShrink],
|
|
89
|
+
['flexShrink', validFlexGrowShrink],
|
|
90
|
+
['viewport', validViewports],
|
|
91
|
+
['colorShade', validColorShades],
|
|
92
|
+
['backgroundColorShade', validColorShades],
|
|
93
|
+
// The colour props take the tuple plus the two CSS-wide keywords that
|
|
94
|
+
// useColorClasses spreads in explicitly.
|
|
95
|
+
['textColor', [...validColors, 'inherit', 'current']],
|
|
96
|
+
['bgColor', [...validColors, ...validSchemeColors, 'inherit', 'current']],
|
|
97
|
+
[
|
|
98
|
+
'backgroundColor',
|
|
99
|
+
[...validColors, ...validSchemeColors, 'inherit', 'current'],
|
|
100
|
+
],
|
|
101
|
+
]);
|
|
102
|
+
/** Props that emit a class only when a flex `display` is also set. */
|
|
103
|
+
export const FLEX_CONTAINER_PROPS = [
|
|
104
|
+
'flexDirection',
|
|
105
|
+
'flexWrap',
|
|
106
|
+
'justifyContent',
|
|
107
|
+
'alignContent',
|
|
108
|
+
'alignItems',
|
|
109
|
+
];
|
|
110
|
+
/** Every `display*` prop name, in declaration order. */
|
|
111
|
+
export const DISPLAY_PROPS = [
|
|
112
|
+
'display',
|
|
113
|
+
...LAYOUT_BANDS.map(b => `display${b}`),
|
|
114
|
+
];
|
|
115
|
+
/** `display` values that turn on a flex container. */
|
|
116
|
+
export const FLEX_DISPLAYS = ['flex', 'inline-flex'];
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prefer the explicit `textColor` / `bgColor` props over the `color` alias.
|
|
3
|
+
*
|
|
4
|
+
* On the content elements `color` renders `has-text-<color>` — the same class
|
|
5
|
+
* as `textColor` — and there is no `.box.is-<color>` CSS for it to mean
|
|
6
|
+
* anything else. The library's own TSDoc says to prefer `textColor` for
|
|
7
|
+
* exactly that reason: read on its own, `<Box color="primary">` looks like a
|
|
8
|
+
* filled box and is not one.
|
|
9
|
+
*
|
|
10
|
+
* This rule is OPT-IN, not part of `recommended`, because unlike the other
|
|
11
|
+
* rules here it reports code that works. `color` is a documented alias, and an
|
|
12
|
+
* author who writes it may well want coloured text. What the rule buys is
|
|
13
|
+
* explicitness at the call site.
|
|
14
|
+
*
|
|
15
|
+
* Two things it must not do, both found by linting the library's own docs:
|
|
16
|
+
*
|
|
17
|
+
* - Fire when the element also sets a background. `<Box backgroundColor="light"
|
|
18
|
+
* color="dark">` is a deliberate, correct pairing — surface from one prop,
|
|
19
|
+
* text from the other — and telling that author "color is not a background"
|
|
20
|
+
* is nonsense.
|
|
21
|
+
* - Fire on elements with a real `is-<color>` modifier. Those are absent from
|
|
22
|
+
* the generated set, so `<Button color="primary">` never reports.
|
|
23
|
+
*
|
|
24
|
+
* It is also silent on an element carrying a spread (which may hold the very
|
|
25
|
+
* background prop that would silence it) and on a `color` whose value it
|
|
26
|
+
* cannot read as a literal.
|
|
27
|
+
*/
|
|
28
|
+
import type { Rule } from 'eslint';
|
|
29
|
+
declare const rule: Rule.RuleModule;
|
|
30
|
+
export default rule;
|
|
31
|
+
//# sourceMappingURL=no-color-as-surface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"no-color-as-surface.d.ts","sourceRoot":"","sources":["../../src/rules/no-color-as-surface.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAenC,QAAA,MAAM,IAAI,EAAE,IAAI,CAAC,UAgEhB,CAAC;AAEF,eAAe,IAAI,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { TEXT_ALIAS_COLOR_ELEMENTS } from '../generated/metadata.js';
|
|
2
|
+
import { attributesOf, elementOf, hasSpread, literalValue, withImports, } from '../lib/elements.js';
|
|
3
|
+
const TEXT_ALIAS = new Set(TEXT_ALIAS_COLOR_ELEMENTS);
|
|
4
|
+
/** Setting either of these shows the author knows where the surface comes from. */
|
|
5
|
+
const BACKGROUND_PROPS = ['bgColor', 'backgroundColor'];
|
|
6
|
+
const rule = {
|
|
7
|
+
meta: {
|
|
8
|
+
type: 'suggestion',
|
|
9
|
+
fixable: 'code',
|
|
10
|
+
docs: {
|
|
11
|
+
description: 'prefer the explicit textColor prop over the ambiguous color alias',
|
|
12
|
+
url: 'https://bestax.io/docs/guides/getting-started/eslint-plugin#no-color-as-surface',
|
|
13
|
+
},
|
|
14
|
+
schema: [],
|
|
15
|
+
messages: {
|
|
16
|
+
ambiguous: '`color` on `{{element}}` is a text-colour alias — it renders `has-text-{{value}}`, and no `is-<color>` CSS exists for it. Write `textColor="{{value}}"` to say so, or `bgColor="{{value}}"` if you wanted a coloured surface.',
|
|
17
|
+
redundant: '`color` on `{{element}}` is ignored here: `textColor` is already set and takes precedence. Remove `color`.',
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
create(context) {
|
|
21
|
+
const { imports, visitor } = withImports();
|
|
22
|
+
return {
|
|
23
|
+
...visitor,
|
|
24
|
+
JSXOpeningElement(node) {
|
|
25
|
+
const opening = node;
|
|
26
|
+
const element = elementOf(context, opening, imports);
|
|
27
|
+
if (element === null || !TEXT_ALIAS.has(element))
|
|
28
|
+
return;
|
|
29
|
+
// A spread may carry the background prop that silences this rule, or
|
|
30
|
+
// the textColor that makes `color` redundant. Either way the element's
|
|
31
|
+
// real prop set is unknowable, so say nothing.
|
|
32
|
+
if (hasSpread(opening))
|
|
33
|
+
return;
|
|
34
|
+
const attrs = attributesOf(opening);
|
|
35
|
+
const named = (n) => attrs.find((a) => a.name.name === n);
|
|
36
|
+
const color = named('color');
|
|
37
|
+
if (!color)
|
|
38
|
+
return;
|
|
39
|
+
if (named('textColor')) {
|
|
40
|
+
context.report({
|
|
41
|
+
node: color,
|
|
42
|
+
messageId: 'redundant',
|
|
43
|
+
data: { element },
|
|
44
|
+
});
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
// A background is set explicitly, so `color` is unambiguously the
|
|
48
|
+
// text half of a deliberate pairing. Nothing to say.
|
|
49
|
+
if (BACKGROUND_PROPS.some(named))
|
|
50
|
+
return;
|
|
51
|
+
// Only a readable literal is judged, like every other rule here. A
|
|
52
|
+
// computed value could be anything, and the message would have to say
|
|
53
|
+
// so in place of the value, which is not advice anyone can act on.
|
|
54
|
+
const value = literalValue(color);
|
|
55
|
+
if (value === null)
|
|
56
|
+
return;
|
|
57
|
+
context.report({
|
|
58
|
+
node: color.name,
|
|
59
|
+
messageId: 'ambiguous',
|
|
60
|
+
data: { element, value },
|
|
61
|
+
fix: fixer => fixer.replaceText(color.name, 'textColor'),
|
|
62
|
+
});
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
export default rule;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Report props the library marks `@deprecated`, and fix the renames.
|
|
3
|
+
*
|
|
4
|
+
* The table is generated from the library's own TSDoc, so a rename lands here
|
|
5
|
+
* with the next `pnpm gen` rather than needing to be noticed. Two shapes come
|
|
6
|
+
* out of it: a rename, which carries the replacement in its note and is
|
|
7
|
+
* autofixable, and a prop that was retired outright (it emits a class no
|
|
8
|
+
* shipped CSS matches, or never had an effect), which is reported with the
|
|
9
|
+
* library's reason and no fix.
|
|
10
|
+
*/
|
|
11
|
+
import type { Rule } from 'eslint';
|
|
12
|
+
declare const rule: Rule.RuleModule;
|
|
13
|
+
export default rule;
|
|
14
|
+
//# sourceMappingURL=no-deprecated-props.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"no-deprecated-props.d.ts","sourceRoot":"","sources":["../../src/rules/no-deprecated-props.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAqBnC,QAAA,MAAM,IAAI,EAAE,IAAI,CAAC,UAoEhB,CAAC;AAEF,eAAe,IAAI,CAAC"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { DEPRECATED_PROPS } from '../generated/metadata.js';
|
|
2
|
+
import { attributesOf, elementOf, hasSpread, withImports, } from '../lib/elements.js';
|
|
3
|
+
/**
|
|
4
|
+
* Own-property reads only. The keys come from the user's source, so a plain
|
|
5
|
+
* `table[name]` resolves `Object.prototype` members: `<Icon valueOf="x" />`
|
|
6
|
+
* found `Object.prototype.valueOf`, passed the truthiness check, and reported
|
|
7
|
+
* a deprecation with an empty note.
|
|
8
|
+
*/
|
|
9
|
+
const own = (obj, key) => (Object.hasOwn(obj, key) ? obj[key] : undefined);
|
|
10
|
+
const rule = {
|
|
11
|
+
meta: {
|
|
12
|
+
type: 'problem',
|
|
13
|
+
fixable: 'code',
|
|
14
|
+
docs: {
|
|
15
|
+
description: 'disallow props the library has deprecated',
|
|
16
|
+
url: 'https://bestax.io/docs/guides/getting-started/eslint-plugin#no-deprecated-props',
|
|
17
|
+
},
|
|
18
|
+
schema: [],
|
|
19
|
+
// One message, because there was only ever one. `renamed` and `retired`
|
|
20
|
+
// carried identical text, and the split mislabelled anything whose note
|
|
21
|
+
// names more than one replacement: `Icon.libraryFeatures` says "Use
|
|
22
|
+
// `variant` and `features` instead", which parses to no single
|
|
23
|
+
// replacement and so was reported as retired — documented as meaning the
|
|
24
|
+
// prop never had an effect, which is false for it. Whether a fix is
|
|
25
|
+
// offered is the only real difference, and that is visible in the fix.
|
|
26
|
+
messages: {
|
|
27
|
+
deprecated: '`{{prop}}` is deprecated on `{{element}}`. {{note}}',
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
create(context) {
|
|
31
|
+
const { imports, visitor } = withImports();
|
|
32
|
+
return {
|
|
33
|
+
...visitor,
|
|
34
|
+
JSXOpeningElement(node) {
|
|
35
|
+
const opening = node;
|
|
36
|
+
const element = elementOf(context, opening, imports);
|
|
37
|
+
if (element === null)
|
|
38
|
+
return;
|
|
39
|
+
const deprecations = own(DEPRECATED_PROPS, element);
|
|
40
|
+
if (!deprecations)
|
|
41
|
+
return;
|
|
42
|
+
const attrs = attributesOf(opening);
|
|
43
|
+
const written = new Set(attrs.map((a) => a.name.name));
|
|
44
|
+
// A spread can hold the replacement, and renaming onto it would let
|
|
45
|
+
// the explicit attribute shadow a value the author meant to keep.
|
|
46
|
+
// Report, but leave the edit to a human.
|
|
47
|
+
const spread = hasSpread(opening);
|
|
48
|
+
// Two deprecated props on one element can rename to the SAME target:
|
|
49
|
+
// Tabs deprecates both `isFullWidth` and `fullwidth` in favour of
|
|
50
|
+
// `isFullwidth`. Fixing both produced `<Tabs isFullwidth isFullwidth>`,
|
|
51
|
+
// which is a duplicate JSX attribute and does not compile.
|
|
52
|
+
const claimed = new Set();
|
|
53
|
+
for (const attr of attrs) {
|
|
54
|
+
const prop = attr.name.name;
|
|
55
|
+
const info = own(deprecations, prop);
|
|
56
|
+
if (!info)
|
|
57
|
+
continue;
|
|
58
|
+
const { replacement, note } = info;
|
|
59
|
+
const fixable = replacement !== null &&
|
|
60
|
+
!spread &&
|
|
61
|
+
!written.has(replacement) &&
|
|
62
|
+
!claimed.has(replacement);
|
|
63
|
+
if (fixable)
|
|
64
|
+
claimed.add(replacement);
|
|
65
|
+
context.report({
|
|
66
|
+
node: attr.name,
|
|
67
|
+
messageId: 'deprecated',
|
|
68
|
+
data: { prop, element, note: note ?? '' },
|
|
69
|
+
fix: fixable
|
|
70
|
+
? fixer => fixer.replaceText(attr.name, replacement)
|
|
71
|
+
: null,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
export default rule;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Report flex container props that emit nothing for want of a flex display.
|
|
3
|
+
*
|
|
4
|
+
* `useFlexboxClasses` gates `flexDirection`, `flexWrap`, `justifyContent`,
|
|
5
|
+
* `alignContent` and `alignItems` on a flex `display`: it computes whether any
|
|
6
|
+
* of the ten `display*` props is `flex` or `inline-flex`, and if none is,
|
|
7
|
+
* those five emit no class at all. So `<Box justifyContent="center">` looks
|
|
8
|
+
* like it centres its children and does nothing whatsoever.
|
|
9
|
+
*
|
|
10
|
+
* `alignSelf`, `flexGrow` and `flexShrink` always emit — they describe the
|
|
11
|
+
* element as a flex CHILD, whose container is elsewhere — so they are not
|
|
12
|
+
* reported.
|
|
13
|
+
*
|
|
14
|
+
* Silence beats a guess: an element carrying a spread, or a `display*` whose
|
|
15
|
+
* value the rule cannot read, is left alone.
|
|
16
|
+
*/
|
|
17
|
+
import type { Rule } from 'eslint';
|
|
18
|
+
declare const rule: Rule.RuleModule;
|
|
19
|
+
export default rule;
|
|
20
|
+
//# sourceMappingURL=no-inert-flex-props.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"no-inert-flex-props.d.ts","sourceRoot":"","sources":["../../src/rules/no-inert-flex-props.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAiBnC,QAAA,MAAM,IAAI,EAAE,IAAI,CAAC,UAsDhB,CAAC;AAEF,eAAe,IAAI,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { DISPLAY_PROPS, FLEX_CONTAINER_PROPS, FLEX_DISPLAYS, } from '../lib/values.js';
|
|
2
|
+
import { attributesOf, hasSpread, literalValue, elementOf, withImports, } from '../lib/elements.js';
|
|
3
|
+
const CONTAINER = new Set(FLEX_CONTAINER_PROPS);
|
|
4
|
+
const DISPLAY = new Set(DISPLAY_PROPS);
|
|
5
|
+
const rule = {
|
|
6
|
+
meta: {
|
|
7
|
+
type: 'problem',
|
|
8
|
+
docs: {
|
|
9
|
+
description: 'disallow flex container props on an element with no flex display',
|
|
10
|
+
url: 'https://bestax.io/docs/guides/getting-started/eslint-plugin#no-inert-flex-props',
|
|
11
|
+
},
|
|
12
|
+
schema: [],
|
|
13
|
+
messages: {
|
|
14
|
+
inert: '`{{prop}}` emits no class here: it applies only when a `display` prop is `flex` or `inline-flex`. Add `display="flex"`, or drop `{{prop}}`.',
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
create(context) {
|
|
18
|
+
const { imports, visitor } = withImports();
|
|
19
|
+
return {
|
|
20
|
+
...visitor,
|
|
21
|
+
JSXOpeningElement(node) {
|
|
22
|
+
const opening = node;
|
|
23
|
+
if (elementOf(context, opening, imports) === null)
|
|
24
|
+
return;
|
|
25
|
+
if (hasSpread(opening))
|
|
26
|
+
return;
|
|
27
|
+
const attrs = attributesOf(opening);
|
|
28
|
+
const containerProps = attrs.filter((a) => CONTAINER.has(a.name.name));
|
|
29
|
+
if (!containerProps.length)
|
|
30
|
+
return;
|
|
31
|
+
const displays = attrs.filter((a) => DISPLAY.has(a.name.name));
|
|
32
|
+
// An unreadable display value could be a flex one; say nothing.
|
|
33
|
+
if (displays.some((a) => literalValue(a) === null)) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (displays.some((a) => FLEX_DISPLAYS.includes(literalValue(a)))) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
for (const attr of containerProps) {
|
|
40
|
+
context.report({
|
|
41
|
+
node: attr,
|
|
42
|
+
messageId: 'inert',
|
|
43
|
+
data: { prop: attr.name.name },
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
export default rule;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Report helper-prop values the library will silently drop.
|
|
3
|
+
*
|
|
4
|
+
* `useBulmaClasses` validates by membership and emits nothing for a value it
|
|
5
|
+
* does not recognise: no throw, no warning, no fallback. So `textColor="blue"`
|
|
6
|
+
* renders nothing and says nothing at runtime.
|
|
7
|
+
*
|
|
8
|
+
* Who this actually helps, stated plainly because it is narrower than it
|
|
9
|
+
* looks: the helper props are typed as literal unions, so `tsc` already
|
|
10
|
+
* rejects a wrong literal in a `.tsx` file, and rather well (it answers
|
|
11
|
+
* `textAlign="center"` with TS2820 and its own "Did you mean 'centered'?").
|
|
12
|
+
* This rule earns its place where that check is not running:
|
|
13
|
+
*
|
|
14
|
+
* - JavaScript and JSX projects, which have no such check at all
|
|
15
|
+
* - code in markdown and MDX, which no `tsc` program includes; every real
|
|
16
|
+
* bug this rule has found so far was in a docs fence
|
|
17
|
+
* - editors and CI stages that lint before, or instead of, typechecking
|
|
18
|
+
*
|
|
19
|
+
* It is deliberately not a substitute for typechecking, and the overlap on
|
|
20
|
+
* `.tsx` is expected rather than a defect.
|
|
21
|
+
*/
|
|
22
|
+
import type { Rule } from 'eslint';
|
|
23
|
+
declare const rule: Rule.RuleModule;
|
|
24
|
+
export default rule;
|
|
25
|
+
//# sourceMappingURL=valid-helper-value.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"valid-helper-value.d.ts","sourceRoot":"","sources":["../../src/rules/valid-helper-value.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AA2CnC,QAAA,MAAM,IAAI,EAAE,IAAI,CAAC,UA+ChB,CAAC;AAEF,eAAe,IAAI,CAAC"}
|