mirror of
https://github.com/sass/sass.git
synced 2024-09-21 02:27:30 +00:00
Improve the output of the ToC-check test. (#3488)
* Include the command for fixing the ToC * Print a patch rather than the entire ToC. * Always enable colors on CI.
This commit is contained in:
parent
6a21d2e470
commit
a082ecfbaa
@ -5,6 +5,8 @@ import * as glob from 'glob';
|
||||
import * as p from 'path';
|
||||
import * as prettier from 'prettier';
|
||||
|
||||
if (process.env.CI) colors.enable();
|
||||
|
||||
/**
|
||||
* A wrapper around the built-in TypeScript parser that removes all comments.
|
||||
*/
|
||||
|
@ -7,6 +7,8 @@ import markdownToc = require('markdown-toc');
|
||||
import * as path from 'path';
|
||||
import {fileURLToPath, pathToFileURL, URL} from 'url';
|
||||
|
||||
if (process.env.CI) colors.enable();
|
||||
|
||||
const files = glob.sync('**/*.md', {
|
||||
ignore: ['node_modules/**/*.md', 'js-api-doc/**/*.md'],
|
||||
});
|
||||
|
@ -4,29 +4,51 @@ import * as fs from 'fs';
|
||||
|
||||
import * as toc from '../tool/toc';
|
||||
|
||||
if (process.env.CI) colors.enable();
|
||||
|
||||
toc.files.forEach(file => {
|
||||
const markdown = fs.readFileSync(file).toString();
|
||||
console.log('Reading: ' + file);
|
||||
|
||||
const currentToc = toc.getCurrent(markdown);
|
||||
if (currentToc === null) {
|
||||
console.log(colors.yellow("File doesn't have a table of contents"));
|
||||
return;
|
||||
}
|
||||
if (currentToc === null) return;
|
||||
|
||||
const generatedToc = toc.generate(markdown);
|
||||
if (currentToc === generatedToc) return;
|
||||
|
||||
const tocDiff = diff.diffLines(currentToc, generatedToc);
|
||||
tocDiff.forEach(part => {
|
||||
const color = part.added
|
||||
? colors.green
|
||||
: part.removed
|
||||
? colors.red
|
||||
: colors.grey;
|
||||
process.stderr.write(color(part.value));
|
||||
});
|
||||
process.stderr.write('\n');
|
||||
console.error(colors.red(`${file}'s table of contents is incorrect:`));
|
||||
const patch = diff.structuredPatch(
|
||||
file,
|
||||
file,
|
||||
currentToc,
|
||||
generatedToc,
|
||||
'actual',
|
||||
'expected'
|
||||
);
|
||||
console.error(colors.red('--- actual'));
|
||||
console.error(colors.green('+++ expected'));
|
||||
for (const hunk of patch.hunks) {
|
||||
console.error(
|
||||
`@@ -${hunk.oldStart},-${hunk.oldLines} ` +
|
||||
`+${hunk.newStart},${hunk.newLines} @@`
|
||||
);
|
||||
for (const line of hunk.lines) {
|
||||
if (line.startsWith('+')) {
|
||||
console.error(colors.green(line));
|
||||
} else if (line.startsWith('-')) {
|
||||
console.error(colors.red(line));
|
||||
} else {
|
||||
console.error(colors.grey(line));
|
||||
}
|
||||
}
|
||||
}
|
||||
console.error();
|
||||
|
||||
process.exitCode = 1;
|
||||
});
|
||||
|
||||
if (process.exitCode === 1) {
|
||||
console.error(
|
||||
'To fix tables of contents, run ' +
|
||||
colors.blue('`npx ts-node tool/update-toc.ts`') +
|
||||
'.'
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user