@rafters/veneer 0.0.4 → 0.0.5

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/dist/bin.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import { i as relativeFile } from "./lint-Bqu-nKvP.mjs";
3
- import { t as check } from "./check-vsAQPYCD.mjs";
2
+ import { i as relativeFile } from "./lint-9HD2n_oJ.mjs";
3
+ import { t as check } from "./check-BWUfShkM.mjs";
4
4
  import path from "node:path";
5
5
  import { existsSync, realpathSync } from "node:fs";
6
6
  import { parseArgs } from "node:util";
@@ -1,4 +1,4 @@
1
- import { a as resolveComponents, c as readConfig, n as report, o as ProjectError, r as compareCodePoints, s as openProject, t as lint } from "./lint-Bqu-nKvP.mjs";
1
+ import { a as resolveComponents, c as readConfig, n as report, o as ProjectError, r as compareCodePoints, s as openProject, t as lint } from "./lint-9HD2n_oJ.mjs";
2
2
  import path from "node:path";
3
3
  import { mkdir, rename, rm, writeFile } from "node:fs/promises";
4
4
  import { lstatSync } from "node:fs";
package/dist/index.mjs CHANGED
@@ -1,3 +1,3 @@
1
- import { n as report, o as ProjectError, s as openProject, t as lint } from "./lint-Bqu-nKvP.mjs";
2
- import { n as writeDocs, t as check } from "./check-vsAQPYCD.mjs";
1
+ import { n as report, o as ProjectError, s as openProject, t as lint } from "./lint-9HD2n_oJ.mjs";
2
+ import { n as writeDocs, t as check } from "./check-BWUfShkM.mjs";
3
3
  export { ProjectError, check, lint, openProject, report, writeDocs };
@@ -991,6 +991,17 @@ function valueAttributes({ ts }, sourceFile) {
991
991
  visit(sourceFile);
992
992
  return found;
993
993
  }
994
+ const FREEHAND_HELP = "use Container or Grid for layout";
995
+ function openingElements({ ts }, sourceFile) {
996
+ const found = [];
997
+ const visit = (node) => {
998
+ if (ts.isJsxOpeningLikeElement(node)) found.push(node);
999
+ ts.forEachChild(node, visit);
1000
+ };
1001
+ visit(sourceFile);
1002
+ return found;
1003
+ }
1004
+ const isDiv = (ts, { tagName }) => ts.isIdentifier(tagName) && tagName.text === "div";
994
1005
  async function lint(project, options) {
995
1006
  const files = options.files?.filter((file) => !file.endsWith(".ts") || isClassesFile(file)) ?? project.checker.getRootFileNames().filter((file) => file.endsWith(".tsx") || file.endsWith(".astro") || isClassesFile(file)).map((file) => relativeFile(project.root, file));
996
1007
  const perFile = [];
@@ -1104,6 +1115,33 @@ async function lint(project, options) {
1104
1115
  }
1105
1116
  return flagged;
1106
1117
  };
1118
+ const isComponentUse = (element) => {
1119
+ if (isDiv(ts, element)) return false;
1120
+ const component = resolveTag(reader, element);
1121
+ const declaration = component?.valueDeclaration ?? component?.declarations?.[0];
1122
+ return declaration !== void 0 && isCheckedUse(declaration.getSourceFile());
1123
+ };
1124
+ const freehandDivs = (file, sourceFile) => {
1125
+ const elements = openingElements(reader, sourceFile);
1126
+ const divs = elements.filter((element) => isDiv(ts, element));
1127
+ if (divs.length === 0 || !elements.some(isComponentUse)) return [];
1128
+ return divs.flatMap(({ tagName }) => {
1129
+ const start = positionOf(reader, sourceFile, tagName.getStart(sourceFile));
1130
+ const end = positionOf(reader, sourceFile, tagName.end);
1131
+ if (!start || !end) return [];
1132
+ return [{
1133
+ file,
1134
+ line: start.line,
1135
+ column: start.column,
1136
+ endLine: end.line,
1137
+ endColumn: end.column,
1138
+ severity: "warning",
1139
+ code: "rafters(freehand-div)",
1140
+ message: "a div laid by hand around rafters components",
1141
+ help: FREEHAND_HELP
1142
+ }];
1143
+ });
1144
+ };
1107
1145
  const found = [];
1108
1146
  for (const [file, diagnostics] of perFile) {
1109
1147
  const absolute = path.join(project.root, file);
@@ -1116,17 +1154,18 @@ async function lint(project, options) {
1116
1154
  if (!isExempt(sourceFile)) {
1117
1155
  found.push(...bracketValues(reader, file, sourceFile, isOwnSource));
1118
1156
  found.push(...await badValues(file, sourceFile));
1157
+ found.push(...freehandDivs(file, sourceFile));
1119
1158
  }
1120
1159
  }
1121
1160
  return found.sort((a, b) => compareCodePoints(a.file, b.file) || a.line - b.line || a.column - b.column);
1122
1161
  }
1123
- function firstLine(message) {
1124
- return (typeof message === "string" ? message : message.value).split(/\r\n|\r|\n/, 1)[0] ?? "";
1162
+ function messageLines(message) {
1163
+ return (typeof message === "string" ? message : message.value).split(/\r\n|\r|\n/);
1125
1164
  }
1126
1165
  function report(diagnostics) {
1127
1166
  const lines = diagnostics.flatMap(({ file, line, column, severity, code, message, help }) => {
1128
- const entry = `${file}:${line}:${column} ${severity} ${code} ${firstLine(message)}`;
1129
- return help === void 0 ? [entry] : [entry, ` help: ${help}`];
1167
+ const entry = messageLines(message).map((text, index) => index === 0 ? `${file}:${line}:${column} ${severity} ${code} ${text}` : ` ${text}`);
1168
+ return help === void 0 ? entry : [...entry, ` help: ${help}`];
1130
1169
  });
1131
1170
  const count = diagnostics.length;
1132
1171
  lines.push(count === 1 ? "1 problem" : `${count} problems`);
package/dist/worker.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { c as readConfig, s as openProject, t as lint } from "./lint-Bqu-nKvP.mjs";
1
+ import { c as readConfig, s as openProject, t as lint } from "./lint-9HD2n_oJ.mjs";
2
2
  import path from "node:path";
3
3
  import { existsSync } from "node:fs";
4
4
  import { promisify } from "node:util";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rafters/veneer",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "description": "Docs, rafters check and the composite compile for rafters projects",
5
5
  "license": "MIT",
6
6
  "repository": {