MCPcopy Create free account
hub / github.com/thetarnav/solid-devtools / gitignore_to_glob_patterns

Function gitignore_to_glob_patterns

eslint.config.mjs:14–55  ·  view source on GitHub ↗

@param {string} gitignore @returns {string[]}

(gitignore)

Source from the content-addressed store, hash-verified

12@param {string} gitignore
13@returns {string[]} */
14function gitignore_to_glob_patterns(gitignore) {
15
16 const patterns = []
17
18 for (let pattern of gitignore.split('\n')) {
19
20 pattern = pattern.trim()
21
22 if (pattern === '' || pattern.startsWith('#')) {
23 continue
24 }
25
26 let negated = false
27 if (pattern[0] === '!') {
28 negated = true
29 pattern = pattern.slice(1)
30 }
31
32 if (pattern[0] === '/') {
33 pattern = pattern.slice(1)
34 } else if (!pattern.startsWith('**/')) {
35 pattern = '**/'+pattern
36 }
37
38 if (negated) {
39 pattern = '!'+pattern
40 }
41
42 if (pattern.indexOf('.') > 0) {
43 patterns.push(pattern)
44 } else {
45 patterns.push(pattern)
46 if (pattern.endsWith('/')) {
47 patterns.push(pattern+'**/*')
48 } else {
49 patterns.push(pattern+'/**/*')
50 }
51 }
52 }
53
54 return patterns
55}
56
57const git_ignored_paths = gitignore_to_glob_patterns(fs.readFileSync('.gitignore', 'utf-8'))
58

Callers 1

eslint.config.mjsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…