@storm-software/eslint
Version:
A package containing the base ESLint configuration used by Storm Software across many projects.
1,494 lines (1,480 loc) • 274 kB
JavaScript
import { isInEditorEnv, interopDefault, ensurePackages, renameRules, parserPlain, isPackageInScope } from './chunk-4ZPL5FXI.js';
import { getTsConfigPath } from './chunk-RPALAP3R.js';
import { banner_plugin_default } from './chunk-6T25DCUR.js';
import { getFileBanner } from './chunk-TBHRJJNJ.js';
import { GLOB_EXCLUDE, GLOB_TS, GLOB_TSX, GLOB_JSX, GLOB_MARKDOWN, GLOB_ASTRO_TS, GLOB_SRC, GLOB_TESTS, GLOB_ASTRO, GLOB_JSON, GLOB_JSON5, GLOB_JSONC, GLOB_YAML, GLOB_TOML, GLOB_MARKDOWN_IN_MARKDOWN, GLOB_MDX, GLOB_CSS, GLOB_POSTCSS, GLOB_SCSS, GLOB_LESS, GLOB_HTML, GLOB_XML, GLOB_SVG, GLOB_GRAPHQL, GLOB_SRC_EXT, GLOB_SRC_FILE } from './chunk-QQBZQ6FI.js';
import { findWorkspaceRoot } from './chunk-BSVVS7SV.js';
import { joinPaths } from './chunk-VIFGWE6I.js';
import { __commonJS, init_esm_shims, __toESM } from './chunk-H2OHWXFL.js';
import * as __import__microsoft_tsdocConfig from '@microsoft/tsdoc-config';
import * as __import_path from 'path';
import * as __import_fs from 'fs';
import * as __import__microsoft_tsdoc from '@microsoft/tsdoc';
import { FlatConfigComposer } from 'eslint-flat-config-utils';
import { isPackageExists } from 'local-pkg';
import cspellConfig from '@cspell/eslint-plugin/recommended';
import defu from 'defu';
import '@cspell/eslint-plugin';
import default3 from '@nx/eslint-plugin/nx.js';
import * as pluginImport from 'eslint-plugin-import-x';
import default4 from 'eslint-plugin-import-zod';
import default5 from 'eslint-plugin-n';
import default6 from 'eslint-plugin-no-secrets';
import default7 from 'eslint-plugin-perfectionist';
import * as jsoncParser from 'jsonc-eslint-parser';
import * as yamlParser from 'yaml-eslint-parser';
import fs, { existsSync, readFileSync } from 'node:fs';
import process2 from 'node:process';
import { findUpSync } from 'find-up-simple';
import { parsePnpmWorkspaceYaml } from 'pnpm-workspace-yaml';
import { basename, normalize, resolve, dirname } from 'pathe';
import { globSync } from 'tinyglobby';
import default8 from 'eslint-plugin-prettier';
import default9 from 'eslint-plugin-unicorn';
import default10 from 'eslint-plugin-unused-imports';
import { loadConfig } from 'c12';
import chalk from 'chalk';
import { join } from 'node:path';
import { readFile } from 'node:fs/promises';
import globalsLib from 'globals';
import { mergeProcessors, processorPassThrough } from 'eslint-merge-processors';
import { readCachedProjectGraph, createProjectGraphAsync } from '@nx/devkit';
import config2 from 'eslint-plugin-prettier/recommended';
import { configs as configs$1 } from 'eslint-plugin-regexp';
// ../../node_modules/.pnpm/eslint-plugin-tsdoc@0.4.0_patch_hash=11b9fbe0e91a2ce3492e80b89a7502a9ff364683b23b9bdfc2c979d988e1682b/node_modules/eslint-plugin-tsdoc/lib/Debug.js
var require_Debug = __commonJS({
"../../node_modules/.pnpm/eslint-plugin-tsdoc@0.4.0_patch_hash=11b9fbe0e91a2ce3492e80b89a7502a9ff364683b23b9bdfc2c979d988e1682b/node_modules/eslint-plugin-tsdoc/lib/Debug.js"(exports) {
init_esm_shims();
Object.defineProperty(exports, "__esModule", { value: true });
exports.Debug = void 0;
var Debug = class {
// To debug the plugin, temporarily uncomment the body of this function
static log(message) {
}
};
exports.Debug = Debug;
}
});
var require_ConfigCache = __commonJS({
"../../node_modules/.pnpm/eslint-plugin-tsdoc@0.4.0_patch_hash=11b9fbe0e91a2ce3492e80b89a7502a9ff364683b23b9bdfc2c979d988e1682b/node_modules/eslint-plugin-tsdoc/lib/ConfigCache.js"(exports) {
init_esm_shims();
var __import___Debug = __toESM(require_Debug());
var __createBinding = exports && exports.__createBinding || (Object.create ? (function(o, m, k, k2) {
if (k2 === void 0) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() {
return m[k];
} };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === void 0) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = exports && exports.__setModuleDefault || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = exports && exports.__importStar || function(mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) {
for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
}
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ConfigCache = void 0;
var tsdoc_config_1 = __import__microsoft_tsdocConfig;
var path = __importStar(__import_path);
var Debug_1 = __import___Debug;
function _nullishCoalesce(lhs, rhsFn) {
if (lhs != null) {
return lhs;
} else {
return rhsFn();
}
}
var _fs = __import_fs;
var _path = __import_path;
var MAX_PATH_SEARCH_DEPTH2 = 30;
var depth2 = 0;
var ROOT_FILES = [
"storm-workspace.json",
"storm-workspace.json",
"storm-workspace.yaml",
"storm-workspace.yml",
"storm-workspace.js",
"storm-workspace.ts",
".storm-workspace.json",
".storm-workspace.yaml",
".storm-workspace.yml",
".storm-workspace.js",
".storm-workspace.ts",
"lerna.json",
"nx.json",
"turbo.json",
"npm-workspace.json",
"yarn-workspace.json",
"pnpm-workspace.json",
"npm-workspace.yaml",
"yarn-workspace.yaml",
"pnpm-workspace.yaml",
"npm-workspace.yml",
"yarn-workspace.yml",
"pnpm-workspace.yml",
"npm-lock.json",
"yarn-lock.json",
"pnpm-lock.json",
"npm-lock.yaml",
"yarn-lock.yaml",
"pnpm-lock.yaml",
"npm-lock.yml",
"yarn-lock.yml",
"pnpm-lock.yml",
"bun.lockb"
];
var ROOT_DIRECTORIES = [
".storm-workspace",
".nx",
".github",
".vscode",
".verdaccio"
];
function findWorkspaceRoot3(startPath) {
const _startPath = _nullishCoalesce(startPath, () => process.cwd());
if (ROOT_DIRECTORIES.some(
(endDirName) => _fs.existsSync.call(void 0, _path.join.call(void 0, _startPath, endDirName))
)) {
return _startPath;
}
if (ROOT_FILES.some(
(endFileName) => _fs.existsSync.call(void 0, _path.join.call(void 0, _startPath, endFileName))
)) {
return _startPath;
}
if (_startPath !== "/" && depth2++ < MAX_PATH_SEARCH_DEPTH2) {
const parent = _path.join.call(void 0, _startPath, "..");
return findWorkspaceRoot3(parent);
}
return void 0;
}
var CACHE_CHECK_INTERVAL_MS = 3 * 1e3;
var CACHE_EXPIRE_MS = 20 * 1e3;
var CACHE_MAX_SIZE = 100;
var ConfigCache = class _ConfigCache {
/**
* Node.js equivalent of performance.now().
*/
static _getTimeInMs() {
const [seconds, nanoseconds] = process.hrtime();
return seconds * 1e3 + nanoseconds / 1e6;
}
static getForSourceFile(sourceFilePath, tsConfigRootDir) {
const sourceFileFolder = path.dirname(path.resolve(sourceFilePath));
const configFilePath = tsConfigRootDir ? path.join(tsConfigRootDir, tsdoc_config_1.TSDocConfigFile.FILENAME) : tsdoc_config_1.TSDocConfigFile.findConfigPathForFolder(sourceFileFolder);
const cacheKey = configFilePath || sourceFileFolder + "/";
Debug_1.Debug.log(`Cache key: "${cacheKey}"`);
const nowMs = _ConfigCache._getTimeInMs();
let cachedConfig = void 0;
cachedConfig = _ConfigCache._cachedConfigs.get(cacheKey);
if (cachedConfig) {
Debug_1.Debug.log("Cache hit");
const loadAgeMs = nowMs - cachedConfig.loadTimeMs;
const lastCheckAgeMs = nowMs - cachedConfig.lastCheckTimeMs;
if (loadAgeMs > CACHE_EXPIRE_MS || loadAgeMs < 0) {
Debug_1.Debug.log("Evicting because item is expired");
cachedConfig = void 0;
_ConfigCache._cachedConfigs.delete(cacheKey);
} else if (lastCheckAgeMs > CACHE_CHECK_INTERVAL_MS || lastCheckAgeMs < 0) {
Debug_1.Debug.log("Checking for modifications");
cachedConfig.lastCheckTimeMs = nowMs;
if (cachedConfig.configFile.checkForModifiedFiles()) {
Debug_1.Debug.log("Evicting because item was modified");
cachedConfig = void 0;
_ConfigCache._cachedConfigs.delete(cacheKey);
}
}
}
if (!cachedConfig) {
if (_ConfigCache._cachedConfigs.size > CACHE_MAX_SIZE) {
Debug_1.Debug.log("Clearing cache");
_ConfigCache._cachedConfigs.clear();
}
const configFile = tsdoc_config_1.TSDocConfigFile.loadFile(configFilePath);
if (configFile.fileNotFound) {
Debug_1.Debug.log(`File not found: "${configFilePath}"`);
} else {
Debug_1.Debug.log(`Loaded: "${configFilePath}"`);
}
cachedConfig = {
configFile,
lastCheckTimeMs: nowMs,
loadTimeMs: nowMs
};
_ConfigCache._cachedConfigs.set(cacheKey, cachedConfig);
}
return cachedConfig.configFile;
}
static _checkConfigFilePath(workspaceRoot, configFilePath) {
const workspaceRootPath = workspaceRoot ? workspaceRoot : "./";
if (!configFilePath) {
return void 0;
}
if (_fs.existsSync(configFilePath)) {
return configFilePath;
} else if (_fs.existsSync(
path.join(
workspaceRootPath,
configFilePath
)
)) {
return path.join(
workspaceRootPath,
configFilePath
);
} else if (_fs.existsSync(
path.join(
workspaceRootPath,
"node_modules",
configFilePath
)
)) {
return path.join(
workspaceRootPath,
"node_modules",
configFilePath
);
} else if (_fs.existsSync(
path.join(
workspaceRootPath,
"node_modules",
"@storm-software",
"tsdoc",
configFilePath
)
)) {
return path.join(
workspaceRootPath,
"node_modules",
"@storm-software",
"tsdoc",
configFilePath
);
} else if (_fs.existsSync(
path.join(
workspaceRootPath,
"node_modules",
"@storm-software",
"tsdoc",
"config",
configFilePath
)
)) {
return path.join(
workspaceRootPath,
"node_modules",
"@storm-software",
"tsdoc",
"config",
configFilePath
);
} else if (_fs.existsSync(
path.join(
workspaceRootPath,
"node_modules",
"@storm-software",
"tsdoc",
"dist",
configFilePath
)
)) {
return path.join(
workspaceRootPath,
"node_modules",
"@storm-software",
"tsdoc",
"dist",
configFilePath
);
}
return void 0;
}
static getStormConfigFile(options) {
const type = options && options.type ? options.type : "recommended";
const configFile = options && options.configFile ? options.configFile : void 0;
let workspaceRoot = "";
if (process.env.STORM_WORKSPACE_ROOT || process.env.NX_WORKSPACE_ROOT_PATH) {
workspaceRoot = process.env.STORM_WORKSPACE_ROOT || process.env.NX_WORKSPACE_ROOT_PATH;
}
if (!workspaceRoot) {
workspaceRoot = findWorkspaceRoot3();
}
let currentConfigFile = process.env.STORM_TSDOC_CONFIG_FILE ? process.env.STORM_TSDOC_CONFIG_FILE : configFile;
Debug_1.Debug.log(`Config file from user options: ${currentConfigFile || "(none)"}`);
let configFilePath = _ConfigCache._checkConfigFilePath(
workspaceRoot,
currentConfigFile
);
if (!configFilePath) {
currentConfigFile = `${((process.env.STORM_TSDOC_TYPE ? process.env.STORM_TSDOC_TYPE : type) || "recommended").replace(/\.jsonc?$/, "")}.json`;
Debug_1.Debug.log(`Config file from user options not found, trying: ${currentConfigFile}`);
configFilePath = _ConfigCache._checkConfigFilePath(
workspaceRoot,
currentConfigFile
);
if (!configFilePath) {
configFilePath = _ConfigCache._checkConfigFilePath(
workspaceRoot,
"recommended.json"
);
if (!configFilePath) {
configFilePath = _ConfigCache._checkConfigFilePath(
workspaceRoot,
"tsdoc.json"
);
}
}
}
const cacheKey = configFilePath || "missing-config-file";
Debug_1.Debug.log(`Storm Software Configuration Cache key: "${cacheKey}"`);
const nowMs = _ConfigCache._getTimeInMs();
let cachedConfig = void 0;
cachedConfig = _ConfigCache._cachedConfigs.get(cacheKey);
if (cachedConfig) {
Debug_1.Debug.log("Cache hit");
const loadAgeMs = nowMs - cachedConfig.loadTimeMs;
const lastCheckAgeMs = nowMs - cachedConfig.lastCheckTimeMs;
if (loadAgeMs > CACHE_EXPIRE_MS || loadAgeMs < 0) {
Debug_1.Debug.log("Evicting because item is expired");
cachedConfig = void 0;
_ConfigCache._cachedConfigs.delete(cacheKey);
} else if (lastCheckAgeMs > CACHE_CHECK_INTERVAL_MS || lastCheckAgeMs < 0) {
Debug_1.Debug.log("Checking for modifications");
cachedConfig.lastCheckTimeMs = nowMs;
if (cachedConfig.configFile.checkForModifiedFiles()) {
Debug_1.Debug.log("Evicting because item was modified");
cachedConfig = void 0;
_ConfigCache._cachedConfigs.delete(cacheKey);
}
}
}
if (!cachedConfig) {
if (_ConfigCache._cachedConfigs.size > CACHE_MAX_SIZE) {
Debug_1.Debug.log("Clearing cache");
_ConfigCache._cachedConfigs.clear();
}
const configFile2 = tsdoc_config_1.TSDocConfigFile.loadFile(configFilePath);
if (configFile2.fileNotFound) {
Debug_1.Debug.log(`File not found: "${configFilePath}"`);
} else {
Debug_1.Debug.log(`Loaded: "${configFilePath}"`);
}
cachedConfig = {
configFile: configFile2,
lastCheckTimeMs: nowMs,
loadTimeMs: nowMs
};
_ConfigCache._cachedConfigs.set(cacheKey, cachedConfig);
}
return cachedConfig.configFile;
}
};
exports.ConfigCache = ConfigCache;
ConfigCache._cachedConfigs = /* @__PURE__ */ new Map();
ConfigCache._cachedPaths = /* @__PURE__ */ new Map();
}
});
var require_lib = __commonJS({
"../../node_modules/.pnpm/eslint-plugin-tsdoc@0.4.0_patch_hash=11b9fbe0e91a2ce3492e80b89a7502a9ff364683b23b9bdfc2c979d988e1682b/node_modules/eslint-plugin-tsdoc/lib/index.js"(exports, module) {
init_esm_shims();
var __import___Debug = __toESM(require_Debug());
var __import___ConfigCache = __toESM(require_ConfigCache());
var tsdoc_1 = __import__microsoft_tsdoc;
var Debug_1 = __import___Debug;
var ConfigCache_1 = __import___ConfigCache;
var tsdocMessageIds = {};
var defaultTSDocConfiguration = new tsdoc_1.TSDocConfiguration();
defaultTSDocConfiguration.allTsdocMessageIds.forEach((messageId) => {
tsdocMessageIds[messageId] = `${messageId}: {{unformattedText}}`;
});
var plugin2 = {
rules: {
// NOTE: The actual ESLint rule name will be "tsdoc/syntax". It is calculated by deleting "eslint-plugin-"
// from the NPM package name, and then appending this string.
syntax: {
meta: {
messages: Object.assign({
"error-loading-storm-config": `Error loading Storm Software's shared TSDoc config file:
{{details}}
Please ensure "@storm-software/tsdoc" is installed in the workspace root.`,
"error-loading-config-file": "Error loading TSDoc config file:\n{{details}}",
"error-applying-storm-config": "Error applying Storm Software's shared TSDoc configuration: {{details}}",
"error-applying-config": "Error applying TSDoc configuration: {{details}}"
}, tsdocMessageIds),
type: "problem",
docs: {
description: "Validates that TypeScript documentation comments conform to the TSDoc standard",
category: "Stylistic Issues",
recommended: true,
url: "https://tsdoc.org/pages/packages/eslint-plugin-tsdoc"
},
schema: [
{
type: "object",
properties: {
type: {
type: "string",
enum: ["typedoc", "api-extractor", "base", "core", "callouts", "recommended"],
description: "The TSDoc configuration type to use from '@storm-software/tsdoc'. Defaults to 'recommended' (@storm-software/tsdoc/recommended.json)."
},
configFile: {
type: "string",
description: "The TSDoc configuration file to use."
}
},
additionalProperties: false
}
]
},
defaultOptions: [
{
type: "recommended"
}
],
create: (context) => {
const tsdocConfiguration = new tsdoc_1.TSDocConfiguration();
const tsConfigDir = context.parserOptions.tsconfigRootDir;
const sourceFilePath = context.filename;
Debug_1.Debug.log(`Linting: "${sourceFilePath}"`);
try {
let tsdocConfigFile = {};
try {
const userOptions = context.options ? Array.isArray(context.options) ? context.options.length > 0 ? context.options[0] : {} : context.options : {};
const config3 = { type: userOptions.type || "recommended", configFile: userOptions.configFile };
Debug_1.Debug.log(`Using eslint-plugin-tsdoc config: ${JSON.stringify(config3, void 0, 2)}`);
tsdocConfigFile = ConfigCache_1.ConfigCache.getStormConfigFile(config3);
if (!tsdocConfigFile.fileNotFound) {
if (tsdocConfigFile.hasErrors) {
context.report({
loc: { line: 1, column: 1 },
messageId: "error-loading-storm-config",
data: {
details: tsdocConfigFile.getErrorSummary()
}
});
}
try {
tsdocConfigFile.configureParser(tsdocConfiguration);
} catch (e) {
context.report({
loc: { line: 1, column: 1 },
messageId: "error-applying-storm-config",
data: {
details: e.message
}
});
}
}
} catch (e) {
context.report({
loc: { line: 1, column: 1 },
messageId: "error-loading-storm-config",
data: {
details: `Unexpected exception: ${e.message}`
}
});
}
if (!tsdocConfigFile || tsdocConfigFile.fileNotFound || tsdocConfigFile.hasErrors) {
tsdocConfigFile = ConfigCache_1.ConfigCache.getForSourceFile(sourceFilePath, tsConfigDir);
if (!tsdocConfigFile.fileNotFound) {
if (tsdocConfigFile.hasErrors) {
context.report({
loc: { line: 1, column: 1 },
messageId: "error-loading-config-file",
data: {
details: tsdocConfigFile.getErrorSummary()
}
});
}
try {
tsdocConfigFile.configureParser(tsdocConfiguration);
} catch (e) {
context.report({
loc: { line: 1, column: 1 },
messageId: "error-applying-config",
data: {
details: e.message
}
});
}
}
}
} catch (e) {
context.report({
loc: { line: 1, column: 1 },
messageId: "error-loading-config-file",
data: {
details: `Unexpected exception: ${e.message}`
}
});
}
const tsdocParser = new tsdoc_1.TSDocParser(tsdocConfiguration);
const sourceCode = context.getSourceCode();
const checkCommentBlocks = function(node2) {
for (const comment of sourceCode.getAllComments()) {
if (comment.type !== "Block") {
continue;
}
if (!comment.range) {
continue;
}
const textRange = tsdoc_1.TextRange.fromStringRange(sourceCode.text, comment.range[0], comment.range[1]);
if (textRange.length < 5) {
continue;
}
if (textRange.buffer[textRange.pos + 2] !== "*") {
continue;
}
const parserContext = tsdocParser.parseRange(textRange);
for (const message of parserContext.log.messages) {
context.report({
loc: {
start: sourceCode.getLocFromIndex(message.textRange.pos),
end: sourceCode.getLocFromIndex(message.textRange.end)
},
messageId: message.messageId,
data: {
unformattedText: message.unformattedText
}
});
}
}
};
return {
Program: checkCommentBlocks
};
}
}
}
};
module.exports = plugin2;
}
});
// src/preset.ts
init_esm_shims();
// src/configs/astro.ts
init_esm_shims();
async function astro(options = {}) {
const { files = [GLOB_ASTRO], overrides = {}, stylistic: stylistic2 = true } = options;
const [pluginAstro, parserAstro, parserTs] = await Promise.all([
interopDefault(import('eslint-plugin-astro')),
interopDefault(import('astro-eslint-parser')),
interopDefault(import('@typescript-eslint/parser'))
]);
return [
{
name: "storm/astro/setup",
plugins: {
astro: pluginAstro
}
},
{
files,
languageOptions: {
globals: pluginAstro.environments.astro.globals,
parser: parserAstro,
parserOptions: {
extraFileExtensions: [".astro"],
parser: parserTs
},
sourceType: "module"
},
name: "storm/astro/rules",
processor: "astro/client-side-ts",
rules: {
// use recommended rules
"astro/missing-client-only-directive-value": "error",
"astro/no-conflict-set-directives": "error",
"astro/no-deprecated-astro-canonicalurl": "error",
"astro/no-deprecated-astro-fetchcontent": "error",
"astro/no-deprecated-astro-resolve": "error",
"astro/no-deprecated-getentrybyslug": "error",
"astro/no-set-html-directive": "off",
"astro/no-unused-define-vars-in-style": "error",
"astro/semi": "off",
"astro/valid-compile": "error",
...stylistic2 ? {
"style/indent": "off",
"style/jsx-closing-tag-location": "off",
"style/jsx-one-expression-per-line": "off",
"style/no-multiple-empty-lines": "off"
} : {},
...overrides
}
}
];
}
// src/configs/cspell.ts
init_esm_shims();
async function cspell(options = {}) {
const { configFile = "./.vscode/cspell.json", overrides = {} } = options;
return [
{
name: "storm/cspell/rules",
...cspellConfig,
rules: {
...cspellConfig.rules,
"@cspell/spellchecker": [
"warn",
{
configFile: joinPaths(findWorkspaceRoot(), configFile),
generateSuggestions: true,
numSuggestions: 10,
autoFix: true
}
],
...overrides
}
}
];
}
// src/configs/disables.ts
init_esm_shims();
async function disables() {
return [
{
files: [`**/scripts/${GLOB_SRC}`],
name: "storm/disables/scripts",
rules: {
"no-console": "off",
"ts/explicit-function-return-type": "off"
}
},
{
files: [`**/cli/${GLOB_SRC}`, `**/cli.${GLOB_SRC_EXT}`],
name: "storm/disables/cli",
rules: {
"no-console": "off"
}
},
{
files: ["**/*.d.?([cm])ts"],
name: "storm/disables/dts",
rules: {
"eslint-comments/no-unlimited-disable": "off",
"import/no-duplicates": "off",
"no-restricted-syntax": "off",
"unused-imports/no-unused-vars": "off"
}
},
{
files: ["**/*.js", "**/*.cjs"],
name: "storm/disables/cjs",
rules: {
"ts/no-require-imports": "off"
}
},
{
files: [`**/*.config.${GLOB_SRC_EXT}`, `**/*.config.*.${GLOB_SRC_EXT}`],
name: "storm/disables/config-files",
rules: {
"no-console": "off",
"ts/explicit-function-return-type": "off"
}
}
];
}
// src/configs/formatters.ts
init_esm_shims();
// src/configs/stylistic.ts
init_esm_shims();
var StylisticConfigDefaults = {
indent: 2,
jsx: true,
quotes: "double",
semi: true
};
async function stylistic(options = {}) {
const {
indent = 2,
jsx: jsx2 = true,
overrides = {},
quotes = "double",
semi = true,
lineEndings = "unix"
} = {
...StylisticConfigDefaults,
...options
};
const pluginStylistic = await interopDefault(
import('@stylistic/eslint-plugin')
);
const config3 = pluginStylistic.configs.customize({
indent,
jsx: jsx2,
pluginName: "style",
quotes,
semi
});
return [
{
name: "storm/stylistic/rules",
plugins: {
style: pluginStylistic
},
rules: {
...config3.rules,
"style/lines-around-comment": "off",
"style/linebreak-style": ["error", lineEndings],
"style/comma-dangle": ["error", "never"],
"style/comma-style": ["error", "last"],
"style/quotes": ["error", quotes],
"style/semi": ["error", semi ? "always" : "never"],
"style/indent": ["error", indent, { SwitchCase: 1 }],
"style/operator-linebreak": [
"error",
"after",
{ overrides: { "=": "none", "?": "before", ":": "before" } }
],
"style/jsx-indent": ["error", indent],
"style/jsx-quotes": [
"error",
quotes === "single" ? "prefer-single" : "prefer-double"
],
"style/brace-style": ["error", "1tbs", { allowSingleLine: false }],
...overrides
}
}
];
}
// src/configs/formatters.ts
function mergePrettierOptions(options, overrides = {}) {
return {
...options,
...overrides,
plugins: [...overrides.plugins || [], ...options.plugins || []]
};
}
async function formatters(options = {}, stylistic2 = {}) {
if (options === true) {
const isPrettierPluginXmlInScope = isPackageInScope("@prettier/plugin-xml");
options = {
astro: isPackageInScope("prettier-plugin-astro"),
css: true,
graphql: true,
html: true,
markdown: true,
svg: isPrettierPluginXmlInScope,
xml: isPrettierPluginXmlInScope
};
}
await ensurePackages([
"eslint-plugin-format",
options.astro ? "prettier-plugin-astro" : void 0,
options.xml || options.svg ? "@prettier/plugin-xml" : void 0
]);
const {
indent = 2,
quotes = "double",
semi = true
} = {
...StylisticConfigDefaults,
...stylistic2
};
const prettierOptions = defu(
{
proseWrap: "always",
quoteProps: "preserve",
bracketSameLine: true,
bracketSpacing: true,
arrowParens: "avoid",
endOfLine: "lf",
printWidth: 120,
semi,
singleQuote: quotes === "single",
tabWidth: typeof indent === "number" ? indent : 2,
trailingComma: "none",
useTabs: indent === "tab"
},
options.prettierOptions ?? {}
);
const prettierXmlOptions = {
xmlQuoteAttributes: "double",
xmlSelfClosingSpace: true,
xmlSortAttributesByKey: false,
xmlWhitespaceSensitivity: "ignore"
};
const dprintOptions = defu(
{
indentWidth: typeof indent === "number" ? indent : 2,
quoteStyle: quotes === "single" ? "preferSingle" : "preferDouble",
useTabs: indent === "tab"
},
options.dprintOptions ?? {}
);
const pluginFormat = await interopDefault(import('eslint-plugin-format'));
const configs3 = [
{
name: "storm/formatter/setup",
plugins: {
format: pluginFormat
}
}
];
if (options.css) {
configs3.push(
{
files: [GLOB_CSS, GLOB_POSTCSS],
languageOptions: {
parser: parserPlain
},
name: "storm/formatter/css",
rules: {
"format/prettier": [
"error",
mergePrettierOptions(prettierOptions, {
parser: "css"
})
]
}
},
{
files: [GLOB_SCSS],
languageOptions: {
parser: parserPlain
},
name: "storm/formatter/scss",
rules: {
"format/prettier": [
"error",
mergePrettierOptions(prettierOptions, {
parser: "scss"
})
]
}
},
{
files: [GLOB_LESS],
languageOptions: {
parser: parserPlain
},
name: "storm/formatter/less",
rules: {
"format/prettier": [
"error",
mergePrettierOptions(prettierOptions, {
parser: "less"
})
]
}
}
);
}
if (options.html) {
configs3.push({
files: [GLOB_HTML],
languageOptions: {
parser: parserPlain
},
name: "storm/formatter/html",
rules: {
"format/prettier": [
"error",
mergePrettierOptions(prettierOptions, {
parser: "html"
})
]
}
});
}
if (options.xml) {
configs3.push({
files: [GLOB_XML],
languageOptions: {
parser: parserPlain
},
name: "storm/formatter/xml",
rules: {
"format/prettier": [
"error",
mergePrettierOptions(
{ ...prettierXmlOptions, ...prettierOptions },
{
parser: "xml",
plugins: ["@prettier/plugin-xml"]
}
)
]
}
});
}
if (options.svg) {
configs3.push({
files: [GLOB_SVG],
languageOptions: {
parser: parserPlain
},
name: "storm/formatter/svg",
rules: {
"format/prettier": [
"error",
mergePrettierOptions(
{ ...prettierXmlOptions, ...prettierOptions },
{
parser: "xml",
plugins: ["@prettier/plugin-xml"]
}
)
]
}
});
}
if (options.markdown) {
const formater = options.markdown === true ? "prettier" : options.markdown;
configs3.push({
files: [GLOB_MARKDOWN],
languageOptions: {
parser: parserPlain
},
name: "storm/formatter/markdown",
rules: {
[`format/${formater}`]: [
"error",
formater === "prettier" ? mergePrettierOptions(prettierOptions, {
embeddedLanguageFormatting: "off",
parser: "markdown"
}) : {
...dprintOptions,
language: "markdown"
}
]
}
});
}
if (options.astro) {
configs3.push({
files: [GLOB_ASTRO],
languageOptions: {
parser: parserPlain
},
name: "storm/formatter/astro",
rules: {
"format/prettier": [
"error",
mergePrettierOptions(prettierOptions, {
parser: "astro",
plugins: ["prettier-plugin-astro"]
})
]
}
});
configs3.push({
files: [GLOB_ASTRO, GLOB_ASTRO_TS],
name: "storm/formatter/astro/disables",
rules: {
"style/arrow-parens": "off",
"style/block-spacing": "off",
"style/comma-dangle": "off",
"style/indent": "off",
"style/no-multi-spaces": "off",
"style/quotes": "off",
"style/semi": "off"
}
});
}
if (options.graphql) {
configs3.push({
files: [GLOB_GRAPHQL],
languageOptions: {
parser: parserPlain
},
name: "storm/formatter/graphql",
rules: {
"format/prettier": [
"error",
mergePrettierOptions(prettierOptions, {
parser: "graphql"
})
]
}
});
}
return configs3;
}
// src/configs/graphql.ts
init_esm_shims();
async function graphql(options = {}) {
const {
relay = true,
operations = true,
schema = true,
overrides = {}
} = options;
await ensurePackages([
"@graphql-eslint/eslint-plugin",
"eslint-plugin-relay"
]);
const [pluginGraphQL, pluginRelay] = await Promise.all([
interopDefault(import('@graphql-eslint/eslint-plugin')),
interopDefault(import('eslint-plugin-relay'))
]);
return [
{
name: "storm/graphql/setup",
files: ["**/*.graphql", "**/*.gql"],
languageOptions: {
parser: pluginGraphQL.parser
},
plugins: {
"@graphql-eslint": pluginGraphQL
}
},
{
name: "storm/graphql/rules",
plugins: {
graphql: pluginGraphQL
},
rules: {
...schema ? {
"@graphql-eslint/description-style": "error",
"@graphql-eslint/known-argument-names": "error",
"@graphql-eslint/known-directives": "error",
"@graphql-eslint/known-type-names": "error",
"@graphql-eslint/lone-schema-definition": "error",
"@graphql-eslint/naming-convention": [
"error",
{
types: "PascalCase",
FieldDefinition: "camelCase",
InputValueDefinition: "camelCase",
Argument: "camelCase",
DirectiveDefinition: "camelCase",
EnumValueDefinition: "UPPER_CASE",
"FieldDefinition[parent.name.value=Query]": {
forbiddenPrefixes: ["query", "get"],
forbiddenSuffixes: ["Query"]
},
"FieldDefinition[parent.name.value=Mutation]": {
forbiddenPrefixes: ["mutation"],
forbiddenSuffixes: ["Mutation"]
},
"FieldDefinition[parent.name.value=Subscription]": {
forbiddenPrefixes: ["subscription"],
forbiddenSuffixes: ["Subscription"]
},
"EnumTypeDefinition,EnumTypeExtension": {
forbiddenPrefixes: ["Enum"],
forbiddenSuffixes: ["Enum"]
},
"InterfaceTypeDefinition,InterfaceTypeExtension": {
forbiddenPrefixes: ["Interface"],
forbiddenSuffixes: ["Interface"]
},
"UnionTypeDefinition,UnionTypeExtension": {
forbiddenPrefixes: ["Union"],
forbiddenSuffixes: ["Union"]
},
"ObjectTypeDefinition,ObjectTypeExtension": {
forbiddenPrefixes: ["Type"],
forbiddenSuffixes: ["Type"]
}
}
],
"@graphql-eslint/no-hashtag-description": "error",
"@graphql-eslint/no-typename-prefix": "error",
"@graphql-eslint/no-unreachable-types": "error",
"@graphql-eslint/possible-type-extension": "error",
"@graphql-eslint/provided-required-arguments": "error",
"@graphql-eslint/require-deprecation-reason": "error",
"@graphql-eslint/require-description": [
"error",
{ types: true, DirectiveDefinition: true, rootField: true }
],
"@graphql-eslint/strict-id-in-types": "error",
"@graphql-eslint/unique-directive-names": "error",
"@graphql-eslint/unique-directive-names-per-location": "error",
"@graphql-eslint/unique-enum-value-names": "error",
"@graphql-eslint/unique-field-definition-names": "error",
"@graphql-eslint/unique-operation-types": "error",
"@graphql-eslint/unique-type-names": "error"
} : {},
...operations ? {
"@graphql-eslint/executable-definitions": "error",
"@graphql-eslint/fields-on-correct-type": "error",
"@graphql-eslint/fragments-on-composite-type": "error",
"@graphql-eslint/known-argument-names": "error",
"@graphql-eslint/known-directives": "error",
"@graphql-eslint/known-fragment-names": "error",
"@graphql-eslint/known-type-names": "error",
"@graphql-eslint/lone-anonymous-operation": "error",
"@graphql-eslint/naming-convention": [
"error",
{
VariableDefinition: "camelCase",
OperationDefinition: {
style: "PascalCase",
forbiddenPrefixes: [
"Query",
"Mutation",
"Subscription",
"Get"
],
forbiddenSuffixes: ["Query", "Mutation", "Subscription"]
},
FragmentDefinition: {
style: "PascalCase",
forbiddenPrefixes: ["Fragment"],
forbiddenSuffixes: ["Fragment"]
}
}
],
"@graphql-eslint/no-anonymous-operations": "error",
"@graphql-eslint/no-deprecated": "error",
"@graphql-eslint/no-duplicate-fields": "error",
"@graphql-eslint/no-fragment-cycles": "error",
"@graphql-eslint/no-undefined-variables": "error",
"@graphql-eslint/no-unused-fragments": "error",
"@graphql-eslint/no-unused-variables": "error",
"@graphql-eslint/one-field-subscriptions": "error",
"@graphql-eslint/overlapping-fields-can-be-merged": "error",
"@graphql-eslint/possible-fragment-spread": "error",
"@graphql-eslint/provided-required-arguments": "error",
"@graphql-eslint/require-selections": "error",
"@graphql-eslint/scalar-leafs": "error",
"@graphql-eslint/selection-set-depth": ["error", { maxDepth: 7 }],
"@graphql-eslint/unique-argument-names": "error",
"@graphql-eslint/unique-directive-names-per-location": "error",
"@graphql-eslint/unique-fragment-name": "error",
"@graphql-eslint/unique-input-field-names": "error",
"@graphql-eslint/unique-operation-name": "error",
"@graphql-eslint/unique-variable-names": "error",
"@graphql-eslint/value-literals-of-correct-type": "error",
"@graphql-eslint/variables-are-input-types": "error",
"@graphql-eslint/variables-in-allowed-position": "error"
} : {},
...overrides
}
},
relay ? {
name: "storm/graphql/relay",
plugins: { relay: pluginRelay },
rules: {
// errors
"relay/graphql-syntax": "error",
"relay/graphql-naming": "error",
// warnings
"relay/compat-uses-vars": "warn",
"relay/generated-typescript-types": "warn",
"relay/no-future-added-value": "warn",
"relay/unused-fields": "warn",
"relay/must-colocate-fragment-spreads": "warn",
"relay/function-required-argument": "warn",
"relay/hook-required-argument": "warn",
// @graphql-eslint rules
"@graphql-eslint/relay-arguments": "error",
"@graphql-eslint/relay-connection-types": "error",
"@graphql-eslint/relay-edge-types": "error",
"@graphql-eslint/relay-page-info": "error"
}
} : {}
];
}
// src/configs/ignores.ts
init_esm_shims();
async function ignores(userIgnores = []) {
return [
{
ignores: [...GLOB_EXCLUDE, ...userIgnores],
name: "storm/ignores"
}
];
}
// src/configs/imports.ts
init_esm_shims();
// src/plugins.ts
init_esm_shims();
// ../../node_modules/.pnpm/eslint-plugin-pnpm@0.3.0_patch_hash=72dcde755c336eeca3e6170de1106fd85ecb66171e060788f80_9a83dbe288d598de72c3e754ec4675de/node_modules/eslint-plugin-pnpm/dist/index.mjs
init_esm_shims();
var name = "eslint-plugin-pnpm";
var version = "0.3.0";
var blobUrl = "https://github.com/antfu/eslint-plugin-pnpm/blob/main/src/rules/";
function RuleCreator(urlCreator) {
return function createNamedRule({
name: name2,
meta: meta2,
...rule
}) {
return createRule({
meta: {
...meta2,
docs: {
...meta2.docs,
url: urlCreator(name2)
}
},
...rule
});
};
}
function createRule({
create,
defaultOptions,
meta: meta2
}) {
return {
create: (context) => {
const optionsWithDefault = context.options.map((options, index) => {
return {
...defaultOptions[index] || {},
...options || {}
};
});
return create(context, optionsWithDefault);
},
defaultOptions,
meta: meta2
};
}
var createEslintRule = RuleCreator(
(ruleName) => `${blobUrl}${ruleName}.test.ts`
);
function getPackageJsonRootNode(context) {
if (!context.filename.endsWith("package.json"))
return;
const ast = context.sourceCode.ast;
const root = ast.body[0];
if (root.expression.type === "JSONObjectExpression")
return root.expression;
}
function* iterateDependencies(context, fields) {
const root = getPackageJsonRootNode(context);
if (!root)
return;
for (const fieldName of fields) {
const path = fieldName.split(".");
let node2 = root;
for (let i = 0; i < path.length; i++) {
const item = node2.properties.find((property) => property.key.type === "JSONLiteral" && property.key.value === path[i]);
if (!item?.value || item.value.type !== "JSONObjectExpression") {
node2 = void 0;
break;
}
node2 = item.value;
}
if (!node2 || node2 === root)
continue;
for (const property of node2.properties) {
if (property.value.type !== "JSONLiteral" || property.key.type !== "JSONLiteral")
continue;
if (typeof property.value.value !== "string")
continue;
const packageName = String(property.key.value);
const specifier = String(property.value.value);
yield {
packageName,
specifier,
property
};
}
}
}
function readPnpmWorkspace() {
const filepath = findUpSync("pnpm-workspace.yaml", { cwd: process2.cwd() });
if (!filepath)
throw new Error("pnpm-workspace.yaml not found");
const content = fs.readFileSync(filepath, "utf-8");
const workspace2 = parsePnpmWorkspaceYaml(content);
let queueTimer;
const queue = [];
const write = () => {
fs.writeFileSync(filepath, workspace2.toString());
};
const hasQueue = () => queueTimer != null;
const queueChange = (fn, order) => {
if (order === "pre")
queue.unshift(fn);
else
queue.push(fn);
if (queueTimer != null)
clearTimeout(queueTimer);
queueTimer = setTimeout(() => {
queueTimer = void 0;
const clone2 = [...queue];
queue.length = 0;
for (const fn2 of clone2)
fn2(workspace2);
if (workspace2.hasChanged())
write();
}, 1e3);
};
return {
filepath,
...workspace2,
hasQueue,
queueChange
};
}
var WORKSPACE_CACHE_TIME = 1e4;
var workspaceLastRead;
var workspace;
function getPnpmWorkspace() {
if (workspaceLastRead && workspace && !workspace.hasQueue() && Date.now() - workspaceLastRead > WORKSPACE_CACHE_TIME) {
workspace = void 0;
}
if (!workspace) {
workspace = readPnpmWorkspace();
workspaceLastRead = Date.now();
}
return workspace;
}
var RULE_NAME$4 = "json-enforce-catalog";
var DEFAULT_FIELDS$1 = [
"dependencies",
"devDependencies"
];
var IGNORED_DEPENDENCIES = [
"typescript"
];
var enforceCatalog = createEslintRule({
name: RULE_NAME$4,
meta: {
type: "layout",
docs: {
description: 'Enforce using "catalog:" in `package.json`'
},
fixable: "code",
schema: [
{
type: "object",
properties: {
allowedProtocols: {
type: "array",
description: "Allowed protocols in specifier to not be converted to catalog",
items: {
type: "string"
}
},
autofix: {
type: "boolean",
description: "Whether to autofix the linting error",
default: true
},
defaultCatalog: {
type: "string",
description: "Default catalog to use when moving version to catalog with autofix"
},
reuseExistingCatalog: {
type: "boolean",
description: "Whether to reuse existing catalog when moving version to catalog with autofix",
default: true
},
conflicts: {
type: "string",
description: "Strategy to handle conflicts when adding packages to catalogs",
enum: ["new-catalog", "overrides", "error"],
default: "new-catalog"
},
fields: {
type: "array",
description: "Fields to check for catalog",
items: { type: "string" },
default: DEFAULT_FIELDS$1
},
ignore: {
type: "array",
description: "A list of dependencies to ignore",
items: { type: "string" },
default: IGNORED_DEPENDENCIES
}
},
additionalProperties: false
}
],
messages: {
expectCatalog: 'Expect to use catalog instead of plain specifier, got "{{specifier}}" for package "{{packageName}}".'
}
},
defaultOptions: [{}],
create(context, [options]) {
const {
allowedProtocols = ["workspace", "link", "file"],
defaultCatalog = "default",
autofix = true,
reuseExistingCatalog = true,
conflicts = "new-catalog",
fields = DEFAULT_FIELDS$1,
ignore = IGNORED_DEPENDENCIES
} = options || {};
for (const { packageName, specifier, property } of iterateDependencies(context, fields)) {
if (ignore?.some((i) => i === packageName))
continue;
if (specifier.startsWith("catalog:"))
continue;
if (allowedProtocols?.some((p) => specifier.startsWith(p)))
continue;
const workspace2 = getPnpmWorkspace();
if (!workspace2)
return {};
let targetCatalog = reuseExistingCatalog ? workspace2.getPackageCatalogs(packageName)[0] || defaultCatalog : defaultCatalog;
const resolvedConflicts = workspace2.hasSpecifierConflicts(
targetCatalog,
packageName,
specifier
);
let shouldFix = autofix;
if (conflicts === "error") {
if (resolvedConflicts.conflicts) {
shouldFix = false;
}
}
if (conflicts === "new-catalog" && resolvedConflicts.conflicts) {
targetCatalog = resolvedConflicts.newCatalogName;
}
context.report({
node: property.value,
messageId: "expectCatalog",
data: {
specifier,
packageName
},
fix: shouldFix ? (fixer) => {
workspace2.queueChange(() => {
workspace2.setPackage(targetCatalog, packageName, specifier);
});
return fixer.replaceText(
property.value,
targetCatalog === "default" ? JSON.stringify("catalog:") : JSON.stringify(`catalog:${targetCatalog}`)
);
} : void 0
});
}
return {};
}
});
var RULE_NAME$3 = "json-prefer-workspace-settings";
var preferWorkspaceSettings = createEslintRule({
name: RULE_NAME$3,
meta: {
type: "layout",
docs: {
description: "Prefer having pnpm settings in `pnpm-workspace.yaml` instead of `package.json`. This would requires pnpm v10.6+, see https://github.com/orgs/pnpm/discussions/9037."
},
fixable: "code",
schema: [
{
type: "object",
properties: {
autofix: {
type: "boolean",
description: "Whether to autofix the linting error",
default: true
}
},
additionalProperties: false
}
],
me