| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent ecccf48 commit 5daa313
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -29361,11 +29361,26 @@ const linter = unified() | |||
| 29361 | 29361 | ||
| 29362 | 29362 | paths.forEach(async (path) => { | |
| 29363 | 29363 | const file = await read(path); | |
| 29364 | + // We need to calculate `fileContents` before running `linter.process(files)` | ||
| 29365 | + // because `linter.process(files)` mutates `file` and returns it as `result`. | ||
| 29366 | + // So we won't be able to use `file` after that to see if its contents have | ||
| 29367 | + // changed as they will have been altered to the changed version. | ||
| 29368 | + const fileContents = file.toString(); | ||
| 29364 | 29369 | const result = await linter.process(file); | |
| 29370 | + const isDifferent = fileContents !== result.toString(); | ||
| 29365 | 29371 | if (format) { | |
| 29366 | - fs.writeFileSync(path, result.toString()); | ||
| 29367 | - } else if (result.messages.length) { | ||
| 29368 | - process.exitCode = 1; | ||
| 29369 | - console.error(reporter(result)); | ||
| 29372 | + if (isDifferent) { | ||
| 29373 | + fs.writeFileSync(path, result.toString()); | ||
| 29374 | + } | ||
| 29375 | + } else { | ||
| 29376 | + if (isDifferent) { | ||
| 29377 | + process.exitCode = 1; | ||
| 29378 | + const cmd = process.platform === 'win32' ? 'vcbuild' : 'make'; | ||
| 29379 | + console.error(`${path} is not formatted. Please run '${cmd} format-md'.`); | ||
| 29380 | + } | ||
| 29381 | + if (result.messages.length) { | ||
| 29382 | + process.exitCode = 1; | ||
| 29383 | + console.error(reporter(result)); | ||
| 29384 | + } | ||
| 29370 | 29385 | } | |
| 29371 | 29386 | }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -28,11 +28,26 @@ const linter = unified() | |||
| 28 | 28 | ||
| 29 | 29 | paths.forEach(async (path) => { | |
| 30 | 30 | const file = await read(path); | |
| 31 | + // We need to calculate `fileContents` before running `linter.process(files)` | ||
| 32 | + // because `linter.process(files)` mutates `file` and returns it as `result`. | ||
| 33 | + // So we won't be able to use `file` after that to see if its contents have | ||
| 34 | + // changed as they will have been altered to the changed version. | ||
| 35 | + const fileContents = file.toString(); | ||
| 31 | 36 | const result = await linter.process(file); | |
| 37 | + const isDifferent = fileContents !== result.toString(); | ||
| 32 | 38 | if (format) { | |
| 33 | - fs.writeFileSync(path, result.toString()); | ||
| 34 | - } else if (result.messages.length) { | ||
| 35 | - process.exitCode = 1; | ||
| 36 | - console.error(reporter(result)); | ||
| 39 | + if (isDifferent) { | ||
| 40 | + fs.writeFileSync(path, result.toString()); | ||
| 41 | + } | ||
| 42 | + } else { | ||
| 43 | + if (isDifferent) { | ||
| 44 | + process.exitCode = 1; | ||
| 45 | + const cmd = process.platform === 'win32' ? 'vcbuild' : 'make'; | ||
| 46 | + console.error(`${path} is not formatted. Please run '${cmd} format-md'.`); | ||
| 47 | + } | ||
| 48 | + if (result.messages.length) { | ||
| 49 | + process.exitCode = 1; | ||
| 50 | + console.error(reporter(result)); | ||
| 51 | + } | ||
| 37 | 52 | } | |
| 38 | 53 | }); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments