@utoo/lint 0.4.12 → 0.4.14

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/config.cjs CHANGED
@@ -1,3 +1,5 @@
1
+ const { isConfigPath, withConfigPath } = require("./lib/config-path.cjs");
2
+
1
3
  let globalIgnoreCount = 0;
2
4
 
3
5
  function defineConfig(...args) {
@@ -39,11 +41,12 @@ function expandConfigExtends(config, baseConfigName) {
39
41
  if (!("extends" in config)) {
40
42
  return [config];
41
43
  }
42
- if (!Array.isArray(config.extends)) {
43
- throw new TypeError("The `extends` property must be an array.");
44
+ if (typeof config.extends !== "string" && !Array.isArray(config.extends)) {
45
+ throw new TypeError("The `extends` property must be a string or an array.");
44
46
  }
45
47
 
46
- const { extends: extendsList, ...baseConfig } = config;
48
+ const { extends: extensions, ...baseConfig } = config;
49
+ const extendsList = typeof extensions === "string" ? [extensions] : extensions;
47
50
  const expanded = [];
48
51
  for (const [index, extension] of flattenConfigArgs(resolveConfigExtends(config, extendsList)).entries()) {
49
52
  if ("basePath" in extension) {
@@ -65,6 +68,14 @@ function resolveConfigExtends(config, extendsList) {
65
68
  if (typeof extension !== "string") {
66
69
  return extension;
67
70
  }
71
+ if (isConfigPath(extension)) {
72
+ return withConfigPath(extension, (loaded) => {
73
+ const resolved = flattenConfigArgs([loaded]).flatMap((entry, index) =>
74
+ expandConfigExtends(entry, `${extension}[${index}]`)
75
+ );
76
+ return withConfigNames(resolved, extension);
77
+ });
78
+ }
68
79
  const pluginConfig = pluginConfigForName(config, extension);
69
80
  if (!pluginConfig) {
70
81
  const { namespace, configName } = splitPluginConfigName(extension);
@@ -133,7 +144,7 @@ function extendConfigFiles(baseFiles = [], extensionFiles = []) {
133
144
 
134
145
  function isGlobalIgnores(config) {
135
146
  const keys = Object.keys(config);
136
- return keys.includes("ignores") && keys.every((key) => key === "name" || key === "ignores");
147
+ return keys.includes("ignores") && keys.every((key) => key === "name" || key === "ignores" || key === "__utooLintConfigName");
137
148
  }
138
149
 
139
150
  function withConfigNames(config, name) {
package/config.js CHANGED
@@ -1,3 +1,5 @@
1
+ import { isConfigPath, withConfigPath } from "./lib/config-path.cjs";
2
+
1
3
  let globalIgnoreCount = 0;
2
4
 
3
5
  export function defineConfig(...args) {
@@ -39,11 +41,12 @@ function expandConfigExtends(config, baseConfigName) {
39
41
  if (!("extends" in config)) {
40
42
  return [config];
41
43
  }
42
- if (!Array.isArray(config.extends)) {
43
- throw new TypeError("The `extends` property must be an array.");
44
+ if (typeof config.extends !== "string" && !Array.isArray(config.extends)) {
45
+ throw new TypeError("The `extends` property must be a string or an array.");
44
46
  }
45
47
 
46
- const { extends: extendsList, ...baseConfig } = config;
48
+ const { extends: extensions, ...baseConfig } = config;
49
+ const extendsList = typeof extensions === "string" ? [extensions] : extensions;
47
50
  const expanded = [];
48
51
  for (const [index, extension] of flattenConfigArgs(resolveConfigExtends(config, extendsList)).entries()) {
49
52
  if ("basePath" in extension) {
@@ -65,6 +68,14 @@ function resolveConfigExtends(config, extendsList) {
65
68
  if (typeof extension !== "string") {
66
69
  return extension;
67
70
  }
71
+ if (isConfigPath(extension)) {
72
+ return withConfigPath(extension, (loaded) => {
73
+ const resolved = flattenConfigArgs([loaded]).flatMap((entry, index) =>
74
+ expandConfigExtends(entry, `${extension}[${index}]`)
75
+ );
76
+ return withConfigNames(resolved, extension);
77
+ });
78
+ }
68
79
  const pluginConfig = pluginConfigForName(config, extension);
69
80
  if (!pluginConfig) {
70
81
  const { namespace, configName } = splitPluginConfigName(extension);
@@ -133,7 +144,7 @@ function extendConfigFiles(baseFiles = [], extensionFiles = []) {
133
144
 
134
145
  function isGlobalIgnores(config) {
135
146
  const keys = Object.keys(config);
136
- return keys.includes("ignores") && keys.every((key) => key === "name" || key === "ignores");
147
+ return keys.includes("ignores") && keys.every((key) => key === "name" || key === "ignores" || key === "__utooLintConfigName");
137
148
  }
138
149
 
139
150
  function withConfigNames(config, name) {
package/index.d.ts CHANGED
@@ -102,7 +102,7 @@ export interface ConfigObject {
102
102
  parserOptions?: Record<string, unknown>;
103
103
  globals?: Record<string, unknown>;
104
104
  env?: Record<string, unknown>;
105
- extends?: Array<string | ConfigObject | ConfigObject[]>;
105
+ extends?: string | Array<string | ConfigObject | ConfigObject[]>;
106
106
  basePath?: string;
107
107
  [key: string]: unknown;
108
108
  }
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+
3
+ const { realpathSync } = require("node:fs");
4
+ const { isAbsolute } = require("node:path");
5
+
6
+ // Shared by the ESM and CommonJS helpers, including helpers imported by a
7
+ // preset. Keep the entry active while its own extends are being expanded.
8
+ const activePaths = [];
9
+
10
+ function isConfigPath(value) {
11
+ return isAbsolute(value);
12
+ }
13
+
14
+ function withConfigPath(configPath, expand) {
15
+ const canonicalPath = realpathSync(configPath);
16
+ if (activePaths.includes(canonicalPath)) {
17
+ throw new TypeError(`Circular config extends: ${[...activePaths, canonicalPath].join(" -> ")}`);
18
+ }
19
+ activePaths.push(canonicalPath);
20
+ try {
21
+ // Load executable presets with the same Node/TypeScript support used by
22
+ // the application config. Do not load jiti for object-only configurations.
23
+ const { readConfigModule } = require("./config-module.cjs");
24
+ const value = readConfigModule(canonicalPath);
25
+ if (value === null || typeof value !== "object") {
26
+ throw new TypeError(`Config file "${configPath}" must export a config object or array, received ${typeof value}.`);
27
+ }
28
+ return expand(value);
29
+ } finally {
30
+ activePaths.pop();
31
+ }
32
+ }
33
+
34
+ module.exports = { isConfigPath, withConfigPath };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@utoo/lint",
3
- "version": "0.4.12",
3
+ "version": "0.4.14",
4
4
  "description": "High-performance JavaScript and TypeScript linter powered by Yuku",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -74,11 +74,11 @@
74
74
  "use-at-your-own-risk.js"
75
75
  ],
76
76
  "optionalDependencies": {
77
- "@utoo/lint-darwin-arm64": "0.4.12",
78
- "@utoo/lint-darwin-x64": "0.4.12",
79
- "@utoo/lint-linux-arm64": "0.4.12",
80
- "@utoo/lint-linux-x64": "0.4.12",
81
- "@utoo/lint-win32-x64": "0.4.12"
77
+ "@utoo/lint-darwin-arm64": "0.4.14",
78
+ "@utoo/lint-darwin-x64": "0.4.14",
79
+ "@utoo/lint-linux-arm64": "0.4.14",
80
+ "@utoo/lint-linux-x64": "0.4.14",
81
+ "@utoo/lint-win32-x64": "0.4.14"
82
82
  },
83
83
  "dependencies": {
84
84
  "@eslint/eslintrc": "2.1.4",