@bfra.me/eslint-config 0.44.0 → 0.44.2

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/lib/index.d.ts CHANGED
@@ -16993,6 +16993,12 @@ declare function sortRenovateConfig(): Promise<Config[]>;
16993
16993
  */
16994
16994
  declare function sortTsconfig(): Promise<Config[]>;
16995
16995
 
16996
+ declare const StylisticConfigDefaults: {
16997
+ readonly indent: 2;
16998
+ readonly jsx: true;
16999
+ readonly quotes: "single";
17000
+ readonly semi: false;
17001
+ };
16996
17002
  /**
16997
17003
  * Configuration options for stylistic ESLint rules.
16998
17004
  *
@@ -17410,32 +17416,6 @@ declare function defineConfig<C extends Config = Config, CN extends ConfigNames
17410
17416
  */
17411
17417
  declare const composeConfig: <C extends Config = Config, CN extends ConfigNames = ConfigNames>(...configs: ResolvableFlatConfig<Config extends C ? C : Config>[]) => FlatConfigComposer<Config extends C ? C : Config, CN>;
17412
17418
 
17413
- /**
17414
- * Check if the process is running in a Git hook or under lint-staged.
17415
- *
17416
- * @example
17417
- * ```ts
17418
- * import {isInGitLifecycle} from '@bfra.me/eslint-config'
17419
- *
17420
- * if (isInGitLifecycle) {
17421
- * console.log('Running in a Git hook or under lint-staged')
17422
- * }
17423
- * ```
17424
- */
17425
- declare const isInGitLifecycle: boolean;
17426
- /**
17427
- * Check if the process is running in an editor.
17428
- *
17429
- * @example
17430
- * ```ts
17431
- * import {isInEditor} from '@bfra.me/eslint-config'
17432
- *
17433
- * if (isInEditor) {
17434
- * console.log('Running in an editor')
17435
- * }
17436
- */
17437
- declare const isInEditor: boolean;
17438
-
17439
17419
  declare const GLOB_SRC_EXT = "?([cm])[jt]s?(x)";
17440
17420
  declare const GLOB_SRC = "**/*.?([cm])[jt]s?(x)";
17441
17421
  declare const GLOB_JS = "**/*.?([cm])js";
@@ -17466,4 +17446,4 @@ declare const GLOB_EXCLUDE: string[];
17466
17446
 
17467
17447
  declare const config: eslint_flat_config_utils.FlatConfigComposer<Config, ConfigNames>;
17468
17448
 
17469
- export { type AstroOptions, type Config, type ConfigNames, type FallbackOptions, type Flatten, GLOB_ASTRO, GLOB_ASTRO_TS, GLOB_CODE_IN_MARKDOWN_FILES, GLOB_EXCLUDE, GLOB_EXT_IN_MARKDOWN_FILES, GLOB_JS, GLOB_JSON, GLOB_JSON5, GLOB_JSONC, GLOB_JSON_FILES, GLOB_JSX, GLOB_MARKDOWN, GLOB_MARKDOWN_CODE, GLOB_MARKDOWN_FILES, GLOB_MARKDOWN_IN_MARKDOWN, GLOB_PACKAGE_JSON_FILES, GLOB_RENOVATE_CONFIG, GLOB_SRC, GLOB_SRC_EXT, GLOB_TESTS, GLOB_TOML, GLOB_TOML_FILES, GLOB_TS, GLOB_TSX, GLOB_TS_CONFIG, GLOB_YAML, GLOB_YAML_FILES, type ImportsOptions, type JSDocOptions, type JavaScriptOptions, type JsoncOptions, type MarkdownCodeBlockOptions, type MarkdownFrontmatterOptions, type MarkdownLanguage, type MarkdownOptions, type NextjsOptions, type Options, type OptionsFiles, type OptionsIsInEditor, type OptionsOverrides, type OptionsPerfectionist, type OptionsStylistic, type OptionsTypeScript, type OptionsTypeScriptErasableSyntaxOnly, type OptionsTypeScriptParserOptions, type OptionsTypeScriptWithTypes, type PackageJsonOptions, type PerfectionistOptions, type PrettierOptions, type ReactOptions, type RegexpOptions, type Rules, type StylisticConfig, type StylisticOptions, type TomlOptions, type TypeScriptOptions, type UnicornOptions, type VitestOptions, type YamlOptions, astro, command, composeConfig, config, config as default, defineConfig, epilogue, eslintComments, fallback, gitignore, ignores, imports, isInEditor, isInGitLifecycle, javascript, jsdoc, jsonc, markdown, nextjs, node, packageJson, perfectionist, pnpm, prettier, react, regexp, sortPackageJson, sortRenovateConfig, sortTsconfig, stylistic, toml, typescript, unicorn, vitest, yaml };
17449
+ export { type AstroOptions, type Config, type ConfigNames, type FallbackOptions, type Flatten, GLOB_ASTRO, GLOB_ASTRO_TS, GLOB_CODE_IN_MARKDOWN_FILES, GLOB_EXCLUDE, GLOB_EXT_IN_MARKDOWN_FILES, GLOB_JS, GLOB_JSON, GLOB_JSON5, GLOB_JSONC, GLOB_JSON_FILES, GLOB_JSX, GLOB_MARKDOWN, GLOB_MARKDOWN_CODE, GLOB_MARKDOWN_FILES, GLOB_MARKDOWN_IN_MARKDOWN, GLOB_PACKAGE_JSON_FILES, GLOB_RENOVATE_CONFIG, GLOB_SRC, GLOB_SRC_EXT, GLOB_TESTS, GLOB_TOML, GLOB_TOML_FILES, GLOB_TS, GLOB_TSX, GLOB_TS_CONFIG, GLOB_YAML, GLOB_YAML_FILES, type ImportsOptions, type JSDocOptions, type JavaScriptOptions, type JsoncOptions, type MarkdownCodeBlockOptions, type MarkdownFrontmatterOptions, type MarkdownLanguage, type MarkdownOptions, type NextjsOptions, type Options, type OptionsFiles, type OptionsIsInEditor, type OptionsOverrides, type OptionsPerfectionist, type OptionsStylistic, type OptionsTypeScript, type OptionsTypeScriptErasableSyntaxOnly, type OptionsTypeScriptParserOptions, type OptionsTypeScriptWithTypes, type PackageJsonOptions, type PerfectionistOptions, type PrettierOptions, type ReactOptions, type RegexpOptions, type Rules, type StylisticConfig, StylisticConfigDefaults, type StylisticOptions, type TomlOptions, type TypeScriptOptions, type UnicornOptions, type VitestOptions, type YamlOptions, astro, command, composeConfig, config, config as default, defineConfig, epilogue, eslintComments, fallback, gitignore, ignores, imports, javascript, jsdoc, jsonc, markdown, nextjs, node, packageJson, perfectionist, pnpm, prettier, react, regexp, sortPackageJson, sortRenovateConfig, sortTsconfig, stylistic, toml, typescript, unicorn, vitest, yaml };
package/lib/index.js CHANGED
@@ -112,7 +112,7 @@ var GLOB_EXCLUDE = [
112
112
  import { fileURLToPath } from "url";
113
113
 
114
114
  // package.json
115
- var version = "0.44.0";
115
+ var version = "0.44.2";
116
116
 
117
117
  // src/parsers/any-parser.ts
118
118
  var lineBreakPattern = /\r\n|[\n\r\u2028\u2029]/u;
@@ -145,14 +145,31 @@ function parseForESLint(text) {
145
145
  }
146
146
  var anyParser = { meta, parseForESLint };
147
147
 
148
- // src/require-of.ts
148
+ // src/utils.ts
149
+ import process from "process";
149
150
  import { fileURLToPath as fileURLToPath2 } from "url";
151
+ import isInCI from "is-in-ci";
150
152
  import { isPackageExists } from "local-pkg";
151
153
  var scopeUrl = fileURLToPath2(new URL(".", import.meta.url));
152
- var packageExistsCache = /* @__PURE__ */ new Map();
154
+ // @__NO_SIDE_EFFECTS__
155
+ async function interopDefault(m) {
156
+ const resolved = await m;
157
+ return typeof resolved === "object" && resolved !== null && "default" in resolved ? /* @__PURE__ */ interopDefault(resolved.default) : resolved;
158
+ }
153
159
  function isPackageInScope(name) {
154
160
  return isPackageExists(name, { paths: [scopeUrl] });
155
161
  }
162
+ function isInGitLifecycle() {
163
+ return !!(typeof process.env.GIT_PARAMS === "string" && process.env.GIT_PARAMS.length > 0 || typeof process.env.VSCODE_GIT_COMMAND === "string" && process.env.VSCODE_GIT_COMMAND.length > 0 || process.env.npm_lifecycle_script?.startsWith("lint-staged") || process.env.npm_lifecycle_script?.startsWith("nano-staged"));
164
+ }
165
+ function isInEditorEnv() {
166
+ if (isInCI) return false;
167
+ if (isInGitLifecycle()) return false;
168
+ return !!(typeof process.env.VSCODE_PID === "string" && process.env.VSCODE_PID.length > 0 || typeof process.env.VSCODE_CWD === "string" && process.env.VSCODE_CWD.length > 0 || typeof process.env.JETBRAINS_IDE === "string" && process.env.JETBRAINS_IDE.length > 0 || typeof process.env.VIM === "string" && process.env.VIM.length > 0 || typeof process.env.NVIM === "string" && process.env.NVIM.length > 0);
169
+ }
170
+
171
+ // src/require-of.ts
172
+ var packageExistsCache = /* @__PURE__ */ new Map();
156
173
  var has = (name) => {
157
174
  if (!packageExistsCache.has(name)) {
158
175
  packageExistsCache.set(name, isPackageInScope(name));
@@ -167,13 +184,6 @@ async function requireOf(names, getConfig, fallback2) {
167
184
  return getConfig();
168
185
  }
169
186
 
170
- // src/utils.ts
171
- // @__NO_SIDE_EFFECTS__
172
- async function interopDefault(m) {
173
- const resolved = await m;
174
- return typeof resolved === "object" && resolved !== null && "default" in resolved ? /* @__PURE__ */ interopDefault(resolved.default) : resolved;
175
- }
176
-
177
187
  // src/configs/fallback.ts
178
188
  async function fallback(missingList = [], options) {
179
189
  const rules = await interopDefault(import("./missing-module-for-config-TSYIJQQT.js"));
@@ -387,7 +397,7 @@ function imports(options = {}) {
387
397
  // src/configs/javascript.ts
388
398
  import globals from "globals";
389
399
  async function javascript(options = {}) {
390
- const { isInEditor: isInEditor2 = false, jsx = true, overrides = {} } = options;
400
+ const { isInEditor = false, jsx = true, overrides = {} } = options;
391
401
  const pluginUnusedImports = await interopDefault(import("eslint-plugin-unused-imports"));
392
402
  return [
393
403
  {
@@ -576,7 +586,7 @@ async function javascript(options = {}) {
576
586
  "prefer-template": "error",
577
587
  "symbol-description": "error",
578
588
  "unicode-bom": ["error", "never"],
579
- "unused-imports/no-unused-imports": isInEditor2 ? "off" : "error",
589
+ "unused-imports/no-unused-imports": isInEditor ? "off" : "error",
580
590
  "unused-imports/no-unused-vars": [
581
591
  "error",
582
592
  {
@@ -1059,7 +1069,7 @@ async function packageJson(options = {}) {
1059
1069
  // src/configs/perfectionist.ts
1060
1070
  async function perfectionist(options = {}) {
1061
1071
  const {
1062
- isInEditor: isInEditor2 = false,
1072
+ isInEditor = false,
1063
1073
  overrides = {},
1064
1074
  sortExports = true,
1065
1075
  sortImports = true,
@@ -1076,22 +1086,22 @@ async function perfectionist(options = {}) {
1076
1086
  rules: {
1077
1087
  ...sortNamedExports && {
1078
1088
  "perfectionist/sort-named-exports": [
1079
- isInEditor2 ? "warn" : "error",
1089
+ isInEditor ? "warn" : "error",
1080
1090
  { groupKind: "values-first", type: "natural" }
1081
1091
  ]
1082
1092
  },
1083
1093
  ...sortNamedImports && {
1084
1094
  "perfectionist/sort-named-imports": [
1085
- isInEditor2 ? "warn" : "error",
1095
+ isInEditor ? "warn" : "error",
1086
1096
  { groupKind: "values-first", type: "natural" }
1087
1097
  ]
1088
1098
  },
1089
1099
  ...sortExports && {
1090
- "perfectionist/sort-exports": [isInEditor2 ? "warn" : "error", { type: "natural" }]
1100
+ "perfectionist/sort-exports": [isInEditor ? "warn" : "error", { type: "natural" }]
1091
1101
  },
1092
1102
  ...sortImports && {
1093
1103
  "perfectionist/sort-imports": [
1094
- isInEditor2 ? "warn" : "error",
1104
+ isInEditor ? "warn" : "error",
1095
1105
  {
1096
1106
  groups: [
1097
1107
  "type",
@@ -1159,14 +1169,14 @@ async function pnpm() {
1159
1169
  }
1160
1170
 
1161
1171
  // src/configs/prettier.ts
1162
- import process from "process";
1172
+ import process2 from "process";
1163
1173
  import { isPackageExists as isPackageExists2 } from "local-pkg";
1164
1174
  async function prettier(options = {}) {
1165
- const { isInEditor: isInEditor2, overrides } = options;
1175
+ const { isInEditor, overrides } = options;
1166
1176
  return requireOf(
1167
1177
  ["eslint-config-prettier", "eslint-plugin-prettier", "prettier"],
1168
1178
  async () => {
1169
- process.env.ESLINT_CONFIG_PRETTIER_NO_DEPRECATED ??= "true";
1179
+ process2.env.ESLINT_CONFIG_PRETTIER_NO_DEPRECATED ??= "true";
1170
1180
  const [configPrettier, pluginPrettier, pluginJsonc, pluginYaml] = await Promise.all([
1171
1181
  interopDefault(import("eslint-config-prettier")),
1172
1182
  interopDefault(import("eslint-plugin-prettier")),
@@ -1180,7 +1190,7 @@ async function prettier(options = {}) {
1180
1190
  prettier: pluginPrettier
1181
1191
  },
1182
1192
  rules: {
1183
- "prettier/prettier": isInEditor2 ? "warn" : "error",
1193
+ "prettier/prettier": isInEditor ? "warn" : "error",
1184
1194
  ...configPrettier.rules,
1185
1195
  ...pluginJsonc?.configs.prettier.rules,
1186
1196
  "toml/array-bracket-newline": "off",
@@ -1742,7 +1752,7 @@ async function toml(options = {}) {
1742
1752
  }
1743
1753
 
1744
1754
  // src/configs/typescript.ts
1745
- import process2 from "process";
1755
+ import process3 from "process";
1746
1756
  var TypeAwareRules = {
1747
1757
  "@typescript-eslint/await-thenable": "error",
1748
1758
  "@typescript-eslint/dot-notation": ["error", { allowKeywords: true }],
@@ -1833,7 +1843,7 @@ async function typescript(options = {}) {
1833
1843
  allowDefaultProject: ["./*.js"],
1834
1844
  defaultProject: tsconfigPath
1835
1845
  },
1836
- tsconfigRootDir: process2.cwd()
1846
+ tsconfigRootDir: process3.cwd()
1837
1847
  } : {},
1838
1848
  ...parserOptions
1839
1849
  }
@@ -2037,7 +2047,7 @@ async function unicorn(options = {}) {
2037
2047
 
2038
2048
  // src/configs/vitest.ts
2039
2049
  async function vitest(options = {}) {
2040
- const { files = GLOB_TESTS, isInEditor: isInEditor2 = false, overrides = {}, tsconfigPath } = options;
2050
+ const { files = GLOB_TESTS, isInEditor = false, overrides = {}, tsconfigPath } = options;
2041
2051
  const isTypeAware = typeof tsconfigPath === "string" && tsconfigPath.trim().length > 0;
2042
2052
  return requireOf(
2043
2053
  ["@vitest/eslint-plugin"],
@@ -2065,7 +2075,7 @@ async function vitest(options = {}) {
2065
2075
  rules: {
2066
2076
  ...vitest2.configs?.recommended.rules ?? {},
2067
2077
  "vitest/consistent-test-it": ["error", { fn: "it", withinDescribe: "it" }],
2068
- "vitest/no-focused-tests": isInEditor2 ? "off" : ["error", { fixable: true }],
2078
+ "vitest/no-focused-tests": isInEditor ? "off" : ["error", { fixable: true }],
2069
2079
  "vitest/no-import-node-test": "error",
2070
2080
  "vitest/prefer-hooks-in-order": "error",
2071
2081
  "vitest/prefer-lowercase-title": "error",
@@ -2138,14 +2148,6 @@ async function yaml(options = {}) {
2138
2148
  ];
2139
2149
  }
2140
2150
 
2141
- // src/env.ts
2142
- import { env } from "process";
2143
- import isInCI from "is-in-ci";
2144
- var isInGitLifecycle = !!(typeof env.GIT_PARAMS === "string" && env.GIT_PARAMS.length > 0 || typeof env.VSCODE_GIT_COMMAND === "string" && env.VSCODE_GIT_COMMAND.length > 0 || env.npm_lifecycle_script?.startsWith("lint-staged") || env.npm_lifecycle_script?.startsWith("nano-staged"));
2145
- var isInEditor = !isInCI && !isInGitLifecycle && Boolean(
2146
- typeof env.VSCODE_PID === "string" && env.VSCODE_PID.length > 0 || typeof env.VSCODE_CWD === "string" && env.VSCODE_CWD.length > 0 || typeof env.JETBRAINS_IDE === "string" && env.JETBRAINS_IDE.length > 0 || typeof env.VIM === "string" && env.VIM.length > 0 || typeof env.NVIM === "string" && env.NVIM.length > 0
2147
- );
2148
-
2149
2151
  // src/define-config.ts
2150
2152
  var AllowedConfigPropertiesForOptions = [
2151
2153
  "name",
@@ -2174,11 +2176,15 @@ async function defineConfig(options = {}, ...userConfigs) {
2174
2176
  typescript: enableTypeScript = isPackageExists4("typescript"),
2175
2177
  unicorn: enableUnicorn = true
2176
2178
  } = options;
2177
- const isInEditor2 = options.isInEditor ?? isInEditor;
2178
- if (isInEditor2)
2179
- console.log(
2180
- "[@bfra.me/eslint-config] Editor specific config is enabled. Some rules may be disabled."
2181
- );
2179
+ let isInEditor = options.isInEditor;
2180
+ if (isInEditor == null) {
2181
+ isInEditor = isInEditorEnv();
2182
+ if (isInEditor) {
2183
+ console.log(
2184
+ "[@bfra.me/eslint-config] Editor specific config is enabled. Some rules may be disabled."
2185
+ );
2186
+ }
2187
+ }
2182
2188
  const stylisticOptions = options.stylistic === false || enablePrettier ? false : typeof options.stylistic === "object" ? options.stylistic : {};
2183
2189
  if (stylisticOptions && !("jsx" in stylisticOptions)) {
2184
2190
  stylisticOptions.jsx = typeof enableJsx === "object" ? true : enableJsx;
@@ -2189,7 +2195,7 @@ async function defineConfig(options = {}, ...userConfigs) {
2189
2195
  }
2190
2196
  configs.push(
2191
2197
  ignores(options.ignores),
2192
- javascript({ isInEditor: isInEditor2, jsx: enableJsx, overrides: getOverrides(options, "javascript") }),
2198
+ javascript({ isInEditor, jsx: enableJsx, overrides: getOverrides(options, "javascript") }),
2193
2199
  eslintComments(),
2194
2200
  node(),
2195
2201
  jsdoc({ stylistic: stylisticOptions }),
@@ -2202,7 +2208,7 @@ async function defineConfig(options = {}, ...userConfigs) {
2202
2208
  if (enablePerfectionist) {
2203
2209
  configs.push(
2204
2210
  perfectionist({
2205
- isInEditor: isInEditor2,
2211
+ isInEditor,
2206
2212
  overrides: getOverrides(options, "perfectionist"),
2207
2213
  ...resolveSubOptions(options, "perfectionist")
2208
2214
  })
@@ -2243,7 +2249,7 @@ async function defineConfig(options = {}, ...userConfigs) {
2243
2249
  if (options.vitest) {
2244
2250
  configs.push(
2245
2251
  vitest({
2246
- isInEditor: isInEditor2,
2252
+ isInEditor,
2247
2253
  overrides: getOverrides(options, "vitest"),
2248
2254
  tsconfigPath
2249
2255
  })
@@ -2312,7 +2318,7 @@ async function defineConfig(options = {}, ...userConfigs) {
2312
2318
  if (enablePrettier) {
2313
2319
  configs.push(
2314
2320
  prettier({
2315
- isInEditor: isInEditor2,
2321
+ isInEditor,
2316
2322
  overrides: getOverrides(options, "prettier")
2317
2323
  })
2318
2324
  );
@@ -2369,6 +2375,7 @@ export {
2369
2375
  GLOB_TS_CONFIG,
2370
2376
  GLOB_YAML,
2371
2377
  GLOB_YAML_FILES,
2378
+ StylisticConfigDefaults,
2372
2379
  astro,
2373
2380
  command,
2374
2381
  composeConfig,
@@ -2381,8 +2388,6 @@ export {
2381
2388
  gitignore,
2382
2389
  ignores,
2383
2390
  imports,
2384
- isInEditor,
2385
- isInGitLifecycle,
2386
2391
  javascript,
2387
2392
  jsdoc,
2388
2393
  jsonc,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bfra.me/eslint-config",
3
- "version": "0.44.0",
3
+ "version": "0.44.2",
4
4
  "description": "Shared ESLint configuration for bfra.me",
5
5
  "keywords": [
6
6
  "bfra.me",
@@ -2,12 +2,12 @@ import type {Config} from '../config'
2
2
  import type {Flatten, OptionsOverrides, StylisticConfig} from '../options'
3
3
  import {interopDefault} from '../utils'
4
4
 
5
- const StylisticConfigDefaults: StylisticConfig = {
5
+ export const StylisticConfigDefaults = {
6
6
  indent: 2,
7
7
  jsx: true,
8
8
  quotes: 'single',
9
9
  semi: false,
10
- }
10
+ } as const
11
11
 
12
12
  /**
13
13
  * Configuration options for stylistic ESLint rules.
@@ -32,7 +32,7 @@ import {
32
32
  vitest,
33
33
  yaml,
34
34
  } from './configs'
35
- import * as Env from './env'
35
+ import {isInEditorEnv} from './utils'
36
36
 
37
37
  // These are merged into the Options interface
38
38
  type AllowedConfigForOptions = Omit<Config, 'files'>
@@ -78,12 +78,16 @@ export async function defineConfig<C extends Config = Config, CN extends ConfigN
78
78
  unicorn: enableUnicorn = true,
79
79
  } = options
80
80
 
81
- const isInEditor = options.isInEditor ?? Env.isInEditor
82
- if (isInEditor)
83
- // eslint-disable-next-line no-console
84
- console.log(
85
- '[@bfra.me/eslint-config] Editor specific config is enabled. Some rules may be disabled.',
86
- )
81
+ let isInEditor = options.isInEditor
82
+ if (isInEditor == null) {
83
+ isInEditor = isInEditorEnv()
84
+ if (isInEditor) {
85
+ // eslint-disable-next-line no-console
86
+ console.log(
87
+ '[@bfra.me/eslint-config] Editor specific config is enabled. Some rules may be disabled.',
88
+ )
89
+ }
90
+ }
87
91
 
88
92
  const stylisticOptions =
89
93
  options.stylistic === false || enablePrettier
package/src/index.ts CHANGED
@@ -4,7 +4,6 @@ export * from './compose-config'
4
4
  export * from './config.d'
5
5
  export * from './configs'
6
6
  export * from './define-config'
7
- export * from './env'
8
7
  export * from './globs'
9
8
  export * from './options'
10
9
  export * from './rules.d'
package/src/require-of.ts CHANGED
@@ -1,14 +1,8 @@
1
1
  import type {Config} from './config'
2
- import {fileURLToPath} from 'node:url'
3
- import {isPackageExists} from 'local-pkg'
2
+ import {isPackageInScope} from './utils'
4
3
 
5
- const scopeUrl = fileURLToPath(new URL('.', import.meta.url))
6
4
  const packageExistsCache = new Map<string, boolean>()
7
5
 
8
- function isPackageInScope(name: string): boolean {
9
- return isPackageExists(name, {paths: [scopeUrl]})
10
- }
11
-
12
6
  const has = (name: string) => {
13
7
  if (!packageExistsCache.has(name)) {
14
8
  packageExistsCache.set(name, isPackageInScope(name))
package/src/utils.ts CHANGED
@@ -1,4 +1,10 @@
1
1
  import type {Awaitable} from 'eslint-flat-config-utils'
2
+ import process from 'node:process'
3
+ import {fileURLToPath} from 'node:url'
4
+ import isInCI from 'is-in-ci'
5
+ import {isPackageExists} from 'local-pkg'
6
+
7
+ const scopeUrl = fileURLToPath(new URL('.', import.meta.url))
2
8
 
3
9
  /* #__NO_SIDE_EFFECTS__ */
4
10
  export async function interopDefault<T>(
@@ -9,3 +15,55 @@ export async function interopDefault<T>(
9
15
  ? interopDefault(resolved.default as Awaitable<T>)
10
16
  : (resolved as T extends {default: infer U} ? U : T)
11
17
  }
18
+
19
+ export function isPackageInScope(name: string): boolean {
20
+ return isPackageExists(name, {paths: [scopeUrl]})
21
+ }
22
+
23
+ /**
24
+ * Check if the process is running in a Git hook or under lint-staged.
25
+ *
26
+ * @example
27
+ * ```ts
28
+ * import {isInGitLifecycle} from '@bfra.me/eslint-config'
29
+ *
30
+ * if (isInGitLifecycle) {
31
+ * console.log('Running in a Git hook or under lint-staged')
32
+ * }
33
+ * ```
34
+ */
35
+ export function isInGitLifecycle(): boolean {
36
+ return !!(
37
+ false ||
38
+ (typeof process.env.GIT_PARAMS === 'string' && process.env.GIT_PARAMS.length > 0) ||
39
+ (typeof process.env.VSCODE_GIT_COMMAND === 'string' &&
40
+ process.env.VSCODE_GIT_COMMAND.length > 0) ||
41
+ process.env.npm_lifecycle_script?.startsWith('lint-staged') ||
42
+ process.env.npm_lifecycle_script?.startsWith('nano-staged')
43
+ )
44
+ }
45
+
46
+ /**
47
+ * Check if the process is running in an editor.
48
+ *
49
+ * @example
50
+ * ```ts
51
+ * import {isInEditor} from '@bfra.me/eslint-config'
52
+ *
53
+ * if (isInEditor) {
54
+ * console.log('Running in an editor')
55
+ * }
56
+ */
57
+ export function isInEditorEnv(): boolean {
58
+ if (isInCI) return false
59
+ if (isInGitLifecycle()) return false
60
+
61
+ return !!(
62
+ false ||
63
+ (typeof process.env.VSCODE_PID === 'string' && process.env.VSCODE_PID.length > 0) ||
64
+ (typeof process.env.VSCODE_CWD === 'string' && process.env.VSCODE_CWD.length > 0) ||
65
+ (typeof process.env.JETBRAINS_IDE === 'string' && process.env.JETBRAINS_IDE.length > 0) ||
66
+ (typeof process.env.VIM === 'string' && process.env.VIM.length > 0) ||
67
+ (typeof process.env.NVIM === 'string' && process.env.NVIM.length > 0)
68
+ )
69
+ }
package/src/env.ts DELETED
@@ -1,43 +0,0 @@
1
- import {env} from 'node:process'
2
- import isInCI from 'is-in-ci'
3
-
4
- /**
5
- * Check if the process is running in a Git hook or under lint-staged.
6
- *
7
- * @example
8
- * ```ts
9
- * import {isInGitLifecycle} from '@bfra.me/eslint-config'
10
- *
11
- * if (isInGitLifecycle) {
12
- * console.log('Running in a Git hook or under lint-staged')
13
- * }
14
- * ```
15
- */
16
- export const isInGitLifecycle = !!(
17
- (typeof env.GIT_PARAMS === 'string' && env.GIT_PARAMS.length > 0) ||
18
- (typeof env.VSCODE_GIT_COMMAND === 'string' && env.VSCODE_GIT_COMMAND.length > 0) ||
19
- env.npm_lifecycle_script?.startsWith('lint-staged') ||
20
- env.npm_lifecycle_script?.startsWith('nano-staged')
21
- )
22
-
23
- /**
24
- * Check if the process is running in an editor.
25
- *
26
- * @example
27
- * ```ts
28
- * import {isInEditor} from '@bfra.me/eslint-config'
29
- *
30
- * if (isInEditor) {
31
- * console.log('Running in an editor')
32
- * }
33
- */
34
- export const isInEditor =
35
- !isInCI &&
36
- !isInGitLifecycle &&
37
- Boolean(
38
- (typeof env.VSCODE_PID === 'string' && env.VSCODE_PID.length > 0) ||
39
- (typeof env.VSCODE_CWD === 'string' && env.VSCODE_CWD.length > 0) ||
40
- (typeof env.JETBRAINS_IDE === 'string' && env.JETBRAINS_IDE.length > 0) ||
41
- (typeof env.VIM === 'string' && env.VIM.length > 0) ||
42
- (typeof env.NVIM === 'string' && env.NVIM.length > 0),
43
- )