@jsse/eslint-config 0.9.0 → 0.9.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/CHANGELOG.md +14 -0
- package/README.md +68 -21
- package/dist/cli.js +29 -30
- package/dist/dist-DS02OtwI.js +143 -0
- package/dist/{fixable-rules-map-CvRdO-mG.d.ts → fixable-rules-map-CCZ-PRHv.d.ts} +1073 -658
- package/dist/{fixable-rules-map-B2-5HybI.js → fixable-rules-map-dNndx2ig.js} +16 -0
- package/dist/fixable.d.ts +2 -2
- package/dist/fixable.js +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +851 -335
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +54 -54
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import process from "node:process";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path, { dirname, join, relative, resolve } from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
//#region node_modules/.pnpm/@eslint+compat@2.1.0_eslint@10.6.0_jiti@2.7.0_/node_modules/@eslint/compat/dist/esm/index.js
|
|
6
|
+
/**
|
|
7
|
+
* @fileoverview Ignore file utilities for the compat package.
|
|
8
|
+
* @author Nicholas C. Zakas
|
|
9
|
+
*/
|
|
10
|
+
/** @typedef {import("@eslint/core").ConfigObject} FlatConfig */
|
|
11
|
+
/**
|
|
12
|
+
* Converts an ESLint ignore pattern to a minimatch pattern.
|
|
13
|
+
* @param {string} pattern The .eslintignore or .gitignore pattern to convert.
|
|
14
|
+
* @returns {string} The converted pattern.
|
|
15
|
+
*
|
|
16
|
+
* @deprecated Use the `convertIgnorePatternToMinimatch()` function exported by
|
|
17
|
+
* `@eslint/config-helpers` instead.
|
|
18
|
+
*/
|
|
19
|
+
function convertIgnorePatternToMinimatch(pattern) {
|
|
20
|
+
const isNegated = pattern.startsWith("!");
|
|
21
|
+
const negatedPrefix = isNegated ? "!" : "";
|
|
22
|
+
const patternToTest = (isNegated ? pattern.slice(1) : pattern).trimEnd();
|
|
23
|
+
if ([
|
|
24
|
+
"",
|
|
25
|
+
"**",
|
|
26
|
+
"/**",
|
|
27
|
+
"**/"
|
|
28
|
+
].includes(patternToTest)) return `${negatedPrefix}${patternToTest}`;
|
|
29
|
+
const firstIndexOfSlash = patternToTest.indexOf("/");
|
|
30
|
+
return `${negatedPrefix}${firstIndexOfSlash < 0 || firstIndexOfSlash === patternToTest.length - 1 ? "**/" : ""}${(firstIndexOfSlash === 0 ? patternToTest.slice(1) : patternToTest).replaceAll(/(?=((?:\\.|[^{(])*))\1([{(])/guy, "$1\\$2")}${patternToTest.endsWith("/**") ? "/*" : ""}`;
|
|
31
|
+
}
|
|
32
|
+
//#endregion
|
|
33
|
+
//#region node_modules/.pnpm/eslint-config-flat-gitignore@2.3.0_eslint@10.6.0_jiti@2.7.0_/node_modules/eslint-config-flat-gitignore/dist/index.mjs
|
|
34
|
+
function toArray(array) {
|
|
35
|
+
array = array ?? [];
|
|
36
|
+
return Array.isArray(array) ? array : [array];
|
|
37
|
+
}
|
|
38
|
+
const toPath = (urlOrPath) => urlOrPath instanceof URL ? fileURLToPath(urlOrPath) : urlOrPath;
|
|
39
|
+
function findUpSync(name, { cwd = process.cwd(), type = "file", stopAt } = {}) {
|
|
40
|
+
let directory = path.resolve(toPath(cwd) ?? "");
|
|
41
|
+
const { root } = path.parse(directory);
|
|
42
|
+
stopAt = path.resolve(directory, toPath(stopAt) ?? root);
|
|
43
|
+
const isAbsoluteName = path.isAbsolute(name);
|
|
44
|
+
while (directory) {
|
|
45
|
+
const filePath = isAbsoluteName ? name : path.join(directory, name);
|
|
46
|
+
try {
|
|
47
|
+
const stats = fs.statSync(filePath, { throwIfNoEntry: false });
|
|
48
|
+
if (type === "file" && stats?.isFile() || type === "directory" && stats?.isDirectory()) return filePath;
|
|
49
|
+
} catch {}
|
|
50
|
+
if (directory === stopAt || directory === root) break;
|
|
51
|
+
directory = path.dirname(directory);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
const GITIGNORE = ".gitignore";
|
|
55
|
+
const GITMODULES = ".gitmodules";
|
|
56
|
+
const RE_NEWLINE = /\r?\n/u;
|
|
57
|
+
const RE_PARENT_PATH = /^(?:\.\.\/)+$/;
|
|
58
|
+
const RE_PATH_SEP = /[/\\]/;
|
|
59
|
+
const RE_SUBMODULE_PATH = /path\s*=\s*(.+)/u;
|
|
60
|
+
function ignore(options = {}) {
|
|
61
|
+
const ignores = [];
|
|
62
|
+
const { cwd = process.cwd(), root = false, recursive = false, files: _files = root ? GITIGNORE : findUpSync(GITIGNORE, { cwd }) || [], filesGitModules: _filesGitModules = root ? fs.existsSync(join(cwd, GITMODULES)) ? GITMODULES : [] : findUpSync(GITMODULES, { cwd }) || [], strict = true } = options;
|
|
63
|
+
const files = new Set(toArray(_files).map((file) => resolve(cwd, file)));
|
|
64
|
+
if (recursive) {
|
|
65
|
+
const additionalIgnoreDirs = typeof recursive === "boolean" ? [] : recursive.skipDirs;
|
|
66
|
+
for (const file of findNestedFiles(cwd, GITIGNORE, additionalIgnoreDirs)) files.add(file);
|
|
67
|
+
}
|
|
68
|
+
const filesList = [...files];
|
|
69
|
+
const filesGitModules = toArray(_filesGitModules).map((file) => resolve(cwd, file));
|
|
70
|
+
for (const file of filesList) {
|
|
71
|
+
let content = "";
|
|
72
|
+
try {
|
|
73
|
+
content = fs.readFileSync(file, "utf8");
|
|
74
|
+
} catch (error) {
|
|
75
|
+
if (strict) throw error;
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
const relativePath = relative(cwd, dirname(file)).replaceAll("\\", "/");
|
|
79
|
+
const globs = content.split(RE_NEWLINE).filter((line) => line && !line.startsWith("#")).map((line) => convertIgnorePatternToMinimatch(line)).map((glob) => relativeMinimatch(glob, relativePath, cwd)).filter((glob) => glob !== null);
|
|
80
|
+
ignores.push(...globs);
|
|
81
|
+
}
|
|
82
|
+
for (const file of filesGitModules) {
|
|
83
|
+
let content = "";
|
|
84
|
+
try {
|
|
85
|
+
content = fs.readFileSync(file, "utf8");
|
|
86
|
+
} catch (error) {
|
|
87
|
+
if (strict) throw error;
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
const dirs = parseGitSubmodules(content);
|
|
91
|
+
ignores.push(...dirs.map((dir) => `${dir}/**`));
|
|
92
|
+
}
|
|
93
|
+
if (strict && filesList.length === 0) throw new Error("No .gitignore file found");
|
|
94
|
+
return {
|
|
95
|
+
name: options.name || "gitignore",
|
|
96
|
+
ignores
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
function findNestedFiles(cwd, fileName, additionalIgnoreDirs) {
|
|
100
|
+
const files = [];
|
|
101
|
+
const directoriesToSkip = /* @__PURE__ */ new Set([
|
|
102
|
+
".git",
|
|
103
|
+
"node_modules",
|
|
104
|
+
...additionalIgnoreDirs
|
|
105
|
+
]);
|
|
106
|
+
const queue = [cwd];
|
|
107
|
+
while (queue.length) {
|
|
108
|
+
const directory = queue.shift();
|
|
109
|
+
const entries = fs.readdirSync(directory, { withFileTypes: true });
|
|
110
|
+
for (const entry of entries) {
|
|
111
|
+
const absolutePath = join(directory, entry.name);
|
|
112
|
+
if (entry.isFile() && entry.name === fileName) files.push(absolutePath);
|
|
113
|
+
if (entry.isDirectory() && !directoriesToSkip.has(entry.name)) queue.push(absolutePath);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return files;
|
|
117
|
+
}
|
|
118
|
+
function relativeMinimatch(pattern, relativePath, cwd) {
|
|
119
|
+
if ([
|
|
120
|
+
"",
|
|
121
|
+
".",
|
|
122
|
+
"/"
|
|
123
|
+
].includes(relativePath)) return pattern;
|
|
124
|
+
const negated = pattern.startsWith("!") ? "!" : "";
|
|
125
|
+
let cleanPattern = negated ? pattern.slice(1) : pattern;
|
|
126
|
+
if (!relativePath.endsWith("/")) relativePath = `${relativePath}/`;
|
|
127
|
+
if (!relativePath.startsWith("..")) return `${negated}${relativePath}${cleanPattern}`;
|
|
128
|
+
if (!RE_PARENT_PATH.test(relativePath)) throw new Error("The ignore file location should be either a parent or child directory");
|
|
129
|
+
if (cleanPattern.startsWith("**")) return pattern;
|
|
130
|
+
const parents = relative(resolve(cwd, relativePath), cwd).split(RE_PATH_SEP);
|
|
131
|
+
while (parents.length && cleanPattern.startsWith(`${parents[0]}/`)) {
|
|
132
|
+
cleanPattern = cleanPattern.slice(parents[0].length + 1);
|
|
133
|
+
parents.shift();
|
|
134
|
+
}
|
|
135
|
+
if (cleanPattern.startsWith("**")) return `${negated}${cleanPattern}`;
|
|
136
|
+
if (parents.length === 0) return `${negated}${cleanPattern}`;
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
function parseGitSubmodules(content) {
|
|
140
|
+
return content.split(RE_NEWLINE).map((line) => RE_SUBMODULE_PATH.exec(line)).filter((match) => match !== null).map((match) => match[1].trim());
|
|
141
|
+
}
|
|
142
|
+
//#endregion
|
|
143
|
+
export { ignore as default };
|