@bfra.me/eslint-config 0.44.1 → 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 +1 -27
- package/lib/index.js +44 -37
- package/package.json +1 -1
- package/src/define-config.ts +14 -10
- package/src/index.ts +0 -1
- package/src/utils.ts +50 -0
- package/src/env.ts +0 -43
package/lib/index.d.ts
CHANGED
|
@@ -17416,32 +17416,6 @@ declare function defineConfig<C extends Config = Config, CN extends ConfigNames
|
|
|
17416
17416
|
*/
|
|
17417
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>;
|
|
17418
17418
|
|
|
17419
|
-
/**
|
|
17420
|
-
* Check if the process is running in a Git hook or under lint-staged.
|
|
17421
|
-
*
|
|
17422
|
-
* @example
|
|
17423
|
-
* ```ts
|
|
17424
|
-
* import {isInGitLifecycle} from '@bfra.me/eslint-config'
|
|
17425
|
-
*
|
|
17426
|
-
* if (isInGitLifecycle) {
|
|
17427
|
-
* console.log('Running in a Git hook or under lint-staged')
|
|
17428
|
-
* }
|
|
17429
|
-
* ```
|
|
17430
|
-
*/
|
|
17431
|
-
declare const isInGitLifecycle: boolean;
|
|
17432
|
-
/**
|
|
17433
|
-
* Check if the process is running in an editor.
|
|
17434
|
-
*
|
|
17435
|
-
* @example
|
|
17436
|
-
* ```ts
|
|
17437
|
-
* import {isInEditor} from '@bfra.me/eslint-config'
|
|
17438
|
-
*
|
|
17439
|
-
* if (isInEditor) {
|
|
17440
|
-
* console.log('Running in an editor')
|
|
17441
|
-
* }
|
|
17442
|
-
*/
|
|
17443
|
-
declare const isInEditor: boolean;
|
|
17444
|
-
|
|
17445
17419
|
declare const GLOB_SRC_EXT = "?([cm])[jt]s?(x)";
|
|
17446
17420
|
declare const GLOB_SRC = "**/*.?([cm])[jt]s?(x)";
|
|
17447
17421
|
declare const GLOB_JS = "**/*.?([cm])js";
|
|
@@ -17472,4 +17446,4 @@ declare const GLOB_EXCLUDE: string[];
|
|
|
17472
17446
|
|
|
17473
17447
|
declare const config: eslint_flat_config_utils.FlatConfigComposer<Config, ConfigNames>;
|
|
17474
17448
|
|
|
17475
|
-
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,
|
|
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
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
// src/define-config.ts
|
|
2
|
+
import { isPackageExists as isPackageExists4 } from "local-pkg";
|
|
3
|
+
|
|
1
4
|
// src/compose-config.ts
|
|
2
5
|
import { composer } from "eslint-flat-config-utils";
|
|
3
6
|
var composeConfig = (...configs) => composer(...configs);
|
|
@@ -109,7 +112,7 @@ var GLOB_EXCLUDE = [
|
|
|
109
112
|
import { fileURLToPath } from "url";
|
|
110
113
|
|
|
111
114
|
// package.json
|
|
112
|
-
var version = "0.44.
|
|
115
|
+
var version = "0.44.2";
|
|
113
116
|
|
|
114
117
|
// src/parsers/any-parser.ts
|
|
115
118
|
var lineBreakPattern = /\r\n|[\n\r\u2028\u2029]/u;
|
|
@@ -143,7 +146,9 @@ function parseForESLint(text) {
|
|
|
143
146
|
var anyParser = { meta, parseForESLint };
|
|
144
147
|
|
|
145
148
|
// src/utils.ts
|
|
149
|
+
import process from "process";
|
|
146
150
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
151
|
+
import isInCI from "is-in-ci";
|
|
147
152
|
import { isPackageExists } from "local-pkg";
|
|
148
153
|
var scopeUrl = fileURLToPath2(new URL(".", import.meta.url));
|
|
149
154
|
// @__NO_SIDE_EFFECTS__
|
|
@@ -154,6 +159,14 @@ async function interopDefault(m) {
|
|
|
154
159
|
function isPackageInScope(name) {
|
|
155
160
|
return isPackageExists(name, { paths: [scopeUrl] });
|
|
156
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
|
+
}
|
|
157
170
|
|
|
158
171
|
// src/require-of.ts
|
|
159
172
|
var packageExistsCache = /* @__PURE__ */ new Map();
|
|
@@ -384,7 +397,7 @@ function imports(options = {}) {
|
|
|
384
397
|
// src/configs/javascript.ts
|
|
385
398
|
import globals from "globals";
|
|
386
399
|
async function javascript(options = {}) {
|
|
387
|
-
const { isInEditor
|
|
400
|
+
const { isInEditor = false, jsx = true, overrides = {} } = options;
|
|
388
401
|
const pluginUnusedImports = await interopDefault(import("eslint-plugin-unused-imports"));
|
|
389
402
|
return [
|
|
390
403
|
{
|
|
@@ -573,7 +586,7 @@ async function javascript(options = {}) {
|
|
|
573
586
|
"prefer-template": "error",
|
|
574
587
|
"symbol-description": "error",
|
|
575
588
|
"unicode-bom": ["error", "never"],
|
|
576
|
-
"unused-imports/no-unused-imports":
|
|
589
|
+
"unused-imports/no-unused-imports": isInEditor ? "off" : "error",
|
|
577
590
|
"unused-imports/no-unused-vars": [
|
|
578
591
|
"error",
|
|
579
592
|
{
|
|
@@ -1056,7 +1069,7 @@ async function packageJson(options = {}) {
|
|
|
1056
1069
|
// src/configs/perfectionist.ts
|
|
1057
1070
|
async function perfectionist(options = {}) {
|
|
1058
1071
|
const {
|
|
1059
|
-
isInEditor
|
|
1072
|
+
isInEditor = false,
|
|
1060
1073
|
overrides = {},
|
|
1061
1074
|
sortExports = true,
|
|
1062
1075
|
sortImports = true,
|
|
@@ -1073,22 +1086,22 @@ async function perfectionist(options = {}) {
|
|
|
1073
1086
|
rules: {
|
|
1074
1087
|
...sortNamedExports && {
|
|
1075
1088
|
"perfectionist/sort-named-exports": [
|
|
1076
|
-
|
|
1089
|
+
isInEditor ? "warn" : "error",
|
|
1077
1090
|
{ groupKind: "values-first", type: "natural" }
|
|
1078
1091
|
]
|
|
1079
1092
|
},
|
|
1080
1093
|
...sortNamedImports && {
|
|
1081
1094
|
"perfectionist/sort-named-imports": [
|
|
1082
|
-
|
|
1095
|
+
isInEditor ? "warn" : "error",
|
|
1083
1096
|
{ groupKind: "values-first", type: "natural" }
|
|
1084
1097
|
]
|
|
1085
1098
|
},
|
|
1086
1099
|
...sortExports && {
|
|
1087
|
-
"perfectionist/sort-exports": [
|
|
1100
|
+
"perfectionist/sort-exports": [isInEditor ? "warn" : "error", { type: "natural" }]
|
|
1088
1101
|
},
|
|
1089
1102
|
...sortImports && {
|
|
1090
1103
|
"perfectionist/sort-imports": [
|
|
1091
|
-
|
|
1104
|
+
isInEditor ? "warn" : "error",
|
|
1092
1105
|
{
|
|
1093
1106
|
groups: [
|
|
1094
1107
|
"type",
|
|
@@ -1156,14 +1169,14 @@ async function pnpm() {
|
|
|
1156
1169
|
}
|
|
1157
1170
|
|
|
1158
1171
|
// src/configs/prettier.ts
|
|
1159
|
-
import
|
|
1172
|
+
import process2 from "process";
|
|
1160
1173
|
import { isPackageExists as isPackageExists2 } from "local-pkg";
|
|
1161
1174
|
async function prettier(options = {}) {
|
|
1162
|
-
const { isInEditor
|
|
1175
|
+
const { isInEditor, overrides } = options;
|
|
1163
1176
|
return requireOf(
|
|
1164
1177
|
["eslint-config-prettier", "eslint-plugin-prettier", "prettier"],
|
|
1165
1178
|
async () => {
|
|
1166
|
-
|
|
1179
|
+
process2.env.ESLINT_CONFIG_PRETTIER_NO_DEPRECATED ??= "true";
|
|
1167
1180
|
const [configPrettier, pluginPrettier, pluginJsonc, pluginYaml] = await Promise.all([
|
|
1168
1181
|
interopDefault(import("eslint-config-prettier")),
|
|
1169
1182
|
interopDefault(import("eslint-plugin-prettier")),
|
|
@@ -1177,7 +1190,7 @@ async function prettier(options = {}) {
|
|
|
1177
1190
|
prettier: pluginPrettier
|
|
1178
1191
|
},
|
|
1179
1192
|
rules: {
|
|
1180
|
-
"prettier/prettier":
|
|
1193
|
+
"prettier/prettier": isInEditor ? "warn" : "error",
|
|
1181
1194
|
...configPrettier.rules,
|
|
1182
1195
|
...pluginJsonc?.configs.prettier.rules,
|
|
1183
1196
|
"toml/array-bracket-newline": "off",
|
|
@@ -1739,7 +1752,7 @@ async function toml(options = {}) {
|
|
|
1739
1752
|
}
|
|
1740
1753
|
|
|
1741
1754
|
// src/configs/typescript.ts
|
|
1742
|
-
import
|
|
1755
|
+
import process3 from "process";
|
|
1743
1756
|
var TypeAwareRules = {
|
|
1744
1757
|
"@typescript-eslint/await-thenable": "error",
|
|
1745
1758
|
"@typescript-eslint/dot-notation": ["error", { allowKeywords: true }],
|
|
@@ -1830,7 +1843,7 @@ async function typescript(options = {}) {
|
|
|
1830
1843
|
allowDefaultProject: ["./*.js"],
|
|
1831
1844
|
defaultProject: tsconfigPath
|
|
1832
1845
|
},
|
|
1833
|
-
tsconfigRootDir:
|
|
1846
|
+
tsconfigRootDir: process3.cwd()
|
|
1834
1847
|
} : {},
|
|
1835
1848
|
...parserOptions
|
|
1836
1849
|
}
|
|
@@ -2034,7 +2047,7 @@ async function unicorn(options = {}) {
|
|
|
2034
2047
|
|
|
2035
2048
|
// src/configs/vitest.ts
|
|
2036
2049
|
async function vitest(options = {}) {
|
|
2037
|
-
const { files = GLOB_TESTS, isInEditor
|
|
2050
|
+
const { files = GLOB_TESTS, isInEditor = false, overrides = {}, tsconfigPath } = options;
|
|
2038
2051
|
const isTypeAware = typeof tsconfigPath === "string" && tsconfigPath.trim().length > 0;
|
|
2039
2052
|
return requireOf(
|
|
2040
2053
|
["@vitest/eslint-plugin"],
|
|
@@ -2062,7 +2075,7 @@ async function vitest(options = {}) {
|
|
|
2062
2075
|
rules: {
|
|
2063
2076
|
...vitest2.configs?.recommended.rules ?? {},
|
|
2064
2077
|
"vitest/consistent-test-it": ["error", { fn: "it", withinDescribe: "it" }],
|
|
2065
|
-
"vitest/no-focused-tests":
|
|
2078
|
+
"vitest/no-focused-tests": isInEditor ? "off" : ["error", { fixable: true }],
|
|
2066
2079
|
"vitest/no-import-node-test": "error",
|
|
2067
2080
|
"vitest/prefer-hooks-in-order": "error",
|
|
2068
2081
|
"vitest/prefer-lowercase-title": "error",
|
|
@@ -2135,14 +2148,6 @@ async function yaml(options = {}) {
|
|
|
2135
2148
|
];
|
|
2136
2149
|
}
|
|
2137
2150
|
|
|
2138
|
-
// src/env.ts
|
|
2139
|
-
import { env } from "process";
|
|
2140
|
-
import isInCI from "is-in-ci";
|
|
2141
|
-
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"));
|
|
2142
|
-
var isInEditor = !isInCI && !isInGitLifecycle && Boolean(
|
|
2143
|
-
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
|
|
2144
|
-
);
|
|
2145
|
-
|
|
2146
2151
|
// src/define-config.ts
|
|
2147
2152
|
var AllowedConfigPropertiesForOptions = [
|
|
2148
2153
|
"name",
|
|
@@ -2165,17 +2170,21 @@ async function defineConfig(options = {}, ...userConfigs) {
|
|
|
2165
2170
|
packageJson: enablePackageJson = false,
|
|
2166
2171
|
perfectionist: enablePerfectionist = true,
|
|
2167
2172
|
pnpm: enableCatalogs = false,
|
|
2168
|
-
prettier: enablePrettier =
|
|
2173
|
+
prettier: enablePrettier = isPackageExists4("prettier"),
|
|
2169
2174
|
react: enableReact = false,
|
|
2170
2175
|
regexp: enableRegexp = true,
|
|
2171
|
-
typescript: enableTypeScript =
|
|
2176
|
+
typescript: enableTypeScript = isPackageExists4("typescript"),
|
|
2172
2177
|
unicorn: enableUnicorn = true
|
|
2173
2178
|
} = options;
|
|
2174
|
-
|
|
2175
|
-
if (
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
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
|
+
}
|
|
2179
2188
|
const stylisticOptions = options.stylistic === false || enablePrettier ? false : typeof options.stylistic === "object" ? options.stylistic : {};
|
|
2180
2189
|
if (stylisticOptions && !("jsx" in stylisticOptions)) {
|
|
2181
2190
|
stylisticOptions.jsx = typeof enableJsx === "object" ? true : enableJsx;
|
|
@@ -2186,7 +2195,7 @@ async function defineConfig(options = {}, ...userConfigs) {
|
|
|
2186
2195
|
}
|
|
2187
2196
|
configs.push(
|
|
2188
2197
|
ignores(options.ignores),
|
|
2189
|
-
javascript({ isInEditor
|
|
2198
|
+
javascript({ isInEditor, jsx: enableJsx, overrides: getOverrides(options, "javascript") }),
|
|
2190
2199
|
eslintComments(),
|
|
2191
2200
|
node(),
|
|
2192
2201
|
jsdoc({ stylistic: stylisticOptions }),
|
|
@@ -2199,7 +2208,7 @@ async function defineConfig(options = {}, ...userConfigs) {
|
|
|
2199
2208
|
if (enablePerfectionist) {
|
|
2200
2209
|
configs.push(
|
|
2201
2210
|
perfectionist({
|
|
2202
|
-
isInEditor
|
|
2211
|
+
isInEditor,
|
|
2203
2212
|
overrides: getOverrides(options, "perfectionist"),
|
|
2204
2213
|
...resolveSubOptions(options, "perfectionist")
|
|
2205
2214
|
})
|
|
@@ -2240,7 +2249,7 @@ async function defineConfig(options = {}, ...userConfigs) {
|
|
|
2240
2249
|
if (options.vitest) {
|
|
2241
2250
|
configs.push(
|
|
2242
2251
|
vitest({
|
|
2243
|
-
isInEditor
|
|
2252
|
+
isInEditor,
|
|
2244
2253
|
overrides: getOverrides(options, "vitest"),
|
|
2245
2254
|
tsconfigPath
|
|
2246
2255
|
})
|
|
@@ -2309,7 +2318,7 @@ async function defineConfig(options = {}, ...userConfigs) {
|
|
|
2309
2318
|
if (enablePrettier) {
|
|
2310
2319
|
configs.push(
|
|
2311
2320
|
prettier({
|
|
2312
|
-
isInEditor
|
|
2321
|
+
isInEditor,
|
|
2313
2322
|
overrides: getOverrides(options, "prettier")
|
|
2314
2323
|
})
|
|
2315
2324
|
);
|
|
@@ -2379,8 +2388,6 @@ export {
|
|
|
2379
2388
|
gitignore,
|
|
2380
2389
|
ignores,
|
|
2381
2390
|
imports,
|
|
2382
|
-
isInEditor,
|
|
2383
|
-
isInGitLifecycle,
|
|
2384
2391
|
javascript,
|
|
2385
2392
|
jsdoc,
|
|
2386
2393
|
jsonc,
|
package/package.json
CHANGED
package/src/define-config.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type {Config, ConfigNames, FlatConfigComposer, ResolvableFlatConfig} from './config'
|
|
2
2
|
import type {Options} from './options'
|
|
3
|
+
import {isPackageExists} from 'local-pkg'
|
|
3
4
|
import {composeConfig} from './compose-config'
|
|
4
5
|
import {
|
|
5
6
|
astro,
|
|
@@ -31,8 +32,7 @@ import {
|
|
|
31
32
|
vitest,
|
|
32
33
|
yaml,
|
|
33
34
|
} from './configs'
|
|
34
|
-
import
|
|
35
|
-
import {isPackageInScope} from './utils'
|
|
35
|
+
import {isInEditorEnv} from './utils'
|
|
36
36
|
|
|
37
37
|
// These are merged into the Options interface
|
|
38
38
|
type AllowedConfigForOptions = Omit<Config, 'files'>
|
|
@@ -71,19 +71,23 @@ export async function defineConfig<C extends Config = Config, CN extends ConfigN
|
|
|
71
71
|
packageJson: enablePackageJson = false,
|
|
72
72
|
perfectionist: enablePerfectionist = true,
|
|
73
73
|
pnpm: enableCatalogs = false,
|
|
74
|
-
prettier: enablePrettier =
|
|
74
|
+
prettier: enablePrettier = isPackageExists('prettier'),
|
|
75
75
|
react: enableReact = false,
|
|
76
76
|
regexp: enableRegexp = true,
|
|
77
|
-
typescript: enableTypeScript =
|
|
77
|
+
typescript: enableTypeScript = isPackageExists('typescript'),
|
|
78
78
|
unicorn: enableUnicorn = true,
|
|
79
79
|
} = options
|
|
80
80
|
|
|
81
|
-
|
|
82
|
-
if (isInEditor)
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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
package/src/utils.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type {Awaitable} from 'eslint-flat-config-utils'
|
|
2
|
+
import process from 'node:process'
|
|
2
3
|
import {fileURLToPath} from 'node:url'
|
|
4
|
+
import isInCI from 'is-in-ci'
|
|
3
5
|
import {isPackageExists} from 'local-pkg'
|
|
4
6
|
|
|
5
7
|
const scopeUrl = fileURLToPath(new URL('.', import.meta.url))
|
|
@@ -17,3 +19,51 @@ export async function interopDefault<T>(
|
|
|
17
19
|
export function isPackageInScope(name: string): boolean {
|
|
18
20
|
return isPackageExists(name, {paths: [scopeUrl]})
|
|
19
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
|
-
)
|