@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,78 @@
|
|
|
1
|
+
import { HELPER_VALUES } from '../lib/values.js';
|
|
2
|
+
import { attributesOf, literalValue, elementOf, withImports, } from '../lib/elements.js';
|
|
3
|
+
/**
|
|
4
|
+
* Closest valid values by a cheap edit-distance, for the message.
|
|
5
|
+
*
|
|
6
|
+
* Short values are not suggested for: every entry of a numeric scale is one
|
|
7
|
+
* edit from `"8"`, so `textSize="8"` would be answered with "did you mean 1
|
|
8
|
+
* or 2 or 3", where the full list of valid values is what actually helps.
|
|
9
|
+
*/
|
|
10
|
+
function suggest(value, valid) {
|
|
11
|
+
if (value.length < 3)
|
|
12
|
+
return [];
|
|
13
|
+
const distance = (a, b) => {
|
|
14
|
+
const d = Array.from({ length: a.length + 1 }, () => new Array(b.length + 1).fill(0));
|
|
15
|
+
for (let i = 0; i <= a.length; i++)
|
|
16
|
+
d[i][0] = i;
|
|
17
|
+
for (let j = 0; j <= b.length; j++)
|
|
18
|
+
d[0][j] = j;
|
|
19
|
+
for (let i = 1; i <= a.length; i++) {
|
|
20
|
+
for (let j = 1; j <= b.length; j++) {
|
|
21
|
+
d[i][j] = Math.min(d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1));
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return d[a.length][b.length];
|
|
25
|
+
};
|
|
26
|
+
return valid
|
|
27
|
+
.map(v => [v, distance(value.toLowerCase(), v.toLowerCase())])
|
|
28
|
+
.filter(([, d]) => d <= Math.max(2, Math.ceil(value.length / 3)))
|
|
29
|
+
.sort((x, y) => x[1] - y[1])
|
|
30
|
+
.slice(0, 3)
|
|
31
|
+
.map(([v]) => v);
|
|
32
|
+
}
|
|
33
|
+
const rule = {
|
|
34
|
+
meta: {
|
|
35
|
+
type: 'problem',
|
|
36
|
+
docs: {
|
|
37
|
+
description: 'disallow helper-prop values the library silently drops instead of rendering',
|
|
38
|
+
url: 'https://bestax.io/docs/guides/getting-started/eslint-plugin#valid-helper-value',
|
|
39
|
+
},
|
|
40
|
+
schema: [],
|
|
41
|
+
messages: {
|
|
42
|
+
invalid: '`{{prop}}="{{value}}"` is not a value {{prop}} accepts, so the class is never emitted and nothing renders. Valid values: {{valid}}.',
|
|
43
|
+
invalidWithSuggestion: '`{{prop}}="{{value}}"` is not a value {{prop}} accepts, so the class is never emitted and nothing renders. Did you mean {{suggestions}}?',
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
create(context) {
|
|
47
|
+
const { imports, visitor } = withImports();
|
|
48
|
+
return {
|
|
49
|
+
...visitor,
|
|
50
|
+
JSXOpeningElement(node) {
|
|
51
|
+
const opening = node;
|
|
52
|
+
if (elementOf(context, opening, imports) === null)
|
|
53
|
+
return;
|
|
54
|
+
for (const attr of attributesOf(opening)) {
|
|
55
|
+
const prop = attr.name.name;
|
|
56
|
+
const valid = HELPER_VALUES.get(prop);
|
|
57
|
+
if (!valid)
|
|
58
|
+
continue;
|
|
59
|
+
const value = literalValue(attr);
|
|
60
|
+
if (value === null || valid.includes(value))
|
|
61
|
+
continue;
|
|
62
|
+
const suggestions = suggest(value, valid);
|
|
63
|
+
context.report({
|
|
64
|
+
node: attr,
|
|
65
|
+
messageId: suggestions.length ? 'invalidWithSuggestion' : 'invalid',
|
|
66
|
+
data: {
|
|
67
|
+
prop,
|
|
68
|
+
value,
|
|
69
|
+
valid: valid.map(v => `\`${v}\``).join(', '),
|
|
70
|
+
suggestions: suggestions.map(v => `\`${v}\``).join(' or '),
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
export default rule;
|
package/package.json
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@allxsmith/eslint-plugin-bestax",
|
|
3
|
+
"version": "0.0.0-development",
|
|
4
|
+
"description": "ESLint rules for @allxsmith/bestax-bulma — catches helper-prop values the library silently drops, deprecated props, and the color-as-surface mistake",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
17
|
+
"keywords": [
|
|
18
|
+
"eslint",
|
|
19
|
+
"eslintplugin",
|
|
20
|
+
"eslint-plugin",
|
|
21
|
+
"bestax",
|
|
22
|
+
"bulma",
|
|
23
|
+
"react",
|
|
24
|
+
"typescript",
|
|
25
|
+
"lint",
|
|
26
|
+
"helper-props"
|
|
27
|
+
],
|
|
28
|
+
"author": "Alex Smith",
|
|
29
|
+
"license": "MIT",
|
|
30
|
+
"engines": {
|
|
31
|
+
"node": ">=22"
|
|
32
|
+
},
|
|
33
|
+
"repository": {
|
|
34
|
+
"type": "git",
|
|
35
|
+
"url": "git+https://github.com/allxsmith/bestax.git",
|
|
36
|
+
"directory": "eslint-plugin"
|
|
37
|
+
},
|
|
38
|
+
"homepage": "https://bestax.io/docs/guides/getting-started/eslint-plugin",
|
|
39
|
+
"llms": "https://bestax.io/llms.txt",
|
|
40
|
+
"bugs": {
|
|
41
|
+
"url": "https://github.com/allxsmith/bestax/issues"
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"@allxsmith/bestax-bulma": "^5.15.2"
|
|
45
|
+
},
|
|
46
|
+
"peerDependencies": {
|
|
47
|
+
"eslint": "^10.0.0"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@jest/globals": "^30.0.0",
|
|
51
|
+
"@types/jest": "^30.0.0",
|
|
52
|
+
"@types/node": "^26.3.0",
|
|
53
|
+
"@typescript-eslint/parser": "^8.68.0",
|
|
54
|
+
"@typescript-eslint/types": "^8.68.0",
|
|
55
|
+
"eslint": "^10.9.1",
|
|
56
|
+
"jest": "^30.2.0",
|
|
57
|
+
"ts-jest": "^29.4.12",
|
|
58
|
+
"typescript": "^6.0.3"
|
|
59
|
+
},
|
|
60
|
+
"publishConfig": {
|
|
61
|
+
"access": "public"
|
|
62
|
+
},
|
|
63
|
+
"scripts": {
|
|
64
|
+
"build": "tsc",
|
|
65
|
+
"dev": "tsc --watch",
|
|
66
|
+
"test": "NODE_OPTIONS=\"--experimental-vm-modules\" jest",
|
|
67
|
+
"test:watch": "NODE_OPTIONS=\"--experimental-vm-modules\" jest --watch",
|
|
68
|
+
"test:coverage": "NODE_OPTIONS=\"--experimental-vm-modules\" jest --coverage",
|
|
69
|
+
"lint": "eslint src",
|
|
70
|
+
"typecheck": "tsc --noEmit",
|
|
71
|
+
"format": "prettier --write \"src/**/*.ts\"",
|
|
72
|
+
"format:check": "prettier --check \"src/**/*.ts\"",
|
|
73
|
+
"clean": "rimraf dist",
|
|
74
|
+
"release": "npx semantic-release"
|
|
75
|
+
},
|
|
76
|
+
"readme": "# @allxsmith/eslint-plugin-bestax\n\n[](https://www.npmjs.com/package/@allxsmith/eslint-plugin-bestax)\n[](https://www.npmjs.com/package/@allxsmith/eslint-plugin-bestax)\n[](https://opensource.org/licenses/MIT)\n[](https://socket.dev/npm/package/@allxsmith/eslint-plugin-bestax/overview)\n[](https://scorecard.dev/viewer/?uri=github.com/allxsmith/bestax)\n[](https://www.bestpractices.dev/projects/14361)\n[](https://www.npmjs.com/package/@allxsmith/eslint-plugin-bestax#provenance)\n[](https://github.com/allxsmith/bestax/blob/main/SECURITY.md)\n\nESLint rules for [`@allxsmith/bestax-bulma`](https://www.npmjs.com/package/@allxsmith/bestax-bulma).\n\nEvery rule here reports code that does not do what it looks like it does. The\nlibrary's helper props validate by membership and emit nothing for a value they\ndo not recognise, with no throw and no warning, so `textColor=\"blue\"` renders\nnothing and says nothing.\n\n**Scope, up front:** the helper props are typed as literal unions, so if you\nwrite bestax in `.tsx` and run `tsc`, it already catches a wrong literal. This\nplugin is for the places that check does not reach: JavaScript and JSX\nprojects, code in markdown and MDX, and lint stages that run before or instead\nof typechecking. The deprecation and flex rules are additive everywhere, since\nno type error marks a deprecated prop or a flex prop that emits nothing.\n\n## Requirements\n\nESLint 10, using [flat config](https://eslint.org/docs/latest/use/configure/configuration-files).\nThe plugin is ESM-only, so it cannot be `require()`d from a legacy\n`.eslintrc.js`.\n\n## Setup\n\n```bash\nnpm install --save-dev @allxsmith/eslint-plugin-bestax\n```\n\n```js\n// eslint.config.js\nimport bestax from '@allxsmith/eslint-plugin-bestax';\n\nexport default [bestax.configs.recommended];\n```\n\nThe preset matches `.js`, `.mjs`, `.cjs`, `.jsx` and `.tsx`, and enables JSX\nparsing. It sets no `parser`, so whatever you configure for TypeScript\nsurvives; put your TypeScript config first and this after:\n\n```js\nimport bestax from '@allxsmith/eslint-plugin-bestax';\nimport tseslint from 'typescript-eslint';\n\nexport default [...tseslint.configs.recommended, bestax.configs.recommended];\n```\n\nOr register it yourself and pick rules. `files` is load-bearing: a flat config\nobject without it inherits ESLint's default `**/*.{js,mjs,cjs}` set, so leaving\nit out silently lints none of your JSX.\n\n```js\nimport bestax from '@allxsmith/eslint-plugin-bestax';\n\nexport default [\n {\n files: ['**/*.{jsx,tsx}'],\n plugins: { '@allxsmith/bestax': bestax },\n languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } },\n rules: {\n '@allxsmith/bestax/valid-helper-value': 'error',\n '@allxsmith/bestax/no-deprecated-props': 'warn',\n },\n },\n];\n```\n\n## Rules\n\nIn `recommended` — each reports code that does not do what it says:\n\n| Rule | Fixable | What it catches |\n| --------------------- | ------- | ----------------------------------------------------------------------------------------------------------------------- |\n| `valid-helper-value` | — | Helper values the library silently drops: `textAlign=\"center\"` (it is `centered`), `textSize=\"8\"`, `mt=\"1rem\"` |\n| `no-deprecated-props` | yes | Props the library deprecated: `isFullWidth`, `gapSize*`, `icon`. Also the retired ones that emit a class no CSS matches |\n| `no-inert-flex-props` | — | `justifyContent` and friends without a flex `display`, which emit nothing |\n\nOpt-in — this one reports code that works, and buys explicitness instead:\n\n| Rule | Fixable | What it asks for |\n| --------------------- | ------- | ----------------------------------------------------------------------------- |\n| `no-color-as-surface` | yes | `textColor` instead of the `color` alias, where `color` cannot mean a surface |\n\nEach rule resolves elements through the import and through scope, so neither\nyour own `<Box>` nor a local shadowing the imported one is linted against\nBulma's rules, and each skips a value it cannot read as a literal.\n\nA spread is handled by what it can change: `no-color-as-surface` and\n`no-inert-flex-props` go silent, since a spread may carry the prop that makes\nthe code correct; `no-deprecated-props` reports but offers no fix; and\n`valid-helper-value` still reports, because an explicit attribute wins over a\nspread so a wrong literal is wrong regardless. No autofix changes what the code\nrenders.\n\n### valid-helper-value\n\n```jsx\n<Box textAlign=\"center\" /> // ✗ not a value textAlign accepts. Did you mean `centered`?\n<Box textAlign=\"centered\" /> // ✓\n```\n\nThe valid values come from the library's own exported tuples at lint time, by\nway of its `/constants` subpath, rather than from a list copied into this\npackage. The version those tuples come from is the copy of\n`@allxsmith/bestax-bulma` this plugin resolves, which in an ordinary deduped\ninstall is the same one your app uses; across a major bump it may not be, so\nkeep the two in step. Component-specific `color` props are deliberately not\nchecked, since `<Button color=\"ghost\">` is correct and reporting it would be\nworse than reporting nothing.\n\n### no-deprecated-props\n\n```jsx\n<Button isFullWidth /> // ✗ deprecated → fixes to isFullwidth\n<Tabs color=\"info\" /> // ✗ no .tabs.is-<color> CSS exists; no fix offered\n```\n\nThe table is generated from the library's own TSDoc, so a rename lands here\nwith the library rather than after someone notices.\n\n### no-color-as-surface\n\nOff by default. `color` on the content elements is a documented alias for\n`textColor`, so this rule is about saying which you meant, not about broken\ncode.\n\n```jsx\n<Box color=\"primary\" /> // ✗ ambiguous → fixes to textColor\n<Box bgColor=\"primary\" /> // ✓ a coloured surface\n<Button color=\"primary\" /> // ✓ Button really has an is-primary variant\n\n// ✓ silent: the background is explicit, so `color` is plainly the text half\n<Box backgroundColor=\"light\" color=\"dark\" />\n```\n\n### no-inert-flex-props\n\n```jsx\n<Box justifyContent=\"center\" /> // ✗ emits nothing\n<Box display=\"flex\" justifyContent=\"center\" /> // ✓\n<Box flexGrow=\"1\" /> // ✓ child props always apply\n```\n\n## Links\n\n- [Documentation](https://bestax.io/docs/guides/getting-started/eslint-plugin)\n- [Component library](https://www.npmjs.com/package/@allxsmith/bestax-bulma)\n- [Repository](https://github.com/allxsmith/bestax)\n\n## License\n\nMIT\n"
|
|
77
|
+
}
|