@md-code/component-uniqueness 0.1.4 → 0.3.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 +17 -0
- package/LICENSE +202 -0
- package/README.md +21 -3
- package/dist/config.d.ts +50 -0
- package/dist/config.js +402 -0
- package/dist/constants.d.ts +55 -0
- package/dist/constants.js +86 -0
- package/dist/decision-maker.d.ts +39 -0
- package/dist/decision-maker.js +119 -0
- package/dist/filter/child-element.d.ts +3 -0
- package/dist/filter/child-element.js +17 -0
- package/dist/filter/missing-component.d.ts +10 -0
- package/dist/filter/missing-component.js +96 -0
- package/dist/filter/no-structure.d.ts +3 -0
- package/dist/filter/no-structure.js +16 -0
- package/dist/filter/usages.d.ts +3 -0
- package/dist/filter/usages.js +14 -0
- package/dist/index.d.ts +105 -0
- package/dist/index.js +244 -0
- package/dist/lib-registry.d.ts +4 -0
- package/dist/lib-registry.js +376 -0
- package/dist/logger.d.ts +7 -0
- package/dist/logger.js +70 -0
- package/dist/main.d.ts +25 -0
- package/dist/main.js +666 -0
- package/dist/matcher/a11y.d.ts +19 -0
- package/dist/matcher/a11y.js +311 -0
- package/dist/matcher/behavior.d.ts +10 -0
- package/dist/matcher/behavior.js +32 -0
- package/dist/matcher/css-matching.d.ts +18 -0
- package/dist/matcher/css-matching.js +159 -0
- package/dist/matcher/framework/index.d.ts +2 -0
- package/dist/matcher/framework/index.js +37 -0
- package/dist/matcher/framework/react.d.ts +12 -0
- package/dist/matcher/framework/react.js +70 -0
- package/dist/matcher/index.d.ts +64 -0
- package/dist/matcher/index.js +38 -0
- package/dist/matcher/name.d.ts +15 -0
- package/dist/matcher/name.js +154 -0
- package/dist/matcher/structure.d.ts +22 -0
- package/dist/matcher/structure.js +329 -0
- package/dist/matcher/styles.d.ts +20 -0
- package/dist/matcher/styles.js +49 -0
- package/dist/normalize/candidate.d.ts +3 -0
- package/dist/normalize/candidate.js +21 -0
- package/dist/normalize/dom.d.ts +22 -0
- package/dist/normalize/dom.js +180 -0
- package/dist/normalize/external-html.d.ts +5 -0
- package/dist/normalize/external-html.js +40 -0
- package/dist/normalize/framework.d.ts +20 -0
- package/dist/normalize/framework.js +130 -0
- package/dist/normalize/resolver.d.ts +7 -0
- package/dist/normalize/resolver.js +28 -0
- package/dist/normalize/style-resolver.d.ts +7 -0
- package/dist/normalize/style-resolver.js +28 -0
- package/dist/normalize/style.d.ts +15 -0
- package/dist/normalize/style.js +174 -0
- package/dist/normalize/words.d.ts +3 -0
- package/dist/normalize/words.js +40 -0
- package/dist/package.json +88 -0
- package/dist/playgrounds/angular.d.ts +7 -0
- package/dist/playgrounds/angular.js +9 -0
- package/dist/playgrounds/framework-entrypoint.d.ts +10 -0
- package/dist/playgrounds/framework-entrypoint.js +102 -0
- package/dist/playgrounds/framework.d.ts +10 -0
- package/dist/playgrounds/framework.js +102 -0
- package/dist/playgrounds/react.d.ts +14 -0
- package/dist/playgrounds/react.js +1288 -0
- package/dist/playgrounds/scss.d.ts +6 -0
- package/dist/playgrounds/scss.js +9 -0
- package/dist/playgrounds/style-entrypoint.d.ts +13 -0
- package/dist/playgrounds/style-entrypoint.js +82 -0
- package/dist/playgrounds/style.d.ts +13 -0
- package/dist/playgrounds/style.js +82 -0
- package/dist/playgrounds/styled-components.d.ts +7 -0
- package/dist/playgrounds/styled-components.js +190 -0
- package/dist/playgrounds/tailwind.d.ts +15 -0
- package/dist/playgrounds/tailwind.js +256 -0
- package/dist/playgrounds/vue.d.ts +7 -0
- package/dist/playgrounds/vue.js +9 -0
- package/dist/report/asks.d.ts +27 -0
- package/dist/report/asks.js +28 -0
- package/dist/report/cli-report.d.ts +7 -0
- package/dist/report/cli-report.js +187 -0
- package/dist/report/codes/index.d.ts +37 -0
- package/dist/report/codes/index.js +31 -0
- package/dist/report/errorTypes/index.d.ts +92 -0
- package/dist/report/errorTypes/index.js +186 -0
- package/dist/report/evidence.d.ts +2 -0
- package/dist/report/evidence.js +8 -0
- package/dist/report/explain.d.ts +27 -0
- package/dist/report/explain.js +76 -0
- package/dist/report/index.d.ts +2 -0
- package/dist/report/index.js +24 -0
- package/dist/report/matchers/a11y/model.d.ts +20 -0
- package/dist/report/matchers/a11y/model.js +14 -0
- package/dist/report/matchers/a11y/text.d.ts +2 -0
- package/dist/report/matchers/a11y/text.js +22 -0
- package/dist/report/matchers/behavior/model.d.ts +20 -0
- package/dist/report/matchers/behavior/model.js +12 -0
- package/dist/report/matchers/behavior/text.d.ts +2 -0
- package/dist/report/matchers/behavior/text.js +22 -0
- package/dist/report/matchers/framework/model.d.ts +10 -0
- package/dist/report/matchers/framework/model.js +39 -0
- package/dist/report/matchers/framework/text.d.ts +2 -0
- package/dist/report/matchers/framework/text.js +26 -0
- package/dist/report/matchers/index.d.ts +5 -0
- package/dist/report/matchers/index.js +97 -0
- package/dist/report/matchers/name/model.d.ts +20 -0
- package/dist/report/matchers/name/model.js +30 -0
- package/dist/report/matchers/name/text.d.ts +2 -0
- package/dist/report/matchers/name/text.js +17 -0
- package/dist/report/matchers/set-model.d.ts +31 -0
- package/dist/report/matchers/set-model.js +42 -0
- package/dist/report/matchers/structure/model.d.ts +10 -0
- package/dist/report/matchers/structure/model.js +58 -0
- package/dist/report/matchers/structure/text.d.ts +2 -0
- package/dist/report/matchers/structure/text.js +40 -0
- package/dist/report/matchers/styles/model.d.ts +11 -0
- package/dist/report/matchers/styles/model.js +36 -0
- package/dist/report/matchers/styles/text.d.ts +2 -0
- package/dist/report/matchers/styles/text.js +40 -0
- package/dist/report/user-report/build/bundle.d.ts +3 -0
- package/dist/report/user-report/build/bundle.js +185 -0
- package/dist/report/user-report/build/bundle.prebuilt.js +955 -0
- package/dist/report/user-report/data/collect.d.ts +68 -0
- package/dist/report/user-report/data/collect.js +150 -0
- package/dist/report/user-report/data/folders.d.ts +3 -0
- package/dist/report/user-report/data/folders.js +73 -0
- package/dist/report/user-report/data/groups.d.ts +13 -0
- package/dist/report/user-report/data/groups.js +76 -0
- package/dist/report/user-report/data/links.d.ts +39 -0
- package/dist/report/user-report/data/links.js +222 -0
- package/dist/report/user-report/data/snapshot.d.ts +9 -0
- package/dist/report/user-report/data/snapshot.js +180 -0
- package/dist/report/user-report/data/source.d.ts +13 -0
- package/dist/report/user-report/data/source.js +58 -0
- package/dist/report/user-report/data/word.d.ts +3 -0
- package/dist/report/user-report/data/word.js +32 -0
- package/dist/report/user-report/html/shell.d.ts +2 -0
- package/dist/report/user-report/html/shell.js +27 -0
- package/dist/report/user-report/index.d.ts +7 -0
- package/dist/report/user-report/index.js +47 -0
- package/dist/report/vocabulary/evidence.d.ts +48 -0
- package/dist/report/vocabulary/evidence.js +66 -0
- package/dist/report/vocabulary/format.d.ts +4 -0
- package/dist/report/vocabulary/format.js +20 -0
- package/dist/report/vocabulary/labels.d.ts +134 -0
- package/dist/report/vocabulary/labels.js +87 -0
- package/dist/report/vocabulary/phrases.d.ts +20 -0
- package/dist/report/vocabulary/phrases.js +34 -0
- package/dist/self-catalog.d.ts +4 -0
- package/dist/self-catalog.js +179 -0
- package/dist/utils.d.ts +6 -0
- package/dist/utils.js +125 -0
- package/package.json +86 -71
- package/config.js +0 -372
- package/decision-maker.js +0 -109
- package/filter/drop-child-element.js +0 -14
- package/filter/drop-no-structure.js +0 -13
- package/filter/drop-usages.js +0 -13
- package/filter/missing-component.js +0 -100
- package/index.js +0 -184
- package/logger.js +0 -44
- package/main.js +0 -584
- package/matcher/a11y.js +0 -65
- package/matcher/behavior.js +0 -31
- package/matcher/framework/index.js +0 -15
- package/matcher/framework/react.js +0 -25
- package/matcher/index.js +0 -36
- package/matcher/name.js +0 -132
- package/matcher/structure.js +0 -242
- package/normalize/candidate.js +0 -22
- package/normalize/dom.js +0 -187
- package/normalize/framework.js +0 -110
- package/normalize/style-resolver.js +0 -24
- package/normalize/style.js +0 -175
- package/normalize/words.js +0 -40
- package/playgrounds/angular.js +0 -11
- package/playgrounds/framework-entrypoint.js +0 -90
- package/playgrounds/react.js +0 -998
- package/playgrounds/scss.js +0 -7
- package/playgrounds/style-entrypoint.js +0 -78
- package/playgrounds/styled-components.js +0 -138
- package/playgrounds/tailwind.js +0 -186
- package/playgrounds/vue.js +0 -11
- package/plugin.js +0 -3
- package/report.js +0 -162
- package/utils.js +0 -92
package/index.js
DELETED
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const path = require("node:path");
|
|
4
|
-
|
|
5
|
-
const {
|
|
6
|
-
normalizeOptions,
|
|
7
|
-
inComponentsFolder,
|
|
8
|
-
canSeeCanon,
|
|
9
|
-
isIgnored,
|
|
10
|
-
loadRegistry,
|
|
11
|
-
loadCatalog,
|
|
12
|
-
RULE_NAME,
|
|
13
|
-
RULE_SHORT,
|
|
14
|
-
} = require("./config");
|
|
15
|
-
const { parseComponents, parseElements } = require("./playgrounds/framework-entrypoint.js");
|
|
16
|
-
const { buildCandidate, buildElementCandidate } = require("./normalize/candidate.js");
|
|
17
|
-
const { matchSignals } = require("./matcher");
|
|
18
|
-
const { getFrameworkMatcher } = require("./matcher/framework");
|
|
19
|
-
const { decide, bestOf } = require("./decision-maker");
|
|
20
|
-
const { matchPairs, applyFilters, findParts } = require("./main");
|
|
21
|
-
|
|
22
|
-
const frameworkMatcher = getFrameworkMatcher("react");
|
|
23
|
-
|
|
24
|
-
const isComponentBinding = (node) => {
|
|
25
|
-
if (!node || node.type !== "Identifier") return false;
|
|
26
|
-
if (!/^[A-Z]/.test(node.name)) return false;
|
|
27
|
-
let parent = node.parent;
|
|
28
|
-
while (parent) {
|
|
29
|
-
if (parent.type === "TSInterfaceDeclaration") return false;
|
|
30
|
-
if (parent.type === "TSTypeAliasDeclaration") return false;
|
|
31
|
-
if (parent.type === "TSModuleDeclaration") return false;
|
|
32
|
-
if (parent.type === "ExportNamedDeclaration" || parent.type === "ExportDefaultDeclaration") break;
|
|
33
|
-
parent = parent.parent;
|
|
34
|
-
}
|
|
35
|
-
return true;
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
const normalizedCanons = new WeakMap();
|
|
39
|
-
|
|
40
|
-
const normalizeCanon = (canon, config) => {
|
|
41
|
-
if (!normalizedCanons.has(canon)) normalizedCanons.set(canon, buildCandidate(canon, config));
|
|
42
|
-
|
|
43
|
-
return normalizedCanons.get(canon);
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
const createRule = () => {
|
|
47
|
-
return {
|
|
48
|
-
meta: {
|
|
49
|
-
type: "problem",
|
|
50
|
-
docs: {
|
|
51
|
-
description: "Flag components that duplicate a canonical component, and raw HTML elements that should use the canonical packages.",
|
|
52
|
-
},
|
|
53
|
-
messages: {
|
|
54
|
-
duplicateComponent: "Component \"{{name}}\" duplicates the canonical \"{{canonName}}\" ({{reason}}).",
|
|
55
|
-
rawHtml: "Raw <{{tag}}> outside the canonical packages → replace with `{{component}}` from {{path}} ({{reason}}).",
|
|
56
|
-
partOfComponent: "This <{{tag}}> block in {{owner}} duplicates `{{component}}` from {{path}} ({{reason}}).",
|
|
57
|
-
},
|
|
58
|
-
schema: [
|
|
59
|
-
{
|
|
60
|
-
type: "object",
|
|
61
|
-
properties: {
|
|
62
|
-
registry: { type: "string" },
|
|
63
|
-
registryPath: { type: "string" },
|
|
64
|
-
catalog: { type: "array" },
|
|
65
|
-
catalogPath: { type: "string" },
|
|
66
|
-
includeDynamic: { type: "boolean" },
|
|
67
|
-
dynamicCatalog: { type: "array" },
|
|
68
|
-
dynamicCatalogPath: { type: "string" },
|
|
69
|
-
rawHtml: { type: "boolean" },
|
|
70
|
-
parts: { type: "boolean" },
|
|
71
|
-
tsconfig: { type: "string" },
|
|
72
|
-
weights: { type: "object" },
|
|
73
|
-
thresholds: { type: "object" },
|
|
74
|
-
componentsFolder: { type: "array" },
|
|
75
|
-
include: { type: "array" },
|
|
76
|
-
exclude: { type: "array" },
|
|
77
|
-
exts: { type: "array" },
|
|
78
|
-
ignoreDirs: { type: "array" },
|
|
79
|
-
rootMarkers: { type: "array" },
|
|
80
|
-
},
|
|
81
|
-
additionalProperties: false,
|
|
82
|
-
},
|
|
83
|
-
],
|
|
84
|
-
},
|
|
85
|
-
create(context) {
|
|
86
|
-
const options = context.options && context.options[0] ? context.options[0] : {};
|
|
87
|
-
const config = normalizeOptions(options);
|
|
88
|
-
const filename = context.filename || (context.getFilename ? context.getFilename() : "");
|
|
89
|
-
const relPath = path.relative(context.cwd || process.cwd(), filename).split(path.sep).join("/");
|
|
90
|
-
|
|
91
|
-
const isInComponentsFolder = inComponentsFolder(relPath, config.componentsFolder);
|
|
92
|
-
if (isIgnored(relPath, isInComponentsFolder ? [] : config.include, config.exclude)) return {};
|
|
93
|
-
|
|
94
|
-
const registry = loadRegistry(config);
|
|
95
|
-
const catalogComponents = ((loadCatalog(config) || {}).components) || [];
|
|
96
|
-
const canonNames = [...new Set(catalogComponents.map((c) => c.name))];
|
|
97
|
-
|
|
98
|
-
const checkDuplicates = () => {
|
|
99
|
-
let parsed;
|
|
100
|
-
try {
|
|
101
|
-
parsed = parseComponents(filename, canonNames, config);
|
|
102
|
-
} catch {
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
const normalizeComp = (comp) => buildCandidate(comp, config);
|
|
106
|
-
|
|
107
|
-
for (const comp of parsed) {
|
|
108
|
-
if (!comp.isExported) continue;
|
|
109
|
-
const candidate = normalizeComp({ ...comp, path: relPath });
|
|
110
|
-
const pairs = [];
|
|
111
|
-
for (const canon of catalogComponents) {
|
|
112
|
-
if (canon.name === candidate.name) continue;
|
|
113
|
-
if (!canSeeCanon(relPath, canon.path, config.componentsFolder)) continue;
|
|
114
|
-
const normCanon = normalizeCanon(canon, config);
|
|
115
|
-
const signals = matchSignals(candidate, normCanon, { canonNames, frameworkMatcher });
|
|
116
|
-
const decision = decide(candidate, normCanon, { signals, weights: config.weights, thresholds: config.thresholds });
|
|
117
|
-
pairs.push({ canon: normCanon, signals, decision });
|
|
118
|
-
}
|
|
119
|
-
pairs.sort((a, b) => b.decision.confidence - a.decision.confidence);
|
|
120
|
-
for (const p of pairs) {
|
|
121
|
-
if (!p.decision.isDuplicate) continue;
|
|
122
|
-
const { kept } = applyFilters([{ app: candidate, canon: p.canon, decision: p.decision, tier: p.decision.tier, reason: p.decision.reason }]);
|
|
123
|
-
if (kept.length === 0) continue;
|
|
124
|
-
const line = comp.line || 1;
|
|
125
|
-
context.report({
|
|
126
|
-
loc: { start: { line, column: 0 }, end: { line, column: 0 } },
|
|
127
|
-
messageId: "duplicateComponent",
|
|
128
|
-
data: { name: candidate.name, canonName: p.canon.name, reason: p.decision.reason },
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
if (config.rawHtml && !isInComponentsFolder) {
|
|
133
|
-
const canons = catalogComponents.map((canon) => normalizeCanon(canon, config));
|
|
134
|
-
let elements = [];
|
|
135
|
-
try {
|
|
136
|
-
elements = parseElements(filename, canonNames, config);
|
|
137
|
-
} catch {
|
|
138
|
-
elements = [];
|
|
139
|
-
}
|
|
140
|
-
for (const element of elements) {
|
|
141
|
-
const candidate = buildElementCandidate(element, config);
|
|
142
|
-
if (!candidate) continue;
|
|
143
|
-
const best = bestOf(matchPairs([{ ...candidate, path: relPath }], canons, config));
|
|
144
|
-
if (!best) continue;
|
|
145
|
-
context.report({
|
|
146
|
-
loc: { start: { line: element.line, column: element.column }, end: { line: element.line, column: element.column } },
|
|
147
|
-
messageId: "rawHtml",
|
|
148
|
-
data: { tag: element.name, component: best.canon.name, path: best.canon.path, reason: best.decision.reason },
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
if (config.parts) {
|
|
153
|
-
const canons = catalogComponents.map((canon) => normalizeCanon(canon, config));
|
|
154
|
-
for (const { part, best } of findParts(filename, relPath, canons, config, new Set(canonNames))) {
|
|
155
|
-
context.report({
|
|
156
|
-
loc: { start: { line: part.line, column: part.column }, end: { line: part.endLine, column: 0 } },
|
|
157
|
-
messageId: "partOfComponent",
|
|
158
|
-
data: { owner: part.owner, tag: part.rootTag, component: best.canon.name, path: best.canon.path, reason: best.decision.reason },
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
return {
|
|
165
|
-
"Program:exit": checkDuplicates,
|
|
166
|
-
};
|
|
167
|
-
},
|
|
168
|
-
};
|
|
169
|
-
};
|
|
170
|
-
|
|
171
|
-
const rule = createRule();
|
|
172
|
-
const pkg = require("./package.json");
|
|
173
|
-
|
|
174
|
-
module.exports = {
|
|
175
|
-
meta: {
|
|
176
|
-
name: pkg.name,
|
|
177
|
-
version: pkg.version,
|
|
178
|
-
},
|
|
179
|
-
rules: {
|
|
180
|
-
"component-uniqueness": rule,
|
|
181
|
-
},
|
|
182
|
-
};
|
|
183
|
-
module.exports.RULE_NAME = RULE_NAME;
|
|
184
|
-
module.exports.RULE_SHORT = RULE_SHORT;
|
package/logger.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const fs = require("node:fs");
|
|
4
|
-
const path = require("node:path");
|
|
5
|
-
|
|
6
|
-
const state = {
|
|
7
|
-
enabled: false,
|
|
8
|
-
stream: null,
|
|
9
|
-
file: null,
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
const enabled = () => state.enabled;
|
|
13
|
-
|
|
14
|
-
const enable = (file) => {
|
|
15
|
-
if (!file) return;
|
|
16
|
-
const abs = path.resolve(process.cwd(), file);
|
|
17
|
-
fs.mkdirSync(path.dirname(abs), { recursive: true });
|
|
18
|
-
if (state.stream) state.stream.end();
|
|
19
|
-
state.stream = fs.createWriteStream(abs, { flags: "w" });
|
|
20
|
-
state.file = abs;
|
|
21
|
-
state.enabled = true;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
const disable = () => {
|
|
25
|
-
if (state.stream) state.stream.end();
|
|
26
|
-
state.stream = null;
|
|
27
|
-
state.file = null;
|
|
28
|
-
state.enabled = false;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
const write = (entry) => {
|
|
32
|
-
if (!state.enabled || !state.stream) return;
|
|
33
|
-
state.stream.write(`${JSON.stringify(entry)}\n`);
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
const stage = (name, data) => {
|
|
37
|
-
write({ ts: Date.now(), stage: name, ...data });
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
const flush = () => {
|
|
41
|
-
if (state.stream) state.stream.end();
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
module.exports = { enable, disable, enabled, stage, write, flush };
|