@dloizides/frontend-devtools 1.8.0 → 1.10.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 +20 -0
- package/dist/eslint/index.d.mts +5 -1
- package/dist/eslint/index.d.ts +5 -1
- package/dist/eslint/index.js +188 -9
- package/dist/eslint/index.js.map +1 -1
- package/dist/eslint/index.mjs +183 -10
- package/dist/eslint/index.mjs.map +1 -1
- package/package.json +7 -1
package/dist/eslint/index.mjs
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import fs, { existsSync, readdirSync } from 'fs';
|
|
2
2
|
import path, { basename, dirname, sep, posix, join } from 'path';
|
|
3
|
+
import tanstackQueryPlugin from '@tanstack/eslint-plugin-query';
|
|
4
|
+
import boundariesPlugin from 'eslint-plugin-boundaries';
|
|
5
|
+
import effectPlugin from 'eslint-plugin-react-you-might-not-need-an-effect';
|
|
6
|
+
import sonarjsPlugin from 'eslint-plugin-sonarjs';
|
|
3
7
|
|
|
4
8
|
// src/rules/comment-utils.js
|
|
5
9
|
var DIRECTIVE_PATTERNS = [
|
|
@@ -1904,6 +1908,9 @@ var DEFAULT_ALLOWED_PATH_FRAGMENTS = [
|
|
|
1904
1908
|
var CLIENT_PACKAGE_PATH = /\/packages\/[^/]+-client\//;
|
|
1905
1909
|
var TEST_FILE = /(?:\.(?:test|spec)\.[cm]?[jt]sx?$)|(?:\/__tests__\/)/;
|
|
1906
1910
|
var EXEMPT_URL_SCHEME = /^\s*(?:data|blob):/i;
|
|
1911
|
+
var ABSOLUTE_HTTP_URL = /^https?:\/\/[^/\s]+\//i;
|
|
1912
|
+
var ABSOLUTE_HTTP_LITERAL = /^https?:\/\/[^/\s]+(?:[/?#]|$)/i;
|
|
1913
|
+
var URL_OBJECTS = /* @__PURE__ */ new Set(["URL", "webkitURL"]);
|
|
1907
1914
|
var GLOBAL_OBJECTS = /* @__PURE__ */ new Set(["window", "globalThis", "self"]);
|
|
1908
1915
|
var AXIOS_MODULE = "axios";
|
|
1909
1916
|
function normalisePath(filename) {
|
|
@@ -1932,6 +1939,69 @@ function leadingText(node) {
|
|
|
1932
1939
|
function isDataOrBlobUrl(node) {
|
|
1933
1940
|
return EXEMPT_URL_SCHEME.test(leadingText(node));
|
|
1934
1941
|
}
|
|
1942
|
+
function isThirdPartyLiteralUrl(node) {
|
|
1943
|
+
if (node === void 0) return false;
|
|
1944
|
+
if (node.type === "Literal") return typeof node.value === "string" && ABSOLUTE_HTTP_LITERAL.test(node.value);
|
|
1945
|
+
if (node.type !== "TemplateLiteral") return false;
|
|
1946
|
+
const head = node.quasis[0].value.cooked ?? "";
|
|
1947
|
+
return node.expressions.length === 0 ? ABSOLUTE_HTTP_LITERAL.test(head) : ABSOLUTE_HTTP_URL.test(head);
|
|
1948
|
+
}
|
|
1949
|
+
function unwrapExpression(node) {
|
|
1950
|
+
let current = node;
|
|
1951
|
+
while (current !== void 0 && current !== null && ["TSAsExpression", "TSNonNullExpression", "TSTypeAssertion", "TSSatisfiesExpression"].includes(current.type))
|
|
1952
|
+
current = current.expression;
|
|
1953
|
+
return current;
|
|
1954
|
+
}
|
|
1955
|
+
function memberName(node) {
|
|
1956
|
+
return node.type === "MemberExpression" && !node.computed && node.property.type === "Identifier" ? node.property.name : "";
|
|
1957
|
+
}
|
|
1958
|
+
function isUrlObject(node) {
|
|
1959
|
+
if (node.type === "Identifier") return URL_OBJECTS.has(node.name);
|
|
1960
|
+
return memberName(node) !== "" && URL_OBJECTS.has(memberName(node)) && node.object.type === "Identifier" && GLOBAL_OBJECTS.has(node.object.name);
|
|
1961
|
+
}
|
|
1962
|
+
function isCreateObjectUrlCall(node) {
|
|
1963
|
+
if (node === void 0 || node === null || node.type !== "CallExpression") return false;
|
|
1964
|
+
return memberName(node.callee) === "createObjectURL" && isUrlObject(node.callee.object);
|
|
1965
|
+
}
|
|
1966
|
+
function constInitOf(identifier, scope) {
|
|
1967
|
+
let current = scope;
|
|
1968
|
+
while (current !== null) {
|
|
1969
|
+
const variable = current.set.get(identifier.name);
|
|
1970
|
+
if (variable !== void 0) {
|
|
1971
|
+
const def = variable.defs.length === 1 ? variable.defs[0] : void 0;
|
|
1972
|
+
const isConst = def !== void 0 && def.type === "Variable" && def.parent.kind === "const";
|
|
1973
|
+
return isConst ? unwrapExpression(def.node.init) : void 0;
|
|
1974
|
+
}
|
|
1975
|
+
current = current.upper;
|
|
1976
|
+
}
|
|
1977
|
+
return void 0;
|
|
1978
|
+
}
|
|
1979
|
+
function isNewFileReader(node) {
|
|
1980
|
+
return node !== void 0 && node !== null && node.type === "NewExpression" && node.callee.type === "Identifier" && node.callee.name === "FileReader";
|
|
1981
|
+
}
|
|
1982
|
+
function isFileReaderResult(node, scope) {
|
|
1983
|
+
if (node === void 0 || node === null || memberName(node) !== "result") return false;
|
|
1984
|
+
const object = unwrapExpression(node.object);
|
|
1985
|
+
if (isNewFileReader(object)) return true;
|
|
1986
|
+
return object.type === "Identifier" && isNewFileReader(constInitOf(object, scope));
|
|
1987
|
+
}
|
|
1988
|
+
function isLocalObjectUrl(node, scope) {
|
|
1989
|
+
const target = unwrapExpression(node);
|
|
1990
|
+
if (target === void 0 || target === null) return false;
|
|
1991
|
+
if (isCreateObjectUrlCall(target) || isFileReaderResult(target, scope)) return true;
|
|
1992
|
+
if (target.type !== "Identifier") return false;
|
|
1993
|
+
const init = constInitOf(target, scope);
|
|
1994
|
+
return isCreateObjectUrlCall(init) || isFileReaderResult(init, scope);
|
|
1995
|
+
}
|
|
1996
|
+
function scopeOf(context, node) {
|
|
1997
|
+
const sourceCode = context.sourceCode ?? context.getSourceCode();
|
|
1998
|
+
return typeof sourceCode.getScope === "function" ? sourceCode.getScope(node) : context.getScope();
|
|
1999
|
+
}
|
|
2000
|
+
function isExemptFetchTarget(context, node) {
|
|
2001
|
+
const target = node.arguments[0];
|
|
2002
|
+
if (isDataOrBlobUrl(target) || isThirdPartyLiteralUrl(target)) return true;
|
|
2003
|
+
return isLocalObjectUrl(target, scopeOf(context, node));
|
|
2004
|
+
}
|
|
1935
2005
|
function isAxiosSource(node) {
|
|
1936
2006
|
return node !== void 0 && node.type === "Literal" && node.value === AXIOS_MODULE;
|
|
1937
2007
|
}
|
|
@@ -1967,10 +2037,12 @@ var noRawBackendFetchRule = {
|
|
|
1967
2037
|
const allow = Array.isArray(options.allow) ? options.allow : [];
|
|
1968
2038
|
const filename = context.filename ?? context.getFilename();
|
|
1969
2039
|
if (isExemptFile(filename, allow)) return {};
|
|
2040
|
+
const sourceCode = context.sourceCode ?? context.getSourceCode();
|
|
2041
|
+
if (sourceCode.ast === void 0 || sourceCode.ast.type !== "Program") return {};
|
|
1970
2042
|
return {
|
|
1971
2043
|
CallExpression(node) {
|
|
1972
2044
|
if (isFetchCallee(node.callee)) {
|
|
1973
|
-
if (!
|
|
2045
|
+
if (!isExemptFetchTarget(context, node)) context.report({ node, messageId: "rawFetch" });
|
|
1974
2046
|
return;
|
|
1975
2047
|
}
|
|
1976
2048
|
const isRequire = node.callee.type === "Identifier" && node.callee.name === "require";
|
|
@@ -2098,8 +2170,8 @@ var preferConstEnumRule = {
|
|
|
2098
2170
|
const exportPrefix = isExported ? "export " : "";
|
|
2099
2171
|
const enumMembers = types.map((member) => {
|
|
2100
2172
|
const value = member.literal.value;
|
|
2101
|
-
const
|
|
2102
|
-
return ` ${
|
|
2173
|
+
const memberName2 = toPascalCase(value);
|
|
2174
|
+
return ` ${memberName2} = '${value}',`;
|
|
2103
2175
|
}).join("\n");
|
|
2104
2176
|
const replacement = `${exportPrefix}const enum ${typeName} {
|
|
2105
2177
|
${enumMembers}
|
|
@@ -2129,6 +2201,65 @@ var prefer_const_enum_default = {
|
|
|
2129
2201
|
}
|
|
2130
2202
|
};
|
|
2131
2203
|
|
|
2204
|
+
// src/rules/query-key-factory.js
|
|
2205
|
+
var QUERY_KEY = "queryKey";
|
|
2206
|
+
var TEST_FILE2 = /(?:\.(?:test|spec)\.[cm]?[jt]sx?$)|(?:\/__tests__\/)/;
|
|
2207
|
+
var FACTORY_FILE = /[kK]eys?(?:Factory)?\.[cm]?[jt]sx?$/;
|
|
2208
|
+
var DEFAULT_ALLOWED_PATH_FRAGMENTS2 = ["/generated/", "/autoGeneratedHooks/"];
|
|
2209
|
+
var INLINE_KEY_TYPES = /* @__PURE__ */ new Set(["ArrayExpression", "Literal", "TemplateLiteral"]);
|
|
2210
|
+
var TYPE_WRAPPERS = /* @__PURE__ */ new Set(["TSAsExpression", "TSSatisfiesExpression", "TSNonNullExpression"]);
|
|
2211
|
+
function normalisePath2(filename) {
|
|
2212
|
+
return typeof filename === "string" ? filename.split("\\").join("/") : "";
|
|
2213
|
+
}
|
|
2214
|
+
function isExemptFile2(filename, allow) {
|
|
2215
|
+
const path2 = normalisePath2(filename);
|
|
2216
|
+
if (TEST_FILE2.test(path2)) return true;
|
|
2217
|
+
if (FACTORY_FILE.test(path2)) return true;
|
|
2218
|
+
return [...DEFAULT_ALLOWED_PATH_FRAGMENTS2, ...allow].some((fragment) => path2.includes(fragment));
|
|
2219
|
+
}
|
|
2220
|
+
function unwrap2(node) {
|
|
2221
|
+
let current = node;
|
|
2222
|
+
while (current && TYPE_WRAPPERS.has(current.type)) current = current.expression;
|
|
2223
|
+
return current;
|
|
2224
|
+
}
|
|
2225
|
+
function isQueryKeyProperty(node) {
|
|
2226
|
+
if (node.computed) return false;
|
|
2227
|
+
if (node.key.type === "Identifier") return node.key.name === QUERY_KEY;
|
|
2228
|
+
return node.key.type === "Literal" && node.key.value === QUERY_KEY;
|
|
2229
|
+
}
|
|
2230
|
+
var rule4 = {
|
|
2231
|
+
meta: {
|
|
2232
|
+
type: "suggestion",
|
|
2233
|
+
docs: {
|
|
2234
|
+
description: "PAT-QUERY-KEY-1: a React Query queryKey comes from a key factory, never an inline literal."
|
|
2235
|
+
},
|
|
2236
|
+
schema: [
|
|
2237
|
+
{
|
|
2238
|
+
type: "object",
|
|
2239
|
+
properties: { allow: { type: "array", items: { type: "string" } } },
|
|
2240
|
+
additionalProperties: false
|
|
2241
|
+
}
|
|
2242
|
+
],
|
|
2243
|
+
messages: {
|
|
2244
|
+
inlineKey: "Inline queryKey literal. Build it with a key factory (e.g. clientKeys.detail(id) from clientKeys.ts) so the query and its invalidation share one key."
|
|
2245
|
+
}
|
|
2246
|
+
},
|
|
2247
|
+
create(context) {
|
|
2248
|
+
const options = context.options[0] ?? {};
|
|
2249
|
+
const allow = Array.isArray(options.allow) ? options.allow : [];
|
|
2250
|
+
const filename = context.filename ?? context.getFilename();
|
|
2251
|
+
if (isExemptFile2(filename, allow)) return {};
|
|
2252
|
+
return {
|
|
2253
|
+
Property(node) {
|
|
2254
|
+
if (!isQueryKeyProperty(node)) return;
|
|
2255
|
+
const value = unwrap2(node.value);
|
|
2256
|
+
if (value && INLINE_KEY_TYPES.has(value.type)) context.report({ node: node.value, messageId: "inlineKey" });
|
|
2257
|
+
}
|
|
2258
|
+
};
|
|
2259
|
+
}
|
|
2260
|
+
};
|
|
2261
|
+
var query_key_factory_default = { rules: { "query-key-factory": rule4 } };
|
|
2262
|
+
|
|
2132
2263
|
// src/rules/require-stable-hook-args.js
|
|
2133
2264
|
var STABLE_INIT_CALLS = /* @__PURE__ */ new Set([
|
|
2134
2265
|
"useCallback",
|
|
@@ -2812,6 +2943,7 @@ var ruleModules = [
|
|
|
2812
2943
|
no_raw_backend_fetch_default,
|
|
2813
2944
|
no_raw_color_literal_default,
|
|
2814
2945
|
prefer_const_enum_default,
|
|
2946
|
+
query_key_factory_default,
|
|
2815
2947
|
require_stable_hook_args_default,
|
|
2816
2948
|
single_row_action_source_default,
|
|
2817
2949
|
smart_max_lines_default
|
|
@@ -2819,11 +2951,11 @@ var ruleModules = [
|
|
|
2819
2951
|
function mergeRules(modules) {
|
|
2820
2952
|
const merged = {};
|
|
2821
2953
|
for (const mod of modules) {
|
|
2822
|
-
for (const [name,
|
|
2954
|
+
for (const [name, rule5] of Object.entries(mod.rules)) {
|
|
2823
2955
|
if (merged[name] !== void 0) {
|
|
2824
2956
|
throw new Error(`Duplicate ESLint rule name: "${name}"`);
|
|
2825
2957
|
}
|
|
2826
|
-
merged[name] =
|
|
2958
|
+
merged[name] = rule5;
|
|
2827
2959
|
}
|
|
2828
2960
|
}
|
|
2829
2961
|
return merged;
|
|
@@ -2839,17 +2971,58 @@ var ruleNames = Object.keys(plugin.rules).sort();
|
|
|
2839
2971
|
var legacyPlugins = buildLegacyPlugins();
|
|
2840
2972
|
function buildLegacyPlugins() {
|
|
2841
2973
|
const out = {};
|
|
2842
|
-
for (const [name,
|
|
2843
|
-
out[name] = oneRulePlugin(name,
|
|
2974
|
+
for (const [name, rule5] of Object.entries(rules)) {
|
|
2975
|
+
out[name] = oneRulePlugin(name, rule5);
|
|
2844
2976
|
}
|
|
2845
2977
|
return out;
|
|
2846
2978
|
}
|
|
2847
|
-
function oneRulePlugin(name,
|
|
2979
|
+
function oneRulePlugin(name, rule5) {
|
|
2848
2980
|
return {
|
|
2849
2981
|
meta: { name, version: "1.0.0" },
|
|
2850
|
-
rules: { [name]:
|
|
2982
|
+
rules: { [name]: rule5 }
|
|
2851
2983
|
};
|
|
2852
2984
|
}
|
|
2985
|
+
var OFF_LEVELS = ["off", 0];
|
|
2986
|
+
function pluginOf(mod) {
|
|
2987
|
+
const candidate = mod;
|
|
2988
|
+
const inner = candidate.default;
|
|
2989
|
+
return inner?.rules !== void 0 ? inner : candidate;
|
|
2990
|
+
}
|
|
2991
|
+
function rulesOf(config) {
|
|
2992
|
+
const blocks = Array.isArray(config) ? config : [config ?? {}];
|
|
2993
|
+
return Object.assign({}, ...blocks.map((block) => block.rules ?? {}));
|
|
2994
|
+
}
|
|
2995
|
+
function toWarn(entry) {
|
|
2996
|
+
const level = Array.isArray(entry) ? entry[0] : entry;
|
|
2997
|
+
if (OFF_LEVELS.includes(level)) {
|
|
2998
|
+
return entry;
|
|
2999
|
+
}
|
|
3000
|
+
return Array.isArray(entry) ? ["warn", ...entry.slice(1)] : "warn";
|
|
3001
|
+
}
|
|
3002
|
+
function warnAll(rules2) {
|
|
3003
|
+
return Object.fromEntries(Object.entries(rules2).map(([name, entry]) => [name, toWarn(entry)]));
|
|
3004
|
+
}
|
|
3005
|
+
var tanstackQuery = pluginOf(tanstackQueryPlugin);
|
|
3006
|
+
var effect = pluginOf(effectPlugin);
|
|
3007
|
+
var boundaries = pluginOf(boundariesPlugin);
|
|
3008
|
+
var sonarjs = pluginOf(sonarjsPlugin);
|
|
3009
|
+
var HOUSE_PATTERN_RULE_NAMES = ["query-key-factory"];
|
|
3010
|
+
var patternPacksConfig = {
|
|
3011
|
+
plugins: {
|
|
3012
|
+
"@tanstack/query": tanstackQuery,
|
|
3013
|
+
"react-you-might-not-need-an-effect": effect,
|
|
3014
|
+
boundaries,
|
|
3015
|
+
sonarjs,
|
|
3016
|
+
"@dloizides": plugin
|
|
3017
|
+
},
|
|
3018
|
+
rules: warnAll({
|
|
3019
|
+
...rulesOf(tanstackQuery.configs?.["flat/recommended"]),
|
|
3020
|
+
...rulesOf(effect.configs?.recommended),
|
|
3021
|
+
...rulesOf(boundaries.configs?.recommended),
|
|
3022
|
+
...rulesOf(sonarjs.configs?.recommended),
|
|
3023
|
+
"@dloizides/query-key-factory": "warn"
|
|
3024
|
+
})
|
|
3025
|
+
};
|
|
2853
3026
|
|
|
2854
3027
|
// src/eslint/configs.ts
|
|
2855
3028
|
var DOC_COMMENT_MAX_LINES = 3;
|
|
@@ -2892,6 +3065,6 @@ var recommendedConfig = {
|
|
|
2892
3065
|
rules: { ...commentsConfig.rules, ...rowActionsConfig.rules, ...apiConfig.rules }
|
|
2893
3066
|
};
|
|
2894
3067
|
|
|
2895
|
-
export { API_RULE_NAMES, COMMENT_RULE_NAMES, GAME_RULE_NAMES, ROW_ACTION_RULE_NAMES, apiConfig, commentsConfig, gameConfig, legacyPlugins, plugin, recommendedConfig, rowActionsConfig, ruleNames, rules };
|
|
3068
|
+
export { API_RULE_NAMES, COMMENT_RULE_NAMES, GAME_RULE_NAMES, HOUSE_PATTERN_RULE_NAMES, ROW_ACTION_RULE_NAMES, apiConfig, commentsConfig, gameConfig, legacyPlugins, patternPacksConfig, plugin, recommendedConfig, rowActionsConfig, ruleNames, rules };
|
|
2896
3069
|
//# sourceMappingURL=index.mjs.map
|
|
2897
3070
|
//# sourceMappingURL=index.mjs.map
|