|
1 | 1 | import { fileExists } from '#common' |
2 | 2 | import type { Issues } from '#types' |
| 3 | +import fs from 'node:fs/promises' |
3 | 4 |
|
4 | 5 | export const skip = true |
5 | 6 |
|
6 | 7 | export const issues: Issues = async function* issues({ project }) { |
7 | 8 | const configFile = '.gitattributes' |
8 | 9 |
|
9 | | - // TODO |
10 | | - // let attributes = '' |
11 | | - // try { |
12 | | - // attributes = await fs.readFile(configFile, 'utf-8') |
13 | | - // } catch (err) { |
14 | | - // if (err.code !== 'ENOENT') { |
15 | | - // throw err |
16 | | - // } |
17 | | - // } |
18 | | - // |
19 | | - // const newAttributes = await minimalGitAttributes(attributes) |
20 | | - // |
21 | | - // if (newAttributes !== attributes) { |
22 | | - // yield { |
23 | | - // message: [`File "${configFile}" does not have the expected contents`], |
24 | | - // fix |
25 | | - // } |
26 | | - // } |
27 | | - // |
28 | | - // async function fix() { |
29 | | - // let attributes: string = '' |
30 | | - // try { |
31 | | - // attributes = await fs.readFile(configFile, 'utf-8') |
32 | | - // } catch (err) { |
33 | | - // if (err.code !== 'ENOENT') { |
34 | | - // throw err |
35 | | - // } |
36 | | - // } |
37 | | - // const newAttributes = await minimalGitAttributes(attributes) |
38 | | - // |
39 | | - // if (typeof newAttributes === 'string') { |
40 | | - // await fs.writeFile(configFile, newAttributes) |
41 | | - // } else { |
42 | | - // await fs.rm(configFile).catch((err) => { |
43 | | - // if (err.code === 'ENOENT') { |
44 | | - // return |
45 | | - // } |
46 | | - // throw err |
47 | | - // }) |
48 | | - // } |
49 | | - // } |
50 | | -} |
51 | | - |
52 | | -async function minimalGitAttributes(input: string) { |
53 | | - let content = input |
54 | | - content = content.replaceAll(/# foxxo /gu, '#section:fox-tools/fix ') |
55 | | - |
56 | | - if (!content.includes('#section:fox-tools/fix start')) { |
57 | | - content = `#section:fox-tools/fix start |
58 | | -#section:fox-tools/fix end\n` + content |
59 | | - } |
60 | | - |
61 | | - let newContent = '' |
62 | | - let canRemove = false |
63 | | - for (const line of content.split('\n')) { |
64 | | - if (line.startsWith('#section:fox-tools/fix start')) { |
65 | | - canRemove = true |
66 | | - newContent += line + '\n' |
67 | | - continue |
68 | | - } else if (line.startsWith('#section:fox-tools/fix end')) { |
69 | | - if ((await fileExists('bake')) && !content.includes('bake linguist-generated')) { |
70 | | - newContent += 'bake linguist-generated\n' |
71 | | - } |
72 | | - |
73 | | - canRemove = false |
74 | | - newContent += line + '\n' |
75 | | - continue |
| 10 | + let content = '' |
| 11 | + try { |
| 12 | + content = await fs.readFile(configFile, 'utf-8') |
| 13 | + } catch (err) { |
| 14 | + if (err.code !== 'ENOENT') { |
| 15 | + throw err |
76 | 16 | } |
| 17 | + } |
77 | 18 |
|
78 | | - if (canRemove) { |
79 | | - if (line.includes('text=auto') || line.includes('eol=lf')) { |
80 | | - continue |
81 | | - } |
82 | | - |
83 | | - if (line === 'bake linguist-generated') { |
84 | | - if (!(await fileExists('bake'))) { |
85 | | - continue |
86 | | - } |
| 19 | + const badStrings = ['# foxxo', '#section:fox-tools'] |
| 20 | + for (const string of badStrings) { |
| 21 | + if (content.includes(string)) { |
| 22 | + yield { |
| 23 | + message: [ |
| 24 | + `Expected to find no line that contains "${string}"`, |
| 25 | + ], |
87 | 26 | } |
88 | 27 | } |
89 | | - |
90 | | - newContent += line + '\n' |
91 | 28 | } |
92 | | - content = newContent |
93 | | - content = content.trimEnd() |
94 | | - content += '\n' |
95 | 29 |
|
96 | | - if ( |
97 | | - content === |
98 | | - `#section:fox-tools/fix start |
99 | | -#section:fox-tools/fix end |
100 | | -` |
101 | | - ) { |
102 | | - return null |
| 30 | + if (await fileExists('bake') && !content.includes('bake linguist-generated')) { |
| 31 | + yield { |
| 32 | + message: [ |
| 33 | + `Expected to find a line that contains "bake linguist-generated"`, |
| 34 | + `The file "bake" exists.`, |
| 35 | + ], |
| 36 | + } |
103 | 37 | } |
104 | | - |
105 | | - return content |
106 | 38 | } |
0 commit comments