@mslmio/eslint-config 1.1.1 → 2.0.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/README.md +2 -8
- package/index.js +0 -8
- package/package.json +2 -2
- package/plugin.js +3 -1
- package/rules/prefer-table-facets.js +69 -0
- package/ui.js +1 -0
package/README.md
CHANGED
|
@@ -28,7 +28,7 @@ UI half behind `/ui` means the root entry resolves neither `@shadcn/lint` nor
|
|
|
28
28
|
|---|---|---|
|
|
29
29
|
| `house` | anything TS/JS | `no-property-shorthand`, `curly: all`, `us-spelling`, `no-express-json-spaces` |
|
|
30
30
|
| `lib` | a published library | house + `no-lib-process-env`, `no-module-scope-init` |
|
|
31
|
-
| `ui` | anything rendering Tailwind | house + `require-leading-with-text-size`, `prefer-copy-icon` |
|
|
31
|
+
| `ui` | anything rendering Tailwind | house + `require-leading-with-text-size`, `prefer-copy-icon`, `prefer-table-facets` |
|
|
32
32
|
| `uiLib` | a published UI library | `lib` + `ui` |
|
|
33
33
|
|
|
34
34
|
## Rules
|
|
@@ -43,6 +43,7 @@ UI half behind `/ui` means the root entry resolves neither `@shadcn/lint` nor
|
|
|
43
43
|
| `prefer-copy-icon` | lucide `Copy`, not `Clipboard` |
|
|
44
44
|
| `us-spelling` | US spelling in prose and identifiers |
|
|
45
45
|
| `require-leading-with-text-size` | An arbitrary Tailwind text size must state its own line height |
|
|
46
|
+
| `prefer-table-facets` | A `kind: "select"` filter lists the values its rows hold (facets), never a literal `options` list |
|
|
46
47
|
|
|
47
48
|
`us-spelling` skips regex literals — a pattern matching scraped text has to accept both
|
|
48
49
|
spellings — and takes `allow` for proper names that keep their own:
|
|
@@ -77,13 +78,6 @@ A file's namespace is its top-level directory under that root, so neither the pa
|
|
|
77
78
|
checked out at nor the package's own name changes the verdict. Outside a workspace there is no root,
|
|
78
79
|
and a scoped package's scope is its namespace.
|
|
79
80
|
|
|
80
|
-
## Ignores
|
|
81
|
-
|
|
82
|
-
`house`, and so every preset, globally ignores `.design-sync/**`, `.ds-sync/**` and
|
|
83
|
-
`ds-bundle/**`. Flat config does not read `.gitignore`, and these hold symlinks into app
|
|
84
|
-
components — one moved component leaves a dangling link and `eslint .` exits `ENOENT` instead of
|
|
85
|
-
reporting anything.
|
|
86
|
-
|
|
87
81
|
## License
|
|
88
82
|
|
|
89
83
|
MIT
|
package/index.js
CHANGED
|
@@ -4,13 +4,6 @@ import tsPlugin from "@typescript-eslint/eslint-plugin";
|
|
|
4
4
|
|
|
5
5
|
const TS_GLOBS = ["**/*.ts", "**/*.tsx", "**/*.mts", "**/*.js", "**/*.mjs"];
|
|
6
6
|
|
|
7
|
-
// design-sync scratch and its generated bundle. All three are gitignored, and `ds-src` holds
|
|
8
|
-
// symlinks that dangle the moment a component moves - which makes `eslint .` exit on ENOENT
|
|
9
|
-
// rather than report. Flat config does not read .gitignore, so every consumer needs this.
|
|
10
|
-
export const designSyncIgnores = {
|
|
11
|
-
ignores: [".design-sync/**", ".ds-sync/**", "ds-bundle/**"],
|
|
12
|
-
};
|
|
13
|
-
|
|
14
7
|
// The @typescript-eslint rule set. Without this the parser parses TypeScript and
|
|
15
8
|
// NOTHING lints it - no unused vars, no floating promises, no unsafe any. The rules
|
|
16
9
|
// go in `house` (so every consumer gets them) while the PARSER stays out of it, since
|
|
@@ -42,7 +35,6 @@ typescriptRules.push({
|
|
|
42
35
|
|
|
43
36
|
// Every rule here encodes a documented house rule. Adding one means editing
|
|
44
37
|
export const house = [
|
|
45
|
-
designSyncIgnores,
|
|
46
38
|
...typescriptRules,
|
|
47
39
|
{
|
|
48
40
|
files: TS_GLOBS,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mslmio/eslint-config",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Shareable ESLint flat config and house rules: US spelling, library hygiene, workspace layering, and Tailwind/React conventions.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eslint",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"eslint-plugin",
|
|
10
10
|
"flat-config",
|
|
11
11
|
"typescript",
|
|
12
|
-
"
|
|
12
|
+
"workspace",
|
|
13
13
|
"layering",
|
|
14
14
|
"tailwind",
|
|
15
15
|
"react"
|
package/plugin.js
CHANGED
|
@@ -6,9 +6,10 @@ import usSpelling from "./rules/us-spelling.js";
|
|
|
6
6
|
import requireLeadingWithTextSize from "./rules/require-leading-with-text-size.js";
|
|
7
7
|
import noPropertyShorthand from "./rules/no-property-shorthand.js";
|
|
8
8
|
import noUpwardImport from "./rules/no-upward-import.js";
|
|
9
|
+
import preferTableFacets from "./rules/prefer-table-facets.js";
|
|
9
10
|
|
|
10
11
|
export default {
|
|
11
|
-
meta: { name: "@mslmio/eslint-plugin", version: "2.
|
|
12
|
+
meta: { name: "@mslmio/eslint-plugin", version: "2.5.0" },
|
|
12
13
|
rules: {
|
|
13
14
|
"no-lib-process-env": noLibProcessEnv,
|
|
14
15
|
"no-module-scope-init": noModuleScopeInit,
|
|
@@ -18,5 +19,6 @@ export default {
|
|
|
18
19
|
"require-leading-with-text-size": requireLeadingWithTextSize,
|
|
19
20
|
"no-property-shorthand": noPropertyShorthand,
|
|
20
21
|
"no-upward-import": noUpwardImport,
|
|
22
|
+
"prefer-table-facets": preferTableFacets,
|
|
21
23
|
},
|
|
22
24
|
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// A table's picklist filter offers the values its rows actually hold - served by
|
|
2
|
+
// the backend as FACETS - rather than a literal list. A literal list is a second
|
|
3
|
+
// copy of a vocabulary the backend owns, and the next value it starts writing is
|
|
4
|
+
// missing from the picklist until someone remembers to add it.
|
|
5
|
+
//
|
|
6
|
+
// Reported: `options` on an object with `kind: "select"` that is an array
|
|
7
|
+
// literal, a `.map` over one, or a map over Object.entries/keys/values - the
|
|
8
|
+
// shapes a hardcoded list takes. Options mapped from runtime data pass. A fixed
|
|
9
|
+
// product vocabulary, one no row can grow, stays literal behind a disable
|
|
10
|
+
// comment saying so.
|
|
11
|
+
export default {
|
|
12
|
+
meta: {
|
|
13
|
+
type: "suggestion",
|
|
14
|
+
docs: {
|
|
15
|
+
description: "A picklist filter lists the values its rows hold (facets), not a literal list",
|
|
16
|
+
},
|
|
17
|
+
schema: [{ type: "object", properties: { docsUrl: { type: "string" } }, additionalProperties: false }],
|
|
18
|
+
messages: {
|
|
19
|
+
literal:
|
|
20
|
+
"A picklist filter should list the values its rows hold: leave `options` off and serve " +
|
|
21
|
+
"them as facets. A fixed product vocabulary stays literal behind a disable comment " +
|
|
22
|
+
"saying why.{{docs}}",
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
create(context) {
|
|
26
|
+
const docs = docsSuffix(context);
|
|
27
|
+
return {
|
|
28
|
+
ObjectExpression(node) {
|
|
29
|
+
const kind = property(node, "kind");
|
|
30
|
+
const options = property(node, "options");
|
|
31
|
+
if (!kind || !options || kind.value.type !== "Literal" || kind.value.value !== "select") {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if (isLiteralList(options.value)) {
|
|
35
|
+
context.report({ node: options, messageId: "literal", data: { docs: docs } });
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
function property(node, name) {
|
|
43
|
+
return node.properties.find((p) => p.type === "Property" && !p.computed
|
|
44
|
+
&& ((p.key.type === "Identifier" && p.key.name === name)
|
|
45
|
+
|| (p.key.type === "Literal" && p.key.value === name)));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function isLiteralList(v) {
|
|
49
|
+
if (v.type === "ArrayExpression") {
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
if (v.type !== "CallExpression" || v.callee.type !== "MemberExpression" || v.callee.computed
|
|
53
|
+
|| v.callee.property.name !== "map") {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
const source = v.callee.object;
|
|
57
|
+
if (source.type === "ArrayExpression") {
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
return source.type === "CallExpression" && source.callee.type === "MemberExpression"
|
|
61
|
+
&& source.callee.object.type === "Identifier" && source.callee.object.name === "Object"
|
|
62
|
+
&& ["entries", "keys", "values"].includes(source.callee.property.name);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// A link only an internal caller can resolve, so the public default is none.
|
|
66
|
+
function docsSuffix(context) {
|
|
67
|
+
const url = context.options[0]?.docsUrl;
|
|
68
|
+
return url ? ` See ${url}.` : "";
|
|
69
|
+
}
|