Problem: the hexagonal refactor churns the backend tree for nine more phases; the UI delivery stack (web/ SPA, cmd/desktop Wails wrapper, compose/web image) must move to its own repo first so doc/layout rewrites land once on a backend-only tree. Change: - New repo git.hubris.network/dtoro/oikos-web (v0.33.0): web/, desktop/ (updateURL repointed to oikos-web releases), compose/, own CI (web + desktop jobs), own deploy script (CI-green gate, TOCTOU guard, version-tagged images, prune-to-3), own webhook receiver on :9798 + launchd unit, own compose project publishing the same 8091:80. - Cutover executed on mac-mini in order: oikos stack's web service stopped+removed, oikos-web project brought up on 8091; outer Caddy untouched (targets the published port) — serving + Authentik flow + /wails 404 quirk verified post-cutover. - Stripped from oikos: web/, cmd/desktop/, compose/web/, desktop CI workflow, ci.yml web job, Makefile ui/desktop/desktop-package/install targets, the compose web service, oikos-web from deploy.sh's fallback prune list; wails + go-keyring dropped from go.mod, vendor synced. - README / CONTRIBUTING / AGENTS.md / .agents dev+operations docs now point at the new repo; mbse + mascot design docs carry a path note. Risk: production SPA serving depends on the new pipeline now; rollback is versioned-image re-up of the old web service from a pre-split checkout (port 8091). Desktop builds installed before the split still check dtoro/oikos releases — one manual reinstall, noted in the oikos-web release notes. Verification: go vet, make test (race), make generate-check, golangci (no new findings; baseline down 400→365); post-cutover curls — localhost:8091 200, /wails/runtime.js 404, outer Caddy 302 Authentik.
196 lines
4.9 KiB
JavaScript
196 lines
4.9 KiB
JavaScript
/**
|
|
* @fileoverview Disallow construction of dense arrays using the Array constructor
|
|
* @author Matt DuVall <http://www.mattduvall.com/>
|
|
*/
|
|
|
|
"use strict";
|
|
|
|
//------------------------------------------------------------------------------
|
|
// Requirements
|
|
//------------------------------------------------------------------------------
|
|
|
|
const {
|
|
getVariableByName,
|
|
isClosingParenToken,
|
|
isOpeningParenToken,
|
|
isStartOfExpressionStatement,
|
|
needsPrecedingSemicolon,
|
|
} = require("./utils/ast-utils");
|
|
|
|
//------------------------------------------------------------------------------
|
|
// Rule Definition
|
|
//------------------------------------------------------------------------------
|
|
|
|
/** @type {import('../types').Rule.RuleModule} */
|
|
module.exports = {
|
|
meta: {
|
|
dialects: ["javascript", "typescript"],
|
|
language: "javascript",
|
|
type: "suggestion",
|
|
|
|
docs: {
|
|
description: "Disallow `Array` constructors",
|
|
recommended: false,
|
|
url: "https://eslint.org/docs/latest/rules/no-array-constructor",
|
|
},
|
|
|
|
fixable: "code",
|
|
|
|
hasSuggestions: true,
|
|
|
|
schema: [],
|
|
|
|
messages: {
|
|
preferLiteral: "The array literal notation [] is preferable.",
|
|
useLiteral: "Replace with an array literal.",
|
|
useLiteralAfterSemicolon:
|
|
"Replace with an array literal, add preceding semicolon.",
|
|
},
|
|
},
|
|
|
|
create(context) {
|
|
const sourceCode = context.sourceCode;
|
|
|
|
/**
|
|
* Checks if there are comments in Array constructor expressions.
|
|
* @param {ASTNode} node A CallExpression or NewExpression node.
|
|
* @returns {boolean} True if there are comments, false otherwise.
|
|
*/
|
|
function hasCommentsInArrayConstructor(node) {
|
|
const firstToken = sourceCode.getFirstToken(node);
|
|
const lastToken = sourceCode.getLastToken(node);
|
|
|
|
let lastRelevantToken = sourceCode.getLastToken(node.callee);
|
|
|
|
while (
|
|
lastRelevantToken !== lastToken &&
|
|
!isOpeningParenToken(lastRelevantToken)
|
|
) {
|
|
lastRelevantToken = sourceCode.getTokenAfter(lastRelevantToken);
|
|
}
|
|
|
|
return sourceCode.commentsExistBetween(
|
|
firstToken,
|
|
lastRelevantToken,
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Gets the text between the calling parentheses of a CallExpression or NewExpression.
|
|
* @param {ASTNode} node A CallExpression or NewExpression node.
|
|
* @returns {string} The text between the calling parentheses, or an empty string if there are none.
|
|
*/
|
|
function getArgumentsText(node) {
|
|
const lastToken = sourceCode.getLastToken(node);
|
|
|
|
if (!isClosingParenToken(lastToken)) {
|
|
return "";
|
|
}
|
|
|
|
let firstToken = node.callee;
|
|
|
|
do {
|
|
firstToken = sourceCode.getTokenAfter(firstToken);
|
|
if (!firstToken || firstToken === lastToken) {
|
|
return "";
|
|
}
|
|
} while (!isOpeningParenToken(firstToken));
|
|
|
|
return sourceCode.text.slice(
|
|
firstToken.range[1],
|
|
lastToken.range[0],
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Disallow construction of dense arrays using the Array constructor
|
|
* @param {ASTNode} node node to evaluate
|
|
* @returns {void}
|
|
* @private
|
|
*/
|
|
function check(node) {
|
|
if (
|
|
node.callee.type !== "Identifier" ||
|
|
node.callee.name !== "Array" ||
|
|
node.typeArguments ||
|
|
(node.arguments.length === 1 &&
|
|
node.arguments[0].type !== "SpreadElement")
|
|
) {
|
|
return;
|
|
}
|
|
|
|
const variable = getVariableByName(
|
|
sourceCode.getScope(node),
|
|
"Array",
|
|
);
|
|
|
|
/*
|
|
* Check if `Array` is a predefined global variable: predefined globals have no declarations,
|
|
* meaning that the `identifiers` list of the variable object is empty.
|
|
*/
|
|
if (variable && variable.identifiers.length === 0) {
|
|
const argsText = getArgumentsText(node);
|
|
let fixText;
|
|
let messageId;
|
|
|
|
const nonSpreadCount = node.arguments.reduce(
|
|
(count, arg) =>
|
|
arg.type !== "SpreadElement" ? count + 1 : count,
|
|
0,
|
|
);
|
|
|
|
const shouldSuggest =
|
|
node.optional ||
|
|
(node.arguments.length > 0 && nonSpreadCount < 2) ||
|
|
hasCommentsInArrayConstructor(node);
|
|
|
|
/*
|
|
* Check if the suggested change should include a preceding semicolon or not.
|
|
* Due to JavaScript's ASI rules, a missing semicolon may be inserted automatically
|
|
* before an expression like `Array()` or `new Array()`, but not when the expression
|
|
* is changed into an array literal like `[]`.
|
|
*/
|
|
if (
|
|
isStartOfExpressionStatement(node) &&
|
|
needsPrecedingSemicolon(sourceCode, node)
|
|
) {
|
|
fixText = `;[${argsText}]`;
|
|
messageId = "useLiteralAfterSemicolon";
|
|
} else {
|
|
fixText = `[${argsText}]`;
|
|
messageId = "useLiteral";
|
|
}
|
|
|
|
context.report({
|
|
node,
|
|
messageId: "preferLiteral",
|
|
fix(fixer) {
|
|
if (shouldSuggest) {
|
|
return null;
|
|
}
|
|
|
|
return fixer.replaceText(node, fixText);
|
|
},
|
|
suggest: [
|
|
{
|
|
messageId,
|
|
fix(fixer) {
|
|
if (shouldSuggest) {
|
|
return fixer.replaceText(node, fixText);
|
|
}
|
|
|
|
return null;
|
|
},
|
|
},
|
|
],
|
|
});
|
|
}
|
|
}
|
|
|
|
return {
|
|
CallExpression: check,
|
|
NewExpression: check,
|
|
};
|
|
},
|
|
};
|